示例#1
0
def test_security_SD ():
  hFile = handle (TEST_FILE)
  try:
    sa = win32security.GetSecurityInfo (hFile, win32security.SE_FILE_OBJECT, OPTIONS)
    assert equal (sa, security.security (sa, options=OPTIONS))
  finally:
    hFile.Close ()
示例#2
0
 def test_Security_set_sacl_none(self):
     s = security.security()
     s.sacl = None
     assert s.pyobject().GetSecurityDescriptorSacl() is None
     sd = win32security.SECURITY_DESCRIPTOR()
     sd.SetSecurityDescriptorSacl(1, None, 0)
     assert equal(sd, s)
示例#3
0
def test_Security_set_sacl_none ():
  s = security.security ()
  s.sacl = None
  assert s.pyobject ().GetSecurityDescriptorSacl () is None
  sd = win32security.SECURITY_DESCRIPTOR ()
  sd.SetSecurityDescriptorSacl (1, None, 0)
  assert equal (sd, s)  
示例#4
0
def test_Security_set_owner ():
  administrator = security.principal ("Administrator")
  s = security.security ()
  s.owner = "Administrator"
  assert s.owner == administrator
  sd = win32security.SECURITY_DESCRIPTOR ()
  sd.SetSecurityDescriptorOwner (administrator.pyobject (), 0)
  assert equal (sd, s)
示例#5
0
def test_Security_set_group ():
  everyone = security.principal ("Everyone")
  s = security.security ()
  s.group = "Everyone"
  assert s.group == everyone
  sd = win32security.SECURITY_DESCRIPTOR ()
  sd.SetSecurityDescriptorGroup (everyone.pyobject (), 0)
  assert equal (sd, s)
示例#6
0
def test_security_SD():
    hFile = handle(TEST_FILE)
    try:
        sa = win32security.GetSecurityInfo(hFile, win32security.SE_FILE_OBJECT,
                                           OPTIONS)
        assert equal(sa, security.security(sa, options=OPTIONS))
    finally:
        hFile.Close()
示例#7
0
 def test_Security_set_owner(self):
     administrator = security.principal("Administrator")
     s = security.security()
     s.owner = "Administrator"
     assert s.owner == administrator
     sd = win32security.SECURITY_DESCRIPTOR()
     sd.SetSecurityDescriptorOwner(administrator.pyobject(), 0)
     assert equal(sd, s)
示例#8
0
 def test_Security_set_group(self):
     everyone = security.principal("Everyone")
     s = security.security()
     s.group = "Everyone"
     assert s.group == everyone
     sd = win32security.SECURITY_DESCRIPTOR()
     sd.SetSecurityDescriptorGroup(everyone.pyobject(), 0)
     assert equal(sd, s)
示例#9
0
def test_security_string_event ():
  hEvent = win32event.CreateEvent (None, 0, 0, GUID)
  try:
    assert equal (
      win32security.GetNamedSecurityInfo (GUID, win32security.SE_KERNEL_OBJECT, OPTIONS),
      security.security (GUID, security.SE_OBJECT_TYPE.KERNEL_OBJECT, options=OPTIONS)
    )
  finally:
    hEvent.Close ()
示例#10
0
def test_security_HANDLE_no_type ():
  hFile = handle (TEST_FILE)
  try:
    assert equal (
      win32security.GetSecurityInfo (hFile, win32security.SE_FILE_OBJECT, OPTIONS),
      security.security (hFile, options=OPTIONS)
    )
  finally:
    hFile.Close ()
示例#11
0
def test_Security_set_sacl_empty ():
  s = security.security ()
  s.sacl = []
  assert len (s.sacl) == 0
  assert s.pyobject ().GetSecurityDescriptorSacl ().GetAceCount () == 0
  sd = win32security.SECURITY_DESCRIPTOR ()
  acl = win32security.ACL ()
  sd.SetSecurityDescriptorSacl (1, acl, 0)
  assert equal (sd, s)
示例#12
0
def test_Security_break_sacl_inheritance_no_copy ():
  s = security.security (TEST_FILE, options=OPTIONS)
  assert s.sacl.inherited
  s.break_inheritance (copy_first=False, break_dacl=False, break_sacl=True)
  s.to_object ()
  sd = win32security.GetNamedSecurityInfo (TEST_FILE, win32security.SE_FILE_OBJECT, OPTIONS)
  assert (sd.GetSecurityDescriptorControl ()[0] & win32security.SE_SACL_PROTECTED)
  assert (not sd.GetSecurityDescriptorControl ()[0] & win32security.SE_DACL_PROTECTED)
  assert sd.GetSecurityDescriptorSacl ().GetAceCount () == 0
