1
0
mirror of https://github.com/samba-team/samba.git synced 2025-08-02 00:22:11 +03:00

r9391: Convert all the code to use struct ldb_dn to ohandle ldap like distinguished names

Provide more functions to handle DNs in this form
(This used to be commit 692e35b779)
This commit is contained in:
Simo Sorce
2005-08-18 15:02:01 +00:00
committed by Gerald (Jerry) Carter
parent a8d51f8762
commit 3e4c4cff21
56 changed files with 1493 additions and 880 deletions

View File

@ -161,7 +161,7 @@ static struct MprVar mprLdbMessage(struct ldb_context *ldb, struct ldb_message *
const char *multivalued[] = { "objectClass", "memberOf", "privilege",
"member", NULL };
var = mprObject(msg->dn);
var = mprObject(ldb_dn_linearize(msg, msg->dn));
for (i=0;i<msg->num_elements;i++) {
struct ldb_message_element *el = &msg->elements[i];
@ -196,7 +196,7 @@ static struct MprVar mprLdbMessage(struct ldb_context *ldb, struct ldb_message *
/* add the dn if it is not already specified */
if (mprGetProperty(&var, "dn", 0) == 0) {
mprSetVar(&var, "dn", mprString(msg->dn));
mprSetVar(&var, "dn", mprString(ldb_dn_linearize(msg, msg->dn)));
}
return var;

View File

@ -51,7 +51,8 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv)
{
const char **attrs = NULL;
const char *expression;
const char *basedn = NULL;
const char *base = NULL;
struct ldb_dn *basedn = NULL;
int scope = LDB_SCOPE_DEFAULT;
TALLOC_CTX *tmp_ctx = talloc_new(mprMemCtx());
struct ldb_context *ldb;
@ -79,9 +80,16 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv)
goto failed;
}
if (argc > 1) {
basedn = mprToString(argv[1]);
base = mprToString(argv[1]);
/* a null basedn is valid */
}
if (base != NULL) {
basedn = ldb_dn_explode(tmp_ctx, base);
if (basedn == NULL) {
ejsSetErrorMsg(eid, "ldb.search malformed base dn");
goto failed;
}
}
if (argc > 2) {
scope = mprToInt(argv[2]);
switch (scope) {
@ -160,7 +168,7 @@ static int ejs_ldbAddModify(MprVarHandle eid, int argc, struct MprVar **argv,
*/
static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv)
{
const char *dn;
struct ldb_dn *dn;
struct ldb_context *ldb;
int ret;
@ -169,14 +177,21 @@ static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv)
return -1;
}
dn = mprToString(argv[0]);
ldb = ejs_get_ldb_context(eid);
if (ldb == NULL) {
return -1;
}
dn = ldb_dn_explode(ldb, mprToString(argv[0]));
if (dn == NULL) {
ejsSetErrorMsg(eid, "ldb.delete malformed dn");
return -1;
}
ret = ldb_delete(ldb, dn);
talloc_free(dn);
mpr_Return(eid, mprCreateBoolVar(ret == 0));
return 0;
}
@ -188,7 +203,7 @@ static int ejs_ldbDelete(MprVarHandle eid, int argc, struct MprVar **argv)
*/
static int ejs_ldbRename(MprVarHandle eid, int argc, struct MprVar **argv)
{
const char *dn1, *dn2;
struct ldb_dn *dn1, *dn2;
struct ldb_context *ldb;
int ret;
@ -197,20 +212,23 @@ static int ejs_ldbRename(MprVarHandle eid, int argc, struct MprVar **argv)
return -1;
}
dn1 = mprToString(argv[0]);
dn2 = mprToString(argv[1]);
if (dn1 == NULL || dn2 == NULL) {
ejsSetErrorMsg(eid, "ldb.rename invalid arguments");
return -1;
}
ldb = ejs_get_ldb_context(eid);
if (ldb == NULL) {
return -1;
}
dn1 = ldb_dn_explode(ldb, mprToString(argv[0]));
dn2 = ldb_dn_explode(ldb, mprToString(argv[1]));
if (dn1 == NULL || dn2 == NULL) {
ejsSetErrorMsg(eid, "ldb.rename invalid or malformed arguments");
return -1;
}
ret = ldb_rename(ldb, dn1, dn2);
talloc_free(dn1);
talloc_free(dn2);
mpr_Return(eid, mprCreateBoolVar(ret == 0));
return 0;
}