diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 17:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-05-05 17:47:29 +0000 |
commit | 4f5791ebd03eaec1c7da0865a383175b05102712 (patch) | |
tree | 8ce7b00f7a76baa386372422adebbe64510812d4 /source4/scripting/bin/machineaccountpw | |
parent | Initial commit. (diff) | |
download | samba-upstream.tar.xz samba-upstream.zip |
Adding upstream version 2:4.17.12+dfsg.upstream/2%4.17.12+dfsgupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'source4/scripting/bin/machineaccountpw')
-rwxr-xr-x | source4/scripting/bin/machineaccountpw | 42 |
1 files changed, 42 insertions, 0 deletions
diff --git a/source4/scripting/bin/machineaccountpw b/source4/scripting/bin/machineaccountpw new file mode 100755 index 0000000..eab773e --- /dev/null +++ b/source4/scripting/bin/machineaccountpw @@ -0,0 +1,42 @@ +#!/usr/bin/env python3 +import optparse +import sys + +# Find right directory when running from source tree +sys.path.insert(0, "bin/python") + + +import samba +from samba import getopt as options +from samba import NTSTATUSError +from samba.credentials import Credentials +parser = optparse.OptionParser("machineaccountpw") +sambaopts = options.SambaOptions(parser) +parser.add_option_group(sambaopts) +parser.add_option_group(options.VersionOptions(parser)) +opts, args = parser.parse_args() + +if len(args) != 0: + parser.print_usage() + sys.exit(1) + +try: + lp_ctx = sambaopts.get_loadparm() +except RuntimeError as error: + print("Unable to load smb.conf %s: %s" % (sambaopts.get_loadparm_path(), + error), + file=sys.stderr) + sys.exit(1) + +creds = Credentials() + +creds.guess(lp_ctx) +try: + creds.set_machine_account(lp_ctx) +except NTSTATUSError as error: + print("Failed to find a stored machine account credential on this system: %s" \ + % error.args[1], + file=sys.stderr) + sys.exit(1) + +print(creds.get_password()) |