1
0
mirror of https://github.com/samba-team/samba.git synced 2025-07-28 11:42:03 +03:00

samba-tool: moved machinepw to domain machinepassword

This is part of the samba-tool work to fit the object-action model

Signed-off-by: Andrew Tridgell <tridge@samba.org>
This commit is contained in:
Giampaolo Lauria
2011-06-27 17:04:10 -04:00
committed by Andrew Tridgell
parent 8c7718ac16
commit 41b2b7e160

View File

@ -25,7 +25,8 @@
import samba.getopt as options
import ldb
import os
from samba import Ldb
from samba.auth import system_session
from samba.samdb import SamDB
from samba.dcerpc.samr import DOMAIN_PASSWORD_COMPLEX, DOMAIN_PASSWORD_STORE_CLEARTEXT
@ -37,6 +38,40 @@ from samba.netcmd import (
)
class cmd_domain_machinepassword(Command):
"""Gets a machine password out of our SAM"""
synopsis = "%prog domain machinepassword <accountname>"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"versionopts": options.VersionOptions,
"credopts": options.CredentialsOptions,
}
takes_args = ["secret"]
def run(self, secret, sambaopts=None, credopts=None, versionopts=None):
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)
name = lp.get("secrets database")
path = lp.get("private dir")
url = os.path.join(path, name)
if not os.path.exists(url):
raise CommandError("secret database not found at %s " % url)
secretsdb = Ldb(url=url, session_info=system_session(),
credentials=creds, lp=lp)
result = secretsdb.search(attrs=["secret"],
expression="(&(objectclass=primaryDomain)(samaccountname=%s))" % secret)
if len(result) != 1:
raise CommandError("search returned %d records, expected 1" % len(result))
self.outf.write("%s\n" % result[0]["secret"])
class cmd_domain_passwordsettings(Command):
"""Sets password settings
@ -209,4 +244,5 @@ class cmd_domain(SuperCommand):
"""Domain management"""
subcommands = {}
subcommands["machinepassword"] = cmd_domain_machinepassword()
subcommands["passwordsettings"] = cmd_domain_passwordsettings()