summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/common
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2005-10-12 06:10:23 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:39:41 -0500
commita599edf04cbdeef9014923ba0d3713b8ff84f266 (patch)
tree3754385df962fd26fe8bd0e16f3c3b706a385c24 /source4/lib/ldb/common
parent655138602c75925a6d655841ee80cf5346a9a399 (diff)
downloadsamba-a599edf04cbdeef9014923ba0d3713b8ff84f266.tar.gz
samba-a599edf04cbdeef9014923ba0d3713b8ff84f266.tar.bz2
samba-a599edf04cbdeef9014923ba0d3713b8ff84f266.zip
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. (This used to be commit f6818daecca95760c12f79fd307770cbe3346f57)
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r--source4/lib/ldb/common/attrib_handlers.c26
-rw-r--r--source4/lib/ldb/common/ldb_debug.c18
-rw-r--r--source4/lib/ldb/common/ldb_dn.c19
-rw-r--r--source4/lib/ldb/common/ldb_ldif.c14
-rw-r--r--source4/lib/ldb/common/ldb_match.c21
-rw-r--r--source4/lib/ldb/common/ldb_msg.c111
-rw-r--r--source4/lib/ldb/common/ldb_parse.c48
-rw-r--r--source4/lib/ldb/common/ldb_utf8.c1
8 files changed, 195 insertions, 63 deletions
diff --git a/source4/lib/ldb/common/attrib_handlers.c b/source4/lib/ldb/common/attrib_handlers.c
index 61ca566570..d073203b3c 100644
--- a/source4/lib/ldb/common/attrib_handlers.c
+++ b/source4/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/source4/lib/ldb/common/ldb_debug.c b/source4/lib/ldb/common/ldb_debug.c
index 59f00ccc96..d046c8cd1f 100644
--- a/source4/lib/ldb/common/ldb_debug.c
+++ b/source4/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/source4/lib/ldb/common/ldb_dn.c b/source4/lib/ldb/common/ldb_dn.c
index 2cd7d590fe..92e06025d5 100644
--- a/source4/lib/ldb/common/ldb_dn.c
+++ b/source4/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/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c
index b268cca578..7ba6a00147 100644
--- a/source4/lib/ldb/common/ldb_ldif.c
+++ b/source4/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/source4/lib/ldb/common/ldb_match.c b/source4/lib/ldb/common/ldb_match.c
index 14031a6dd1..7573cfc808 100644
--- a/source4/lib/ldb/common/ldb_match.c
+++ b/source4/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/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c
index c2f40f308a..01941f5728 100644
--- a/source4/lib/ldb/common/ldb_msg.c
+++ b/source4/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;i<msg1->num_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/source4/lib/ldb/common/ldb_parse.c b/source4/lib/ldb/common/ldb_parse.c
index e61511ebec..5824a8d003 100644
--- a/source4/lib/ldb/common/ldb_parse.c
+++ b/source4/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;i<tree->u.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/source4/lib/ldb/common/ldb_utf8.c b/source4/lib/ldb/common/ldb_utf8.c
index cd68180f77..69faeb46d3 100644
--- a/source4/lib/ldb/common/ldb_utf8.c
+++ b/source4/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);
}
-