summaryrefslogtreecommitdiff
path: root/source4/scripting/ejs
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-07-21 01:56:22 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:29:50 -0500
commit7a8ac7588720ebd1ea61a539ca4040d322c4fcf2 (patch)
tree831472476edd430a115d11fadf6bcb6b3573b2a1 /source4/scripting/ejs
parent4327a3f1ba274d111ec4ffe4989abc879803a714 (diff)
downloadsamba-7a8ac7588720ebd1ea61a539ca4040d322c4fcf2.tar.gz
samba-7a8ac7588720ebd1ea61a539ca4040d322c4fcf2.tar.bz2
samba-7a8ac7588720ebd1ea61a539ca4040d322c4fcf2.zip
r8659: return ldif formatted attributes in the ejs ldb search call, so sids show up as strings
not binary blobs (This used to be commit d2c29a5a51f68cabb9ef587376bf0a6b936cdd76)
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r--source4/scripting/ejs/mprutil.c30
-rw-r--r--source4/scripting/ejs/smbcalls_ldb.c2
2 files changed, 24 insertions, 8 deletions
diff --git a/source4/scripting/ejs/mprutil.c b/source4/scripting/ejs/mprutil.c
index 14d120c45a..99eff80276 100644
--- a/source4/scripting/ejs/mprutil.c
+++ b/source4/scripting/ejs/mprutil.c
@@ -151,7 +151,7 @@ struct MprVar mprData(const uint8_t *p, size_t length)
/*
turn a ldb_message into a ejs object variable
*/
-struct MprVar mprLdbMessage(struct ldb_message *msg)
+static struct MprVar mprLdbMessage(struct ldb_context *ldb, struct ldb_message *msg)
{
struct MprVar var;
int i;
@@ -166,16 +166,29 @@ struct MprVar mprLdbMessage(struct ldb_message *msg)
for (i=0;i<msg->num_elements;i++) {
struct ldb_message_element *el = &msg->elements[i];
struct MprVar val;
+ const struct ldb_attrib_handler *attr;
+ struct ldb_val v;
+
+ attr = ldb_attrib_handler(ldb, el->name);
+ if (attr == NULL) {
+ goto failed;
+ }
+
if (el->num_values == 1 &&
!str_list_check_ci(multivalued, el->name)) {
- val = mprData(el->values[0].data, el->values[0].length);
+ if (attr->ldif_write_fn(ldb, msg, &el->values[0], &v) != 0) {
+ goto failed;
+ }
+ val = mprData(v.data, v.length);
} else {
int j;
val = mprObject(el->name);
for (j=0;j<el->num_values;j++) {
- mprAddArray(&val, j,
- mprData(el->values[j].data,
- el->values[j].length));
+ if (attr->ldif_write_fn(ldb, msg,
+ &el->values[j], &v) != 0) {
+ goto failed;
+ }
+ mprAddArray(&val, j, mprData(v.data, v.length));
}
}
mprSetVar(&var, el->name, val);
@@ -187,20 +200,23 @@ struct MprVar mprLdbMessage(struct ldb_message *msg)
}
return var;
+failed:
+ return mprCreateUndefinedVar();
}
/*
turn an array of ldb_messages into a ejs object variable
*/
-struct MprVar mprLdbArray(struct ldb_message **msg, int count, const char *name)
+struct MprVar mprLdbArray(struct ldb_context *ldb,
+ struct ldb_message **msg, int count, const char *name)
{
struct MprVar res;
int i;
res = mprObject(name);
for (i=0;i<count;i++) {
- mprAddArray(&res, i, mprLdbMessage(msg[i]));
+ mprAddArray(&res, i, mprLdbMessage(ldb, msg[i]));
}
if (i==0) {
mprSetVar(&res, "length", mprCreateIntegerVar(0));
diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c
index f09039731f..50ba6fce68 100644
--- a/source4/scripting/ejs/smbcalls_ldb.c
+++ b/source4/scripting/ejs/smbcalls_ldb.c
@@ -103,7 +103,7 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv)
ejsSetErrorMsg(eid, "ldb.search failed - %s", ldb_errstring(ldb));
mpr_Return(eid, mprCreateUndefinedVar());
} else {
- mpr_Return(eid, mprLdbArray(res, ret, "ldb_message"));
+ mpr_Return(eid, mprLdbArray(ldb, res, ret, "ldb_message"));
}
talloc_free(tmp_ctx);