rem: grp.comment, grp.nt_name, grp.sid, grp.sid_name_use); 
add: grp.comment, grp.nt_name, grp.sid, grp.unixname, grp.sid_name_use); 
context: function upgrade_registry(regdb,prefix,ldb){	assert(regdb != undefined);	var prefix_up = strupper(prefix);	var ldif = new Array();	for (var i in regdb.keys) {		var rk = regdb.keys[i];		var pts = split("/", rk.name);		/* Only handle selected hive */		if (strupper(pts[0]) != prefix_up) {			continue;		}		var keydn = regkey_to_dn(rk.name);		var pts = split("/", rk.name);		/* Convert key name to dn */		ldif[rk.name] = sprintf("dn: %sname: %s", keydn, pts[0]);				for (var j in rk.values) {			var rv = rk.values[j];			ldif[rk.name + " (" + rv.name + ")"] = sprintf("dn: %s,value=%svalue: %stype: %ddata:: %s", keydn, rv.name, rv.name, rv.type, ldb.encode(rv.data));		}	}	return ldif;}function upgrade_sam_policy(samba3,dn){	var ldif = sprintf("dn: %schangetype: modifyreplace: minPwdLengthminPwdLength: %dpwdHistoryLength: %dminPwdAge: %dmaxPwdAge: %dlockoutDuration: %dsamba3ResetCountMinutes: %dsamba3UserMustLogonToChangePassword: %dsamba3BadLockoutMinutes: %dsamba3DisconnectTime: %dsamba3RefuseMachinePwdChange: %d", dn, samba3.policy.min_password_length, 	samba3.policy.password_history, samba3.policy.minimum_password_age,	samba3.policy.maximum_password_age, samba3.policy.lockout_duration,	samba3.policy.reset_count_minutes, samba3.policy.user_must_logon_to_change_password,	samba3.policy.bad_lockout_minutes, samba3.policy.disconnect_time, 	samba3.policy.refuse_machine_password_change);	return ldif;}function upgrade_sam_account(acc,domaindn){	var ldb = ldb_init();	var ldif = sprintf("dn: cn=%s,%sobjectClass: userlastLogon: %dlastLogoff: %dunixName: %sname: %scn: %sdescription: %sprimaryGroupID: %dbadPwdcount: %dlogonCount: %dsamba3Domain: %ssamba3DirDrive: %ssamba3MungedDial: %ssamba3Homedir: %ssamba3LogonScript: %ssamba3ProfilePath: %ssamba3Workstations: %ssamba3KickOffTime: %dsamba3BadPwdTime: %dsamba3PassLastSetTime: %dsamba3PassCanChangeTime: %dsamba3PassMustChangeTime: %dsamba3Rid: %dntPwdHash:: %slmPwdHash:: %s", 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, acc.pass_last_set_time, acc.pass_can_change_time, acc.pass_must_change_time, acc.user_rid,	ldb.encode(acc.lm_pw), ldb.encode(acc.nt_pw)); 	return ldif;}function upgrade_sam_group(grp,domaindn){	var ldif = sprintf("dn: cn=%s,%sobjectClass: topobjectClass: groupdescription: %scn: %sobjectSid: %sunixName: FIXMEsamba3SidNameUse: %d", grp.nt_name, domaindn, grp.comment, grp.nt_name, grp.sid, grp.sid_name_use);	return ldif;}function upgrade_winbind(samba3,domaindn){	var ldif = sprintf("		dn: dc=noneuserHwm: %dgroupHwm: %d", samba3.idmap.user_hwm, samba3.idmap.group_hwm);	for (var i in samba3.idmap.mappings) {		var m = samba3.idmap.mappings[i];		ldif = ldif + sprintf("dn: SID=%s,%sSID: %stype: %dunixID: %d", m.sid, domaindn, m.sid, m.type, m.unix_id);	}		return ldif;}*/function upgrade_wins(samba3){	var ldif = "";	for (i in samba3.winsentries) {		var e = samba3.winsentries[i];				ldif = ldif + sprintf("dn: type=%d,name=%sname: %sobjectClass: winsnbFlags: %xexpires: %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]);		}	}	return ldif;}function upgrade_provision(samba3){	var subobj = new Object();	var nss = nss_init();	var lp = loadparm_init();	var rdn_list;	var domainname = samba3.configuration.get("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.configuration.get("realm");	if (realm == undefined) {		realm = domainname;		println("No realm specified in smb.conf file, assuming '" + realm + "'");	}	random_init(local);	subobj.REALM        = realm;	subobj.DOMAIN       = domainname;	subobj.HOSTNAME     = hostname();	assert(subobj.REALM);	assert(subobj.DOMAIN);	assert(subobj.HOSTNAME);	subobj.HOSTIP       = hostip();	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 = randsid();	}		if (hostsec) {		subobj.HOSTGUID     = hostsec.guid;	} else {		subobj.HOSTGUID = randguid();	}	subobj.INVOCATIONID = randguid();	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.DATESTRING   = datestring;	subobj.USN          = nextusn;	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");	subobj.USERS        = findnss(nss.getgrnam, "users", "guest", "other");	subobj.DNSDOMAIN    = strlower(subobj.REALM);	subobj.DNSNAME      = sprintf("%s.%s", 				      strlower(subobj.HOSTNAME), 				      subobj.DNSDOMAIN);	subobj.BASEDN       = "DC=" + join(",DC=", split(".", subobj.REALM));	rdn_list = split(".", subobj.REALM);	return subobj;}smbconf_keep = new Array(	"dos charset", 	"unix charset",	"display charset",	"comment",	"path",	"directory",	"workgroup",	"realm",	"netbios name",	"netbios aliases",	"netbios scope",	"server string",	"interfaces",	"bind interfaces only",	"security",	"auth methods",	"encrypt passwords",	"null passwords",	"obey pam restrictions",	"password server",	"smb passwd file",	"private dir",	"passwd chat",	"password level",	"lanman auth",	"ntlm auth",	"client NTLMv2 auth",	"client lanman auth",	"client plaintext auth",	"read only",	"hosts allow",	"hosts deny",	"log level",	"debuglevel",	"log file",	"smb ports",	"large readwrite",	"max protocol",	"min protocol",	"unicode",	"read raw",	"write raw",	"disable netbios",	"nt status support",	"announce version",	"announce as",	"max mux",	"max xmit",	"name resolve order",	"max wins ttl",	"min wins ttl",	"time server",	"unix extensions",	"use spnego",	"server signing",	"client signing",	"max connections",	"paranoid server security",	"socket options",	"strict sync",	"max print jobs",	"printable",	"print ok",	"printer name",	"printer",	"map system",	"map hidden",	"map archive",	"domain logons",	"preferred master",	"prefered master",	"local master",	"domain master",	"browseable",	"browsable",	"wins server",	"wins support",	"csc policy",	"strict locking",	"config file",	"preload",	"auto services",	"lock dir",	"lock directory",	"pid directory",	"socket address",	"copy",	"include",	"available",	"volume",	"fstype",	"panic action",	"msdfs root",	"host msdfs",	"winbind separator");/*   Remove configuration variables not present in Samba4	oldconf: Old configuration structure	mark: Whether removed configuration variables should be 		kept in the new configuration as "samba3:<name>" */function upgrade_smbconf(oldconf,mark){	var data = oldconf.data();	var newconf = param_init();	for (var s in data) {		for (var p in data[s]) {			var keep = false;			for (var k in smbconf_keep) { 				if (smbconf_keep[k] == p) {					keep = true;					break;				}			}			if (keep) {				newconf.set(s, p, oldconf.get(s, p));			} else if (mark) {				newconf.set(s, "samba3:"+p, oldconf.get(s,p));			}		}	}	return newconf;}function upgrade(subobj, samba3, message, paths){	var ret = 0;	var lp = loadparm_init();	var samdb = ldb_init();	var ok = samdb.connect(paths.samdb);	assert(ok);	message("Writing configuration\n");	var newconf = upgrade_smbconf(samba3.configuration,true);	newconf.save(paths.smbconf);	message("Importing account policies\n");	var ldif = upgrade_sam_policy(samba3,subobj.BASEDN);	ok = samdb.modify(ldif);	assert(ok);	message("Importing users\n");	for (var i in samba3.samaccounts) {		var msg = "... " + samba3.samaccounts[i].username;		var ldif = upgrade_sam_account(samba3.samaccounts[i],subobj.BASEDN);		ok = samdb.add(ldif);		if (!ok) { 			msg = msg + "... error: " + samdb.errstring();			ret = ret + 1; 		}		message(msg + "\n");	}	message("Importing groups\n");	for (var i in samba3.groupmappings) {		var msg = "... " + samba3.groupmappings[i].nt_name;		var ldif = upgrade_sam_group(samba3.groupmappings[i],subobj.BASEDN);		ok = samdb.add(ldif);		if (!ok) { 			msg = msg + "... error: " + samdb.errstring();			ret = ret + 1; 		}		message(msg + "\n");	}	message("Importing registry data\n");	var hives = new Array("hkcr","hkcu","hklm","hkpd","hku","hkpt"); 	for (var i in hives) {		var hn = hives[i];		message("... " + hn + "\n");		var regdb = ldb_init();		ok = regdb.connect(paths[hn]);		assert(ok);		var ldif = upgrade_registry(samba3.registry, hn, regdb);		for (var j in ldif) {			var msg = "... ... " + j;			ok = regdb.add(ldif[j]);			if (!ok) { 				msg = msg + "... error: " + regdb.errstring();				ret = ret + 1; 			}			message(msg + "\n");		}	}	message("Importing WINS data\n");	var winsdb = ldb_init();	ok = winsdb.connect(paths.winsdb);	assert(ok);	ldb_erase(winsdb);	var ldif = upgrade_wins(samba3);	ok = winsdb.add(ldif);	assert(ok);	// figure out ldapurl, if applicable	var ldapurl = undefined;	var pdb = samba3.configuration.get_list("passdb backend");	if (pdb != undefined) {		for (var b in pdb) {			if (substr(pdb[b], 0, 7) == "ldapsam") {				ldapurl = substr(pdb[b], 8);			}		}	}	// URL was not specified in passdb backend but ldap /is/ used	if (ldapurl == "") {		ldapurl = "ldap://" + samba3.configuration.get("ldap server");	}	// Enable samba3sam module if original passdb backend was ldap	if (ldapurl != undefined) {		message("Enabling Samba3 LDAP mappings for SAM database\n");		var ldif = sprintf("dn: @MAP=samba3sam@MAP_URL: %s", ldapurl);		ok = samdb.add(ldif);		assert(ok);		ok = samdb.modify("dn: @MODULESreplace: @LIST@LIST: samldb,timestamps,objectguid,rdn_name,samba3sam");		assert(ok);	}	return ret;}function upgrade_verify(subobj, samba3,paths,message){	message("Verifying account policies\n");	var samldb = ldb_init();	var ne = 0;	var ok = samldb.connect(paths.samdb);	assert(ok);		// FIXME}
meta: 1392	/local1/tlutelli/issta_data/temp/all_js/javascript/2007_temp/2007/1392/05db3024ba6a8cd0b3182595f4f6f2f1f0987e44/upgrade.js/clean/source4/scripting/libjs/upgrade.js