2008-03-26 15:42:20 +11:00
#!/usr/bin/python
#
# add a new user to a Samba4 server
# Copyright Andrew Tridgell 2005
# Copyright Jelmer Vernooij 2008
2008-03-28 01:08:49 -05:00
# Released under the GNU GPL version 3 or later
2008-03-26 15:42:20 +11:00
#
2008-05-11 05:45:49 +02:00
import sys
# Find right directory when running from source tree
sys.path.insert(0, "bin/python")
2008-03-26 15:42:20 +11:00
import samba.getopt as options
import optparse
2008-03-28 12:08:54 +11:00
from getpass import getpass
2008-05-22 01:47:36 +02:00
from samba.auth import system_session
2008-03-26 15:42:20 +11:00
parser = optparse.OptionParser("newuser [options] <username> [<password>]")
sambaopts = options.SambaOptions(parser)
parser.add_option_group(sambaopts)
parser.add_option_group(options.VersionOptions(parser))
credopts = options.CredentialsOptions(parser)
parser.add_option_group(credopts)
parser.add_option("--quiet", help="Be quiet", action="store_true")
parser.add_option("--unixname", help="Unix Username", type=str)
opts, args = parser.parse_args()
if len(args) == 0:
parser.print_usage()
sys.exit(1)
username = args[0]
if len(args) > 1:
password = args[1]
else:
2008-03-28 12:08:54 +11:00
password = getpass("New Password: ")
2008-03-26 15:42:20 +11:00
if opts.unixname is None:
opts.unixname = username
lp = sambaopts.get_loadparm()
2008-04-14 11:51:02 +02:00
creds = credopts.get_credentials(lp)
2008-08-01 21:12:37 +02:00
samdb = sambaopts.get_hostconfig().get_samdb(session_info=system_session(),
credentials=creds)
2008-03-26 15:42:20 +11:00
samdb.newuser(username, opts.unixname, password)