*/
#include "includes.h"
+#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_errors.h"
+#include "ldb/tools/cmdline.h"
+
+#ifdef _SAMBA_BUILD_
+#include "system/filesys.h"
+#endif
static int failures;
printf("Usage: ldbadd <options> <ldif...>\n");
printf("Options:\n");
printf(" -H ldb_url choose the database (or $LDB_URL)\n");
+ printf(" -o options pass options like modules to activate\n");
+ printf(" e.g: -o modules:timestamps\n");
printf("\n");
printf("Adds records to a ldb, reading ldif the specified list of files\n\n");
exit(1);
break;
}
- ret = ldb_add(ldb, &ldif->msg);
- if (ret != 0) {
+ ldif->msg = ldb_msg_canonicalize(ldb, ldif->msg);
+
+ ret = ldb_add(ldb, ldif->msg);
+ if (ret != LDB_SUCCESS) {
fprintf(stderr, "ERR: \"%s\" on DN %s\n",
- ldb_errstring(ldb), ldif->msg.dn);
+ ldb_errstring(ldb), ldb_dn_linearize(ldb, ldif->msg->dn));
failures++;
} else {
count++;
- int main(int argc, char * const argv[])
+ int main(int argc, const char **argv)
{
struct ldb_context *ldb;
- int count=0;
- const char *ldb_url;
- const char **options = NULL;
- int ldbopts;
- int opt, i;
-
- ldb_url = getenv("LDB_URL");
-
- ldbopts = 0;
- while ((opt = getopt(argc, argv, "hH:o:")) != EOF) {
- switch (opt) {
- case 'H':
- ldb_url = optarg;
- break;
-
- case 'o':
- ldbopts++;
- if (options == NULL) {
- options = (const char **)malloc(sizeof(char *) * (ldbopts + 1));
- } else {
- options = (const char **)realloc(options, sizeof(char *) * (ldbopts + 1));
- if (options == NULL) {
- fprintf(stderr, "Out of memory!\n");
- exit(-1);
- }
+ int i, count=0;
+ struct ldb_cmdline *options;
+
+ ldb = ldb_init(NULL);
+
+ options = ldb_cmdline_process(ldb, argc, argv, usage);
+
+ if (options->argc == 0) {
+ count += process_file(ldb, stdin);
+ } else {
+ for (i=0;i<options->argc;i++) {
+ const char *fname = options->argv[i];
+ FILE *f;
+ f = fopen(fname, "r");
+ if (!f) {
+ perror(fname);
+ exit(1);
}
- options[ldbopts - 1] = optarg;
- options[ldbopts] = NULL;
- break;
-
- case 'h':
- default:
- usage();
- break;
- }
- }
-
- if (!ldb_url) {
- fprintf(stderr, "You must specify a ldb URL\n\n");
- usage();
- }
-
- argc -= optind;
- argv += optind;
-
- ldb = ldb_connect(ldb_url, 0, options);
-
- if (!ldb) {
- perror("ldb_connect");
- exit(1);
- }
-
- ldb_set_debug_stderr(ldb);
-
- if (argc == 0) {
- usage();
- }
-
- for (i=0;i<argc;i++) {
- FILE *f;
- if (strcmp(argv[i],"-") == 0) {
- f = stdin;
- } else {
- f = fopen(argv[i], "r");
- }
- if (!f) {
- perror(argv[i]);
- exit(1);
- }
- count += process_file(ldb, f);
- if (f != stdin) {
+ count += process_file(ldb, f);
fclose(f);
}
}
- ldb_close(ldb);
+ talloc_free(ldb);
printf("Added %d records with %d failures\n", count, failures);