diff options
author | Simo Sorce <idra@samba.org> | 2005-07-16 18:17:08 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:29:33 -0500 |
commit | 54c30b05854e15031eb490fc5f45205329c81001 (patch) | |
tree | 5852c1f76a6dd6b8bcf0a3af89e0e47054e5590b | |
parent | cb2c43f7b032c26adf82f3ba7d6e3dc855f89fa4 (diff) | |
download | samba-54c30b05854e15031eb490fc5f45205329c81001.tar.gz samba-54c30b05854e15031eb490fc5f45205329c81001.tar.bz2 samba-54c30b05854e15031eb490fc5f45205329c81001.zip |
r8516: let us use all parameters of ldbsearch in ldb.search
(This used to be commit e709e3792846e2bd48b55112c74395d1ab3a1b6a)
-rw-r--r-- | source4/scripting/ejs/smbcalls_ldb.c | 39 |
1 files changed, 31 insertions, 8 deletions
diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c index c8c6366f2d..4151eaedab 100644 --- a/source4/scripting/ejs/smbcalls_ldb.c +++ b/source4/scripting/ejs/smbcalls_ldb.c @@ -44,22 +44,26 @@ static struct ldb_context *ejs_get_ldb_context(int eid) res = ldb.search("expression"); var attrs = new Array("attr1", "attr2", "attr3"); ldb.search("expression", attrs); + var basedn = "cn=this,dc=is,dc=a,dc=test"; + ldb.search("expression", attrs, ldb.SCOPE_SUBTREE, basedn); */ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv) { const char **attrs = NULL; const char *expression; + const char *basedn = NULL; + int scope = LDB_SCOPE_DEFAULT; TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx()); struct ldb_context *ldb; int ret; struct ldb_message **res; /* validate arguments */ - if (argc < 1 || argc > 2) { - ejsSetErrorMsg(eid, "ldb.search invalid arguments"); + if (argc < 1 || argc > 4) { + ejsSetErrorMsg(eid, "ldb.search invalid number of arguments"); goto failed; } - if (argc == 2 && argv[1]->type != MPR_TYPE_OBJECT) { + if (argc > 3 && argv[3]->type != MPR_TYPE_OBJECT) { ejsSetErrorMsg(eid, "ldb.search attributes must be an object"); goto failed; } @@ -71,14 +75,30 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv) expression = mprToString(argv[0]); if (expression == NULL) { - ejsSetErrorMsg(eid, "ldb.search invalid arguments"); + ejsSetErrorMsg(eid, "ldb.search invalid expression"); goto failed; } - if (argc == 2) { - attrs = mprToList(tmp_ctx, argv[1]); + if (argc > 1) { + basedn = mprToString(argv[1]); + /* a null basedn is valid */ } - - ret = ldb_search(ldb, NULL, LDB_SCOPE_DEFAULT, expression, attrs, &res); + if (argc > 2) { + scope = mprToInt(argv[2]); + switch (scope) { + case LDB_SCOPE_DEFAULT: + case LDB_SCOPE_BASE: + case LDB_SCOPE_ONELEVEL: + case LDB_SCOPE_SUBTREE: + break; /* ok */ + default: + ejsSetErrorMsg(eid, "ldb.search invalid scope"); + goto failed; + } + } + if (argc > 3) { + attrs = mprToList(tmp_ctx, argv[3]); + } + ret = ldb_search(ldb, basedn, scope, expression, attrs, &res); if (ret == -1) { ejsSetErrorMsg(eid, "ldb.search failed - %s", ldb_errstring(ldb)); mpr_Return(eid, mprCreateUndefinedVar()); @@ -261,6 +281,9 @@ static int ejs_ldb_init(MprVarHandle eid, int argc, struct MprVar **argv) mprSetCFunction(ldb, "modify", ejs_ldbModify); mprSetCFunction(ldb, "delete", ejs_ldbDelete); mprSetCFunction(ldb, "rename", ejs_ldbRename); + mprSetVar(ldb, "SCOPE_BASE", mprCreateNumberVar(LDB_SCOPE_BASE)); + mprSetVar(ldb, "SCOPE_ONE", mprCreateNumberVar(LDB_SCOPE_ONELEVEL)); + mprSetVar(ldb, "SCOPE_SUBTREE", mprCreateNumberVar(LDB_SCOPE_SUBTREE)); return 0; } |