示例#13
0
 def test_Security_set_sacl_empty(self):
     s = security.security()
     s.sacl = []
     assert len(s.sacl) == 0
     assert s.pyobject().GetSecurityDescriptorSacl().GetAceCount() == 0
     sd = win32security.SECURITY_DESCRIPTOR()
     acl = win32security.ACL()
     sd.SetSecurityDescriptorSacl(1, acl, 0)
     assert equal(sd, s)
示例#14
0
def test_security_HANDLE_no_type():
    hFile = handle(TEST_FILE)
    try:
        assert equal(
            win32security.GetSecurityInfo(hFile, win32security.SE_FILE_OBJECT,
                                          OPTIONS),
            security.security(hFile, options=OPTIONS))
    finally:
        hFile.Close()
示例#15
0
 def test_security_HANDLE_file_type(self):
     with self.test_file() as TEST_FILE:
         hFile = handle(TEST_FILE)
         try:
             assert equal(
                 win32security.GetSecurityInfo(hFile, win32security.SE_FILE_OBJECT, OPTIONS),
                 security.security(hFile, security.SE_OBJECT_TYPE.FILE_OBJECT, options=OPTIONS)
             )
         finally:
             hFile.Close()
示例#16
0
 def test_security_string_event(self):
     hEvent = win32event.CreateEvent(None, 0, 0, self.GUID)
     try:
         assert equal(
             win32security.GetNamedSecurityInfo(
                 self.GUID, win32security.SE_KERNEL_OBJECT, OPTIONS),
             security.security(self.GUID,
                               security.SE_OBJECT_TYPE.KERNEL_OBJECT,
                               options=OPTIONS))
     finally:
         hEvent.Close()
示例#17
0
 def test_Security_break_dacl_inheritance_copy(self):
     with self.test_file() as TEST_FILE:
         s = security.security(TEST_FILE, options=OPTIONS)
         n_aces = len(s.dacl)
         assert s.dacl.inherited
         s.break_inheritance(copy_first=True, break_dacl=True, break_sacl=False)
         s.to_object()
         sd = win32security.GetNamedSecurityInfo(TEST_FILE, win32security.SE_FILE_OBJECT, OPTIONS)
         assert(sd.GetSecurityDescriptorControl()[0] & win32security.SE_DACL_PROTECTED)
         assert(not sd.GetSecurityDescriptorControl()[0] & win32security.SE_SACL_PROTECTED)
         assert sd.GetSecurityDescriptorDacl().GetAceCount() == n_aces
示例#18
0
def test_Security_add_to_dacl_simple():
    administrator = security.principal("Administrator")
    s = security.security()
    s.dacl = []
    s.dacl.append(("Administrator", "F", "ALLOW"))
    sd = win32security.SECURITY_DESCRIPTOR()
    dacl = win32security.ACL()
    dacl.AddAccessAllowedAceEx(win32security.ACL_REVISION_DS,
                               security.DACE.FLAGS, ntsecuritycon.GENERIC_ALL,
                               administrator.pyobject())
    sd.SetSecurityDescriptorDacl(1, dacl, 0)
    assert equal(sd, s)
示例#19
0
def test_Security_add_to_sacl_simple():
    administrator = security.principal("Administrator")
    s = security.security()
    s.sacl = []
    s.sacl.append(("Administrator", "F", "SUCCESS"))
    sd = win32security.SECURITY_DESCRIPTOR()
    sacl = win32security.ACL()
    sacl.AddAuditAccessAceEx(win32security.ACL_REVISION_DS,
                             security.SACE.FLAGS, ntsecuritycon.GENERIC_ALL,
                             administrator.pyobject(), 1, 0)
    sd.SetSecurityDescriptorSacl(1, sacl, 0)
    assert equal(sd, s)
示例#20
0
def test_Security_break_dacl_inheritance_no_copy ():
  filepath = test_file ()
  print "AceCount before", win32security.GetNamedSecurityInfo (filepath, win32security.SE_FILE_OBJECT, OPTIONS).GetSecurityDescriptorDacl ().GetAceCount ()
  s = security.security (filepath, options=OPTIONS)
  assert s.dacl.inherited
  s.break_inheritance (copy_first=False, break_dacl=True, break_sacl=False)
  print "dacl", s.dacl.dumped ()
  s.to_object ()
  sd = win32security.GetNamedSecurityInfo (filepath, win32security.SE_FILE_OBJECT, OPTIONS)
  print "AceCount", sd.GetSecurityDescriptorDacl ().GetAceCount ()
  assert (sd.GetSecurityDescriptorControl ()[0] & win32security.SE_DACL_PROTECTED)
  assert (not sd.GetSecurityDescriptorControl ()[0] & win32security.SE_SACL_PROTECTED)
  assert sd.GetSecurityDescriptorDacl ().GetAceCount () == 0
