summaryrefslogtreecommitdiffstats
path: root/source4/scripting/bin/machineaccountpw
diff options
context:
space:
mode:
Diffstat (limited to '')
-rwxr-xr-xsource4/scripting/bin/machineaccountpw42
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())