diff options
-rw-r--r-- | source4/lib/samba3/secrets.c | 2 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_samba3.c | 4 | ||||
-rw-r--r-- | source4/scripting/libjs/upgrade.js | 103 | ||||
-rw-r--r-- | source4/setup/upgrade | 54 | ||||
-rw-r--r-- | swat/install/samba3.esp | 42 |
5 files changed, 137 insertions, 68 deletions
diff --git a/source4/lib/samba3/secrets.c b/source4/lib/samba3/secrets.c index 25ab8f5db5..43f0a2ec12 100644 --- a/source4/lib/samba3/secrets.c +++ b/source4/lib/samba3/secrets.c @@ -72,7 +72,7 @@ static struct samba3_domainsecrets *secrets_find_domain(TALLOC_CTX *ctx, struct db->domains = talloc_realloc(ctx, db->domains, struct samba3_domainsecrets, db->domain_count+1); ZERO_STRUCT(db->domains[db->domain_count]); - db->domains[db->domain_count].name = talloc_strdup(ctx, key); + db->domains[db->domain_count].name = talloc_strdup(db->domains, key); db->domain_count++; diff --git a/source4/scripting/ejs/smbcalls_samba3.c b/source4/scripting/ejs/smbcalls_samba3.c index 66e1299566..e6f6481060 100644 --- a/source4/scripting/ejs/smbcalls_samba3.c +++ b/source4/scripting/ejs/smbcalls_samba3.c @@ -210,6 +210,8 @@ static struct MprVar mprSecrets(struct samba3_secrets *sec) mprSetVar(&mpv, "ldappws", es); + es = mprObject("array"); + for (i = 0; i < sec->domain_count; i++) { mprAddArray(&es, i, mprDomainSecrets(&sec->domains[i])); } @@ -448,7 +450,7 @@ static int ejs_samba3_read(MprVarHandle eid, int argc, struct MprVar **argv) mprAssert(samba3); - mprSetThisPtr(eid, "samba3", samba3); + mprSetPtrChild(&mpv, "samba3", samba3); mprSetVar(&mpv, "winsentries", mprWinsEntries(samba3)); mprSetVar(&mpv, "samaccounts", mprSamAccounts(samba3)); mprSetVar(&mpv, "shares", mprShares(samba3)); diff --git a/source4/scripting/libjs/upgrade.js b/source4/scripting/libjs/upgrade.js index 3a6d2eec0a..c8539c9fcb 100644 --- a/source4/scripting/libjs/upgrade.js +++ b/source4/scripting/libjs/upgrade.js @@ -32,14 +32,17 @@ function regkey_to_dn(name) function upgrade_registry(regdb,prefix) { + assert(regdb != undefined); var prefix_up = strupper(prefix); var ldif = ""; for (var i in regdb.keys) { var rk = regdb.keys[i]; + var pts = split("/", rk.name); + /* Only handle selected hive */ - if (strncmp(prefix_up, rk.name, strlen(prefix_up)) != 0) { + if (strupper(pts[0]) != prefix_up) { continue; } @@ -72,6 +75,8 @@ function upgrade_sam_policy(samba3,dn) { var ldif = sprintf(" dn: %s +changetype: modify +replace: minPwdLength minPwdLength: %d pwdHistoryLength: %d minPwdAge: %d @@ -124,7 +129,7 @@ samba3PassCanChangeTime: %d samba3PassMustChangeTime: %d samba3Rid: %d -", acc.fullname, domaindn, sam.logon_time, acc.logoff_time, acc.username, acc.nt_username, +", acc.fullname, domaindn, acc.logon_time, acc.logoff_time, acc.username, acc.nt_username, acc.fullname, acc.acct_desc, acc.group_rid, acc.bad_password_count, acc.logon_count, acc.domain, acc.dir_drive, acc.munged_dial, acc.homedir, acc.logon_script, acc.profile_path, acc.workstations, acc.kickoff_time, acc.bad_password_time, @@ -145,7 +150,8 @@ description: %s cn: %s objectSid: %s unixName: FIXME -samba3SidNameUse: %d", grp.nt_name, domaindn, +samba3SidNameUse: %d +", grp.nt_name, domaindn, grp.comment, grp.nt_name, grp.sid, grp.sid_name_use); return ldif; @@ -185,7 +191,8 @@ dn: type=%d,name=%s name: %s objectClass: wins nbFlags: %x -expires: %s", e.type, e.name, e.name, e.type, e.nb_flags, sys.ldap_time(e.ttl)); +expires: %s +", e.type, e.name, e.name, e.type, e.nb_flags, sys.ldaptime(e.ttl)); for (var i in e.ips) { ldif = ldif + sprintf("address: %s\n", e.ips[i]); @@ -203,9 +210,20 @@ function upgrade_provision(samba3) var rdn_list; var domainname = samba3.get_param("global", "workgroup"); + + if (domainname == undefined) { + domainname = samba3.secrets.domains[0].name; + println("No domain specified in smb.conf file, assuming '" + domainname + "'"); + } + var domsec = samba3.find_domainsecrets(domainname); var hostsec = samba3.find_domainsecrets(hostname()); var realm = samba3.get_param("global", "realm"); + + if (realm == undefined) { + realm = domainname; + println("No realm specified in smb.conf file, assuming '" + realm + "'"); + } random_init(local); subobj.REALM = realm; @@ -217,9 +235,20 @@ function upgrade_provision(samba3) assert(subobj.HOSTNAME); subobj.HOSTIP = hostip(); - subobj.DOMAINGUID = domsec.guid; - subobj.DOMAINSID = domsec.sid; - subobj.HOSTGUID = hostsec.guid; + if (domsec != undefined) { + subobj.DOMAINGUID = domsec.guid; + subobj.DOMAINSID = domsec.sid; + } else { + println("Can't find domain secrets for '" + domainname + "'; using random SID and GUID"); + subobj.DOMAINGUID = randguid(); + subobj.DOMAINSID = randguid(); + } + + if (hostsec) { + subobj.HOSTGUID = hostsec.guid; + } else { + subobj.HOSTGUID = randguid(); + } subobj.INVOCATIONID = randguid(); subobj.KRBTGTPASS = randpass(12); subobj.MACHINEPASS = randpass(12); @@ -230,7 +259,7 @@ function upgrade_provision(samba3) subobj.LDAPTIME = ldaptime; subobj.DATESTRING = datestring; subobj.USN = nextusn; - subobj.ROOT = findnss(nss.getpwnam, split(samba3.get_param("global", "admin users"))); + subobj.ROOT = findnss(nss.getpwnam, "root"); subobj.NOBODY = findnss(nss.getpwnam, "nobody"); subobj.NOGROUP = findnss(nss.getgrnam, "nogroup", "nobody"); subobj.WHEEL = findnss(nss.getgrnam, "wheel", "root"); @@ -365,3 +394,61 @@ function upgrade_smbconf(samba3) { //FIXME } + +function upgrade(subobj, samba3, message) +{ + var samdb = ldb_init(); + var ok = samdb.connect("sam.ldb"); + assert(ok); + + message("Importing account policies\n"); + var ldif = upgrade_sam_policy(samba3,subobj.BASEDN); + ldifprint(ldif); + ok = samdb.modify(ldif); + assert(ok); + + // FIXME: Enable samba3sam module if original passdb backend was ldap + + message("Importing users\n"); + for (var i in samba3.samaccounts) { + message("Importing user '" + samba3.samaccounts[i].username + "'\n"); + var ldif = upgrade_sam_account(samba3.samaccounts[i],subobj.BASEDN); + ldifprint(ldif); + ok = samdb.add(ldif); + assert(ok); + } + + message("Importing groups\n"); + for (var i in samba3.groupmappings) { + message("Importing group '" + samba3.groupmappings[i].username + "'\n"); + var ldif = upgrade_sam_group(samba3.groupmappings[i],subobj.BASEDN); + ldifprint(ldif); + ok = samdb.add(ldif); + assert(ok); + } + + message("Importing registry data\n"); + var hives = new Array("hkcr","hkcu","hklm","hkpd"); + for (var i in hives) { + println("... " + hives[i]); + var regdb = ldb_init(); + ok = regdb.connect(hives[i] + ".ldb"); + assert(ok); + var ldif = upgrade_registry(samba3.registry, hives[i]); + ldifprint(ldif); + ok = regdb.add(ldif); + assert(ok); + } + + message("Importing WINS data\n"); + var winsdb = ldb_init(); + ok = winsdb.connect("wins.ldb"); + assert(ok); + + var ldif = upgrade_wins(samba3); + ldifprint(ldif); + ok = winsdb.add(ldif); + assert(ok); + + return ok; +} diff --git a/source4/setup/upgrade b/source4/setup/upgrade index 5d0b14bdd7..fed09f2a4e 100644 --- a/source4/setup/upgrade +++ b/source4/setup/upgrade @@ -11,7 +11,6 @@ options = GetOptions(ARGV, "POPT_COMMON_SAMBA", "POPT_COMMON_VERSION", 'ldif', - 'dn=s', 'quiet', 'blank'); if (options == undefined) { @@ -35,8 +34,8 @@ function message() function ldifprint(data) { - if (options["ldif"] != undefined) { - print data; + if (options.ldif != undefined) { + print(data); } } @@ -64,9 +63,7 @@ if (options.ARGV.length != 2) { exit(1); } -if (options.dn == undefined) { - options.dn = "dc=example,dc=org"; -} +var lp = loadparm_init(); message("Reading Samba3 databases and smb.conf\n"); var samba3 = samba3_read(options.ARGV[0], options.ARGV[1]); @@ -82,49 +79,10 @@ var smbconf = upgrade_smbconf(samba3); message("Provisioning\n"); var subobj = upgrade_provision(samba3); -provision(subobj, message, blank); - -var samdb = ldb_init(); -samdb.connect(lp.get("setup directory") + "/samdb.ldb"); - -message("Importing account policies\n"); -var ldif = upgrade_policy(samba3); -ldifprint(ldif); -samdb.modify(ldif); - -// FIXME: Enable samba3sam module if original passdb backend was ldap - -message("Importing users\n"); -for (var i in samba3.samaccounts) { - message("Importing user '" + samba3.samaccounts[i].username + "'"); - var ldif = upgrade_sam_account(samba3.samaccounts[i]); - ldifprint(ldif); - samdb.add(ldif); -} - -message("Importing groups\n"); -for (var i in samba3.groupmappings) { - message("Importing group '" + samba3.groupmappings[i].username + "'"); - var ldif = upgrade_sam_group(samba3.groupmappings[i]); - ldifprint(ldif); - samdb.add(ldif); -} - -message("Importing WINS data\n"); -var ldif = upgrade_wins(samba3) -ldifprint(ldif); -setup_ldb(ldif, "wins", Object()); - -message("Importing registry data\n"); -var hives = ["hkcr","hkcu","hklm","hkpd"]; -for (var i in hives) { - var regdb = ldb_init(); - regdb.connect(lp.get("setup directory") + "/" + hives[i] + ".ldb"); - var ldif = upgrade_registry(samba3, hives[i]); - ldifprint(ldif); - ldb.add(ldif); -} +provision(subobj, message, options.blank); +ok = upgrade(subobj,samba3,message); +assert(ok); message("All OK\n"); return 0; diff --git a/swat/install/samba3.esp b/swat/install/samba3.esp index 6fa246bb1c..59c658a47c 100644 --- a/swat/install/samba3.esp +++ b/swat/install/samba3.esp @@ -1,5 +1,11 @@ <% page_header("columns", "Upgrade", "install"); + /* frontend to Samba3 upgrade. + Based on provision.esp + (C) Jelmer Vernooij 2005 + Published under the GNU GPL + */ + include("/scripting/forms.js"); libinclude("base.js"); libinclude("provision.js"); @@ -14,24 +20,40 @@ if (form['submit'] == "Cancel") { } if (form['submit'] == "Import") { - write("LIBDIR: " + form['LIBDIR'] + "\n" + "SMBCONF: " + form['SMBCONF']); var samba3 = samba3_read(form['SMBCONF'], form['LIBDIR']); - domainname = samba3.get_param("global", "workgroup"); - var sec = samba3.find_domainsecrets(domainname); - write("<p>Import data from Samba3 installation.</p>\n"); - write("<table>\n"); - write("<tr><td>Domain name</td><td>" + domainname + "</td></tr>\n"); - write("<tr><td>Domain SID</td><td>" + sec.sid + "</td></tr>\n"); - write("<tr><td>Domain GUID</td><td>" + sec.guid + "</td></tr>\n"); - write("</table>"); + var subobj = upgrade_provision(samba3); var f = FormObj("Import from Samba3", 0, 2); + + f.add("REALM", "Realm"); + f.add("DOMAIN", "Domain Name"); + f.add("HOSTNAME", "Hostname"); + f.add("ADMINPASS", "Administrator Password", "password"); + f.add("CONFIRM", "Confirm Password", "password"); + f.add("DOMAINSID", "Domain SID"); + f.add("HOSTGUID", "Host GUID"); + f.add("BASEDN", "Base DN"); + f.add("HOSTIP", "Host IP"); + f.add("DEFAULTSITE", "Default Site"); + + for (i=0;i<f.element.length;i++) { + f.element[i].value = subobj[f.element[i].name]; + } + f.submit[0] = "Continue"; f.submit[1] = "Cancel"; f.display(); } else if (form['submit'] == "Continue") { - // FIXME + var subobj = Object(); + for (r in form) { + subobj[r] = form[r]; + } + + provision(subobj, writefln, false); + + var samba3 = samba3_read(form['SMBCONF'], form['LIBDIR']); + upgrade(subobj, samba3, writefln); } else { var f = FormObj("Import from Samba3", 0, 2); |