示例#21
0
def test_Security_break_sacl_inheritance_no_copy():
    s = security.security(TEST_FILE, options=OPTIONS)
    assert s.sacl.inherited
    s.break_inheritance(copy_first=False, break_dacl=False, break_sacl=True)
    s.to_object()
    sd = win32security.GetNamedSecurityInfo(TEST_FILE,
                                            win32security.SE_FILE_OBJECT,
                                            OPTIONS)
    assert (sd.GetSecurityDescriptorControl()[0]
            & win32security.SE_SACL_PROTECTED)
    assert (not sd.GetSecurityDescriptorControl()[0]
            & win32security.SE_DACL_PROTECTED)
    assert sd.GetSecurityDescriptorSacl().GetAceCount() == 0
示例#22
0
 def test_security_HANDLE_file_type(self):
     with self.test_file() as TEST_FILE:
         hFile = handle(TEST_FILE)
         try:
             assert equal(
                 win32security.GetSecurityInfo(hFile,
                                               win32security.SE_FILE_OBJECT,
                                               OPTIONS),
                 security.security(hFile,
                                   security.SE_OBJECT_TYPE.FILE_OBJECT,
                                   options=OPTIONS))
         finally:
             hFile.Close()
示例#23
0
 def test_Security_break_dacl_inheritance_no_copy(self):
     with self.test_file() as filepath:
         s = security.security(filepath, options=OPTIONS)
         assert s.dacl.inherited
         s.break_inheritance(copy_first=False,
                             break_dacl=True,
                             break_sacl=False)
         s.to_object()
         sd = win32security.GetNamedSecurityInfo(
             filepath, win32security.SE_FILE_OBJECT, OPTIONS)
         assert (sd.GetSecurityDescriptorControl()[0]
                 & win32security.SE_DACL_PROTECTED)
         assert (not sd.GetSecurityDescriptorControl()[0]
                 & win32security.SE_SACL_PROTECTED)
         assert sd.GetSecurityDescriptorDacl().GetAceCount() == 0
示例#24
0
def test_Security_add_to_dacl_simple ():
  administrator = security.principal ("Administrator")
  s = security.security ()
  s.dacl = []
  s.dacl.append (("Administrator", "F", "ALLOW"))
  sd = win32security.SECURITY_DESCRIPTOR ()
  dacl = win32security.ACL ()
  dacl.AddAccessAllowedAceEx (
    win32security.ACL_REVISION_DS, 
    security.DACE.FLAGS,
    ntsecuritycon.GENERIC_ALL, 
    administrator.pyobject ()
  )
  sd.SetSecurityDescriptorDacl (1, dacl, 0)
  assert equal (sd, s)
示例#25
0
 def test_Security_break_dacl_inheritance_no_copy(self):
     #
     # This is currently failing because, within the test folder,
     # the file created doesn't have inherited ACEs at the point
     # at which the inheritance is broken. Since unherited ACEs are
     # copied regardless, the test fails.
     #
     with self.test_file() as filepath:
         s = security.security(filepath, options=OPTIONS)
         assert s.dacl.inherited
         s.break_inheritance(copy_first=False, break_dacl=True, break_sacl=False)
         s.to_object()
         sd = win32security.GetNamedSecurityInfo(filepath, win32security.SE_FILE_OBJECT, OPTIONS)
         self.assertTrue(sd.GetSecurityDescriptorControl()[0] & win32security.SE_DACL_PROTECTED)
         self.assertTrue(not sd.GetSecurityDescriptorControl()[0] & win32security.SE_SACL_PROTECTED)
         self.assertEqual(sd.GetSecurityDescriptorDacl().GetAceCount(), 0)
示例#26
0
def test_Security_add_to_sacl_simple ():
  administrator = security.principal ("Administrator")
  s = security.security ()
  s.sacl = []
  s.sacl.append (("Administrator", "F", "SUCCESS"))
  sd = win32security.SECURITY_DESCRIPTOR ()
  sacl = win32security.ACL ()
  sacl.AddAuditAccessAceEx (
    win32security.ACL_REVISION_DS, 
    security.SACE.FLAGS,
    ntsecuritycon.GENERIC_ALL,
    administrator.pyobject (),
    1, 0
  )
  sd.SetSecurityDescriptorSacl (1, sacl, 0)
  assert equal (sd, s)
