rem: assert(res.length == 1 && res[0].defaultNamingContext != undefined); var domain_dn = res[0].defaultNamingContext; 
add: assert(res.error == 0); assert(res.msgs.length == 1 && res.msgs[0].defaultNamingContext != undefined); var domain_dn = res.msgs[0].defaultNamingContext; 
context: function enable_account(ldb, user_dn){	var attrs = new Array("userAccountControl");	var res = ldb.search(NULL, user_dn, ldb.SCOPE_ONELEVEL, attrs);	assert(res.length == 1);	var userAccountControl = res[0].userAccountControl;	userAccountControl = userAccountControl - 2; /* remove disabled bit */	var mod = sprintf("dn: %schangetype: modifyreplace: userAccountControluserAccountControl: %u", 			  user_dn, userAccountControl);	var ok = ldb.modify(mod);	return ok;	}/*  add a new user record*/function newuser(username, unixname, password, message, session_info, credentials){	var lp = loadparm_init();	var samdb = lp.get("sam database");	var ldb = ldb_init();	random_init(local);	ldb.session_info = session_info;	ldb.credentials = credentials;	/* connect to the sam */	var ok = ldb.connect(samdb);	assert(ok);	ldb.transaction_start();	/* find the DNs for the domain and the domain users group */	var attrs = new Array("defaultNamingContext");	res = ldb.search("defaultNamingContext=*", "", ldb.SCOPE_BASE, attrs);	assert(res.length == 1 && res[0].defaultNamingContext != undefined);	var domain_dn = res[0].defaultNamingContext;	assert(domain_dn != undefined);	var dom_users = searchone(ldb, domain_dn, "name=Domain Users", "dn");	assert(dom_users != undefined);	var user_dn = sprintf("CN=%s,CN=Users,%s", username, domain_dn);	/*	  the new user record. note the reliance on the samdb module to fill	  in a sid, guid etc	*/	var ldif = sprintf("dn: %ssAMAccountName: %smemberOf: %sunixName: %ssambaPassword: %sobjectClass: user",			   user_dn, username, dom_users,			   unixname, password);	/*	  add the user to the users group as well	*/	var modgroup = sprintf("dn: %schangetype: modifyadd: membermember: %s", 			       dom_users, user_dn);	/*	  now the real work	*/	message("Adding user %s\n", user_dn);	ok = ldb.add(ldif);	if (ok != true) {		message("Failed to add %s - %s\n", user_dn, ldb.errstring());		return false;	}	message("Modifying group %s\n", dom_users);	ok = ldb.modify(modgroup);	if (ok != true) {		message("Failed to modify %s - %s\n", dom_users, ldb.errstring());		return false;	}	/*	  modify the userAccountControl to remove the disabled bit	*/	ok = enable_account(ldb, user_dn);	if (ok) {		ldb.transaction_commit();	}	return ok;}// Check whether a name is valid as a NetBIOS name. // FIXME: There are probably more constraints here. // crh has a paragraph on this in his book (1.4.1.1)function valid_netbios_name(name){	if (strlen(name) > 13) return false;	return true;}function provision_validate(subobj, message){	var lp = loadparm_init();	if (!valid_netbios_name(subobj.DOMAIN)) {		message("Invalid NetBIOS name for domain\n");		return false;	}	if (!valid_netbios_name(subobj.NETBIOSNAME)) {		message("Invalid NetBIOS name for host\n");		return false;	}	if (strupper(lp.get("workgroup")) != strupper(subobj.DOMAIN)) {		message("workgroup '%s' in smb.conf must match chosen domain '%s'\n",			lp.get("workgroup"), subobj.DOMAIN);		return false;	}	if (strupper(lp.get("realm")) != strupper(subobj.REALM)) {		message("realm '%s' in smb.conf must match chosen realm '%s'\n",			lp.get("realm"), subobj.REALM);		return false;	}	return true;}function join_domain(domain, netbios_name, join_type, creds, message) {	var ctx = NetContext(creds);	var joindom = new Object();	joindom.domain = domain;	joindom.join_type = join_type;	joindom.netbios_name = netbios_name;	if (!ctx.JoinDomain(joindom)) {		message("Domain Join failed: " + joindom.error_string);		return false;	}	return true;}/* Vampire a remote domain.  Session info and credentials are required for for * access to our local database (might be remote ldap) */ function vampire(domain, session_info, credentials, message) {	var ctx = NetContext(credentials);	var vampire_ctx = new Object();	var machine_creds = credentials_init();	machine_creds.set_domain(form.DOMAIN);	if (!machine_creds.set_machine_account()) {		message("Failed to access domain join information!");		return false;	}	vampire_ctx.machine_creds = machine_creds;	vampire_ctx.session_info = session_info;	if (!ctx.SamSyncLdb(vampire_ctx)) {		message("Migration of remote domain to Samba failed: " + vampire_ctx.error_string);		return false;	}	return true;}return 0;
meta: 5771	/local1/tlutelli/issta_data/temp/all_js/javascript/2007_temp/2007/5771/7ca399c0755e186508a4ed9796cbbbe6f50181e9/provision.js/clean/source4/scripting/libjs/provision.js