diff options
author | Andrew Bartlett <abartlet@samba.org> | 2007-02-22 01:54:40 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 14:48:44 -0500 |
commit | 7dc7156bd76425df129102a42dd29a85fd8c7ebc (patch) | |
tree | 2da9bd209f1cd6f102a48b26094f838860e7e181 /source4/scripting | |
parent | 81adf162a80b6b0c6c24d40f783ddcd1c9813532 (diff) | |
download | samba-7dc7156bd76425df129102a42dd29a85fd8c7ebc.tar.gz samba-7dc7156bd76425df129102a42dd29a85fd8c7ebc.tar.bz2 samba-7dc7156bd76425df129102a42dd29a85fd8c7ebc.zip |
r21496: A number of ldb control and LDAP changes, surrounding the
'phantom_root' flag in the search_options control
- Add in support for LDB controls to the js layer
- Test the behaviour
- Implement support for the 'phantom_root' flag in the partitions module
- Make the LDAP server set the 'phantom_root' flag in the search_options control
- This replaces the global_catalog flag passed down as an opaque pointer
- Rework the string-format control parsing function into
ldb_parse_control_strings(), returning errors by ldb_errorstring()
method, rather than with printf to stderr
- Rework some of the ldb_control handling logic
Andrew Bartlett
(This used to be commit 2b3df7f38d7790358dbb4de1b8609bf794a351fb)
Diffstat (limited to 'source4/scripting')
-rw-r--r-- | source4/scripting/ejs/smbcalls_ldb.c | 48 |
1 files changed, 45 insertions, 3 deletions
diff --git a/source4/scripting/ejs/smbcalls_ldb.c b/source4/scripting/ejs/smbcalls_ldb.c index fc44862985..3f970cea58 100644 --- a/source4/scripting/ejs/smbcalls_ldb.c +++ b/source4/scripting/ejs/smbcalls_ldb.c @@ -49,6 +49,7 @@ static struct ldb_context *ejs_get_ldb_context(int eid) ldb.search("expression", attrs); var basedn = "cn=this,dc=is,dc=a,dc=test"; ldb.search("expression", basedn, ldb.SCOPE_SUBTREE, attrs); + ldb.search("expression", basedn, ldb.SCOPE_SUBTREE, attrs, controls); */ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv) { @@ -60,10 +61,12 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv) TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx()); struct ldb_context *ldb; int ret; + struct ldb_control **parsed_controls = NULL; struct ldb_result *res=NULL; + struct ldb_request *req; /* validate arguments */ - if (argc < 1 || argc > 4) { + if (argc < 1 || argc > 5) { ejsSetErrorMsg(eid, "ldb.search invalid number of arguments"); goto failed; } @@ -88,6 +91,8 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv) ejsSetErrorMsg(eid, "ldb.search malformed base dn"); goto failed; } + } else { + basedn = ldb_get_default_basedn(ldb); } if (argc > 2) { scope = mprToInt(argv[2]); @@ -105,14 +110,51 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv) if (argc > 3) { attrs = mprToList(tmp_ctx, argv[3]); } - ret = ldb_search(ldb, basedn, scope, expression, attrs, &res); + if (argc > 4) { + const char **controls; + controls = mprToList(tmp_ctx, argv[4]); + if (controls) { + parsed_controls = ldb_parse_control_strings(ldb, tmp_ctx, controls); + if (!parsed_controls) { + ejsSetErrorMsg(eid, "ldb.search cannot parse controls: %s", + ldb_errstring(ldb)); + goto failed; + } + } + } + + res = talloc_zero(tmp_ctx, struct ldb_result); + if (!res) { + return LDB_ERR_OPERATIONS_ERROR; + } + + ret = ldb_build_search_req(&req, ldb, tmp_ctx, + basedn, + scope, + expression, + attrs, + parsed_controls, + res, + ldb_search_default_callback); + + if (ret == LDB_SUCCESS) { + + ldb_set_timeout(ldb, req, 0); /* use default timeout */ + + ret = ldb_request(ldb, req); + + if (ret == LDB_SUCCESS) { + ret = ldb_wait(req->handle, LDB_WAIT_ALL); + } + } + if (ret != LDB_SUCCESS) { ejsSetErrorMsg(eid, "ldb.search failed - %s", ldb_errstring(ldb)); mpr_Return(eid, mprLdbResult(ldb, ret, NULL)); } else { mpr_Return(eid, mprLdbResult(ldb, ret, res)); - talloc_free(res); } + talloc_free(tmp_ctx); return 0; |