mirror of
https://github.com/samba-team/samba.git
synced 2025-01-13 13:18:06 +03:00
d3b385d596
I regularly get requests for my simple script to print the password from the secrets.tdb (or secrets.ldb on the AD DC). This removes the old script that only reads the secrets.ldb. Neither new nor old script has tests, however it seems better to have it in the tree where it can be found rather that me digging it out of my outbound e-mail. Originally posted here: https://lists.samba.org/archive/samba/2017-November/212362.html Signed-off-by: Andrew Bartlett <abartlet@samba.org> Reviewed-by: Stefan Metzmacher <metze@samba.org>
43 lines
1.1 KiB
Python
Executable File
43 lines
1.1 KiB
Python
Executable File
#!/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())
|