3 # add a new user to a Samba4 server
4 # Copyright Andrew Tridgell 2005
5 # Copyright Jelmer Vernooij 2008
6 # Released under the GNU GPL version 3 or later
9 import samba.getopt as options
13 from getpass import getpass
14 from auth import system_session
15 from samba.samdb import SamDB
17 parser = optparse.OptionParser("setpassword [username] [options]")
18 sambaopts = options.SambaOptions(parser)
19 parser.add_option_group(sambaopts)
20 parser.add_option_group(options.VersionOptions(parser))
21 credopts = options.CredentialsOptions(parser)
22 parser.add_option_group(credopts)
23 parser.add_option("--filter", help="LDAP Filter to set password on", type=str)
24 parser.add_option("--newpassword", help="Set password", type=str)
26 opts, args = parser.parse_args()
29 # print a message if quiet is not set
39 password = opts.newpassword;
41 password = getpass("New Password: ")
48 print "Either username or --filter must be specified"
50 filter = "(&(objectclass=user)(samAccountName=%s))" % (username)
53 lp = sambaopts.get_loadparm()
54 creds = credopts.get_credentials(lp)
56 samdb = SamDB(url=lp.get("sam database"), session_info=system_session(),
57 credentials=creds, lp=lp)
58 samdb.setpassword(filter, password)