MCPcopy Create free account
hub / github.com/XiaoliChan/LDAPShell / do_set_dontreqpreauth

Method do_set_dontreqpreauth

utils/ldap_shell.py:418–464  ·  view source on GitHub ↗
(self, line)

Source from the content-addressed store, hash-verified

416 self.search('(|%s)' % search_query, *attributes)
417
418 def do_set_dontreqpreauth(self, line):
419 UF_DONT_REQUIRE_PREAUTH = 4194304
420
421 args = shlex.split(line)
422 if len(args) != 2:
423 raise Exception("Username (SAMAccountName) and true/false flag required (e.g. jsmith true).")
424
425 user_name = args[0]
426 flag_str = args[1]
427 flag = False
428
429 if flag_str.lower() == "true":
430 flag = True
431 elif flag_str.lower() == "false":
432 flag = False
433 else:
434 raise Exception("The specified flag must be either true or false")
435
436 self.client.search(self.domain_dumper.root, '(sAMAccountName=%s)' % escape_filter_chars(user_name), attributes=['objectSid', 'userAccountControl'])
437 if len(self.client.entries) != 1:
438 raise Exception("Error expected only one search result got %d results", len(self.client.entries))
439
440 user_dn = self.client.entries[0].entry_dn
441 if not user_dn:
442 raise Exception("User not found in LDAP: %s" % user_name)
443
444 entry = self.client.entries[0]
445 userAccountControl = entry["userAccountControl"].value
446 print("Original userAccountControl: %d" % userAccountControl)
447
448 if flag:
449 userAccountControl = userAccountControl | UF_DONT_REQUIRE_PREAUTH
450 else:
451 userAccountControl = userAccountControl & ~UF_DONT_REQUIRE_PREAUTH
452
453 print("Updated userAccountControl: %d" % userAccountControl)
454 self.client.modify(user_dn, {'userAccountControl':(ldap3.MODIFY_REPLACE, [userAccountControl])})
455
456 if self.client.result['result'] == 0:
457 print("Updated userAccountControl attribute successfully")
458 else:
459 if self.client.result['result'] == 50:
460 raise Exception('Could not modify object, the server reports insufficient rights: %s', self.client.result['message'])
461 elif self.client.result['result'] == 19:
462 raise Exception('Could not modify object, the server reports a constrained violation: %s', self.client.result['message'])
463 else:
464 raise Exception('The server returned an error: %s', self.client.result['message'])
465
466 def do_get_user_groups(self, user_name):
467 user_dn = self.get_dn(user_name)

Callers

nothing calls this directly

Calls 1

searchMethod · 0.80

Tested by

no test coverage detected