2005-07-14 09:51:49 +00:00
#!/bin/sh
exec smbscript "$0" ${1+"$@"}
2005-07-13 05:29:05 +00:00
/*
add a new user to a Samba4 server
Copyright Andrew Tridgell 2005
Released under the GNU GPL v2 or later
*/
2005-08-22 14:32:58 +00:00
options = GetOptions(ARGV,
2005-07-13 05:29:05 +00:00
"POPT_AUTOHELP",
"POPT_COMMON_SAMBA",
"POPT_COMMON_VERSION",
'username=s',
'unixname=s',
'password=s',
'quiet');
2005-08-22 14:32:58 +00:00
if (options == undefined) {
2005-10-17 11:33:13 +00:00
println("Failed to parse options");
2005-07-13 05:29:05 +00:00
return -1;
}
libinclude("base.js");
2005-07-18 23:58:18 +00:00
libinclude("provision.js");
2005-07-13 05:29:05 +00:00
/*
print a message if quiet is not set
*/
function message()
{
if (options["quiet"] == undefined) {
print(vsprintf(arguments));
}
}
/*
show some help
*/
function ShowHelp()
{
print("
Samba4 newuser
newuser [options]
--username USERNAME choose new username
--unixname USERNAME choose unix name of new user
--password PASSWORD set password
You must provide at least a username
");
exit(1);
}
if (options['username'] == undefined) {
ShowHelp();
}
if (options['password'] == undefined) {
2005-10-17 11:33:13 +00:00
random_init(local);
2005-07-13 05:29:05 +00:00
options.password = randpass(12);
printf("chose random password %s\n", options.password);
}
if (options['unixname'] == undefined) {
options.unixname = options.username;
}
2005-08-16 10:52:02 +00:00
var nss = nss_init();
if (nss.getpwnam(options.unixname) == undefined) {
2005-07-13 05:29:05 +00:00
printf("ERROR: Unix user '%s' does not exist\n", options.unixname);
exit(1);
}
2005-07-18 23:58:18 +00:00
newuser(options.username, options.unixname, options.password, message);
2005-07-13 05:29:05 +00:00
return 0;