1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-25 23:21:54 +03:00

r8659: return ldif formatted attributes in the ejs ldb search call, so sids show up as strings

not binary blobs
(This used to be commit d2c29a5a51)
This commit is contained in:
Andrew Tridgell 2005-07-21 01:56:22 +00:00 committed by Gerald (Jerry) Carter
parent 4327a3f1ba
commit 7a8ac75887
4 changed files with 27 additions and 11 deletions

View File

@ -440,4 +440,7 @@ int ldb_set_debug_stderr(struct ldb_context *ldb);
int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value); int ldb_set_opaque(struct ldb_context *ldb, const char *name, void *value);
void *ldb_get_opaque(struct ldb_context *ldb, const char *name); void *ldb_get_opaque(struct ldb_context *ldb, const char *name);
const struct ldb_attrib_handler *ldb_attrib_handler(struct ldb_context *ldb,
const char *attrib);
#endif #endif

View File

@ -172,9 +172,6 @@ int lsqlite3_connect(struct ldb_context *ldb,
struct ldb_module *timestamps_module_init(struct ldb_context *ldb, const char *options[]); struct ldb_module *timestamps_module_init(struct ldb_context *ldb, const char *options[]);
struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *options[]); struct ldb_module *schema_module_init(struct ldb_context *ldb, const char *options[]);
const struct ldb_attrib_handler *ldb_attrib_handler(struct ldb_context *ldb,
const char *attrib);
int ldb_match_msg(struct ldb_context *ldb, int ldb_match_msg(struct ldb_context *ldb,
struct ldb_message *msg, struct ldb_message *msg,
struct ldb_parse_tree *tree, struct ldb_parse_tree *tree,

View File

@ -151,7 +151,7 @@ struct MprVar mprData(const uint8_t *p, size_t length)
/* /*
turn a ldb_message into a ejs object variable turn a ldb_message into a ejs object variable
*/ */
struct MprVar mprLdbMessage(struct ldb_message *msg) static struct MprVar mprLdbMessage(struct ldb_context *ldb, struct ldb_message *msg)
{ {
struct MprVar var; struct MprVar var;
int i; int i;
@ -166,16 +166,29 @@ struct MprVar mprLdbMessage(struct ldb_message *msg)
for (i=0;i<msg->num_elements;i++) { for (i=0;i<msg->num_elements;i++) {
struct ldb_message_element *el = &msg->elements[i]; struct ldb_message_element *el = &msg->elements[i];
struct MprVar val; struct MprVar val;
const struct ldb_attrib_handler *attr;
struct ldb_val v;
attr = ldb_attrib_handler(ldb, el->name);
if (attr == NULL) {
goto failed;
}
if (el->num_values == 1 && if (el->num_values == 1 &&
!str_list_check_ci(multivalued, el->name)) { !str_list_check_ci(multivalued, el->name)) {
val = mprData(el->values[0].data, el->values[0].length); if (attr->ldif_write_fn(ldb, msg, &el->values[0], &v) != 0) {
goto failed;
}
val = mprData(v.data, v.length);
} else { } else {
int j; int j;
val = mprObject(el->name); val = mprObject(el->name);
for (j=0;j<el->num_values;j++) { for (j=0;j<el->num_values;j++) {
mprAddArray(&val, j, if (attr->ldif_write_fn(ldb, msg,
mprData(el->values[j].data, &el->values[j], &v) != 0) {
el->values[j].length)); goto failed;
}
mprAddArray(&val, j, mprData(v.data, v.length));
} }
} }
mprSetVar(&var, el->name, val); mprSetVar(&var, el->name, val);
@ -187,20 +200,23 @@ struct MprVar mprLdbMessage(struct ldb_message *msg)
} }
return var; return var;
failed:
return mprCreateUndefinedVar();
} }
/* /*
turn an array of ldb_messages into a ejs object variable turn an array of ldb_messages into a ejs object variable
*/ */
struct MprVar mprLdbArray(struct ldb_message **msg, int count, const char *name) struct MprVar mprLdbArray(struct ldb_context *ldb,
struct ldb_message **msg, int count, const char *name)
{ {
struct MprVar res; struct MprVar res;
int i; int i;
res = mprObject(name); res = mprObject(name);
for (i=0;i<count;i++) { for (i=0;i<count;i++) {
mprAddArray(&res, i, mprLdbMessage(msg[i])); mprAddArray(&res, i, mprLdbMessage(ldb, msg[i]));
} }
if (i==0) { if (i==0) {
mprSetVar(&res, "length", mprCreateIntegerVar(0)); mprSetVar(&res, "length", mprCreateIntegerVar(0));

View File

@ -103,7 +103,7 @@ static int ejs_ldbSearch(MprVarHandle eid, int argc, struct MprVar **argv)
ejsSetErrorMsg(eid, "ldb.search failed - %s", ldb_errstring(ldb)); ejsSetErrorMsg(eid, "ldb.search failed - %s", ldb_errstring(ldb));
mpr_Return(eid, mprCreateUndefinedVar()); mpr_Return(eid, mprCreateUndefinedVar());
} else { } else {
mpr_Return(eid, mprLdbArray(res, ret, "ldb_message")); mpr_Return(eid, mprLdbArray(ldb, res, ret, "ldb_message"));
} }
talloc_free(tmp_ctx); talloc_free(tmp_ctx);