/* add to the list of ldif handlers for this ldb context */ void ldb_remove_attrib_handler(struct ldb_context *ldb, const char *attrib) { const struct ldb_attrib_handler *h; int i; h = ldb_attrib_handler(ldb, attrib); if (h == &ldb_default_attrib_handler) { return; } if (h->flags & LDB_ATTR_FLAG_ALLOCATED) { talloc_free(discard_const_p(char, h->attr)); }
/* turn a ldb_message into a ejs object variable */ static struct MprVar mprLdbMessage(struct ldb_context *ldb, struct ldb_message *msg) { struct MprVar var; int i; /* we force some attributes to always be an array in the returned structure. This makes the scripting easier, as you don't need a special case for the single value case */ const char *multivalued[] = { "objectClass", "memberOf", "privilege", "member", NULL }; var = mprObject(ldb_dn_alloc_linearized(msg, msg->dn)); for (i=0;i<msg->num_elements;i++) { struct ldb_message_element *el = &msg->elements[i]; 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 && !str_list_check_ci(multivalued, el->name)) { if (attr->ldif_write_fn(ldb, msg, &el->values[0], &v) != 0) { goto failed; } /* FIXME: nasty hack, remove me when ejs will support * arbitrary string and does not truncate on \0 */ if (strlen((char *)v.data) != v.length) { val = mprDataBlob(v); } else { val = mprData(v.data, v.length); } } else { int j; val = mprArray(el->name); for (j=0;j<el->num_values;j++) { if (attr->ldif_write_fn(ldb, msg, &el->values[j], &v) != 0) { goto failed; } /* FIXME: nasty hack, remove me when ejs will support * arbitrary string and does not truncate on \0 */ if (strlen((char *)v.data) != v.length) { mprAddArray(&val, j, mprDataBlob(v)); } else { mprAddArray(&val, j, mprData(v.data, v.length)); } } } mprSetVar(&var, el->name, val); } /* add the dn if it is not already specified */ if (mprGetProperty(&var, "dn", 0) == 0) { mprSetVar(&var, "dn", mprString(ldb_dn_alloc_linearized(msg, msg->dn))); } return var; failed: return mprCreateUndefinedVar(); }