2005-07-14 13:51:49 +04:00
#!/bin/sh
exec smbscript "$0" ${1+"$@"}
2005-07-13 09:29:05 +04:00
/*
add a new user to a Samba4 server
Copyright Andrew Tridgell 2005
Released under the GNU GPL v2 or later
*/
2005-08-22 18:32:58 +04:00
options = GetOptions(ARGV,
2005-07-13 09:29:05 +04:00
"POPT_AUTOHELP",
"POPT_COMMON_SAMBA",
"POPT_COMMON_VERSION",
2006-01-07 00:45:36 +03:00
"POPT_COMMON_CREDENTIALS",
2005-07-13 09:29:05 +04:00
'username=s',
'unixname=s',
'password=s',
'quiet');
2005-08-22 18:32:58 +04:00
if (options == undefined) {
2005-10-17 15:33:13 +04:00
println("Failed to parse options");
2005-07-13 09:29:05 +04:00
return -1;
}
libinclude("base.js");
2005-07-19 03:58:18 +04:00
libinclude("provision.js");
2005-07-13 09:29:05 +04: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 15:33:13 +04:00
random_init(local);
2005-07-13 09:29:05 +04:00
options.password = randpass(12);
printf("chose random password %s\n", options.password);
}
if (options['unixname'] == undefined) {
options.unixname = options.username;
}
2005-08-16 14:52:02 +04:00
var nss = nss_init();
if (nss.getpwnam(options.unixname) == undefined) {
2005-07-13 09:29:05 +04:00
printf("ERROR: Unix user '%s' does not exist\n", options.unixname);
exit(1);
}
2006-01-07 00:45:36 +03:00
var creds = options.get_credentials();
var system_session = system_session();
newuser(options.username, options.unixname, options.password, message, system_session, creds);
2005-07-13 09:29:05 +04:00
return 0;