diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2005-08-29 18:52:24 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:34:56 -0500 |
commit | 11f3f0fa6cfb0486bdc526465dc4c0e19467a30f (patch) | |
tree | 5afbcf0b284c5af9d158166c2b6b66c3e2700933 /source4 | |
parent | 615e1c55bfd0b5e5cb2ac77b19a0c395ef566bd2 (diff) | |
download | samba-11f3f0fa6cfb0486bdc526465dc4c0e19467a30f.tar.gz samba-11f3f0fa6cfb0486bdc526465dc4c0e19467a30f.tar.bz2 samba-11f3f0fa6cfb0486bdc526465dc4c0e19467a30f.zip |
r9754: Upgrading with the command line utility now works, at least partially (-:
Upgrading using SWAT should work as well now.
(This used to be commit 8baa2ac377315ae8b365f58c2bda0bf3d0c5aec3)
Diffstat (limited to 'source4')
-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 |
4 files changed, 105 insertions, 58 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; |