ldb: Release ldb 2.2.1
[Samba.git] / source4 / scripting / bin / machineaccountpw
blobeab773ec7c08b175c6acc2853ce44f44f9dcc29c
1 #!/usr/bin/env python3
2 import optparse
3 import sys
5 # Find right directory when running from source tree
6 sys.path.insert(0, "bin/python")
9 import samba
10 from samba import getopt as options
11 from samba import NTSTATUSError
12 from samba.credentials import Credentials
13 parser = optparse.OptionParser("machineaccountpw")
14 sambaopts = options.SambaOptions(parser)
15 parser.add_option_group(sambaopts)
16 parser.add_option_group(options.VersionOptions(parser))
17 opts, args = parser.parse_args()
19 if len(args) != 0:
20     parser.print_usage()
21     sys.exit(1)
23 try:
24     lp_ctx = sambaopts.get_loadparm()
25 except RuntimeError as error:
26     print("Unable to load smb.conf %s: %s" % (sambaopts.get_loadparm_path(),
27                                               error),
28           file=sys.stderr)
29     sys.exit(1)
31 creds = Credentials()
33 creds.guess(lp_ctx)
34 try:
35     creds.set_machine_account(lp_ctx)
36 except NTSTATUSError as error:
37     print("Failed to find a stored machine account credential on this system: %s" \
38           % error.args[1],
39           file=sys.stderr)
40     sys.exit(1)
42 print(creds.get_password())