summaryrefslogtreecommitdiff
path: root/source4
diff options
context:
space:
mode:
Diffstat (limited to 'source4')
-rw-r--r--source4/lib/ldb/include/ldb.h3
-rw-r--r--source4/lib/ldb/include/ldb_private.h3
-rw-r--r--source4/scripting/ejs/mprutil.c30
-rw-r--r--source4/scripting/ejs/smbcalls_ldb.c2
4 files changed, 27 insertions, 11 deletions
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index 6670089902..7399b8ffe7 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -440,4 +440,7 @@ int ldb_set_debug_stderr(struct ldb_context *ldb);
int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value);
void *ldb_get_opaque(struct ldb_context *ldb, const char *name);
+const struct ldb_attrib_handler *ldb_attrib_handler(struct ldb_context *ldb,
+ const char *attrib);
+
#endif
diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h
index da813eb588..0abf056db4 100644
--- a/source4/lib/ldb/include/ldb_private.h
+++ b/source4/lib/ldb/include/ldb_private.h
@@ -172,9 +172,6 @@ int lsqlite3_connect(struct ldb_context *ldb,
struct ldb_module *timestamps_module_init(struct ldb_context *ldb, const char *options[]);
struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *options[]);
-const struct ldb_attrib_handler *ldb_attrib_handler(struct ldb_context *ldb,
- const char *attrib);
-
int ldb_match_msg(struct ldb_context *ldb,
struct ldb_message *msg,
struct ldb_parse_tree *tree,
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);