Exemple #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 ()
Exemple #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)
Exemple #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)  
Exemple #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)
Exemple #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)
Exemple #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()
Exemple #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)
Exemple #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)
Exemple #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 ()
Exemple #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 ()
Exemple #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)
Exemple #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
Exemple #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)
Exemple #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()
Exemple #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()
Exemple #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()
Exemple #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
Exemple #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)
Exemple #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)
Exemple #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
Exemple #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
Exemple #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()
Exemple #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
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #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)
Exemple #28
0
def test_Security_set_owner_none ():
  s = security.security ()
  s.owner = None
  s.owner
Exemple #29
0
def test_Security_set_group_none ():
  s = security.security ()
  s.group = None
  s.group
Exemple #30
0
def test_Security_set_group_none():
    s = security.security()
    s.group = None
    s.group
Exemple #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))
Exemple #32
0
 def test_security_Security(self):
     s = security.Security()
     assert security.security(s) is s
Exemple #33
0
 def test_security_None(self):
     assert security.security(None) is None
Exemple #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
Exemple #35
0
 def test_security_nonsense(self):
     with self.assertRaises(security.x_security):
         security.security(object)
Exemple #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)
  )
Exemple #37
0
 def test_Security_no_sacl(self):
     with self.assertRaises(security.x_value_not_set):
         security.security().sacl
Exemple #38
0
def test_security_None ():
  assert security.security (None) is None
Exemple #39
0
def test_security_Security ():
  s = security.Security ()
  assert security.security (s) is s
Exemple #40
0
def test_Security_no_sacl ():
  security.security ().sacl
Exemple #41
0
from winsys import dialogs, security

[filename] = dialogs.dialog("Choose file", ("Filename", ""))
security.security(filename).dump()
Exemple #42
0
def test_security_nonsense ():
  security.security (object)
Exemple #43
0
 def test_security_default(self):
     assert security.security() == security.Security()
Exemple #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
Exemple #45
0
def test_Security_no_dacl ():
  security.security ().dacl
Exemple #46
0
def test_Security_no_group ():
  security.security ().group
Exemple #47
0
def test_security_nonsense():
    security.security(object)
Exemple #48
0
def test_security_default ():
  assert security.security () == security.Security ()
Exemple #49
0
 def test_Security_no_sacl(self):
     with self.assertRaises(security.x_value_not_set):
         security.security().sacl
Exemple #50
0
def test_Security_no_owner():
    security.security().owner
Exemple #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
Exemple #52
0
def test_Security_no_group():
    security.security().group
Exemple #53
0
def test_Security_no_dacl():
    security.security().dacl
Exemple #54
0
def test_Security_no_sacl():
    security.security().sacl
Exemple #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
Exemple #56
0
def test_Security_set_owner_none():
    s = security.security()
    s.owner = None
    s.owner
Exemple #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)
Exemple #58
0
def test_Security_no_owner ():
  security.security ().owner