/*
write to ldif, using a caller supplied write method
*/
-int ldif_write(struct ldb_context *ldb,
- int (*fprintf_fn)(void *, const char *, ...),
- void *private_data,
- const struct ldb_ldif *ldif)
+int ldb_ldif_write(struct ldb_context *ldb,
+ int (*fprintf_fn)(void *, const char *, ...),
+ void *private_data,
+ const struct ldb_ldif *ldif)
{
int i, j;
int total=0, ret;
/*
free a message from a ldif_read
*/
-void ldif_read_free(struct ldb_context *ldb, struct ldb_ldif *ldif)
+void ldb_ldif_read_free(struct ldb_context *ldb, struct ldb_ldif *ldif)
{
struct ldb_message *msg = &ldif->msg;
int i;
/*
read from a LDIF source, creating a ldb_message
*/
-struct ldb_ldif *ldif_read(struct ldb_context *ldb,
- int (*fgetc_fn)(void *), void *private_data)
+struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
+ int (*fgetc_fn)(void *), void *private_data)
{
struct ldb_ldif *ldif;
struct ldb_message *msg;
return ldif;
failed:
- if (ldif) ldif_read_free(ldb, ldif);
+ if (ldif) ldb_ldif_read_free(ldb, ldif);
return NULL;
}
return fgetc(state->f);
}
-struct ldb_ldif *ldif_read_file(struct ldb_context *ldb, FILE *f)
+struct ldb_ldif *ldb_ldif_read_file(struct ldb_context *ldb, FILE *f)
{
struct ldif_read_file_state state;
state.f = f;
- return ldif_read(ldb, fgetc_file, &state);
+ return ldb_ldif_read(ldb, fgetc_file, &state);
}
return EOF;
}
-struct ldb_ldif *ldif_read_string(struct ldb_context *ldb, const char *s)
+struct ldb_ldif *ldb_ldif_read_string(struct ldb_context *ldb, const char *s)
{
struct ldif_read_string_state state;
state.s = s;
- return ldif_read(ldb, fgetc_string, &state);
+ return ldb_ldif_read(ldb, fgetc_string, &state);
}
return ret;
}
-int ldif_write_file(struct ldb_context *ldb, FILE *f, const struct ldb_ldif *ldif)
+int ldb_ldif_write_file(struct ldb_context *ldb, FILE *f, const struct ldb_ldif *ldif)
{
struct ldif_write_file_state state;
state.f = f;
- return ldif_write(ldb, fprintf_file, &state, ldif);
+ return ldb_ldif_write(ldb, fprintf_file, &state, ldif);
}
*/
#include "includes.h"
+#include "ldb/include/ldb_parse.h"
/*
void *data;
};
-#include "ldb_parse.h"
-
-
/* these flags are used in ldd_message_element.flags fields. The
LDA_FLAGS_MOD_* flags are used in ldap_modify() calls to specify
whether attributes are being added, deleted or modified */
/*
ldif manipulation functions
*/
-int ldif_write(struct ldb_context *ldb,
- int (*fprintf_fn)(void *, const char *, ...),
- void *private_data,
- const struct ldb_ldif *ldif);
-void ldif_read_free(struct ldb_context *ldb, struct ldb_ldif *);
-struct ldb_ldif *ldif_read(struct ldb_context *ldb,
- int (*fgetc_fn)(void *), void *private_data);
-struct ldb_ldif *ldif_read_file(struct ldb_context *ldb, FILE *f);
-struct ldb_ldif *ldif_read_string(struct ldb_context *ldb, const char *s);
-int ldif_write_file(struct ldb_context *ldb, FILE *f, const struct ldb_ldif *msg);
+int ldb_ldif_write(struct ldb_context *ldb,
+ int (*fprintf_fn)(void *, const char *, ...),
+ void *private_data,
+ const struct ldb_ldif *ldif);
+void ldb_ldif_read_free(struct ldb_context *ldb, struct ldb_ldif *);
+struct ldb_ldif *ldb_ldif_read(struct ldb_context *ldb,
+ int (*fgetc_fn)(void *), void *private_data);
+struct ldb_ldif *ldb_ldif_read_file(struct ldb_context *ldb, FILE *f);
+struct ldb_ldif *ldb_ldif_read_string(struct ldb_context *ldb, const char *s);
+int ldb_ldif_write_file(struct ldb_context *ldb, FILE *f, const struct ldb_ldif *msg);
/* useful functions for ldb_message structure manipulation */
#include "includes.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
+#include "ldb/include/ldb_parse.h"
struct dn_list {
unsigned int count;
#include "includes.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
+#include "ldb/include/ldb_parse.h"
/*
const struct ldb_message *message,
struct TDB_DATA *data)
{
- int i, j;
+ int i, j, real_elements=0;
size_t size;
char *p;
size_t len;
+ for (i=0;i<message->num_elements;i++) {
+ if (message->elements[i].num_values != 0) {
+ real_elements++;
+ }
+ }
+
/* work out how big it needs to be */
size = 8;
p = data->dptr;
put_uint32(p, 0, LTDB_PACKING_FORMAT);
- put_uint32(p, 4, message->num_elements);
+ put_uint32(p, 4, real_elements);
p += 8;
/* the dn needs to be packed so we can be case preserving
message->elements = ldb_malloc_array_p(ldb, struct ldb_message_element,
message->num_elements);
-
if (!message->elements) {
errno = ENOMEM;
goto failed;
}
+ memset(message->elements, 0,
+ message->num_elements * sizeof(struct ldb_message_element));
+
for (i=0;i<message->num_elements;i++) {
if (remaining < 10) {
errno = EIO;
}
}
p += 4;
+ remaining -= 4;
for (j=0;j<message->elements[i].num_values;j++) {
len = pull_uint32(p, 0);
if (len > remaining-5) {
}
}
+ if (remaining != 0) {
+ ldb_debug(ldb, LDB_DEBUG_ERROR,
+ "Error: %d bytes unread in ltdb_unpack_data\n", remaining);
+ }
+
return 0;
failed:
#include "includes.h"
#include "ldb/ldb_tdb/ldb_tdb.h"
+#include "ldb/include/ldb_parse.h"
/*
free a message that has all parts separately allocated
continue;
}
+ if (ldb_attr_cmp(attrs[i], "dn") == 0) {
+ struct ldb_message_element el2;
+ struct ldb_val val;
+
+ el2.flags = 0;
+ el2.name = ldb_strdup(ldb, "dn");
+ if (!el2.name) {
+ msg_free_all_parts(ldb, ret);
+ ldb_free(ldb, el2.name);
+ return NULL;
+ }
+ el2.num_values = 1;
+ el2.values = &val;
+ val.data = ret->dn;
+ val.length = strlen(ret->dn);
+
+ if (msg_add_element(ldb, ret, &el2) != 0) {
+ msg_free_all_parts(ldb, ret);
+ ldb_free(ldb, el2.name);
+ return NULL;
+ }
+ ldb_free(ldb, el2.name);
+ continue;
+ }
+
el = ldb_msg_find_element(msg, attrs[i]);
if (!el) {
continue;
ret = ltdb_unpack_data(ldb, &tdb_data2, msg);
if (ret == -1) {
- free(tdb_data2.dptr);
+ ldb_free(ldb, tdb_data2.dptr);
return -1;
}
struct ldb_ldif *ldif;
int ret, count=0;
- while ((ldif = ldif_read_file(ldb, f))) {
+ while ((ldif = ldb_ldif_read_file(ldb, f))) {
if (ldif->changetype != LDB_CHANGETYPE_ADD &&
ldif->changetype != LDB_CHANGETYPE_NONE) {
fprintf(stderr, "Only CHANGETYPE_ADD records allowed\n");
} else {
count++;
}
- ldif_read_free(ldb, ldif);
+ ldb_ldif_read_free(ldb, ldif);
}
return count;
for (i=0;i<argc;i++) {
ret = ldb_delete(ldb, argv[i]);
if (ret != 0) {
- printf("delete of '%s' failed\n", argv[i]);
+ printf("delete of '%s' failed - %s\n",
+ argv[i], ldb_errstring(ldb));
}
}
ldif.changetype = LDB_CHANGETYPE_NONE;
ldif.msg = *msgs[i];
- ldif_write_file(ldb, f, &ldif);
+ ldb_ldif_write_file(ldb, f, &ldif);
}
return 0;
return -1;
}
- while ((ldif = ldif_read_file(ldb, f))) {
+ while ((ldif = ldb_ldif_read_file(ldb, f))) {
msgs2 = ldb_realloc_p(ldb, msgs2, struct ldb_message *, count2+1);
if (!msgs2) {
fprintf(stderr, "out of memory");
struct ldb_ldif *ldif;
int ret = -1, count = 0;
- while ((ldif = ldif_read_file(ldb, f))) {
+ while ((ldif = ldb_ldif_read_file(ldb, f))) {
switch (ldif->changetype) {
case LDB_CHANGETYPE_NONE:
case LDB_CHANGETYPE_ADD:
} else {
count++;
}
- ldif_read_free(ldb, ldif);
+ ldb_ldif_read_free(ldb, ldif);
}
return count;
ldif.changetype = LDB_CHANGETYPE_NONE;
ldif.msg = *msgs[i];
- ldif_write_file(ldb, stdout, &ldif);
+ ldb_ldif_write_file(ldb, stdout, &ldif);
}
if (ret > 0) {