in ad-joining/register-computer/kerberos/password.py [0:0]
def set_password(self, upn, password):
bin_path = os.path.join(os.path.dirname(os.path.realpath(__file__)), "bin")
config_file = self.__generate_config_file()
env = os.environ.copy()
env["LD_LIBRARY_PATH"] = bin_path # for libcom_err.so
env["KRB5_CONFIG"] = config_file
env["KSETPWD_AGENT_PASSWORD"] = self.__client_password
env["KSETPWD_TARGET_PASSWORD"] = password
ksetpwd = os.path.join(bin_path, KerberosPasswordClient.KSETPWD_BINARY)
logging.info("Launching %s with environment config at %s and admin server %s" % (ksetpwd, config_file, self.__admin_server))
# NB. Realm names must be upper case to work.
process = subprocess.run(
[ksetpwd, self.__client_upn.upper(), upn.upper()],
capture_output=True,
env=env)
# Delete KRB5 config
os.unlink(config_file)
if process.returncode == 0:
if process.stderr:
logging.info(process.stderr)
if process.stdout:
logging.info(process.stdout)
else:
if process.stderr:
logging.warning(process.stderr)
if process.stdout:
logging.warning(process.stdout)
raise KerberosException("Password reset failed: %d" % process.returncode, process.returncode)