Remove unused import, function.
[ira/wip.git] / source4 / setup / newuser
1 #!/usr/bin/python
2 #
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
7 #
8
9 import sys
10
11 # Find right directory when running from source tree
12 sys.path.insert(0, "bin/python")
13
14 import samba.getopt as options
15 import optparse
16 from getpass import getpass
17 from samba.auth import system_session
18 from samba.samdb import SamDB
19
20 parser = optparse.OptionParser("newuser [options] <username> [<password>]")
21 sambaopts = options.SambaOptions(parser)
22 parser.add_option_group(sambaopts)
23 parser.add_option_group(options.VersionOptions(parser))
24 credopts = options.CredentialsOptions(parser)
25 parser.add_option_group(credopts)
26 parser.add_option("--quiet", help="Be quiet", action="store_true")
27 parser.add_option("--unixname", help="Unix Username", type=str)
28
29 opts, args = parser.parse_args()
30
31 if len(args) == 0:
32         parser.print_usage()
33         sys.exit(1)
34
35 username = args[0]
36 if len(args) > 1:
37         password = args[1]
38 else:
39         password = getpass("New Password: ")
40
41 if opts.unixname is None:
42         opts.unixname = username
43
44 lp = sambaopts.get_loadparm()
45 creds = credopts.get_credentials(lp)
46
47 samdb = SamDB(url=lp.get("sam database"), session_info=system_session(), 
48               credentials=creds, lp=lp)
49 samdb.newuser(username, opts.unixname, password)