summaryrefslogtreecommitdiff
path: root/source4/scripting/ejs
diff options
context:
space:
mode:
Diffstat (limited to 'source4/scripting/ejs')
-rw-r--r--source4/scripting/ejs/mprutil.c31
-rw-r--r--source4/scripting/ejs/smbcalls.h1
-rw-r--r--source4/scripting/ejs/smbcalls_ldb.c10
3 files changed, 28 insertions, 14 deletions
diff --git a/source4/scripting/ejs/mprutil.c b/source4/scripting/ejs/mprutil.c
index cfed69dbe0..459f198dca 100644
--- a/source4/scripting/ejs/mprutil.c
+++ b/source4/scripting/ejs/mprutil.c
@@ -223,19 +223,32 @@ failed:
/*
- turn an array of ldb_messages into a ejs object variable
+ build a MprVar result object for ldb operations with lots of funky properties
*/
-struct MprVar mprLdbArray(struct ldb_context *ldb,
- struct ldb_message **msg, int count, const char *name)
+struct MprVar mprLdbResult(struct ldb_context *ldb, int err, struct ldb_result *result)
{
- struct MprVar res;
- int i;
+ struct MprVar ret;
+ struct MprVar ary;
+
+ ret = mprObject("ldbret");
+
+ mprSetVar(&ret, "error", mprCreateIntegerVar(err));
+ mprSetVar(&ret, "errstr", mprString(ldb_errstring(ldb)));
+
+ ary = mprArray("ldb_message");
+ if (result) {
+ int i;
- res = mprArray(name);
- for (i=0;i<count;i++) {
- mprAddArray(&res, i, mprLdbMessage(ldb, msg[i]));
+ for (i = 0; i < result->count; i++) {
+ mprAddArray(&ary, i, mprLdbMessage(ldb, result->msgs[i]));
+ }
}
- return res;
+
+ mprSetVar(&ret, "msgs", ary);
+
+ /* TODO: add referrals, exteded ops, and controls */
+
+ return ret;
}
diff --git a/source4/scripting/ejs/smbcalls.h b/source4/scripting/ejs/smbcalls.h
index 9fa9100276..a525403493 100644
--- a/source4/scripting/ejs/smbcalls.h
+++ b/source4/scripting/ejs/smbcalls.h
@@ -21,6 +21,7 @@
*/
#include "lib/appweb/ejs/ejs.h"
+#include "lib/ldb/include/ldb.h"
void mpr_Return(int eid, struct MprVar);
NTSTATUS mprSetVar(struct MprVar *v, const char *name, struct MprVar val);
diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c
index 3c368bba4f..fc44862985 100644
--- a/source4/scripting/ejs/smbcalls_ldb.c
+++ b/source4/scripting/ejs/smbcalls_ldb.c
@@ -108,9 +108,9 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv)
ret = ldb_search(ldb, basedn, scope, expression, attrs, &res);
if (ret != LDB_SUCCESS) {
ejsSetErrorMsg(eid, "ldb.search failed - %s", ldb_errstring(ldb));
- mpr_Return(eid, mprCreateUndefinedVar());
+ mpr_Return(eid, mprLdbResult(ldb, ret, NULL));
} else {
- mpr_Return(eid, mprLdbArray(ldb, res->msgs, res->count, "ldb_message"));
+ mpr_Return(eid, mprLdbResult(ldb, ret, res));
talloc_free(res);
}
talloc_free(tmp_ctx);
@@ -161,7 +161,7 @@ static int ejs_ldbAddModify(MprVarHandle eid, int argc, struct MprVar **argv,
return -1;
}
- mpr_Return(eid, mprCreateBoolVar(ret == 0));
+ mpr_Return(eid, mprLdbResult(ldb, ret, NULL));
return 0;
}
@@ -197,7 +197,7 @@ static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv)
talloc_free(dn);
- mpr_Return(eid, mprCreateBoolVar(ret == 0));
+ mpr_Return(eid, mprLdbResult(ldb, ret, NULL));
return 0;
}
@@ -234,7 +234,7 @@ static int ejs_ldbRename(MprVarHandle eid, int argc, struct MprVar **argv)
talloc_free(dn1);
talloc_free(dn2);
- mpr_Return(eid, mprCreateBoolVar(ret == 0));
+ mpr_Return(eid, mprLdbResult(ldb, ret, NULL));
return 0;
}