#!/usr/bin/python
#
-# Add a new user to a Samba4 server
+# Sets a user password on a Samba4 server
# Copyright Jelmer Vernooij 2008
#
# Based on the original in EJS:
parser.add_option_group(credopts)
parser.add_option("--filter", help="LDAP Filter to set password on", type=str)
parser.add_option("--newpassword", help="Set password", type=str)
+parser.add_option("--must-change-at-next-login", help="Force password to be changed on next login", action="store_true")
opts, args = parser.parse_args()
if not opts.quiet:
print text
-if len(args) == 0:
+filter = opts.filter
+
+if (len(args) == 0) and (filter is None):
+ print "Either the username or '--filter' must be specified!"
parser.print_usage()
sys.exit(1)
if password is None:
password = getpass("New Password: ")
-filter = opts.filter
-
if filter is None:
username = args[0]
- if username is None:
- print "Either username or --filter must be specified"
-
filter = "(&(objectclass=user)(samAccountName=%s))" % (username)
-
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp)
samdb = SamDB(url=lp.get("sam database"), session_info=system_session(),
credentials=creds, lp=lp)
-samdb.setpassword(filter, password)
+samdb.setpassword(filter, password, force_password_change_at_next_login=opts.must_change_at_next_login)
+