diff options
Diffstat (limited to 'source4/lib/ldb/common')
-rw-r--r-- | source4/lib/ldb/common/ldb.c | 2 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_ldif.c | 22 | ||||
-rw-r--r-- | source4/lib/ldb/common/ldb_msg.c | 133 | ||||
-rw-r--r-- | source4/lib/ldb/common/util.c | 6 |
4 files changed, 158 insertions, 5 deletions
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c index 3ba4434e07..146745043f 100644 --- a/source4/lib/ldb/common/ldb.c +++ b/source4/lib/ldb/common/ldb.c @@ -80,7 +80,7 @@ int ldb_search(struct ldb_context *ldb, const char *base, enum ldb_scope scope, const char *expression, - const char *attrs[], struct ldb_message ***res) + char * const attrs[], struct ldb_message ***res) { return ldb->ops->search(ldb, base, scope, expression, attrs, res); } diff --git a/source4/lib/ldb/common/ldb_ldif.c b/source4/lib/ldb/common/ldb_ldif.c index b4c27c3369..5f2fccfebc 100644 --- a/source4/lib/ldb/common/ldb_ldif.c +++ b/source4/lib/ldb/common/ldb_ldif.c @@ -90,7 +90,7 @@ char *ldb_base64_encode(const char *buf, int len) { const char *b64 = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/"; int bit_offset, byte_offset, idx, i; - unsigned char *d = (unsigned char *)buf; + const unsigned char *d = (const unsigned char *)buf; int bytes = (len*8 + 5)/6; char *out; @@ -222,6 +222,23 @@ int ldif_write(int (*fprintf_fn)(void *, const char *, ...), } for (i=0;i<msg->num_elements;i++) { + if (ldif->changetype == LDB_CHANGETYPE_MODIFY) { + switch (msg->elements[i].flags & LDB_FLAG_MOD_MASK) { + case LDB_FLAG_MOD_ADD: + fprintf_fn(private, "add: %s\n", + msg->elements[i].name); + break; + case LDB_FLAG_MOD_DELETE: + fprintf_fn(private, "delete: %s\n", + msg->elements[i].name); + break; + case LDB_FLAG_MOD_REPLACE: + fprintf_fn(private, "replace: %s\n", + msg->elements[i].name); + break; + } + } + for (j=0;j<msg->elements[i].num_values;j++) { if (ldb_should_b64_encode(&msg->elements[i].values[j])) { ret = fprintf_fn(private, "%s:: ", @@ -246,6 +263,9 @@ int ldif_write(int (*fprintf_fn)(void *, const char *, ...), CHECK_RET; } } + if (ldif->changetype == LDB_CHANGETYPE_MODIFY) { + fprintf_fn(private, "-\n"); + } } ret = fprintf_fn(private,"\n"); CHECK_RET; diff --git a/source4/lib/ldb/common/ldb_msg.c b/source4/lib/ldb/common/ldb_msg.c new file mode 100644 index 0000000000..633cc91f2c --- /dev/null +++ b/source4/lib/ldb/common/ldb_msg.c @@ -0,0 +1,133 @@ +/* + ldb database library + + Copyright (C) Andrew Tridgell 2004 + + ** 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 +*/ + +/* + * Name: ldb + * + * Component: ldb message component utility functions + * + * Description: functions for manipulating ldb_message structures + * + * Author: Andrew Tridgell + */ + +#include "includes.h" + + +/* + find an element in a message by attribute name +*/ +struct ldb_message_element *ldb_msg_find_element(const struct ldb_message *msg, + const char *attr_name) +{ + int i; + for (i=0;i<msg->num_elements;i++) { + if (strcmp(msg->elements[i].name, attr_name) == 0) { + return &msg->elements[i]; + } + } + return NULL; +} + + +/* + find a value in an element +*/ +struct ldb_val *ldb_msg_find_val(const struct ldb_message_element *el, + struct ldb_val *val) +{ + int i; + for (i=0;i<el->num_values;i++) { + if (ldb_val_equal(val, &el->values[i])) { + return &el->values[i]; + } + } + return NULL; +} + + +/* + add an empty element to a message +*/ +int ldb_msg_add_empty(struct ldb_message *msg, const char *attr_name, int flags) +{ + struct ldb_message_element *els; + + els = realloc_p(msg->elements, struct ldb_message_element, msg->num_elements+1); + if (!els) { + errno = ENOMEM; + return -1; + } + + els[msg->num_elements].values = NULL; + els[msg->num_elements].num_values = 0; + els[msg->num_elements].flags = flags; + els[msg->num_elements].name = strdup(attr_name); + if (!els[msg->num_elements].name) { + return -1; + } + + msg->elements = els; + msg->num_elements++; + + return 0; +} + +/* + add an empty element to a message +*/ +int ldb_msg_add(struct ldb_message *msg, + const struct ldb_message_element *el, + int flags) +{ + if (ldb_msg_add_empty(msg, el->name, flags) != 0) { + return -1; + } + + msg->elements[msg->num_elements-1] = *el; + msg->elements[msg->num_elements-1].flags = flags; + + return 0; +} + +/* + compare two ldb_message_element structures +*/ +int ldb_msg_element_compare(struct ldb_message_element *el1, + struct ldb_message_element *el2) +{ + int i; + + if (el1->num_values != el2->num_values) { + return el1->num_values - el2->num_values; + } + + for (i=0;i<el1->num_values;i++) { + if (!ldb_msg_find_val(el2, &el1->values[i])) { + return -1; + } + } + + return 0; +} diff --git a/source4/lib/ldb/common/util.c b/source4/lib/ldb/common/util.c index d198a1ad92..e1a7ada1c6 100644 --- a/source4/lib/ldb/common/util.c +++ b/source4/lib/ldb/common/util.c @@ -77,11 +77,11 @@ int list_find(const void *needle, int r; test_i = (min_i + max_i) / 2; - r = comp_fn(needle, *(void **)(base_p + (size * test_i))); + r = comp_fn(needle, *(void * const *)(base_p + (size * test_i))); if (r == 0) { /* scan back for first element */ while (test_t > 0 && - comp_fn(needle, *(void **)(base_p + (size * (test_i-1)))) == 0) { + comp_fn(needle, *(void * const *)(base_p + (size * (test_i-1)))) == 0) { test_i--; } return test_i; @@ -94,7 +94,7 @@ int list_find(const void *needle, } } - if (comp_fn(needle, *(void **)(base_p + (size * min_i))) == 0) { + if (comp_fn(needle, *(void * const *)(base_p + (size * min_i))) == 0) { return min_i; } |