1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00
samba-mirror/source4/setup/newuser
Jelmer Vernooij 31a2a98d83 Remove unused import, function.
(This used to be commit f134a701e7)
2008-06-11 00:10:43 +02:00

50 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
from samba.samdb import SamDB
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 = SamDB(url=lp.get("sam database"), session_info=system_session(),
credentials=creds, lp=lp)
samdb.newuser(username, opts.unixname, password)