summaryrefslogtreecommitdiff
path: root/source4/scripting
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting')
-rw-r--r--source4/scripting/ejs/smbcalls_string.c57
-rw-r--r--source4/scripting/libjs/provision.js5
-rw-r--r--source4/scripting/libjs/upgrade.js16
3 files changed, 65 insertions, 13 deletions
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);