diff options
Diffstat (limited to 'source4/setup')
-rwxr-xr-x | source4/setup/provision | 163 |
1 files changed, 61 insertions, 102 deletions
diff --git a/source4/setup/provision b/source4/setup/provision index b01ec97a86..86bc49e537 100755 --- a/source4/setup/provision +++ b/source4/setup/provision @@ -5,7 +5,7 @@ Released under the GNU GPL v2 or later */ -options = new Object(); +var options = new Object(); ok = GetOptions(ARGV, options, "POPT_AUTOHELP", "POPT_COMMON_SAMBA", @@ -35,6 +35,9 @@ if (ok == false) { libinclude("base.js"); +/* used to generate sequence numbers for records */ +next_usn = 1; + /* print a message if quiet is not set */ @@ -46,139 +49,88 @@ function message(s) } /* - find a username from a list of possibilities + find a user or group from a list of possibilities */ -function finduser() +function findnss() { - var i, name = arguments[0]; - if (options[name] != undefined) { - return options[name]; - } - for (i=1;i<arguments.length;i++) { - if (getpwnam(arguments[i]) != undefined) { - return arguments[i]; - } - } - println("Unable to find user for " + name); - exit(1); -} - -/* - find a group from a list of possibilities -*/ -function findgroup() -{ - var i, name = arguments[0]; + var i; + assert(arguments.length >= 2); + var nssfn = arguments[0]; + var name = arguments[1]; if (options[name] != undefined) { return options[name]; } - for (i=1;i<arguments.length;i++) { - if (getgrnam(arguments[i]) != undefined) { + for (i=2;i<arguments.length;i++) { + if (nssfn(arguments[i]) != undefined) { return arguments[i]; } } - println("Unable to find group for " + name); + println("Unable to find user/group for " + name); exit(1); } /* - return a variable substitution -*/ -function sub_callback(key) -{ - var lkey = strlower(key); - if (options[lkey] != undefined) { - return options[lkey]; - } - println(key); - return "NOTFOUND{" + key + "}"; -} - - -/* add a foreign security principle */ function add_foreign(str, sid, desc, unixname) { - return str + " -dn: CN=$sid,CN=ForeignSecurityPrincipals,${BASEDN} + var add = " +dn: CN=${SID},CN=ForeignSecurityPrincipals,${BASEDN} objectClass: top objectClass: foreignSecurityPrincipal -cn: $sid -description: $desc +cn: ${SID} +description: ${DESC} instanceType: 4 whenCreated: ${LDAPTIME} whenChanged: ${LDAPTIME} uSNCreated: 1 uSNChanged: 1 showInAdvancedViewOnly: TRUE -name: $sid +name: ${SID} objectGUID: ${NEWGUID} -objectSid: $sid +objectSid: ${SID} objectCategory: CN=Foreign-Security-Principal,CN=Schema,CN=Configuration,${BASEDN} -unixName: $unixname - +unixName: ${UNIXNAME} "; + var sub = new Object(); + sub.SID = sid; + sub.DESC = desc; + sub.UNIXNAME = unixname; + return str + substitute_var(add, sub); } /* - generate a random guid + return current time as a nt time string */ -function randguid() +function nttime() { - return "009876-7656"; + return "" + sys_nttime(); } /* - generate a random sid + return current time as a ldap time string */ -function randsid() +function ldaptime() { - return "1-2-3"; + return sys_ldaptime(sys_nttime()); } /* - generate a random password + return current time as a ldap time string */ -function randpass() +function nextusn() { - return "penguin"; + next_usn = next_usn+1; + return next_usn; } /* - return current time as a nt time string + return first part of hostname */ -function nttime() +function hostname() { - return "1st Feb"; -} - -/* - substitute strings of the form ${NAME} in str, replacing - with substitutions from subobj -*/ -function substitute_var(str) -{ - var list = split("${", str); - var i; - for (i=1;i<list.length;i++) { - var list2 = split("}", list[i]); - if (list2.length < 2) { - return undefined; - } - var key = list2[0]; - if (typeof(subobj[key]) == "string") { - list2[0] = subobj[key]; - } else { - println("KEY=" + key); - var fn = subobj[key]; - list2[0] = fn(); - println("list2fn=" + list2[0]); - } - list[i] = join("", list2); - println("XXX[" + key + "]=" + list[i]); - } - return join("", list); + var s = split(".", sys_hostname()); + return s[0]; } /* @@ -215,6 +167,10 @@ You must provide at least a realm and domain exit(1); } +if (options['host-name'] == undefined) { + options['host-name'] = hostname(); +} + /* main program */ @@ -227,20 +183,20 @@ if (options["realm"] == undefined || options.realm = strlower(options.realm); options['host-name'] = strlower(options['host-name']); options.domain = strupper(options.domain); -options.netbiosname = strupper(options.hostname); +options.netbiosname = strupper(options['host-name']); if (options.hostip == undefined) { - var list = IfaceList(); + var list = sys_interfaces(); options.hostip = list[0]; } message("Provisioning for " + options.domain + " in realm " + options.realm); -options.root = finduser("root", "root"); -options.nobody = finduser("nobody", "nobody"); -options.nogroup = findgroup("nogroup", "nogroup", "nobody"); -options.wheel = findgroup("wheel", "wheel", "root"); -options.users = findgroup("users", "users", "guest", "other"); +options.root = findnss(getpwnam, "root", "root"); +options.nobody = findnss(getpwnam, "nobody", "nobody"); +options.nogroup = findnss(getgrnam, "nogroup", "nogroup", "nobody"); +options.wheel = findnss(getgrnam, "wheel", "wheel", "root"); +options.users = findnss(getgrnam, "users", "users", "guest", "other"); options.dnsdomain = strlower(options.realm); @@ -256,21 +212,24 @@ if (data == undefined) { /* setup the substitution object */ -subobj = new Object(); +var subobj = new Object(); subobj.DOMAINGUID = randguid(); subobj.DOMAINSID = randsid(); subobj.HOSTGUID = randguid(); subobj.INVOCATIONID = randguid(); -subobj.KRBTGTPASS = randpass(); -subobj.MACHINEPASS = randpass(); -subobj.ADMINPASS = randpass(); +subobj.KRBTGTPASS = randpass(12); +subobj.MACHINEPASS = randpass(12); +subobj.ADMINPASS = randpass(12); subobj.DEFAULTSITE = "Default-First-Site-Name"; subobj.NEWGUID = randguid; subobj.NTTIME = nttime; +subobj.LDAPTIME = ldaptime; +subobj.USN = nextusn; for (r in options) { - subobj[strupper(join("", split("-", r)))] = options[r]; + var key = strupper(join("", split("-", r))); + subobj[key] = options[r]; } -printVars(subobj); + data = add_foreign(data, "S-1-5-7", "Anonymous", "${NOBODY}"); data = add_foreign(data, "S-1-1-0", "World", "${NOGROUP}"); @@ -278,7 +237,7 @@ data = add_foreign(data, "S-1-5-2", "Network", "${NOGROUP}"); data = add_foreign(data, "S-1-5-18", "System", "${ROOT}"); data = add_foreign(data, "S-1-5-11", "Authenticated Users", "${USERS}"); -newdata = substitute_var(data); +newdata = substitute_var(data, subobj); -print(newdata); +println(newdata); return 0; |