mirror of
https://github.com/samba-team/samba.git
synced 2024-12-23 17:34:34 +03:00
r8481: switched ldb ejs called over to an OO interface, so you do:
var ldb = ldb_init();
res = ldb.search(dbfile, "(objectClass=user)");
you can also do:
ldbSearch = ldb.search;
res = ldbSearch(dbfile, "(objectClass=user)");
if you want the old interface (ie. you can use this to import
functions into the global or local namespace).
(This used to be commit 3093057d97
)
This commit is contained in:
parent
970ff9ba8d
commit
63535f566e
@ -367,3 +367,18 @@ void mpr_ReturnString(int eid, const char *s)
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
set a C function in a variable
|
||||
*/
|
||||
void mprSetCFunction(struct MprVar *obj, const char *name, MprCFunction fn)
|
||||
{
|
||||
mprSetVar(obj, name, mprCreateCFunctionVar(fn, NULL, MPR_VAR_SCRIPT_HANDLE));
|
||||
}
|
||||
|
||||
/*
|
||||
set a string C function in a variable
|
||||
*/
|
||||
void mprSetStringCFunction(struct MprVar *obj, const char *name, MprStringCFunction fn)
|
||||
{
|
||||
mprSetVar(obj, name, mprCreateStringCFunctionVar(fn, NULL, MPR_VAR_SCRIPT_HANDLE));
|
||||
}
|
||||
|
@ -26,3 +26,6 @@ void mpr_Return(int eid, struct MprVar);
|
||||
NTSTATUS mprSetVar(struct MprVar *v, const char *name, struct MprVar val);
|
||||
NTSTATUS mprGetVar(struct MprVar **v, const char *name);
|
||||
void mprAddArray(struct MprVar *var, int i, struct MprVar v);
|
||||
void mprSetCFunction(struct MprVar *obj, const char *name, MprCFunction fn);
|
||||
void mprSetStringCFunction(struct MprVar *obj, const char *name, MprStringCFunction fn);
|
||||
|
||||
|
@ -222,6 +222,22 @@ static int ejs_ldbModify(MprVarHandle eid, int argc, char **argv)
|
||||
return ejs_ldbAddModify(eid, argc, argv, ldb_modify);
|
||||
}
|
||||
|
||||
/*
|
||||
initialise ldb ejs subsystem
|
||||
*/
|
||||
static int ejs_ldb_init(MprVarHandle eid, int argc, struct MprVar **argv)
|
||||
{
|
||||
struct MprVar ldb = mprObject("ldb");
|
||||
|
||||
mprSetCFunction(&ldb, "search", ejs_ldbSearch);
|
||||
mprSetStringCFunction(&ldb, "add", ejs_ldbAdd);
|
||||
mprSetStringCFunction(&ldb, "modify", ejs_ldbModify);
|
||||
mprSetStringCFunction(&ldb, "delete", ejs_ldbDelete);
|
||||
mprSetStringCFunction(&ldb, "rename", ejs_ldbRename);
|
||||
|
||||
mpr_Return(eid, ldb);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
@ -229,9 +245,5 @@ static int ejs_ldbModify(MprVarHandle eid, int argc, char **argv)
|
||||
*/
|
||||
void smb_setup_ejs_ldb(void)
|
||||
{
|
||||
ejsDefineCFunction(-1, "ldbSearch", ejs_ldbSearch, NULL, MPR_VAR_SCRIPT_HANDLE);
|
||||
ejsDefineStringCFunction(-1, "ldbAdd", ejs_ldbAdd, NULL, MPR_VAR_SCRIPT_HANDLE);
|
||||
ejsDefineStringCFunction(-1, "ldbModify", ejs_ldbModify, NULL, MPR_VAR_SCRIPT_HANDLE);
|
||||
ejsDefineStringCFunction(-1, "ldbDelete", ejs_ldbDelete, NULL, MPR_VAR_SCRIPT_HANDLE);
|
||||
ejsDefineStringCFunction(-1, "ldbRename", ejs_ldbRename, NULL, MPR_VAR_SCRIPT_HANDLE);
|
||||
ejsDefineCFunction(-1, "ldb_init", ejs_ldb_init, NULL, MPR_VAR_SCRIPT_HANDLE);
|
||||
}
|
||||
|
@ -114,6 +114,8 @@ function hostname()
|
||||
function setup_ldb(ldif, dbname, subobj)
|
||||
{
|
||||
var extra = "";
|
||||
var ldb = ldb_init();
|
||||
|
||||
if (arguments.length == 4) {
|
||||
extra = arguments[3];
|
||||
}
|
||||
@ -127,7 +129,7 @@ function setup_ldb(ldif, dbname, subobj)
|
||||
data = data + extra;
|
||||
data = substitute_var(data, subobj);
|
||||
|
||||
ok = ldbAdd(db, data);
|
||||
ok = ldb.add(db, data);
|
||||
assert(ok);
|
||||
}
|
||||
|
||||
|
@ -7,8 +7,9 @@
|
||||
<%
|
||||
var dbfile = lpGet("sam database");
|
||||
var attrs = new Array("name", "dnsDomain", "objectSid", "dn");
|
||||
var ldb = ldb_init();
|
||||
|
||||
res = ldbSearch(dbfile, "(objectClass=domain)", attrs);
|
||||
res = ldb.search(dbfile, "(objectClass=domain)", attrs);
|
||||
multi_table(res, "dn");
|
||||
%>
|
||||
|
||||
@ -17,14 +18,14 @@ multi_table(res, "dn");
|
||||
<%
|
||||
var dbfile = lpGet("sam database");
|
||||
|
||||
res = ldbSearch(dbfile, "(objectClass=user)");
|
||||
res = ldb.search(dbfile, "(objectClass=user)");
|
||||
multi_table(res, "dn");
|
||||
%>
|
||||
|
||||
<h3>A search with bad arguments</h3>
|
||||
|
||||
<%
|
||||
res = ldbSearch("foo");
|
||||
res = ldb.search("foo");
|
||||
%>
|
||||
|
||||
all done
|
||||
|
@ -6,19 +6,20 @@ println("Trying a attribute constrained search on samdb");
|
||||
|
||||
var dbfile = lpGet("sam database");
|
||||
var attrs = new Array("name", "dnsDomain", "objectSid", "dn");
|
||||
var ldb = ldb_init();
|
||||
|
||||
res = ldbSearch(dbfile, "(objectClass=domain)", attrs);
|
||||
res = ldb.search(dbfile, "(objectClass=domain)", attrs);
|
||||
|
||||
printVars(res);
|
||||
|
||||
println("and now an unconstrained search");
|
||||
|
||||
var dbfile = lpGet("sam database");
|
||||
res = ldbSearch(dbfile, "(objectClass=user)");
|
||||
res = ldb.search(dbfile, "(objectClass=user)");
|
||||
printVars(res);
|
||||
|
||||
println("and a bad search");
|
||||
|
||||
res = ldbSearch("foo");
|
||||
res = ldb.search("foo");
|
||||
|
||||
println("all done");
|
||||
|
Loading…
Reference in New Issue
Block a user