1
0
mirror of https://github.com/samba-team/samba.git synced 2025-02-08 05:57:51 +03:00
Jelmer Vernooij 47124efe42 Add helper object Hostconfig to make it easier to get to e.g. the
SAM database.
(This used to be commit be75b2a36ee49f66ada3ec3ababa82d74085d559)
2008-08-01 21:12:37 +02:00

49 lines
1.3 KiB
Python
Executable File

#!/usr/bin/python
#
# add a new user to a Samba4 server
# Copyright Andrew Tridgell 2005
# Copyright Jelmer Vernooij 2008
# Released under the GNU GPL version 3 or later
#
import sys
# Find right directory when running from source tree
sys.path.insert(0, "bin/python")
import samba.getopt as options
import optparse
from getpass import getpass
from samba.auth import system_session
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:
password = getpass("New Password: ")
if opts.unixname is None:
opts.unixname = username
lp = sambaopts.get_loadparm()
creds = credopts.get_credentials(lp)
samdb = sambaopts.get_hostconfig().get_samdb(session_info=system_session(),
credentials=creds)
samdb.newuser(username, opts.unixname, password)