1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-23 17:34:34 +03:00

samba-tool: add user-sensitive command to set not-delegated flag

Signed-off-by: Isaac Boukris <iboukris@gmail.com>
This commit is contained in:
Isaac Boukris 2019-10-27 14:02:00 +02:00 committed by Karolin Seeger
parent aaf037dfb3
commit aa17d5fcaf

View File

@ -2825,6 +2825,63 @@ unixHomeDirectory: {6}
.format(username))
class cmd_user_sensitive(Command):
"""Set/unset or show UF_NOT_DELEGATED for an account."""
synopsis = "%prog <accountname> [(show|on|off)] [options]"
takes_optiongroups = {
"sambaopts": options.SambaOptions,
"credopts": options.CredentialsOptions,
"versionopts": options.VersionOptions,
}
takes_options = [
Option("-H", "--URL", help="LDB URL for database or target server", type=str,
metavar="URL", dest="H"),
]
takes_args = ["accountname", "cmd"]
def run(self, accountname, cmd, H=None, credopts=None, sambaopts=None,
versionopts=None):
if cmd not in ("show", "on", "off"):
raise CommandError("invalid argument: '%s' (choose from 'show', 'on', 'off')" % cmd)
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp, fallback_machine=True)
sam = SamDB(url=H, session_info=system_session(),
credentials=creds, lp=lp)
search_filter = "sAMAccountName=%s" % ldb.binary_encode(accountname)
flag = dsdb.UF_NOT_DELEGATED;
if cmd == "show":
res = sam.search(scope=ldb.SCOPE_SUBTREE, expression=search_filter,
attrs=["userAccountControl"])
if len(res) == 0:
raise Exception("Unable to find account where '%s'" % search_filter)
uac = int(res[0].get("userAccountControl")[0])
self.outf.write("Account-DN: %s\n" % str(res[0].dn))
self.outf.write("UF_NOT_DELEGATED: %s\n" % bool(uac & flag))
return
if cmd == "on":
on = True
elif cmd == "off":
on = False
try:
sam.toggle_userAccountFlags(search_filter, flag, flags_str="Not-Delegated",
on=on, strict=True)
except Exception as err:
raise CommandError(err)
class cmd_user(SuperCommand):
"""User management."""
@ -2844,3 +2901,4 @@ class cmd_user(SuperCommand):
subcommands["show"] = cmd_user_show()
subcommands["move"] = cmd_user_move()
subcommands["addunixattrs"] = cmd_user_add_unix_attrs()
subcommands["sensitive"] = cmd_user_sensitive()