summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmitay Isaacs <amitay@gmail.com>2011-07-27 18:41:56 +1000
committerAndrew Tridgell <tridge@samba.org>2011-07-28 15:20:53 +1000
commit9e7d8edc0646c5e27fc476d17c723661f252ca70 (patch)
tree7c727f36e7825843d60557d16657f39fb30f9b7d
parent9c370846ae4a0e52d816e79246a4e2e6ea58129c (diff)
downloadsamba-9e7d8edc0646c5e27fc476d17c723661f252ca70.tar.gz
samba-9e7d8edc0646c5e27fc476d17c723661f252ca70.tar.bz2
samba-9e7d8edc0646c5e27fc476d17c723661f252ca70.zip
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 <tridge@samba.org>
-rw-r--r--source4/scripting/python/samba/netcmd/user.py33
1 files changed, 33 insertions, 0 deletions
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()