@@ -1135,7 +1135,6 @@ def printTable(items, header):
11351135 resp_parse = parse_result_attributes (resp )
11361136
11371137 for item in resp_parse :
1138- mustCommit = False
11391138 sAMAccountName = ""
11401139 userAccountControl = 0
11411140 delegation = ""
@@ -1145,53 +1144,53 @@ def printTable(items, header):
11451144
11461145 try :
11471146 sAMAccountName = item .get ("sAMAccountName" )
1148- mustCommit = sAMAccountName is not None
1149-
1150- userAccountControl = int (item .get ("userAccountControl" , 0 ))
1151- objectType = item .get ("objectCategory" )
1152-
1153- if userAccountControl & UF_TRUSTED_FOR_DELEGATION :
1154- delegation = "Unconstrained"
1155- rightsTo .append ("N/A" )
1156- elif userAccountControl & UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION :
1157- delegation = "Constrained w/ Protocol Transition"
1158- protocolTransition = 1
1159-
1160- if item .get ("msDS-AllowedToDelegateTo" ) is not None :
1161- if protocolTransition == 0 :
1162- delegation = "Constrained"
1163- rightsTo = item .get ("msDS-AllowedToDelegateTo" )
1164-
1165- # Not an elif as an object could both have RBCD and another type of delegation
1166- if item .get ("msDS-AllowedToActOnBehalfOfOtherIdentity" ) is not None :
1167- databyte = item .get ("msDS-AllowedToActOnBehalfOfOtherIdentity" )
1168- rbcdRights = []
1169- rbcdObjType = []
1170- sd = ldaptypes .SR_SECURITY_DESCRIPTOR (data = bytes (databyte ))
1171- if len (sd ["Dacl" ].aces ) > 0 :
1172- search_filter = "(&(|"
1173- for ace in sd ["Dacl" ].aces :
1174- search_filter += "(objectSid=" + ace ["Ace" ]["Sid" ].formatCanonical () + ")"
1175- search_filter += ")(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))"
1176- delegUserResp = self .search (search_filter , attributes = ["sAMAccountName" , "objectCategory" ], sizeLimit = 999 )
1177- delegUserResp_parse = parse_result_attributes (delegUserResp )
1178-
1179- for rbcd in delegUserResp_parse :
1180- rbcdRights .append (str (rbcd .get ("sAMAccountName" )))
1181- rbcdObjType .append (str (rbcd .get ("objectCategory" )))
1182-
1183- if mustCommit :
1147+ if sAMAccountName :
1148+
1149+ userAccountControl = int (item .get ("userAccountControl" , 0 ))
1150+ objectType = item .get ("objectCategory" )
1151+
1152+ if userAccountControl & UF_TRUSTED_FOR_DELEGATION :
1153+ delegation = "Unconstrained"
1154+ rightsTo .append ("N/A" )
1155+ elif userAccountControl & UF_TRUSTED_TO_AUTHENTICATE_FOR_DELEGATION :
1156+ delegation = "Constrained w/ Protocol Transition"
1157+ protocolTransition = 1
1158+
1159+ if item .get ("msDS-AllowedToDelegateTo" ) is not None :
1160+ if protocolTransition == 0 :
1161+ delegation = "Constrained"
1162+ rightsTo = item .get ("msDS-AllowedToDelegateTo" )
1163+
1164+ # Not an elif as an object could both have RBCD and another type of delegation
1165+ if item .get ("msDS-AllowedToActOnBehalfOfOtherIdentity" ) is not None :
1166+ databyte = item .get ("msDS-AllowedToActOnBehalfOfOtherIdentity" )
1167+ rbcdRights = []
1168+ rbcdObjType = []
1169+ sd = ldaptypes .SR_SECURITY_DESCRIPTOR (data = bytes (databyte ))
1170+ if len (sd ["Dacl" ].aces ) > 0 :
1171+ search_filter = "(&(|"
1172+ for ace in sd ["Dacl" ].aces :
1173+ search_filter += "(objectSid=" + ace ["Ace" ]["Sid" ].formatCanonical () + ")"
1174+ search_filter += ")(!(UserAccountControl:1.2.840.113556.1.4.803:=2)))"
1175+ delegUserResp = self .search (search_filter , attributes = ["sAMAccountName" , "objectCategory" ], sizeLimit = 999 )
1176+ delegUserResp_parse = parse_result_attributes (delegUserResp )
1177+
1178+ for rbcd in delegUserResp_parse :
1179+ rbcdRights .append (str (rbcd .get ("sAMAccountName" )))
1180+ rbcdObjType .append (str (rbcd .get ("objectCategory" )))
1181+
1182+
11841183 if int (userAccountControl ) & UF_ACCOUNTDISABLE :
11851184 self .logger .debug (f"Bypassing disabled account { sAMAccountName } " )
11861185 else :
11871186 for rights , objType in zip (rbcdRights , rbcdObjType ):
11881187 answers .append ([rights , objType , "Resource-Based Constrained" , sAMAccountName ])
11891188
1190- if delegation in ["Unconstrained" , "Constrained" , "Constrained w/ Protocol Transition" ] and mustCommit :
1191- if int (userAccountControl ) & UF_ACCOUNTDISABLE :
1192- self .logger .debug (f"Bypassing disabled account { sAMAccountName } " )
1193- else :
1194- answers .append ([sAMAccountName , objectType , delegation , rightsTo ])
1189+ if delegation in ["Unconstrained" , "Constrained" , "Constrained w/ Protocol Transition" ]:
1190+ if int (userAccountControl ) & UF_ACCOUNTDISABLE :
1191+ self .logger .debug (f"Bypassing disabled account { sAMAccountName } " )
1192+ else :
1193+ answers .append ([sAMAccountName , objectType , delegation , rightsTo ])
11951194
11961195 except Exception as e :
11971196 self .logger .error (f"Skipping item, cannot process due to error { e } " )
0 commit comments