summaryrefslogtreecommitdiff
path: root/source4/scripting/ejs
diff options
context:
space:
mode:
authorSimo Sorce <idra@samba.org>2005-08-18 15:02:01 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:33:32 -0500
commit3e4c4cff2177af33efdb15f03a1bbcb639505cee (patch)
tree852723e443ca41ef6b1d91dd3c11224eddebbd48 /source4/scripting/ejs
parenta8d51f87620a688a286603766cbb7edb2b7c6e60 (diff)
downloadsamba-3e4c4cff2177af33efdb15f03a1bbcb639505cee.tar.gz
samba-3e4c4cff2177af33efdb15f03a1bbcb639505cee.tar.bz2
samba-3e4c4cff2177af33efdb15f03a1bbcb639505cee.zip
r9391: Convert all the code to use struct ldb_dn to ohandle ldap like distinguished names
Provide more functions to handle DNs in this form (This used to be commit 692e35b7797e39533dd2a1c4b63d9da30f1eb5ba)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r--source4/scripting/ejs/mprutil.c4
-rw-r--r--source4/scripting/ejs/smbcalls_ldb.c42
2 files changed, 32 insertions, 14 deletions
diff --git a/source4/scripting/ejs/mprutil.c b/source4/scripting/ejs/mprutil.c
index 700185f07e..8f1e5f71c8 100644
--- a/source4/scripting/ejs/mprutil.c
+++ b/source4/scripting/ejs/mprutil.c
@@ -161,7 +161,7 @@ static struct MprVar mprLdbMessage(struct ldb_context *ldb, struct ldb_message *
const char *multivalued[] = { "objectClass", "memberOf", "privilege",
"member", NULL };
- var = mprObject(msg->dn);
+ var = mprObject(ldb_dn_linearize(msg, msg->dn));
for (i=0;i<msg->num_elements;i++) {
struct ldb_message_element *el = &msg->elements[i];
@@ -196,7 +196,7 @@ static struct MprVar mprLdbMessage(struct ldb_context *ldb, struct ldb_message *
/* add the dn if it is not already specified */
if (mprGetProperty(&var, "dn", 0) == 0) {
- mprSetVar(&var, "dn", mprString(msg->dn));
+ mprSetVar(&var, "dn", mprString(ldb_dn_linearize(msg, msg->dn)));
}
return var;
diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c
index 50ba6fce68..7d268d09f6 100644
--- a/source4/scripting/ejs/smbcalls_ldb.c
+++ b/source4/scripting/ejs/smbcalls_ldb.c
@@ -51,7 +51,8 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv)
{
const char **attrs = NULL;
const char *expression;
- const char *basedn = NULL;
+ const char *base = NULL;
+ struct ldb_dn *basedn = NULL;
int scope = LDB_SCOPE_DEFAULT;
TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx());
struct ldb_context *ldb;
@@ -79,9 +80,16 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv)
goto failed;
}
if (argc > 1) {
- basedn = mprToString(argv[1]);
+ base = mprToString(argv[1]);
/* a null basedn is valid */
}
+ if (base != NULL) {
+ basedn = ldb_dn_explode(tmp_ctx, base);
+ if (basedn == NULL) {
+ ejsSetErrorMsg(eid, "ldb.search malformed base dn");
+ goto failed;
+ }
+ }
if (argc > 2) {
scope = mprToInt(argv[2]);
switch (scope) {
@@ -160,7 +168,7 @@ static int ejs_ldbAddModify(MprVarHandle eid, int argc, struct MprVar **argv,
*/
static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv)
{
- const char *dn;
+ struct ldb_dn *dn;
struct ldb_context *ldb;
int ret;
@@ -169,14 +177,21 @@ static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv)
return -1;
}
- dn = mprToString(argv[0]);
-
ldb = ejs_get_ldb_context(eid);
if (ldb == NULL) {
return -1;
}
+
+ dn = ldb_dn_explode(ldb, mprToString(argv[0]));
+ if (dn == NULL) {
+ ejsSetErrorMsg(eid, "ldb.delete malformed dn");
+ return -1;
+ }
+
ret = ldb_delete(ldb, dn);
+ talloc_free(dn);
+
mpr_Return(eid, mprCreateBoolVar(ret == 0));
return 0;
}
@@ -188,7 +203,7 @@ static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv)
*/
static int ejs_ldbRename(MprVarHandle eid, int argc, struct MprVar **argv)
{
- const char *dn1, *dn2;
+ struct ldb_dn *dn1, *dn2;
struct ldb_context *ldb;
int ret;
@@ -197,20 +212,23 @@ static int ejs_ldbRename(MprVarHandle eid, int argc, struct MprVar **argv)
return -1;
}
- dn1 = mprToString(argv[0]);
- dn2 = mprToString(argv[1]);
- if (dn1 == NULL || dn2 == NULL) {
- ejsSetErrorMsg(eid, "ldb.rename invalid arguments");
+ ldb = ejs_get_ldb_context(eid);
+ if (ldb == NULL) {
return -1;
}
- ldb = ejs_get_ldb_context(eid);
- if (ldb == NULL) {
+ dn1 = ldb_dn_explode(ldb, mprToString(argv[0]));
+ dn2 = ldb_dn_explode(ldb, mprToString(argv[1]));
+ if (dn1 == NULL || dn2 == NULL) {
+ ejsSetErrorMsg(eid, "ldb.rename invalid or malformed arguments");
return -1;
}
ret = ldb_rename(ldb, dn1, dn2);
+ talloc_free(dn1);
+ talloc_free(dn2);
+
mpr_Return(eid, mprCreateBoolVar(ret == 0));
return 0;
}