diff options
Diffstat (limited to 'source4')
-rw-r--r-- | source4/lib/samba3/config.mk | 3 | ||||
-rw-r--r-- | source4/lib/samba3/upgrade.c | 280 | ||||
-rw-r--r-- | source4/scripting/ejs/smbcalls_string.c | 57 | ||||
-rw-r--r-- | source4/scripting/libjs/provision.js | 5 | ||||
-rw-r--r-- | source4/scripting/libjs/upgrade.js | 16 |
5 files changed, 66 insertions, 295 deletions
diff --git a/source4/lib/samba3/config.mk b/source4/lib/samba3/config.mk index 6a122546a5..db5d04ddaa 100644 --- a/source4/lib/samba3/config.mk +++ b/source4/lib/samba3/config.mk @@ -11,7 +11,6 @@ ADD_OBJ_FILES = \ lib/samba3/group.o \ lib/samba3/registry.o \ lib/samba3/secrets.o \ - lib/samba3/share_info.o \ - lib/samba3/upgrade.o + lib/samba3/share_info.o # End SUBSYSTEM LIBSAMBA3 ################################################ diff --git a/source4/lib/samba3/upgrade.c b/source4/lib/samba3/upgrade.c deleted file mode 100644 index 00000c68df..0000000000 --- a/source4/lib/samba3/upgrade.c +++ /dev/null @@ -1,280 +0,0 @@ -/* - Unix SMB/CIFS implementation. - Generate ldb_message 's for samba3_* - - Copyright (C) Jelmer Vernooij 2005 - - This program is free software; you can redistribute it and/or modify - it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - - This program is distributed in the hope that it will be useful, - but WITHOUT ANY WARRANTY; without even the implied warranty of - MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - GNU General Public License for more details. - - You should have received a copy of the GNU General Public License - along with this program; if not, write to the Free Software - Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -*/ - -#include "includes.h" -#include "lib/samba3/samba3.h" -#include "lib/ldb/include/ldb.h" - -static struct ldb_message *msg_array_add(struct ldb_context *ctx, struct ldb_message ***msgs, int *count) -{ - struct ldb_message *ret; - *msgs = talloc_realloc(ctx, *msgs, struct ldb_message *, (*count)+1); - - ret = (*msgs)[*count] = talloc_zero(ctx, struct ldb_message); - (*count)++; - - return ret; -} - -static struct ldb_dn *regkey_to_dn(struct ldb_context *ldb, const char *name) -{ - char *p, *n, *dup; - struct ldb_dn *ret = ldb_dn_explode(ldb, "hive=NONE"); - - p = dup = talloc_strdup(ldb, name); - - while (p) { - n = strchr(p, '/'); - if (n) { *n = '\0'; n++; } - - ret = ldb_dn_build_child(ldb, "key", p, ret); - - p = n; - } - - talloc_free(dup); - - return ret; -} - -/* Where prefix is any of: - * - HKLM - * HKU - * HKCR - * HKPD - * HKPT - */ - -int samba3_upgrade_registry(struct samba3_regdb *regdb, const char *prefix, struct ldb_context *ldb, struct ldb_message ***msgs) -{ - int i; - struct ldb_message *msg; - int count = 0; - char *prefix_up = strupper_talloc(ldb, prefix); - *msgs = NULL; - - for (i = 0; i < regdb->key_count; i++) { - int j; - struct samba3_regkey *rk = ®db->keys[i]; - struct ldb_dn *keydn; - - /* Only handle selected hive */ - if (strncmp(prefix_up, rk->name, strlen(prefix_up)) != 0) { - continue; - } - - msg = msg_array_add(ldb, msgs, &count); - - msg->num_elements = 0; - msg->elements = NULL; - msg->private_data = NULL; - - /* Convert key name to dn */ - keydn = msg->dn = regkey_to_dn(ldb, rk->name); - - ldb_msg_add_string(ldb, msg, "name", strrchr(rk->name, '/')?strrchr(rk->name, '/')+1:rk->name); - - for (j = 0; j < rk->value_count; j++) { - struct samba3_regval *rv = &rk->values[j]; - - msg = msg_array_add(ldb, msgs, &count); - msg->dn = ldb_dn_build_child(ldb, "value", rv->name, keydn); - - ldb_msg_add_string(ldb, msg, "value", rv->name); - ldb_msg_add_fmt(ldb, msg, "type", "%d", rv->type); - ldb_msg_add_value(ldb, msg, "data", &rv->data); - } - } - - talloc_free(prefix_up); - - return count; -} - -int samba3_upgrade_sam(struct samba3 *samba3, struct ldb_context *ldb, struct ldb_message ***msgs) -{ - int count = 0; - struct ldb_message *msg; - struct ldb_dn *domaindn = NULL; - const char *domainname; - struct samba3_domainsecrets *domsec; - int i; - *msgs = NULL; - - domainname = samba3_get_param(samba3, "global", "workgroup"); - - if (domainname == NULL) { - DEBUG(0, ("No domain name specified in smb.conf!\n")); - return -1; - } - - domsec = samba3_find_domainsecrets(samba3, domainname); - - /* Domain */ - msg = msg_array_add(ldb, msgs, &count); - /* FIXME: Guess domain DN by taking ldap bind dn? */ - - ldb_msg_add_string(ldb, msg, "objectClass", "top"); - ldb_msg_add_string(ldb, msg, "objectClass", "domain"); - ldb_msg_add_string(ldb, msg, "objectSid", dom_sid_string(msg, &domsec->sid)); - ldb_msg_add_string(ldb, msg, "objectGUID", GUID_string(msg, &domsec->guid)); - ldb_msg_add_string(ldb, msg, "name", domainname); - ldb_msg_add_string(ldb, msg, "oEMInformation", "Provisioned by Samba4 (upgraded from Samba3)"); - - /* account policy as well */ - - ldb_msg_add_fmt(ldb, msg, "minPwdLength", "%d", samba3->policy.min_password_length); - ldb_msg_add_fmt(ldb, msg, "pwdHistoryLength", "%d", samba3->policy.password_history); - ldb_msg_add_fmt(ldb, msg, "minPwdAge", "%d", samba3->policy.minimum_password_age); - ldb_msg_add_fmt(ldb, msg, "maxPwdAge", "%d", samba3->policy.maximum_password_age); - ldb_msg_add_fmt(ldb, msg, "lockoutDuration", "%d", samba3->policy.lockout_duration); - ldb_msg_add_fmt(ldb, msg, "samba3ResetCountMinutes", "%d", samba3->policy.reset_count_minutes); - ldb_msg_add_fmt(ldb, msg, "samba3UserMustLogonToChangePassword", "%d", samba3->policy.user_must_logon_to_change_password); - ldb_msg_add_fmt(ldb, msg, "samba3BadLockoutMinutes", "%d", samba3->policy.bad_lockout_minutes); - ldb_msg_add_fmt(ldb, msg, "samba3DisconnectTime", "%d", samba3->policy.disconnect_time); - ldb_msg_add_fmt(ldb, msg, "samba3RefuseMachinePwdChange", "%d", samba3->policy.refuse_machine_password_change); - - /* Users */ - for (i = 0; i < samba3->samaccount_count; i++) { - struct samba3_samaccount *sam = &samba3->samaccounts[i]; - - msg = msg_array_add(ldb, msgs, &count); - msg->dn = ldb_dn_build_child(msg, "cn", sam->fullname, domaindn); - - ldb_msg_add_string(ldb, msg, "objectClass", "top"); - ldb_msg_add_string(ldb, msg, "objectClass", "person"); - ldb_msg_add_string(ldb, msg, "objectClass", "user"); - ldb_msg_add_fmt(ldb, msg, "lastLogon", "%d", sam->logon_time); - ldb_msg_add_fmt(ldb, msg, "lastLogoff", "%d", sam->logoff_time); - ldb_msg_add_string(ldb, msg, "unixName", sam->username); - ldb_msg_add_string(ldb, msg, "name", sam->nt_username); - ldb_msg_add_string(ldb, msg, "cn", sam->fullname); - ldb_msg_add_string(ldb, msg, "description", sam->acct_desc); - ldb_msg_add_fmt(ldb, msg, "primaryGroupID", "%d", sam->group_rid); - ldb_msg_add_fmt(ldb, msg, "badPwdcount", "%d", sam->bad_password_count); - ldb_msg_add_fmt(ldb, msg, "logonCount", "%d", sam->logon_count); - - ldb_msg_add_string(ldb, msg, "samba3Domain", sam->domain); - if (sam->dir_drive) - ldb_msg_add_string(ldb, msg, "samba3DirDrive", sam->dir_drive); - - if (sam->munged_dial) - ldb_msg_add_string(ldb, msg, "samba3MungedDial", sam->munged_dial); - - if (sam->homedir) - ldb_msg_add_string(ldb, msg, "samba3Homedir", sam->homedir); - - if (sam->logon_script) - ldb_msg_add_string(ldb, msg, "samba3LogonScript", sam->logon_script); - - if (sam->profile_path) - ldb_msg_add_string(ldb, msg, "samba3ProfilePath", sam->profile_path); - - if (sam->workstations) - ldb_msg_add_string(ldb, msg, "samba3Workstations", sam->workstations); - - ldb_msg_add_fmt(ldb, msg, "samba3KickOffTime", "%d", sam->kickoff_time); - ldb_msg_add_fmt(ldb, msg, "samba3BadPwdTime", "%d", sam->bad_password_time); - ldb_msg_add_fmt(ldb, msg, "samba3PassLastSetTime", "%d", sam->pass_last_set_time); - ldb_msg_add_fmt(ldb, msg, "samba3PassCanChangeTime", "%d", sam->pass_can_change_time); - ldb_msg_add_fmt(ldb, msg, "samba3PassMustChangeTime", "%d", sam->pass_must_change_time); - ldb_msg_add_fmt(ldb, msg, "samba3Rid", "%d", sam->user_rid); - - /* FIXME: Passwords */ - } - - /* Groups */ - for (i = 0; i < samba3->group.groupmap_count; i++) { - struct samba3_groupmapping *grp = &samba3->group.groupmappings[i]; - - msg = msg_array_add(ldb, msgs, &count); - - if (grp->nt_name != NULL) - msg->dn = ldb_dn_build_child(msg, "cn", grp->nt_name, domaindn); - else - msg->dn = ldb_dn_build_child(msg, "cn", dom_sid_string(msg, grp->sid), domaindn); - - ldb_msg_add_string(ldb, msg, "objectClass", "top"); - ldb_msg_add_string(ldb, msg, "objectClass", "group"); - ldb_msg_add_string(ldb, msg, "description", grp->comment); - ldb_msg_add_string(ldb, msg, "cn", grp->nt_name); - ldb_msg_add_string(ldb, msg, "objectSid", dom_sid_string(msg, grp->sid)); - ldb_msg_add_string(ldb, msg, "unixName", "FIXME"); - ldb_msg_add_fmt(ldb, msg, "samba3SidNameUse", "%d", grp->sid_name_use); - } - - return count; -} - -int samba3_upgrade_winbind(struct samba3 *samba3, struct ldb_context *ldb, struct ldb_message ***msgs) -{ - int i; - int count = 0; - struct ldb_message *msg; - struct ldb_dn *basedn = NULL; - *msgs = NULL; - - msg = msg_array_add(ldb, msgs, &count); - - msg->dn = basedn; - - ldb_msg_add_fmt(ldb, msg, "userHwm", "%d", samba3->idmap.user_hwm); - ldb_msg_add_fmt(ldb, msg, "groupHwm", "%d", samba3->idmap.group_hwm); - - for (i = 0; i < samba3->idmap.mapping_count; i++) { - char *sid = dom_sid_string(msg, samba3->idmap.mappings[i].sid); - msg = msg_array_add(ldb, msgs, &count); - - msg->dn = ldb_dn_build_child(ldb, "SID", sid, basedn); - ldb_msg_add_string(ldb, msg, "SID", sid); - ldb_msg_add_fmt(ldb, msg, "type", "%d", samba3->idmap.mappings[i].type); - ldb_msg_add_fmt(ldb, msg, "unixID", "%u", samba3->idmap.mappings[i].unix_id); - } - - return count; -} - -int samba3_upgrade_winsdb(struct samba3 *samba3, struct ldb_context *ldb, struct ldb_message ***msgs) -{ - int i; - int count = 0; - - for (i = 0; i < samba3->winsdb_count; i++) { - struct samba3_winsdb_entry *e = &samba3->winsdb_entries[i]; - int j; - struct ldb_message *msg = msg_array_add(ldb, msgs, &count); - - msg->dn = ldb_dn_string_compose(ldb, NULL, "type=%d,name=%s", e->type, e->name); - - ldb_msg_add_string(ldb, msg, "name", e->name); - ldb_msg_add_fmt(ldb, msg, "type", "%d", e->type); - ldb_msg_add_string(ldb, msg, "objectClass", "wins"); - ldb_msg_add_fmt(ldb, msg, "nbFlags", "%x", e->nb_flags); - ldb_msg_add_string(ldb, msg, "expires", - ldap_timestring(msg, e->ttl)); - - for (j = 0; j < e->ip_count; j++) { - ldb_msg_add_string(ldb, msg, "address", sys_inet_ntoa(e->ips[j])); - } - } - - return count; -} diff --git a/source4/scripting/ejs/smbcalls_string.c b/source4/scripting/ejs/smbcalls_string.c index 1b6b7d09dd..e127cdf8af 100644 --- a/source4/scripting/ejs/smbcalls_string.c +++ b/source4/scripting/ejs/smbcalls_string.c @@ -4,6 +4,7 @@ provide access to string functions Copyright (C) Andrew Tridgell 2005 + Copyright (C) Jelmer Vernooij 2005 (substr) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -124,6 +125,61 @@ static int ejs_split(MprVarHandle eid, int argc, char **argv) return 0; } +/* + usage: + str = substr(orig[, start_offset[, length]]); + + special cases: + if start_offset < 0 then start_offset+=strlen(orig) + if length < 0 then length+=strlen(orig)-start_offset + + (as found in many other languages) +*/ +static int ejs_substr(MprVarHandle eid, int argc, struct MprVar **argv) +{ + int start_offset = 0; + int length = 0; + const char *orig; + char *target; + + if (argc < 1 || argc > 3 || + argv[0]->type != MPR_TYPE_STRING) { + ejsSetErrorMsg(eid, "substr invalid arguments"); + return -1; + } + + if (argc == 1) { + mpr_Return(eid, *argv[0]); + return 0; + } + + orig = mprToString(argv[0]); + start_offset = mprToInt(argv[1]); + if (start_offset < 0) start_offset += strlen(orig); + if (start_offset < 0 || start_offset > strlen(orig)) { + ejsSetErrorMsg(eid, "substr arg 2 out of bounds"); + return -1; + } + + if (argc == 3) { + length = mprToInt(argv[1]); + if (length < 0) length += strlen(orig) - start_offset; + if (length < 0 || length+start_offset > strlen(orig)) { + ejsSetErrorMsg(eid, "substr arg 3 out of bounds"); + return -1; + } + } else { + length = strlen(orig); + } + + target = talloc_strndup(mprMemCtx(), orig+start_offset, length); + + mpr_Return(eid, mprString(target)); + + talloc_free(target); + + return 0; +} /* usage: @@ -421,6 +477,7 @@ static int ejs_string_init(MprVarHandle eid, int argc, struct MprVar **argv) { struct MprVar *obj = mprInitObject(eid, "string", argc, argv); + mprSetCFunction(obj, "substr", ejs_substr); mprSetStringCFunction(obj, "strlen", ejs_strlen); mprSetStringCFunction(obj, "strlower", ejs_strlower); mprSetStringCFunction(obj, "strupper", ejs_strupper); diff --git a/source4/scripting/libjs/provision.js b/source4/scripting/libjs/provision.js index e166f3101f..b43d435ca9 100644 --- a/source4/scripting/libjs/provision.js +++ b/source4/scripting/libjs/provision.js @@ -217,6 +217,8 @@ function provision(subobj, message, blank) subobj.HOSTNAME = strlower(subobj.HOSTNAME); subobj.DOMAIN = strupper(subobj.DOMAIN); subobj.NETBIOSNAME = strupper(subobj.HOSTNAME); + var rdns = split(",", subobj.BASEDN); + subobj.RDN_DC = substr(rdns[0], strlen("DC=")); data = add_foreign(data, "S-1-5-7", "Anonymous", "${NOBODY}"); data = add_foreign(data, "S-1-1-0", "World", "${NOGROUP}"); @@ -297,9 +299,8 @@ function provision_guess() subobj.DNSNAME = sprintf("%s.%s", strlower(subobj.HOSTNAME), subobj.DNSDOMAIN); - subobj.BASEDN = "DC=" + join(",DC=", split(".", subobj.REALM)); rdn_list = split(".", subobj.REALM); - subobj.RDN_DC = rdn_list[0]; + subobj.BASEDN = "DC=" + join(",DC=", rdn_list); return subobj; } diff --git a/source4/scripting/libjs/upgrade.js b/source4/scripting/libjs/upgrade.js index c8539c9fcb..682721e931 100644 --- a/source4/scripting/libjs/upgrade.js +++ b/source4/scripting/libjs/upgrade.js @@ -241,7 +241,7 @@ function upgrade_provision(samba3) } else { println("Can't find domain secrets for '" + domainname + "'; using random SID and GUID"); subobj.DOMAINGUID = randguid(); - subobj.DOMAINSID = randguid(); + subobj.DOMAINSID = randsid(); } if (hostsec) { @@ -270,7 +270,6 @@ function upgrade_provision(samba3) subobj.DNSDOMAIN); subobj.BASEDN = "DC=" + join(",DC=", split(".", subobj.REALM)); rdn_list = split(".", subobj.REALM); - subobj.RDN_DC = rdn_list[0]; return subobj; } @@ -403,7 +402,6 @@ function upgrade(subobj, samba3, message) message("Importing account policies\n"); var ldif = upgrade_sam_policy(samba3,subobj.BASEDN); - ldifprint(ldif); ok = samdb.modify(ldif); assert(ok); @@ -411,31 +409,28 @@ function upgrade(subobj, samba3, message) message("Importing users\n"); for (var i in samba3.samaccounts) { - message("Importing user '" + samba3.samaccounts[i].username + "'\n"); + message("... " + 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"); + message("... " + samba3.groupmappings[i].nt_name + "\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"); + var hives = new Array("hkcr","hkcu","hklm","hkpd","hku","hkpt"); for (var i in hives) { - println("... " + hives[i]); + message("... " + hives[i] + "\n"); 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); } @@ -446,7 +441,6 @@ function upgrade(subobj, samba3, message) assert(ok); var ldif = upgrade_wins(samba3); - ldifprint(ldif); ok = winsdb.add(ldif); assert(ok); |