Add some more header properties as inline comments to the generated samba3 client.
[samba.git] / source / setup / newuser
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 */
8
9 options = GetOptions(ARGV,
10                 "POPT_AUTOHELP",
11                 'username=s',
12                 'unixname=s',
13                 'password=s',
14                 "POPT_COMMON_SAMBA",
15                 "POPT_COMMON_VERSION",
16                 "POPT_COMMON_CREDENTIALS",
17                 'quiet');
18
19 if (options == undefined) {
20    println("Failed to parse options");
21    return -1;
22 }
23
24 libinclude("base.js");
25 libinclude("provision.js");
26
27 /*
28   print a message if quiet is not set
29 */
30 function message() 
31 {
32         if (options["quiet"] == undefined) {
33                 print(vsprintf(arguments));
34         }
35 }
36
37 /*
38  show some help
39 */
40 function ShowHelp()
41 {
42         print("
43 Samba4 newuser
44
45 newuser [options]
46   --username  USERNAME     choose new username
47   --unixname  USERNAME     choose unix name of new user
48   --password  PASSWORD     set password
49
50 You must provide at least a username
51 ");
52         exit(1);
53 }
54
55 if (options['username'] == undefined) {
56         ShowHelp();
57 }
58
59 if (options['password'] == undefined) {
60         random_init(local);
61         options.password = randpass(12);
62         printf("chose random password %s\n", options.password);
63 }
64 if (options['unixname'] == undefined) {
65         options.unixname = options.username;
66 }
67
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);
72 }
73
74 var creds = options.get_credentials();
75 var system_session = system_session();
76
77
78 newuser(options.username, options.unixname, options.password, message, system_session, creds);
79
80 return 0;