From 9e7d8edc0646c5e27fc476d17c723661f252ca70 Mon Sep 17 00:00:00 2001 From: Amitay Isaacs Date: Wed, 27 Jul 2011 18:41:56 +1000 Subject: samba-tool: Add user password command to change user's own password This command is a user-level command and differs from setpassword command which is administrator command. Signed-off-by: Andrew Tridgell --- source4/scripting/python/samba/netcmd/user.py | 33 +++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'source4/scripting') diff --git a/source4/scripting/python/samba/netcmd/user.py b/source4/scripting/python/samba/netcmd/user.py index b93996e152..b13bc0d606 100644 --- a/source4/scripting/python/samba/netcmd/user.py +++ b/source4/scripting/python/samba/netcmd/user.py @@ -194,6 +194,38 @@ class cmd_user_setexpiry(Command): +class cmd_user_password(Command): + """Change password for a user account (the one provided in authentication)""" + + synopsis = "%prog user password [options]" + + takes_options = [ + Option("--newpassword", help="New password", type=str), + ] + + def run(self, credopts=None, sambaopts=None, versionopts=None, + newpassword=None): + + lp = sambaopts.get_loadparm() + creds = credopts.get_credentials(lp) + + # FIXME: How to ensure user is authenticated before prompting for new password? + net = Net(creds, lp, server=credopts.ipaddress) + + password = newpassword + while 1: + if password is not None and password is not '': + break + password = getpass("New Password: ") + + try: + net.change_password(password) + except Exception, msg: + raise CommandError("Failed to change password : %s" % msg) + print "Changed password OK" + + + class cmd_user_setpassword(Command): """(Re)sets the password of a user account""" @@ -252,4 +284,5 @@ class cmd_user(SuperCommand): subcommands["delete"] = cmd_user_delete() subcommands["enable"] = cmd_user_enable() subcommands["setexpiry"] = cmd_user_setexpiry() + subcommands["password"] = cmd_user_password() subcommands["setpassword"] = cmd_user_setpassword() -- cgit