From f6818daecca95760c12f79fd307770cbe3346f57 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 12 Oct 2005 06:10:23 +0000 Subject: [PATCH] r10913: This patch isn't as big as it looks ... most of the changes are fixes to make all the ldb code compile without warnings on gcc4. Unfortunately That required a lot of casts :-( I have also added the start of an 'operational' module, which will replace the timestamp module, plus add support for some other operational attributes In ldb_msg_*() I added some new utility functions to make the operational module sane, and remove the 'ldb' argument from the ldb_msg_add_*() functions. That argument was only needed back in the early days of ldb when we didn't use the hierarchical talloc and thus needed a place to get the allocation function from. Now its just a pain to pass around everywhere. Also added a ldb_debug_set() function that calls ldb_debug() plus sets the result using ldb_set_errstring(). That saves on some awkward coding in a few places. --- source/auth/gensec/schannel_state.c | 18 +- source/dsdb/samdb/ldb_modules/objectguid.c | 2 +- source/dsdb/samdb/ldb_modules/samba3sam.c | 8 +- source/dsdb/samdb/ldb_modules/samldb.c | 17 +- source/dsdb/samdb/samdb.c | 20 +- source/include/ioctl.h | 4 +- source/lib/ldb/common/attrib_handlers.c | 26 +-- source/lib/ldb/common/ldb_debug.c | 18 ++ source/lib/ldb/common/ldb_dn.c | 19 +- source/lib/ldb/common/ldb_ldif.c | 14 +- source/lib/ldb/common/ldb_match.c | 21 +- source/lib/ldb/common/ldb_msg.c | 111 ++++++++--- source/lib/ldb/common/ldb_parse.c | 48 +++++ source/lib/ldb/common/ldb_utf8.c | 1 - source/lib/ldb/config.mk | 9 + source/lib/ldb/include/ldb.h | 44 +++-- source/lib/ldb/include/ldb_private.h | 2 + source/lib/ldb/ldb_tdb/ldb_cache.c | 13 +- source/lib/ldb/ldb_tdb/ldb_index.c | 28 +-- source/lib/ldb/ldb_tdb/ldb_pack.c | 14 +- source/lib/ldb/ldb_tdb/ldb_search.c | 16 +- source/lib/ldb/ldb_tdb/ldb_tdb.c | 2 +- source/lib/ldb/modules/ldb_map.c | 37 ++-- source/lib/ldb/modules/operational.c | 217 +++++++++++++++++++++ source/lib/ldb/modules/rdn_name.c | 6 +- source/lib/ldb/modules/schema.c | 81 +++----- source/lib/ldb/modules/timestamps.c | 2 +- source/lib/ldb/tools/ldbtest.c | 42 ++-- source/lib/ldb/tools/oLschema2ldif.c | 12 +- source/lib/registry/reg_backend_ldb.c | 12 +- source/libcli/ldap/ldap.c | 11 +- source/libnet/libnet_join.c | 6 +- source/nbt_server/wins/winsdb.c | 21 +- source/rpc_server/lsa/dcesrv_lsa.c | 2 +- source/web_server/web_server.c | 2 +- 35 files changed, 625 insertions(+), 281 deletions(-) create mode 100644 source/lib/ldb/modules/operational.c diff --git a/source/auth/gensec/schannel_state.c b/source/auth/gensec/schannel_state.c index 0c4f99499c..5b398b2996 100644 --- a/source/auth/gensec/schannel_state.c +++ b/source/auth/gensec/schannel_state.c @@ -118,15 +118,15 @@ NTSTATUS schannel_store_session_key(TALLOC_CTX *mem_ctx, seed.data = creds->seed.data; seed.length = sizeof(creds->seed.data); - ldb_msg_add_string(ldb, msg, "objectClass", "schannelState"); - ldb_msg_add_value(ldb, msg, "sessionKey", &val); - ldb_msg_add_value(ldb, msg, "seed", &seed); - ldb_msg_add_string(ldb, msg, "negotiateFlags", f); - ldb_msg_add_string(ldb, msg, "secureChannelType", sct); - ldb_msg_add_string(ldb, msg, "accountName", creds->account_name); - ldb_msg_add_string(ldb, msg, "computerName", creds->computer_name); - ldb_msg_add_string(ldb, msg, "flatname", creds->domain); - ldb_msg_add_string(ldb, msg, "rid", rid); + ldb_msg_add_string(msg, "objectClass", "schannelState"); + ldb_msg_add_value(msg, "sessionKey", &val); + ldb_msg_add_value(msg, "seed", &seed); + ldb_msg_add_string(msg, "negotiateFlags", f); + ldb_msg_add_string(msg, "secureChannelType", sct); + ldb_msg_add_string(msg, "accountName", creds->account_name); + ldb_msg_add_string(msg, "computerName", creds->computer_name); + ldb_msg_add_string(msg, "flatname", creds->domain); + ldb_msg_add_string(msg, "rid", rid); ldb_delete(ldb, msg->dn); diff --git a/source/dsdb/samdb/ldb_modules/objectguid.c b/source/dsdb/samdb/ldb_modules/objectguid.c index 7dc6a433c0..70bbaf179c 100644 --- a/source/dsdb/samdb/ldb_modules/objectguid.c +++ b/source/dsdb/samdb/ldb_modules/objectguid.c @@ -101,7 +101,7 @@ static int objectguid_add_record(struct ldb_module *module, const struct ldb_mes return -1; } - ret = ldb_msg_add_value(module->ldb, msg2, "objectGUID", &v); + ret = ldb_msg_add_value(msg2, "objectGUID", &v); if (ret) { return ret; } diff --git a/source/dsdb/samdb/ldb_modules/samba3sam.c b/source/dsdb/samdb/ldb_modules/samba3sam.c index a68f6f0640..5e88cd6469 100644 --- a/source/dsdb/samdb/ldb_modules/samba3sam.c +++ b/source/dsdb/samdb/ldb_modules/samba3sam.c @@ -55,17 +55,17 @@ static void generate_hashes (struct ldb_module *module, const char *local_attr, if (!upwd) return; - ldb_msg_add_string(module->ldb, remote_fb, local_attr, upwd); + ldb_msg_add_string(remote_fb, local_attr, upwd); val.length = 16; val.data = talloc_zero_size(module, val.length); E_md4hash(upwd, val.data); - ldb_msg_add_value(module->ldb, remote_mp, "sambaNTPassword", &val); + ldb_msg_add_value(remote_mp, "sambaNTPassword", &val); val.data = talloc_zero_size(module, val.length); E_deshash(upwd, val.data); - ldb_msg_add_value(module->ldb, remote_mp, "sambaLMPassword", &val); + ldb_msg_add_value(remote_mp, "sambaLMPassword", &val); } @@ -119,7 +119,7 @@ static void generate_sambaPrimaryGroupSID(struct ldb_module *module, const char sidstring = dom_sid_string(remote_mp, sid); talloc_free(sid); - ldb_msg_add_fmt(module->ldb, remote_mp, "sambaPrimaryGroupSID", "%s-%d", sidstring, ldb_msg_find_uint(local, "primaryGroupID", 0)); + ldb_msg_add_fmt(remote_mp, "sambaPrimaryGroupSID", "%s-%d", sidstring, ldb_msg_find_uint(local, "primaryGroupID", 0)); talloc_free(sidstring); } diff --git a/source/dsdb/samdb/ldb_modules/samldb.c b/source/dsdb/samdb/ldb_modules/samldb.c index 906a2299f7..5ed84cc10d 100644 --- a/source/dsdb/samdb/ldb_modules/samldb.c +++ b/source/dsdb/samdb/ldb_modules/samldb.c @@ -107,17 +107,17 @@ static int samldb_allocate_next_rid(struct ldb_context *ldb, TALLOC_CTX *mem_ctx els[1].flags = LDB_FLAG_MOD_ADD; els[1].name = els[0].name; - vals[0].data = talloc_asprintf(mem_ctx, "%u", *id); + vals[0].data = (uint8_t *)talloc_asprintf(mem_ctx, "%u", *id); if (!vals[0].data) { return -1; } - vals[0].length = strlen(vals[0].data); + vals[0].length = strlen((char *)vals[0].data); - vals[1].data = talloc_asprintf(mem_ctx, "%u", (*id)+1); + vals[1].data = (uint8_t *)talloc_asprintf(mem_ctx, "%u", (*id)+1); if (!vals[1].data) { return -1; } - vals[1].length = strlen(vals[1].data); + vals[1].length = strlen((char *)vals[1].data); ret = ldb_modify(ldb, &msg); if (ret != 0) { @@ -240,7 +240,8 @@ static struct ldb_message_element *samldb_find_attribute(const struct ldb_messag return &msg->elements[i]; } for (j = 0; j < msg->elements[i].num_values; j++) { - if (strcasecmp(value, msg->elements[i].values[j].data) == 0) { + if (strcasecmp(value, + (char *)msg->elements[i].values[j].data) == 0) { return &msg->elements[i]; } } @@ -260,7 +261,7 @@ static BOOL samldb_msg_add_string(struct ldb_module *module, struct ldb_message return False; } - if (ldb_msg_add_string(module->ldb, msg, aname, aval) != 0) { + if (ldb_msg_add_string(msg, aname, aval) != 0) { return False; } @@ -276,7 +277,7 @@ static BOOL samldb_msg_add_sid(struct ldb_module *module, struct ldb_message *ms if (!NT_STATUS_IS_OK(status)) { return -1; } - return (ldb_msg_add_value(module->ldb, msg, name, &v) == 0); + return (ldb_msg_add_value(msg, name, &v) == 0); } static BOOL samldb_find_or_add_attribute(struct ldb_module *module, struct ldb_message *msg, const char *name, const char *value, const char *set_value) @@ -497,7 +498,7 @@ static struct ldb_message *samldb_fill_foreignSecurityPrincipal_object(struct ld } if ((attribute = samldb_find_attribute(msg2, "objectSid", NULL)) == NULL ) { - struct dom_sid *sid = dom_sid_parse_talloc(msg2, rdn->value.data); + struct dom_sid *sid = dom_sid_parse_talloc(msg2, (char *)rdn->value.data); if (sid == NULL) { ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_foreignSecurityPrincipal_object: internal error! Can't parse sid in CN\n"); return NULL; diff --git a/source/dsdb/samdb/samdb.c b/source/dsdb/samdb/samdb.c index bc8dcd0f06..6afa83e1aa 100644 --- a/source/dsdb/samdb/samdb.c +++ b/source/dsdb/samdb/samdb.c @@ -699,7 +699,7 @@ int samdb_msg_add_string(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struc if (s == NULL || a == NULL) { return -1; } - return ldb_msg_add_string(sam_ldb, msg, a, s); + return ldb_msg_add_string(msg, a, s); } /* @@ -715,7 +715,7 @@ int samdb_msg_add_dom_sid(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, stru if (!NT_STATUS_IS_OK(status)) { return -1; } - return ldb_msg_add_value(sam_ldb, msg, attr_name, &v); + return ldb_msg_add_value(msg, attr_name, &v); } @@ -731,7 +731,7 @@ int samdb_msg_add_delete(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struc } /* we use an empty replace rather than a delete, as it allows for samdb_replace() to be used everywhere */ - return ldb_msg_add_empty(sam_ldb, msg, a, LDB_FLAG_MOD_REPLACE); + return ldb_msg_add_empty(msg, a, LDB_FLAG_MOD_REPLACE); } /* @@ -749,7 +749,7 @@ int samdb_msg_add_addval(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struc v = talloc_strdup(mem_ctx, value); if (v == NULL) return -1; - ret = ldb_msg_add_string(sam_ldb, msg, a, v); + ret = ldb_msg_add_string(msg, a, v); if (ret != 0) return ret; el = ldb_msg_find_element(msg, a); @@ -774,7 +774,7 @@ int samdb_msg_add_delval(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struc v = talloc_strdup(mem_ctx, value); if (v == NULL) return -1; - ret = ldb_msg_add_string(sam_ldb, msg, a, v); + ret = ldb_msg_add_string(msg, a, v); if (ret != 0) return ret; el = ldb_msg_find_element(msg, a); @@ -826,7 +826,7 @@ int samdb_msg_add_hash(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct return -1; } val.length = 16; - return ldb_msg_add_value(sam_ldb, msg, attr_name, &val); + return ldb_msg_add_value(msg, attr_name, &val); } /* @@ -845,7 +845,7 @@ int samdb_msg_add_hashes(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struc for (i=0;iunits_per_week / 8; val.data = hours->bits; - return ldb_msg_add_value(sam_ldb, msg, attr_name, &val); + return ldb_msg_add_value(msg, attr_name, &val); } /* @@ -875,7 +875,7 @@ int samdb_msg_add_logon_hours(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, int samdb_msg_add_value(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct ldb_message *msg, const char *attr_name, const struct ldb_val *val) { - return ldb_msg_add_value(sam_ldb, msg, attr_name, val); + return ldb_msg_add_value(msg, attr_name, val); } /* @@ -890,7 +890,7 @@ int samdb_msg_set_value(struct ldb_context *sam_ldb, TALLOC_CTX *mem_ctx, struct if (el) { el->num_values = 0; } - return ldb_msg_add_value(sam_ldb, msg, attr_name, val); + return ldb_msg_add_value(msg, attr_name, val); } /* diff --git a/source/include/ioctl.h b/source/include/ioctl.h index 272004d3dc..1c08a58d76 100644 --- a/source/include/ioctl.h +++ b/source/include/ioctl.h @@ -26,5 +26,5 @@ /* filesystem control codes */ #define FSCTL_FILESYSTEM 0x90000 -#define FSCTL_SET_SPARSE (FSCTL_FILESYSTEM | 0xc4) - +#define FSCTL_SET_SPARSE (FSCTL_FILESYSTEM | (49<<2)) +#define FSCTL_REQUEST_BATCH_OPLOCK (FSCTL_FILESYSTEM | (2<<2)) diff --git a/source/lib/ldb/common/attrib_handlers.c b/source/lib/ldb/common/attrib_handlers.c index 61ca566570..d073203b3c 100644 --- a/source/lib/ldb/common/attrib_handlers.c +++ b/source/lib/ldb/common/attrib_handlers.c @@ -53,7 +53,7 @@ static int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { uint8_t *s1, *s2; - out->data = talloc_size(mem_ctx, strlen(in->data)+1); + out->data = talloc_size(mem_ctx, strlen((char *)in->data)+1); if (out->data == NULL) { ldb_oom(ldb); return -1; @@ -69,7 +69,7 @@ static int ldb_handler_fold(struct ldb_context *ldb, void *mem_ctx, s2++; s1++; } *s2 = 0; - out->length = strlen(out->data); + out->length = strlen((char *)out->data); return 0; } @@ -82,15 +82,15 @@ static int ldb_canonicalise_Integer(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *in, struct ldb_val *out) { char *end; - long long i = strtoll(in->data, &end, 0); + long long i = strtoll((char *)in->data, &end, 0); if (*end != 0) { return -1; } - out->data = talloc_asprintf(mem_ctx, "%lld", i); + out->data = (uint8_t *)talloc_asprintf(mem_ctx, "%lld", i); if (out->data == NULL) { return -1; } - out->length = strlen(out->data); + out->length = strlen((char *)out->data); return 0; } @@ -100,7 +100,7 @@ static int ldb_canonicalise_Integer(struct ldb_context *ldb, void *mem_ctx, static int ldb_comparison_Integer(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { - return strtoll(v1->data, NULL, 0) - strtoll(v2->data, NULL, 0); + return strtoll((char *)v1->data, NULL, 0) - strtoll((char *)v2->data, NULL, 0); } /* @@ -123,7 +123,7 @@ int ldb_comparison_binary(struct ldb_context *ldb, void *mem_ctx, static int ldb_comparison_fold(struct ldb_context *ldb, void *mem_ctx, const struct ldb_val *v1, const struct ldb_val *v2) { - const char *s1=v1->data, *s2=v2->data; + const char *s1=(const char *)v1->data, *s2=(const char *)v2->data; while (*s1 == ' ') s1++; while (*s2 == ' ') s2++; /* TODO: make utf8 safe, possibly with helper function from application */ @@ -153,16 +153,16 @@ static int ldb_canonicalise_dn(struct ldb_context *ldb, void *mem_ctx, out->length = 0; out->data = NULL; - dn = ldb_dn_explode_casefold(ldb, in->data); + dn = ldb_dn_explode_casefold(ldb, (char *)in->data); if (dn == NULL) { return -1; } - out->data = ldb_dn_linearize(mem_ctx, dn); + out->data = (uint8_t *)ldb_dn_linearize(mem_ctx, dn); if (out->data == NULL) { goto done; } - out->length = strlen(out->data); + out->length = strlen((char *)out->data); ret = 0; @@ -181,10 +181,10 @@ static int ldb_comparison_dn(struct ldb_context *ldb, void *mem_ctx, struct ldb_dn *dn1 = NULL, *dn2 = NULL; int ret; - dn1 = ldb_dn_explode_casefold(mem_ctx, v1->data); + dn1 = ldb_dn_explode_casefold(mem_ctx, (char *)v1->data); if (dn1 == NULL) return -1; - dn2 = ldb_dn_explode_casefold(mem_ctx, v2->data); + dn2 = ldb_dn_explode_casefold(mem_ctx, (char *)v2->data); if (dn2 == NULL) { talloc_free(dn1); return -1; @@ -209,7 +209,7 @@ static int ldb_comparison_objectclass(struct ldb_context *ldb, void *mem_ctx, if (ret == 0) { return 0; } - subclasses = ldb_subclass_list(ldb, v1->data); + subclasses = ldb_subclass_list(ldb, (char *)v1->data); if (subclasses == NULL) { return ret; } diff --git a/source/lib/ldb/common/ldb_debug.c b/source/lib/ldb/common/ldb_debug.c index 59f00ccc96..d046c8cd1f 100644 --- a/source/lib/ldb/common/ldb_debug.c +++ b/source/lib/ldb/common/ldb_debug.c @@ -86,3 +86,21 @@ void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char * va_end(ap); } + +/* + log a message, and set the ldb error string to the same message +*/ +void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, + const char *fmt, ...) +{ + va_list ap; + char *msg; + va_start(ap, fmt); + msg = talloc_vasprintf(ldb, fmt, ap); + va_end(ap); + if (msg != NULL) { + ldb_set_errstring(ldb->modules, msg); + ldb_debug(ldb, level, "%s", msg); + } +} + diff --git a/source/lib/ldb/common/ldb_dn.c b/source/lib/ldb/common/ldb_dn.c index 2cd7d590fe..92e06025d5 100644 --- a/source/lib/ldb/common/ldb_dn.c +++ b/source/lib/ldb/common/ldb_dn.c @@ -54,7 +54,7 @@ int ldb_dn_check_special(const struct ldb_dn *dn, const char *check) { if (dn == NULL || dn->comp_num != 1) return 0; - return ! strcmp(dn->components[0].value.data, check); + return ! strcmp((char *)dn->components[0].value.data, check); } static int ldb_dn_is_valid_attribute_name(const char *name) @@ -163,7 +163,7 @@ static struct ldb_val ldb_dn_unescape_value(void *mem_ctx, const char *src) } value.length = end - dst; - value.data = dst; + value.data = (uint8_t *)dst; return value; failed: @@ -367,7 +367,7 @@ struct ldb_dn *ldb_dn_explode(void *mem_ctx, const char *dn) if (edn->components == NULL) goto failed; edn->components[0].name = talloc_strdup(edn->components, LDB_SPECIAL); if (edn->components[0].name == NULL) goto failed; - edn->components[0].value.data = talloc_strdup(edn->components, dn); + edn->components[0].value.data = (uint8_t *)talloc_strdup(edn->components, dn); if (edn->components[0].value.data== NULL) goto failed; edn->components[0].value.length = strlen(dn); return edn; @@ -425,7 +425,7 @@ char *ldb_dn_linearize(void *mem_ctx, const struct ldb_dn *edn) /* Special DNs */ if (ldb_dn_is_special(edn)) { - dn = talloc_strdup(mem_ctx, edn->components[0].value.data); + dn = talloc_strdup(mem_ctx, (char *)edn->components[0].value.data); return dn; } @@ -598,7 +598,7 @@ char *ldb_dn_linearize_casefold(struct ldb_context *ldb, const struct ldb_dn *ed /* Special DNs */ if (ldb_dn_is_special(edn)) { - dn = talloc_strdup(ldb, edn->components[0].value.data); + dn = talloc_strdup(ldb, (char *)edn->components[0].value.data); return dn; } @@ -703,7 +703,7 @@ struct ldb_dn_component *ldb_dn_build_component(void *mem_ctx, const char *attr, return NULL; } - dc->value.data = talloc_strdup(dc, val); + dc->value.data = (uint8_t *)talloc_strdup(dc, val); if (dc->value.data == NULL) { talloc_free(dc); return NULL; @@ -736,9 +736,9 @@ struct ldb_dn *ldb_dn_build_child(void *mem_ctx, const char *attr, new->components[0].name = talloc_strdup(new->components, attr); LDB_DN_NULL_FAILED(new->components[0].name); - new->components[0].value.data = talloc_strdup(new->components, value); + new->components[0].value.data = (uint8_t *)talloc_strdup(new->components, value); LDB_DN_NULL_FAILED(new->components[0].value.data); - new->components[0].value.length = strlen(new->components[0].value.data); + new->components[0].value.length = strlen((char *)new->components[0].value.data); return new; @@ -753,7 +753,8 @@ struct ldb_dn *ldb_dn_make_child(void *mem_ctx, const struct ldb_dn_component *c { if (component == NULL) return NULL; - return ldb_dn_build_child(mem_ctx, component->name, component->value.data, base); + return ldb_dn_build_child(mem_ctx, component->name, + (char *)component->value.data, base); } struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const struct ldb_dn *dn2) diff --git a/source/lib/ldb/common/ldb_ldif.c b/source/lib/ldb/common/ldb_ldif.c index b268cca578..7ba6a00147 100644 --- a/source/lib/ldb/common/ldb_ldif.c +++ b/source/lib/ldb/common/ldb_ldif.c @@ -55,7 +55,7 @@ static int ldb_read_data_file(void *mem_ctx, struct ldb_val *value) int ret; int f; - f = open(value->data, O_RDONLY); + f = open((const char *)value->data, O_RDONLY); if (f == -1) { return -1; } @@ -79,7 +79,7 @@ static int ldb_read_data_file(void *mem_ctx, struct ldb_val *value) count = 0; size = statbuf.st_size; - buf = value->data; + buf = (char *)value->data; while (count < statbuf.st_size) { bytes = read(f, buf, size); if (bytes == -1) { @@ -325,7 +325,7 @@ int ldb_ldif_write(struct ldb_context *ldb, msg->elements[i].name); CHECK_RET; ret = base64_encode_f(ldb, fprintf_fn, private_data, - v.data, v.length, + (char *)v.data, v.length, strlen(msg->elements[i].name)+3); CHECK_RET; ret = fprintf_fn(private_data, "\n"); @@ -334,7 +334,7 @@ int ldb_ldif_write(struct ldb_context *ldb, ret = fprintf_fn(private_data, "%s: ", msg->elements[i].name); CHECK_RET; ret = fold_string(fprintf_fn, private_data, - v.data, v.length, + (char *)v.data, v.length, strlen(msg->elements[i].name)+2); CHECK_RET; ret = fprintf_fn(private_data, "\n"); @@ -461,7 +461,7 @@ static int next_attr(void *mem_ctx, char **s, const char **attr, struct ldb_val p++; } - value->data = p; + value->data = (uint8_t *)p; p = strchr(p, '\n'); @@ -475,7 +475,7 @@ static int next_attr(void *mem_ctx, char **s, const char **attr, struct ldb_val } if (base64_encoded) { - int len = ldb_base64_decode(value->data); + int len = ldb_base64_decode((char *)value->data); if (len == -1) { /* it wasn't valid base64 data */ return -1; @@ -588,7 +588,7 @@ struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb, goto failed; } - msg->dn = ldb_dn_explode(msg, value.data); + msg->dn = ldb_dn_explode(msg, (char *)value.data); if (msg->dn == NULL) { ldb_debug(ldb, LDB_DEBUG_ERROR, "Error: Unable to parse dn '%s'\n", diff --git a/source/lib/ldb/common/ldb_match.c b/source/lib/ldb/common/ldb_match.c index 14031a6dd1..7573cfc808 100644 --- a/source/lib/ldb/common/ldb_match.c +++ b/source/lib/ldb/common/ldb_match.c @@ -153,7 +153,8 @@ static int ldb_match_equality(struct ldb_context *ldb, if (ldb_attr_cmp(tree->u.equality.attr, "dn") == 0 || ldb_attr_cmp(tree->u.equality.attr, "distinguishedName") == 0) { - valuedn = ldb_dn_explode_casefold(ldb, tree->u.equality.value.data); + valuedn = ldb_dn_explode_casefold(ldb, + (char *)tree->u.equality.value.data); if (valuedn == NULL) { return 0; } @@ -194,7 +195,7 @@ static int ldb_wildcard_compare(struct ldb_context *ldb, struct ldb_val cnk; struct ldb_val *chunk; char *p, *g; - char *save_p = NULL; + uint8_t *save_p = NULL; int c = 0; h = ldb_attrib_handler(ldb, tree->u.substring.attr); @@ -211,7 +212,7 @@ static int ldb_wildcard_compare(struct ldb_context *ldb, if(h->canonicalise_fn(ldb, ldb, chunk, &cnk) != 0) goto failed; /* FIXME: case of embedded nulls */ - if (strncmp(val.data, cnk.data, cnk.length) != 0) goto failed; + if (strncmp((char *)val.data, (char *)cnk.data, cnk.length) != 0) goto failed; val.length -= cnk.length; val.data += cnk.length; c++; @@ -225,16 +226,16 @@ static int ldb_wildcard_compare(struct ldb_context *ldb, if(h->canonicalise_fn(ldb, ldb, chunk, &cnk) != 0) goto failed; /* FIXME: case of embedded nulls */ - p = strstr(val.data, cnk.data); + p = strstr((char *)val.data, (char *)cnk.data); if (p == NULL) goto failed; if ( (! tree->u.substring.chunks[c + 1]) && (! tree->u.substring.end_with_wildcard) ) { do { /* greedy */ - g = strstr(p + cnk.length, cnk.data); + g = strstr((char *)p + cnk.length, (char *)cnk.data); if (g) p = g; } while(g); } val.length = val.length - (p - (char *)(val.data)) - cnk.length; - val.data = p + cnk.length; + val.data = (uint8_t *)(p + cnk.length); c++; talloc_free(cnk.data); cnk.data = NULL; @@ -282,8 +283,8 @@ static int ldb_match_substring(struct ldb_context *ldb, static int ldb_comparator_and(struct ldb_val *v1, struct ldb_val *v2) { uint64_t i1, i2; - i1 = strtoull(v1->data, NULL, 0); - i2 = strtoull(v2->data, NULL, 0); + i1 = strtoull((char *)v1->data, NULL, 0); + i2 = strtoull((char *)v2->data, NULL, 0); return ((i1 & i2) == i2); } @@ -293,8 +294,8 @@ static int ldb_comparator_and(struct ldb_val *v1, struct ldb_val *v2) static int ldb_comparator_or(struct ldb_val *v1, struct ldb_val *v2) { uint64_t i1, i2; - i1 = strtoull(v1->data, NULL, 0); - i2 = strtoull(v2->data, NULL, 0); + i1 = strtoull((char *)v1->data, NULL, 0); + i2 = strtoull((char *)v2->data, NULL, 0); return ((i1 & i2) != 0); } diff --git a/source/lib/ldb/common/ldb_msg.c b/source/lib/ldb/common/ldb_msg.c index c2f40f308a..01941f5728 100644 --- a/source/lib/ldb/common/ldb_msg.c +++ b/source/lib/ldb/common/ldb_msg.c @@ -107,7 +107,7 @@ struct ldb_val ldb_val_dup(void *mem_ctx, const struct ldb_val *v) /* the +1 is to cope with buggy C library routines like strndup that look one byte beyond */ - v2.data = talloc_array(mem_ctx, char, v->length+1); + v2.data = talloc_array(mem_ctx, uint8_t, v->length+1); if (!v2.data) { v2.length = 0; return v2; @@ -121,13 +121,12 @@ struct ldb_val ldb_val_dup(void *mem_ctx, const struct ldb_val *v) /* add an empty element to a message */ -int ldb_msg_add_empty(struct ldb_context *ldb, - struct ldb_message *msg, const char *attr_name, int flags) +int ldb_msg_add_empty(struct ldb_message *msg, const char *attr_name, int flags) { struct ldb_message_element *els; els = talloc_realloc(msg, msg->elements, - struct ldb_message_element, msg->num_elements+1); + struct ldb_message_element, msg->num_elements+1); if (!els) { errno = ENOMEM; return -1; @@ -150,12 +149,11 @@ int ldb_msg_add_empty(struct ldb_context *ldb, /* add an empty element to a message */ -int ldb_msg_add(struct ldb_context *ldb, - struct ldb_message *msg, +int ldb_msg_add(struct ldb_message *msg, const struct ldb_message_element *el, int flags) { - if (ldb_msg_add_empty(ldb, msg, el->name, flags) != 0) { + if (ldb_msg_add_empty(msg, el->name, flags) != 0) { return -1; } @@ -168,8 +166,7 @@ int ldb_msg_add(struct ldb_context *ldb, /* add a value to a message */ -int ldb_msg_add_value(struct ldb_context *ldb, - struct ldb_message *msg, +int ldb_msg_add_value(struct ldb_message *msg, const char *attr_name, const struct ldb_val *val) { @@ -178,7 +175,7 @@ int ldb_msg_add_value(struct ldb_context *ldb, el = ldb_msg_find_element(msg, attr_name); if (!el) { - ldb_msg_add_empty(ldb, msg, attr_name, 0); + ldb_msg_add_empty(msg, attr_name, 0); el = ldb_msg_find_element(msg, attr_name); } if (!el) { @@ -201,7 +198,7 @@ int ldb_msg_add_value(struct ldb_context *ldb, /* add a string element to a message */ -int ldb_msg_add_string(struct ldb_context *ldb, struct ldb_message *msg, +int ldb_msg_add_string(struct ldb_message *msg, const char *attr_name, const char *str) { struct ldb_val val; @@ -209,13 +206,13 @@ int ldb_msg_add_string(struct ldb_context *ldb, struct ldb_message *msg, val.data = discard_const_p(uint8_t, str); val.length = strlen(str); - return ldb_msg_add_value(ldb, msg, attr_name, &val); + return ldb_msg_add_value(msg, attr_name, &val); } /* add a printf formatted element to a message */ -int ldb_msg_add_fmt(struct ldb_context *ldb, struct ldb_message *msg, +int ldb_msg_add_fmt(struct ldb_message *msg, const char *attr_name, const char *fmt, ...) { struct ldb_val val; @@ -228,10 +225,10 @@ int ldb_msg_add_fmt(struct ldb_context *ldb, struct ldb_message *msg, if (str == NULL) return -1; - val.data = str; + val.data = (uint8_t *)str; val.length = strlen(str); - return ldb_msg_add_value(ldb, msg, attr_name, &val); + return ldb_msg_add_value(msg, attr_name, &val); } /* @@ -287,7 +284,7 @@ int ldb_msg_find_int(const struct ldb_message *msg, if (!v || !v->data) { return default_value; } - return strtol(v->data, NULL, 0); + return strtol((const char *)v->data, NULL, 0); } unsigned int ldb_msg_find_uint(const struct ldb_message *msg, @@ -298,7 +295,7 @@ unsigned int ldb_msg_find_uint(const struct ldb_message *msg, if (!v || !v->data) { return default_value; } - return strtoul(v->data, NULL, 0); + return strtoul((const char *)v->data, NULL, 0); } int64_t ldb_msg_find_int64(const struct ldb_message *msg, @@ -309,7 +306,7 @@ int64_t ldb_msg_find_int64(const struct ldb_message *msg, if (!v || !v->data) { return default_value; } - return strtoll(v->data, NULL, 0); + return strtoll((const char *)v->data, NULL, 0); } uint64_t ldb_msg_find_uint64(const struct ldb_message *msg, @@ -320,7 +317,7 @@ uint64_t ldb_msg_find_uint64(const struct ldb_message *msg, if (!v || !v->data) { return default_value; } - return strtoull(v->data, NULL, 0); + return strtoull((const char *)v->data, NULL, 0); } double ldb_msg_find_double(const struct ldb_message *msg, @@ -331,7 +328,7 @@ double ldb_msg_find_double(const struct ldb_message *msg, if (!v || !v->data) { return default_value; } - return strtod(v->data, NULL); + return strtod((const char *)v->data, NULL); } const char *ldb_msg_find_string(const struct ldb_message *msg, @@ -342,7 +339,7 @@ const char *ldb_msg_find_string(const struct ldb_message *msg, if (!v || !v->data) { return default_value; } - return v->data; + return (const char *)v->data; } /* @@ -479,7 +476,7 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb, continue; } - if (ldb_msg_add(ldb, mod, + if (ldb_msg_add(mod, &msg2->elements[i], el?LDB_FLAG_MOD_REPLACE:LDB_FLAG_MOD_ADD) != 0) { return NULL; @@ -490,7 +487,7 @@ struct ldb_message *ldb_msg_diff(struct ldb_context *ldb, for (i=0;inum_elements;i++) { el = ldb_msg_find_element(msg2, msg1->elements[i].name); if (!el) { - if (ldb_msg_add_empty(ldb, mod, + if (ldb_msg_add_empty(mod, msg1->elements[i].name, LDB_FLAG_MOD_DELETE) != 0) { return NULL; @@ -529,3 +526,71 @@ int ldb_msg_sanity_check(const struct ldb_message *msg) return LDB_SUCCESS; } + + + + +/* + copy an attribute list. This only copies the array, not the elements + (ie. the elements are left as the same pointers) +*/ +const char **ldb_attr_list_copy(TALLOC_CTX *mem_ctx, const char * const *attrs) +{ + const char **ret; + int i; + for (i=0;attrs[i];i++) /* noop */ ; + ret = talloc_array(mem_ctx, const char *, i+1); + if (ret == NULL) { + return NULL; + } + for (i=0;attrs[i];i++) { + ret[i] = attrs[i]; + } + ret[i] = attrs[i]; + return ret; +} + + +/* + return 1 if an attribute is in a list of attributes, or 0 otherwise +*/ +int ldb_attr_in_list(const char * const *attrs, const char *attr) +{ + int i; + for (i=0;attrs[i];i++) { + if (ldb_attr_cmp(attrs[i], attr) == 0) { + return 1; + } + } + return 0; +} + + +/* + rename the specified attribute in a search result +*/ +void ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace) +{ + struct ldb_message_element *el = ldb_msg_find_element(msg, attr); + if (el != NULL) { + el->name = replace; + } +} + + +/* + copy the specified attribute in a search result to a new attribute +*/ +int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *replace) +{ + struct ldb_message_element *el = ldb_msg_find_element(msg, attr); + if (el == NULL) { + return 0; + } + if (ldb_msg_add(msg, el, 0) != 0) { + return -1; + } + ldb_msg_rename_attr(msg, attr, replace); + return 0; +} + diff --git a/source/lib/ldb/common/ldb_parse.c b/source/lib/ldb/common/ldb_parse.c index e61511ebec..5824a8d003 100644 --- a/source/lib/ldb/common/ldb_parse.c +++ b/source/lib/ldb/common/ldb_parse.c @@ -753,3 +753,51 @@ char *ldb_filter_from_tree(void *mem_ctx, struct ldb_parse_tree *tree) return NULL; } + + +/* + replace any occurances of an attribute name in the parse tree with a + new name +*/ +void ldb_parse_tree_attr_replace(struct ldb_parse_tree *tree, + const char *attr, + const char *replace) +{ + int i; + switch (tree->operation) { + case LDB_OP_AND: + case LDB_OP_OR: + for (i=0;iu.list.num_elements;i++) { + ldb_parse_tree_attr_replace(tree->u.list.elements[i], + attr, replace); + } + break; + case LDB_OP_NOT: + ldb_parse_tree_attr_replace(tree->u.isnot.child, attr, replace); + break; + case LDB_OP_EQUALITY: + case LDB_OP_GREATER: + case LDB_OP_LESS: + case LDB_OP_APPROX: + if (ldb_attr_cmp(tree->u.equality.attr, attr) == 0) { + tree->u.equality.attr = replace; + } + break; + case LDB_OP_SUBSTRING: + if (ldb_attr_cmp(tree->u.substring.attr, attr) == 0) { + tree->u.substring.attr = replace; + } + break; + case LDB_OP_PRESENT: + if (ldb_attr_cmp(tree->u.present.attr, attr) == 0) { + tree->u.present.attr = replace; + } + break; + case LDB_OP_EXTENDED: + if (tree->u.extended.attr && + ldb_attr_cmp(tree->u.extended.attr, attr) == 0) { + tree->u.extended.attr = replace; + } + break; + } +} diff --git a/source/lib/ldb/common/ldb_utf8.c b/source/lib/ldb/common/ldb_utf8.c index cd68180f77..69faeb46d3 100644 --- a/source/lib/ldb/common/ldb_utf8.c +++ b/source/lib/ldb/common/ldb_utf8.c @@ -80,4 +80,3 @@ int ldb_attr_cmp(const char *attr1, const char *attr2) { return ldb_caseless_cmp(attr1, attr2); } - diff --git a/source/lib/ldb/config.mk b/source/lib/ldb/config.mk index f75964c44f..cdb0e171e5 100644 --- a/source/lib/ldb/config.mk +++ b/source/lib/ldb/config.mk @@ -7,6 +7,15 @@ INIT_OBJ_FILES = \ # End MODULE libldb_timestamps ################################################ +################################################ +# Start MODULE libldb_operational +[MODULE::libldb_operational] +SUBSYSTEM = LIBLDB +INIT_OBJ_FILES = \ + lib/ldb/modules/operational.o +# End MODULE libldb_operational +################################################ + ################################################ # Start MODULE libldb_rdn_name [MODULE::libldb_rdn_name] diff --git a/source/lib/ldb/include/ldb.h b/source/lib/ldb/include/ldb.h index 73bac2088a..d75ca4fe86 100644 --- a/source/lib/ldb/include/ldb.h +++ b/source/lib/ldb/include/ldb.h @@ -182,24 +182,24 @@ struct ldb_parse_tree { struct ldb_parse_tree *child; } isnot; struct { - char *attr; + const char *attr; struct ldb_val value; } equality; struct { - char *attr; + const char *attr; int start_with_wildcard; int end_with_wildcard; struct ldb_val **chunks; } substring; struct { - char *attr; + const char *attr; } present; struct { - char *attr; + const char *attr; struct ldb_val value; } comparison; struct { - char *attr; + const char *attr; int dnAttributes; char *rule_id; struct ldb_val value; @@ -241,7 +241,10 @@ struct ldb_attrib_handler { ldb_attr_comparison_t comparison_fn; }; -#define LDB_ATTR_FLAG_HIDDEN (1<<0) +#define LDB_ATTR_FLAG_HIDDEN (1<<0) /* the attribute is not returned by default */ +#define LDB_ATTR_FLAG_CONSTRUCTED (1<<1) /* the attribute is constructed from other attributes */ +#define LDB_ATTR_FLAG_CONSTRUCTED (1<<1) /* the attribute is constructed from other attributes */ + /* well-known ldap attribute syntaxes - see rfc2252 section 4.3.2 */ #define LDB_SYNTAX_DN "1.3.6.1.4.1.1466.115.121.1.12" @@ -383,7 +386,7 @@ struct ldb_dn *ldb_dn_make_child(void *mem_ctx, const struct ldb_dn_component *component, const struct ldb_dn *base); struct ldb_dn *ldb_dn_compose(void *mem_ctx, const struct ldb_dn *dn1, const struct ldb_dn *dn2); -struct ldb_dn *ldb_dn_string_compose(void *mem_ctx, const struct ldb_dn *base, const char *child_fmt, ...); +struct ldb_dn *ldb_dn_string_compose(void *mem_ctx, const struct ldb_dn *base, const char *child_fmt, ...) PRINTF_ATTRIBUTE(3,4); struct ldb_dn_component *ldb_dn_get_rdn(void *mem_ctx, const struct ldb_dn *dn); /* useful functions for ldb_message structure manipulation */ @@ -406,22 +409,19 @@ struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el, struct ldb_val *val); /* add a new empty element to a ldb_message */ -int ldb_msg_add_empty(struct ldb_context *ldb, - struct ldb_message *msg, const char *attr_name, int flags); +int ldb_msg_add_empty(struct ldb_message *msg, const char *attr_name, int flags); /* add a element to a ldb_message */ -int ldb_msg_add(struct ldb_context *ldb, - struct ldb_message *msg, +int ldb_msg_add(struct ldb_message *msg, const struct ldb_message_element *el, int flags); -int ldb_msg_add_value(struct ldb_context *ldb, - struct ldb_message *msg, +int ldb_msg_add_value(struct ldb_message *msg, const char *attr_name, const struct ldb_val *val); -int ldb_msg_add_string(struct ldb_context *ldb, struct ldb_message *msg, +int ldb_msg_add_string(struct ldb_message *msg, const char *attr_name, const char *str); -int ldb_msg_add_fmt(struct ldb_context *ldb, struct ldb_message *msg, - const char *attr_name, const char *fmt, ...) PRINTF_ATTRIBUTE(4,5); +int ldb_msg_add_fmt(struct ldb_message *msg, + const char *attr_name, const char *fmt, ...) PRINTF_ATTRIBUTE(3,4); /* compare two message elements - return 0 on match */ int ldb_msg_element_compare(struct ldb_message_element *el1, @@ -485,4 +485,16 @@ 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); + +const char **ldb_attr_list_copy(TALLOC_CTX *mem_ctx, const char * const *attrs); +int ldb_attr_in_list(const char * const *attrs, const char *attr); + + +void ldb_parse_tree_attr_replace(struct ldb_parse_tree *tree, + const char *attr, + const char *replace); + +void ldb_msg_rename_attr(struct ldb_message *msg, const char *attr, const char *replace); +int ldb_msg_copy_attr(struct ldb_message *msg, const char *attr, const char *replace); + #endif diff --git a/source/lib/ldb/include/ldb_private.h b/source/lib/ldb/include/ldb_private.h index 9777ad0d92..2367d6c3f8 100644 --- a/source/lib/ldb/include/ldb_private.h +++ b/source/lib/ldb/include/ldb_private.h @@ -145,6 +145,8 @@ void ldb_set_errstring(struct ldb_module *module, char *err_string); /* The following definitions come from lib/ldb/common/ldb_debug.c */ void ldb_debug(struct ldb_context *ldb, enum ldb_debug_level level, const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); +void ldb_debug_set(struct ldb_context *ldb, enum ldb_debug_level level, + const char *fmt, ...) PRINTF_ATTRIBUTE(3, 4); /* The following definitions come from lib/ldb/common/ldb_ldif.c */ int ldb_should_b64_encode(const struct ldb_val *val); diff --git a/source/lib/ldb/ldb_tdb/ldb_cache.c b/source/lib/ldb/ldb_tdb/ldb_cache.c index 5e40b8fd3f..01f9338009 100644 --- a/source/lib/ldb/ldb_tdb/ldb_cache.c +++ b/source/lib/ldb/ldb_tdb/ldb_cache.c @@ -95,7 +95,7 @@ static int ltdb_attributes_flags(struct ldb_message_element *el, unsigned *v) int j; for (j=0;ltdb_valid_attr_flags[j].name;j++) { if (strcmp(ltdb_valid_attr_flags[j].name, - el->values[i].data) == 0) { + (char *)el->values[i].data) == 0) { value |= ltdb_valid_attr_flags[j].value; break; } @@ -197,7 +197,8 @@ static int ltdb_subclasses_load(struct ldb_module *module) for (i=0;inum_elements;i++) { struct ldb_message_element *el = &msg->elements[i]; for (j=0;jnum_values;j++) { - if (ldb_subclass_add(module->ldb, el->name, el->values[j].data) != 0) { + if (ldb_subclass_add(module->ldb, el->name, + (char *)el->values[j].data) != 0) { goto failed; } } @@ -268,7 +269,7 @@ static int ltdb_baseinfo_init(struct ldb_module *module) el.values = &val; el.num_values = 1; el.flags = 0; - val.data = talloc_strdup(msg, initial_sequence_number); + val.data = (uint8_t *)talloc_strdup(msg, initial_sequence_number); if (!val.data) { goto failed; } @@ -446,7 +447,7 @@ int ltdb_increase_sequence_number(struct ldb_module *module) el.values = &val; el.num_values = 1; el.flags = LDB_FLAG_MOD_REPLACE; - val.data = s; + val.data = (uint8_t *)s; val.length = strlen(s); ret = ltdb_modify_internal(module, msg); @@ -495,7 +496,7 @@ int ltdb_attribute_flags(struct ldb_module *module, const char *attr_name) for (i = 0; i < attr_el->num_values; i++) { for (j=0; ltdb_valid_attr_flags[j].name; j++) { if (strcmp(ltdb_valid_attr_flags[j].name, - attr_el->values[i].data) == 0) { + (char *)attr_el->values[i].data) == 0) { ret |= ltdb_valid_attr_flags[j].value; } } @@ -514,7 +515,7 @@ int ltdb_check_at_attributes_values(const struct ldb_val *value) int i; for (i = 0; ltdb_valid_attr_flags[i].name != NULL; i++) { - if ((strcmp(ltdb_valid_attr_flags[i].name, value->data) == 0)) { + if ((strcmp(ltdb_valid_attr_flags[i].name, (char *)value->data) == 0)) { return 0; } } diff --git a/source/lib/ldb/ldb_tdb/ldb_index.c b/source/lib/ldb/ldb_tdb/ldb_index.c index 7c920dd78b..e80cf74c62 100644 --- a/source/lib/ldb/ldb_tdb/ldb_index.c +++ b/source/lib/ldb/ldb_tdb/ldb_index.c @@ -120,7 +120,7 @@ static struct ldb_dn *ldb_dn_key(struct ldb_context *ldb, return NULL; } if (ldb_should_b64_encode(&v)) { - char *vstr = ldb_base64_encode(ldb, v.data, v.length); + char *vstr = ldb_base64_encode(ldb, (char *)v.data, v.length); if (!vstr) return NULL; dn = talloc_asprintf(ldb, "%s:%s::%s", LTDB_INDEX, attr_folded, vstr); talloc_free(vstr); @@ -261,7 +261,7 @@ static int ltdb_index_dn_objectclass(struct ldb_module *module, struct ldb_context *ldb = module->ldb; unsigned int i; int ret; - const char *target = tree->u.equality.value.data; + const char *target = (const char *)tree->u.equality.value.data; const char **subclasses; list->count = 0; @@ -279,17 +279,19 @@ static int ltdb_index_dn_objectclass(struct ldb_module *module, struct ldb_parse_tree tree2; struct dn_list *list2; tree2.operation = LDB_OP_EQUALITY; - tree2.u.equality.attr = talloc_strdup(list, LTDB_OBJECTCLASS); + tree2.u.equality.attr = LTDB_OBJECTCLASS; if (!tree2.u.equality.attr) { return -1; } - tree2.u.equality.value.data = talloc_strdup(tree2.u.equality.attr, subclasses[i]); + tree2.u.equality.value.data = + (uint8_t *)talloc_strdup(list, subclasses[i]); if (tree2.u.equality.value.data == NULL) { return -1; } tree2.u.equality.value.length = strlen(subclasses[i]); list2 = talloc(list, struct dn_list); if (list2 == NULL) { + talloc_free(tree2.u.equality.value.data); return -1; } if (ltdb_index_dn_objectclass(module, &tree2, @@ -302,7 +304,7 @@ static int ltdb_index_dn_objectclass(struct ldb_module *module, talloc_free(list2); } } - talloc_free(tree2.u.equality.attr); + talloc_free(tree2.u.equality.value.data); } return ret; @@ -747,7 +749,7 @@ static int ltdb_index_add1_new(struct ldb_context *ldb, return -1; } msg->elements[msg->num_elements].values[0].length = strlen(dn); - msg->elements[msg->num_elements].values[0].data = dn; + msg->elements[msg->num_elements].values[0].data = (uint8_t *)dn; msg->elements[msg->num_elements].num_values = 1; msg->num_elements++; @@ -770,7 +772,7 @@ static int ltdb_index_add1_add(struct ldb_context *ldb, /* for multi-valued attributes we can end up with repeats */ for (i=0;ielements[idx].num_values;i++) { - if (strcmp(dn, msg->elements[idx].values[i].data) == 0) { + if (strcmp(dn, (char *)msg->elements[idx].values[i].data) == 0) { return 0; } } @@ -784,7 +786,7 @@ static int ltdb_index_add1_add(struct ldb_context *ldb, msg->elements[idx].values = v2; msg->elements[idx].values[msg->elements[idx].num_values].length = strlen(dn); - msg->elements[idx].values[msg->elements[idx].num_values].data = dn; + msg->elements[idx].values[msg->elements[idx].num_values].data = (uint8_t *)dn; msg->elements[idx].num_values++; return 0; @@ -1027,7 +1029,7 @@ int ltdb_index_del(struct ldb_module *module, const struct ldb_message *msg) static int delete_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void *state) { const char *dn = "DN=" LTDB_INDEX ":"; - if (strncmp(key.dptr, dn, strlen(dn)) == 0) { + if (strncmp((char *)key.dptr, dn, strlen(dn)) == 0) { return tdb_delete(tdb, key); } return 0; @@ -1044,8 +1046,8 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void * int ret; TDB_DATA key2; - if (strncmp(key.dptr, "DN=@", 4) == 0 || - strncmp(key.dptr, "DN=", 3) != 0) { + if (strncmp((char *)key.dptr, "DN=@", 4) == 0 || + strncmp((char *)key.dptr, "DN=", 3) != 0) { return 0; } @@ -1070,14 +1072,14 @@ static int re_index(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, void * talloc_free(msg); return 0; } - if (strcmp(key2.dptr, key.dptr) != 0) { + if (strcmp((char *)key2.dptr, (char *)key.dptr) != 0) { tdb_delete(tdb, key); tdb_store(tdb, key2, data, 0); } talloc_free(key2.dptr); if (msg->dn == NULL) { - dn = key.dptr + 3; + dn = (char *)key.dptr + 3; } else { dn = ldb_dn_linearize(msg->dn, msg->dn); } diff --git a/source/lib/ldb/ldb_tdb/ldb_pack.c b/source/lib/ldb/ldb_tdb/ldb_pack.c index 332dbf03df..bf57aa904c 100644 --- a/source/lib/ldb/ldb_tdb/ldb_pack.c +++ b/source/lib/ldb/ldb_tdb/ldb_pack.c @@ -75,7 +75,7 @@ int ltdb_pack_data(struct ldb_module *module, unsigned int i, j, real_elements=0; size_t size; char *dn; - char *p; + uint8_t *p; size_t len; dn = ldb_dn_linearize(ldb, message->dn); @@ -106,7 +106,7 @@ int ltdb_pack_data(struct ldb_module *module, } /* allocate it */ - data->dptr = talloc_array(ldb, char, size); + data->dptr = talloc_array(ldb, uint8_t, size); if (!data->dptr) { talloc_free(dn); errno = ENOMEM; @@ -157,7 +157,7 @@ int ltdb_unpack_data(struct ldb_module *module, struct ldb_message *message) { struct ldb_context *ldb = module->ldb; - char *p; + uint8_t *p; unsigned int remaining; unsigned int i, j; unsigned format; @@ -183,12 +183,12 @@ int ltdb_unpack_data(struct ldb_module *module, break; case LTDB_PACKING_FORMAT: - len = strnlen(p, remaining); + len = strnlen((char *)p, remaining); if (len == remaining) { errno = EIO; goto failed; } - message->dn = ldb_dn_explode(message, p); + message->dn = ldb_dn_explode(message, (char *)p); if (message->dn == NULL) { errno = ENOMEM; goto failed; @@ -226,13 +226,13 @@ int ltdb_unpack_data(struct ldb_module *module, errno = EIO; goto failed; } - len = strnlen(p, remaining-6); + len = strnlen((char *)p, remaining-6); if (len == remaining-6) { errno = EIO; goto failed; } message->elements[i].flags = 0; - message->elements[i].name = p; + message->elements[i].name = (char *)p; remaining -= len + 1; p += len + 1; message->elements[i].num_values = pull_uint32(p, 0); diff --git a/source/lib/ldb/ldb_tdb/ldb_search.c b/source/lib/ldb/ldb_tdb/ldb_search.c index e0a62962c7..97f8a7d0be 100644 --- a/source/lib/ldb/ldb_tdb/ldb_search.c +++ b/source/lib/ldb/ldb_tdb/ldb_search.c @@ -100,17 +100,13 @@ static int msg_add_distinguished_name(struct ldb_module *module, struct ldb_mess int ret; el.flags = 0; - el.name = talloc_strdup(msg, "distinguishedName"); - if (!el.name) { - return -1; - } + el.name = "distinguishedName"; el.num_values = 1; el.values = &val; - val.data = ldb_dn_linearize(msg, msg->dn); - val.length = strlen(val.data); + val.data = (uint8_t *)ldb_dn_linearize(msg, msg->dn); + val.length = strlen((char *)val.data); ret = msg_add_element(module->ldb, msg, &el, 1); - talloc_free(el.name); return ret; } @@ -190,7 +186,7 @@ static struct ldb_message *ltdb_pull_attrs(struct ldb_module *module, if (ldb_attr_cmp(attrs[i], "distinguishedName") == 0) { if (msg_add_distinguished_name(module, ret) != 0) { - return -1; + return NULL; } continue; } @@ -358,7 +354,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi int ret; if (key.dsize < 4 || - strncmp(key.dptr, "DN=", 3) != 0) { + strncmp((char *)key.dptr, "DN=", 3) != 0) { return 0; } @@ -376,7 +372,7 @@ static int search_func(struct tdb_context *tdb, TDB_DATA key, TDB_DATA data, voi } if (!msg->dn) { - msg->dn = ldb_dn_explode(msg, key.dptr + 3); + msg->dn = ldb_dn_explode(msg, (char *)key.dptr + 3); if (msg->dn == NULL) { talloc_free(msg); return -1; diff --git a/source/lib/ldb/ldb_tdb/ldb_tdb.c b/source/lib/ldb/ldb_tdb/ldb_tdb.c index 22360ffb1c..b9404a557b 100644 --- a/source/lib/ldb/ldb_tdb/ldb_tdb.c +++ b/source/lib/ldb/ldb_tdb/ldb_tdb.c @@ -80,7 +80,7 @@ struct TDB_DATA ltdb_key(struct ldb_module *module, const struct ldb_dn *dn) goto failed; } - key.dptr = key_str; + key.dptr = (uint8_t *)key_str; key.dsize = strlen(key_str) + 1; return key; diff --git a/source/lib/ldb/modules/ldb_map.c b/source/lib/ldb/modules/ldb_map.c index 246fc5709d..48aa7e2ef5 100644 --- a/source/lib/ldb/modules/ldb_map.c +++ b/source/lib/ldb/modules/ldb_map.c @@ -625,7 +625,7 @@ static struct ldb_message *ldb_map_message_incoming(struct ldb_module *module, c for (j = 0; j < oldelm->num_values; j++) elm->values[j] = ldb_val_dup(elm, &oldelm->values[j]); - ldb_msg_add(module->ldb, msg, elm, oldelm->flags); + ldb_msg_add(msg, elm, oldelm->flags); break; case MAP_CONVERT: @@ -642,7 +642,7 @@ static struct ldb_message *ldb_map_message_incoming(struct ldb_module *module, c for (j = 0; j < oldelm->num_values; j++) elm->values[j] = attr->u.convert.convert_remote(module, elm, &oldelm->values[j]); - ldb_msg_add(module->ldb, msg, elm, oldelm->flags); + ldb_msg_add(msg, elm, oldelm->flags); break; case MAP_KEEP: @@ -659,7 +659,7 @@ static struct ldb_message *ldb_map_message_incoming(struct ldb_module *module, c elm->name = talloc_strdup(elm, oldelm->name); - ldb_msg_add(module->ldb, msg, elm, oldelm->flags); + ldb_msg_add(msg, elm, oldelm->flags); break; case MAP_GENERATE: @@ -671,7 +671,7 @@ static struct ldb_message *ldb_map_message_incoming(struct ldb_module *module, c if (!elm) continue; - ldb_msg_add(module->ldb, msg, elm, elm->flags); + ldb_msg_add(msg, elm, elm->flags); break; default: ldb_debug(module->ldb, LDB_DEBUG_ERROR, "Unknown attr->type for %s", attr->local_name); @@ -750,9 +750,11 @@ static int map_search_fb(struct ldb_module *module, const struct ldb_dn *base, { int ret; struct ldb_parse_tree t_and, t_not, t_present, *childs[2]; + char *ismapped; t_present.operation = LDB_OP_PRESENT; - t_present.u.present.attr = talloc_strdup(NULL, "isMapped"); + ismapped = talloc_strdup(module, "isMapped"); + t_present.u.present.attr = ismapped; t_not.operation = LDB_OP_NOT; t_not.u.isnot.child = &t_present; @@ -765,7 +767,7 @@ static int map_search_fb(struct ldb_module *module, const struct ldb_dn *base, ret = ldb_next_search_bytree(module, base, scope, &t_and, attrs, res); - talloc_free(t_present.u.present.attr); + talloc_free(ismapped); return ret; } @@ -847,7 +849,7 @@ static int map_search_mp(struct ldb_module *module, const struct ldb_dn *base, int j; ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Extra data found for remote DN: %s", ldb_dn_linearize(merged, merged->dn)); for (j = 0; j < extrares[0]->num_elements; j++) { - ldb_msg_add(module->ldb, merged, &(extrares[0]->elements[j]), extrares[0]->elements[j].flags); + ldb_msg_add(merged, &(extrares[0]->elements[j]), extrares[0]->elements[j].flags); } } @@ -941,7 +943,7 @@ static int map_add(struct ldb_module *module, const struct ldb_message *msg) fb->dn = talloc_reference(fb, msg->dn); /* We add objectClass, so 'top' should be no problem */ - ldb_msg_add_string(module->ldb, mp, "objectClass", "top"); + ldb_msg_add_string(mp, "objectClass", "top"); /* make a list of remote objectclasses that can be used * given the attributes that are available and add to @@ -971,7 +973,7 @@ static int map_add(struct ldb_module *module, const struct ldb_message *msg) /* Apparently, it contains all required elements */ if (has_musts && has_baseclasses) { - ldb_msg_add_string(module->ldb, mp, "objectClass", privdat->objectclass_maps[i].remote_name); + ldb_msg_add_string(mp, "objectClass", privdat->objectclass_maps[i].remote_name); ldb_debug(module->ldb, LDB_DEBUG_TRACE, "map_add: Adding objectClass %s", privdat->objectclass_maps[i].remote_name); } } @@ -1071,7 +1073,7 @@ static int map_add(struct ldb_module *module, const struct ldb_message *msg) continue; } - ldb_msg_add(module->ldb, mp, elm, 0); + ldb_msg_add(mp, elm, 0); mapped++; } @@ -1083,7 +1085,7 @@ static int map_add(struct ldb_module *module, const struct ldb_message *msg) elm->values = talloc_reference(elm, msg->elements[i].values); elm->name = talloc_strdup(elm, msg->elements[i].name); - ldb_msg_add(module->ldb, fb, elm, 0); + ldb_msg_add(fb, elm, 0); } } @@ -1095,7 +1097,7 @@ static int map_add(struct ldb_module *module, const struct ldb_message *msg) ldb_debug(module->ldb, LDB_DEBUG_TRACE, "ldb_map_add: Added mapped record"); - ldb_msg_add_string(module->ldb, fb, "isMapped", "TRUE"); + ldb_msg_add_string(fb, "isMapped", "TRUE"); ret = ldb_next_add_record(module, fb); if (ret == -1) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, "Adding fallback record failed: %s", ldb_errstring(module->ldb)); @@ -1159,7 +1161,7 @@ static int map_modify(struct ldb_module *module, const struct ldb_message *msg) elm->values[j] = msg->elements[i].values[j]; } - ldb_msg_add(module->ldb, mp, elm, msg->elements[i].flags); + ldb_msg_add(mp, elm, msg->elements[i].flags); mapped++; continue; @@ -1176,7 +1178,7 @@ static int map_modify(struct ldb_module *module, const struct ldb_message *msg) elm->values[j] = attr->u.convert.convert_local(module, mp, &msg->elements[i].values[j]); } - ldb_msg_add(module->ldb, mp, elm, msg->elements[i].flags); + ldb_msg_add(mp, elm, msg->elements[i].flags); mapped++; continue; @@ -1191,7 +1193,7 @@ static int map_modify(struct ldb_module *module, const struct ldb_message *msg) elm->name = talloc_strdup(elm, msg->elements[i].name); - ldb_msg_add(module->ldb, mp, elm, msg->elements[i].flags); + ldb_msg_add(mp, elm, msg->elements[i].flags); mapped++; continue; @@ -1209,8 +1211,7 @@ static int map_modify(struct ldb_module *module, const struct ldb_message *msg) elm->values = talloc_reference(elm, msg->elements[i].values); elm->name = talloc_strdup(elm, msg->elements[i].name); - ldb_msg_add(module->ldb, fb, elm, msg->elements[i].flags); - + ldb_msg_add(fb, elm, msg->elements[i].flags); } } @@ -1218,7 +1219,7 @@ static int map_modify(struct ldb_module *module, const struct ldb_message *msg) ldb_debug(module->ldb, LDB_DEBUG_TRACE, "Modifying fallback record with %d elements", fb->num_elements); fb_ret = ldb_next_modify_record(module, fb); if (fb_ret == -1) { - ldb_msg_add_string(module->ldb, fb, "isMapped", "TRUE"); + ldb_msg_add_string(fb, "isMapped", "TRUE"); fb_ret = ldb_next_add_record(module, fb); } } else fb_ret = 0; diff --git a/source/lib/ldb/modules/operational.c b/source/lib/ldb/modules/operational.c new file mode 100644 index 0000000000..911bc087ca --- /dev/null +++ b/source/lib/ldb/modules/operational.c @@ -0,0 +1,217 @@ +/* + ldb database library + + Copyright (C) Andrew Tridgell 2005 + + ** NOTE! The following LGPL license applies to the ldb + ** library. This does NOT imply that all of Samba is released + ** under the LGPL + + This library is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2 of the License, or (at your option) any later version. + + This library is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with this library; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ +/* + handle operational attributes + */ + +/* + createTimestamp: HIDDEN, searchable, ldaptime, alias for whenCreated + modifyTimestamp: HIDDEN, searchable, ldaptime, alias for whenChanged + + for the above two, we do the search as normal, and if + createTimestamp or modifyTimestamp is asked for, then do + additional searches for whenCreated and whenChanged and fill in + the resulting values + + we also need to replace these with the whenCreated/whenChanged + equivalent in the search expression trees + + whenCreated: not-HIDDEN, CONSTRUCTED, SEARCHABLE + whenChanged: not-HIDDEN, CONSTRUCTED, SEARCHABLE + + on init we need to setup attribute handlers for these so + comparisons are done correctly. The resolution is 1 second. + + on add we need to add both the above, for current time + + on modify we need to change whenChanged + + + subschemaSubentry: HIDDEN, not-searchable, + points at DN CN=Aggregate,CN=Schema,CN=Configuration,$BASEDN + + for this one we do the search as normal, then add the static + value if requested. How do we work out the $BASEDN from inside a + module? + + + structuralObjectClass: HIDDEN, CONSTRUCTED, not-searchable. always same as objectclass? + + for this one we do the search as normal, then if requested ask + for objectclass, change the attribute name, and add it + + attributeTypes: in schema only + objectClasses: in schema only + matchingRules: in schema only + matchingRuleUse: in schema only + creatorsName: not supported by w2k3? + modifiersName: not supported by w2k3? +*/ + + +#include "includes.h" +#include "ldb/include/ldb.h" +#include "ldb/include/ldb_private.h" +#include + +/* + a list of attribute names that should be substituted in the parse + tree before the search is done +*/ +static const struct { + const char *attr; + const char *replace; +} parse_tree_sub[] = { + { "createTimestamp", "whenCreated" }, + { "modifyTimestamp", "whenChanged" } +}; + +/* + a list of attribute names that are hidden, but can be searched for + using another (non-hidden) name to produce the correct result +*/ +static const struct { + const char *attr; + const char *replace; +} search_sub[] = { + { "createTimestamp", "whenCreated" }, + { "modifyTimestamp", "whenChanged" }, + { "structuralObjectClass", "objectClass" } +}; + +/* + hook search operations +*/ +static int operational_search_bytree(struct ldb_module *module, + const struct ldb_dn *base, + enum ldb_scope scope, struct ldb_parse_tree *tree, + const char * const *attrs, + struct ldb_message ***res) +{ + int i, r, a; + int ret; + const char **search_attrs = NULL; + + /* replace any attributes in the parse tree that are + searchable, but are stored using a different name in the + backend */ + for (i=0;i