def buildPerms(self,perms,rfile): gc.collect() gf = getfacl(rfile) counter = 0 uc=None for perm in gf: permhash={} uc=None if counter==0: uc = UserCache().lookupSID(str(perm)) try: name = uc[0] type = uc[1] permhash={"role":"owner","name":name,"type":type} except: name = "root" type = "person" permhash={"role":"owner","name":name,"type":type} perms.append(permhash) elif counter==1: uc = UserCache().lookupSID(user_sid=str(perm)) try: name = uc[0] type = uc[1] except: name = "root" type = "group" permhash={"role":"group","name":name,"type":type} perms.append(permhash) else: permstring = str(perm) sid = permstring[0:permstring.find('::')] uc = UserCache().lookupSID(user_sid=sid) try: name = uc[0] type = uc[1] role = permstring[permstring.rfind('::')+2:len(permstring)] permhash={"role":role,"name":name,"type":type} perms.append(permhash) except: pass counter=counter+1 return perms
from cifsacl import getfacl import ldap # ldapsearch -x -LLL -H ldap://dc.fhcrc.org -s sub -b 'dc=fhcrc,dc=org' -w0ystercracKer -D "*****@*****.**" "objectSid=S-1-5-21-1981756720-1202999891-1092489882-53260" try: gf = getfacl("/mnt/cs_cifs/cs_researcher/Zheng_Y/mcheck_sec25.ptp") con = ldap.initialize('ldap://dc.fhcrc.org') dn = "*****@*****.**" #dn = "cn=starfish,ou=Accounts - non-person Exch,ou=SOps,dc=fhcrc,dc=org" pw = "0ystercracKer" base = "dc=fhcrc,dc=org" retrieve_attributes = ["cn"] #retrieve_attributes = None scope = ldap.SCOPE_SUBTREE con.set_option(ldap.OPT_REFERRALS, 0) con.simple_bind_s(dn, pw) counter = 0 for perm in gf: if counter == 0: print "OWNER: " + perm elif counter == 1: print "GROUP: " + perm else: permstring = str(perm) sid = permstring[0:permstring.find('::')] filter = "objectSid=" + sid result_id = con.search_s(base, ldap.SCOPE_SUBTREE, filter, retrieve_attributes) print result_id[0][1]["cn"][0] type = permstring[permstring.find('::') + 2:permstring.rfind('::')] mask = permstring[permstring.rfind('::') + 2:len(permstring)]
from cifsacl import getfacl import ldap # ldapsearch -x -LLL -H ldap://dc.fhcrc.org -s sub -b 'dc=fhcrc,dc=org' -w0ystercracKer -D "*****@*****.**" "objectSid=S-1-5-21-1981756720-1202999891-1092489882-53260" try: gf = getfacl("/mnt/cs_cifs/cs_researcher/Zheng_Y/mcheck_sec25.ptp") con = ldap.initialize('ldap://dc.fhcrc.org') dn = "*****@*****.**" #dn = "cn=starfish,ou=Accounts - non-person Exch,ou=SOps,dc=fhcrc,dc=org" pw = "0ystercracKer" base = "dc=fhcrc,dc=org" retrieve_attributes=["cn"] #retrieve_attributes = None scope = ldap.SCOPE_SUBTREE con.set_option(ldap.OPT_REFERRALS, 0) con.simple_bind_s(dn,pw) counter = 0 for perm in gf: if counter==0: print "OWNER: "+perm elif counter==1: print "GROUP: "+perm else: permstring = str(perm) sid = permstring[0:permstring.find('::')] filter = "objectSid=" + sid result_id = con.search_s( base, ldap.SCOPE_SUBTREE, filter, retrieve_attributes ) print result_id[0][1]["cn"][0] type = permstring[permstring.find('::')+2:permstring.rfind('::')] mask = permstring[permstring.rfind('::')+2:len(permstring)] print sid+" "+type+" "+mask