07.12.2012 Views

versión color - PET: Python Entre Todos - Python Argentina

versión color - PET: Python Entre Todos - Python Argentina

versión color - PET: Python Entre Todos - Python Argentina

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

43 mbcs<br />

dacl = security_descriptor.GetSecurityDescriptorDacl()<br />

# if we delete an ace in the acl the index is outdated and we have<br />

# to ensure that we do not screw it up. We keep the number of deleted<br />

# items to update accordingly the index.<br />

num_delete = 0<br />

for index in range(0, dacl.GetAceCount()):<br />

ace = dacl.GetAce(index - num_delete)<br />

# check if the ace is for the user and its type is 0, that means<br />

# is a deny ace and we added it, lets remove it<br />

if USER_SID == ace[2] and ace[0][0] == 0:<br />

dacl.DeleteAce(index - num_delete)<br />

num_delete += 1<br />

security_descriptor.SetSecurityDescriptorDacl(1, dacl, 0)<br />

SetFileSecurity(path, DACL_SECURITY_INFORMATION, security_descriptor)<br />

o uno que se los quita:<br />

def add_deny_ace(path, rights):<br />

"""Remove rights from a path for the given groups."""<br />

if not os.path.exists(path):<br />

raise WindowsError('Path %s could not be found.' % path)<br />

if rights is not None:<br />

security_descriptor = GetFileSecurity(path, DACL_SECURITY_INFORMATION)<br />

dacl = security_descriptor.GetSecurityDescriptorDacl()<br />

# set the attributes of the group only if not null<br />

dacl.AddAccessDeniedAceEx(ACL_REVISION_DS,<br />

CONTAINER_INHERIT_ACE | OBJECT_INHERIT_ACE, rights,<br />

USER_SID)<br />

security_descriptor.SetSecurityDescriptorDacl(1, dacl, 0)<br />

SetFileSecurity(path, DACL_SECURITY_INFORMATION, security_descriptor)<br />

def remove_deny_ace(path):<br />

"""Remove the deny ace for the given groups."""<br />

if not os.path.exists(path):<br />

raise WindowsError('Path %s could not be found.' % path)<br />

security_descriptor = GetFileSecurity(path, DACL_SECURITY_INFORMATION)<br />

dacl = security_descriptor.GetSecurityDescriptorDacl()<br />

# if we delete an ace in the acl the index is outdated and we have<br />

# to ensure that we do not screw it up. We keep the number of deleted<br />

# items to update accordingly the index.<br />

num_delete = 0<br />

for index in range(0, dacl.GetAceCount()):<br />

ace = dacl.GetAce(index - num_delete)<br />

# check if the ace is for the user and its type is 1, that means<br />

# is a deny ace and we added it, lets remove it<br />

if USER_SID == ace[2] and ace[0][0] == 1:<br />

dacl.DeleteAce(index - num_delete)<br />

num_delete += 1<br />

security_descriptor.SetSecurityDescriptorDacl(1, dacl, 0)<br />

SetFileSecurity(path, DACL_SECURITY_INFORMATION, security_descriptor)<br />

<strong>Python</strong> <strong>Entre</strong> <strong>Todos</strong> (número 5, Marzo 2012) — http://revista.python.org.ar

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!