r14984: marking mprBreakpoint() as a __noreturn__ function should reduce the
[Samba/aatanasov.git] / source / setup / newuser
blob4d2acf537329103dada5e7cb6a1f68441f5d0dc8
1 #!/bin/sh
2 exec smbscript "$0" ${1+"$@"}
3 /*
4 add a new user to a Samba4 server
5 Copyright Andrew Tridgell 2005
6 Released under the GNU GPL v2 or later
7 */
9 options = GetOptions(ARGV,
10 "POPT_AUTOHELP",
11 "POPT_COMMON_SAMBA",
12 "POPT_COMMON_VERSION",
13 "POPT_COMMON_CREDENTIALS",
14 'username=s',
15 'unixname=s',
16 'password=s',
17 'quiet');
19 if (options == undefined) {
20 println("Failed to parse options");
21 return -1;
24 libinclude("base.js");
25 libinclude("provision.js");
29 print a message if quiet is not set
31 function message()
33 if (options["quiet"] == undefined) {
34 print(vsprintf(arguments));
39 show some help
41 function ShowHelp()
43 print("
44 Samba4 newuser
46 newuser [options]
47 --username USERNAME choose new username
48 --unixname USERNAME choose unix name of new user
49 --password PASSWORD set password
51 You must provide at least a username
52 ");
53 exit(1);
56 if (options['username'] == undefined) {
57 ShowHelp();
59 if (options['password'] == undefined) {
60 random_init(local);
61 options.password = randpass(12);
62 printf("chose random password %s\n", options.password);
64 if (options['unixname'] == undefined) {
65 options.unixname = options.username;
68 var nss = nss_init();
69 if (nss.getpwnam(options.unixname) == undefined) {
70 printf("ERROR: Unix user '%s' does not exist\n", options.unixname);
71 exit(1);
74 var creds = options.get_credentials();
75 var system_session = system_session();
78 newuser(options.username, options.unixname, options.password, message, system_session, creds);
80 return 0;