示例#27
0
 def test_Security_break_dacl_inheritance_no_copy(self):
     #
     # This is currently failing because, within the test folder,
     # the file created doesn't have inherited ACEs at the point
     # at which the inheritance is broken. Since unherited ACEs are
     # copied regardless, the test fails.
     #
     with self.test_file() as filepath:
         s = security.security(filepath, options=OPTIONS)
         assert s.dacl.inherited
         s.break_inheritance(copy_first=False,
                             break_dacl=True,
                             break_sacl=False)
         s.to_object()
         sd = win32security.GetNamedSecurityInfo(
             filepath, win32security.SE_FILE_OBJECT, OPTIONS)
         self.assertTrue(sd.GetSecurityDescriptorControl()[0]
                         & win32security.SE_DACL_PROTECTED)
         self.assertTrue(not sd.GetSecurityDescriptorControl()[0]
                         & win32security.SE_SACL_PROTECTED)
         self.assertEqual(sd.GetSecurityDescriptorDacl().GetAceCount(), 0)
示例#28
0
def test_Security_set_owner_none ():
  s = security.security ()
  s.owner = None
  s.owner
示例#29
0
def test_Security_set_group_none ():
  s = security.security ()
  s.group = None
  s.group
示例#30
0
def test_Security_set_group_none():
    s = security.security()
    s.group = None
    s.group
示例#31
0
 def test_security_string_no_type(self):
     with self.test_file() as TEST_FILE:
         assert equal(
             win32security.GetNamedSecurityInfo(
                 TEST_FILE, win32security.SE_FILE_OBJECT, OPTIONS),
             security.security(TEST_FILE, options=OPTIONS))
示例#32
0
 def test_security_Security(self):
     s = security.Security()
     assert security.security(s) is s
示例#33
0
 def test_security_None(self):
     assert security.security(None) is None
示例#34
0
 def test_Security_set_owner_none(self):
     with self.assertRaises(security.x_value_not_set):
         s = security.security()
         s.owner = None
         s.owner
示例#35
0
 def test_security_nonsense(self):
     with self.assertRaises(security.x_security):
         security.security(object)
示例#36
0
def test_security_string_no_type ():
  assert equal (
    win32security.GetNamedSecurityInfo (TEST_FILE, win32security.SE_FILE_OBJECT, OPTIONS),
    security.security (TEST_FILE, options=OPTIONS)
  )
示例#37
0
 def test_Security_no_sacl(self):
     with self.assertRaises(security.x_value_not_set):
         security.security().sacl
示例#38
0
def test_security_None ():
  assert security.security (None) is None
示例#39
0
def test_security_Security ():
  s = security.Security ()
  assert security.security (s) is s
示例#40
0
def test_Security_no_sacl ():
  security.security ().sacl
示例#41
0
from winsys import dialogs, security

[filename] = dialogs.dialog("Choose file", ("Filename", ""))
security.security(filename).dump()
示例#42
0
def test_security_nonsense ():
  security.security (object)
示例#43
0
 def test_security_default(self):
     assert security.security() == security.Security()
示例#44
0
 def test_Security_set_group_none(self):
     with self.assertRaises(security.x_value_not_set):
         s = security.security()
         s.group = None
         s.group
示例#45
0
def test_Security_no_dacl ():
  security.security ().dacl
示例#46
0
def test_Security_no_group ():
  security.security ().group
示例#47
0
def test_security_nonsense():
    security.security(object)
示例#48
0
def test_security_default ():
  assert security.security () == security.Security ()
示例#49
0
 def test_Security_no_sacl(self):
     with self.assertRaises(security.x_value_not_set):
         security.security().sacl
示例#50
0
def test_Security_no_owner():
    security.security().owner
示例#51
0
 def test_Security_set_group_none(self):
     with self.assertRaises(security.x_value_not_set):
         s = security.security()
         s.group = None
         s.group
示例#52
0
def test_Security_no_group():
    security.security().group
示例#53
0
def test_Security_no_dacl():
    security.security().dacl
示例#54
0
def test_Security_no_sacl():
    security.security().sacl
示例#55
0
 def test_Security_set_owner_none(self):
     with self.assertRaises(security.x_value_not_set):
         s = security.security()
         s.owner = None
         s.owner
示例#56
0
def test_Security_set_owner_none():
    s = security.security()
    s.owner = None
    s.owner
示例#57
0
import sys
from winsys import fs, security

for dace in security.security(sys.executable).dacl:
    print dace.trustee, fs.FILE_ACCESS.names_from_value(dace.access)
示例#58
0
def test_Security_no_owner ():
  security.security ().owner