s3/packaging: source -> source3
[Samba/gebeck_regimport.git] / source4 / setup / newuser
blob281e3849fa91d7fef2712ef2e5049256302210d7
1 #!/usr/bin/python
3 # Add a new user to a Samba4 server
4 # Copyright Jelmer Vernooij 2008
6 # Based on the original in EJS:
7 # Copyright Andrew Tridgell 2005
9 # This program is free software; you can redistribute it and/or modify
10 # it under the terms of the GNU General Public License as published by
11 # the Free Software Foundation; either version 3 of the License, or
12 # (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import sys
23 # Find right directory when running from source tree
24 sys.path.insert(0, "bin/python")
26 import samba.getopt as options
27 import optparse
28 from getpass import getpass
29 from samba.auth import system_session
31 parser = optparse.OptionParser("newuser [options] <username> [<password>]")
32 sambaopts = options.SambaOptions(parser)
33 parser.add_option_group(sambaopts)
34 parser.add_option_group(options.VersionOptions(parser))
35 credopts = options.CredentialsOptions(parser)
36 parser.add_option_group(credopts)
37 parser.add_option("--quiet", help="Be quiet", action="store_true")
38 parser.add_option("--unixname", help="Unix Username", type=str)
40 opts, args = parser.parse_args()
42 if len(args) == 0:
43 parser.print_usage()
44 sys.exit(1)
46 username = args[0]
47 if len(args) > 1:
48 password = args[1]
49 else:
50 password = getpass("New Password: ")
52 if opts.unixname is None:
53 opts.unixname = username
55 lp = sambaopts.get_loadparm()
56 creds = credopts.get_credentials(lp)
58 samdb = sambaopts.get_hostconfig().get_samdb(session_info=system_session(),
59 credentials=creds)
60 samdb.newuser(username, opts.unixname, password)