summaryrefslogtreecommitdiff
path: root/source4/lib/ldb/tools/ldbmodify.c
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-04-10 20:18:22 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 12:51:11 -0500
commitac193579e7db00c7a2ea0aadaaf0d34c10dcf1a5 (patch)
treebcd9a0afdc2996df4a56479932b7d36d32c50f8d /source4/lib/ldb/tools/ldbmodify.c
parent91b30df39bfaec8bfa32be40a13fd62008f66b9e (diff)
downloadsamba-ac193579e7db00c7a2ea0aadaaf0d34c10dcf1a5.tar.gz
samba-ac193579e7db00c7a2ea0aadaaf0d34c10dcf1a5.tar.bz2
samba-ac193579e7db00c7a2ea0aadaaf0d34c10dcf1a5.zip
r152: a quick airport commit ....
added ldbedit, a _really_ useful command added ldbadd, ldbdel, ldbsearch and ldbmodify to build solved lots of timezone issues, we now pass the torture tests with client and server in different zones fixed several build issues I know this breaks the no-LDAP build. Wait till I arrive in San Jose for that fix. (This used to be commit af34710d4da1841653624fe304b1c8d812c0fdd9)
Diffstat (limited to 'source4/lib/ldb/tools/ldbmodify.c')
-rw-r--r--source4/lib/ldb/tools/ldbmodify.c100
1 files changed, 81 insertions, 19 deletions
diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c
index e1cff655db..a93c710a7a 100644
--- a/source4/lib/ldb/tools/ldbmodify.c
+++ b/source4/lib/ldb/tools/ldbmodify.c
@@ -34,27 +34,27 @@
#include "includes.h"
- int main(void)
-{
- static struct ldb_context *ldb;
- struct ldb_ldif *ldif;
- int ret;
- int count=0, failures=0;
- const char *ldb_url;
-
- ldb_url = getenv("LDB_URL");
- if (!ldb_url) {
- ldb_url = "tdb://test.ldb";
- }
+static int failures;
- ldb = ldb_connect(ldb_url, 0, NULL);
-
- if (!ldb) {
- perror("ldb_connect");
- exit(1);
- }
+static void usage(void)
+{
+ printf("Usage: ldbmodify <options> <ldif...>\n");
+ printf("Options:\n");
+ printf(" -H ldb_url choose the database (or $LDB_URL)\n");
+ printf("\n");
+ printf("Modifies a ldb based upon ldif change records\n\n");
+ exit(1);
+}
- while ((ldif = ldif_read_file(stdin))) {
+/*
+ process modifies for one file
+*/
+static int process_file(struct ldb_context *ldb, FILE *f)
+{
+ struct ldb_ldif *ldif;
+ int ret, count = 0;
+
+ while ((ldif = ldif_read_file(f))) {
switch (ldif->changetype) {
case LDB_CHANGETYPE_NONE:
case LDB_CHANGETYPE_ADD:
@@ -77,6 +77,68 @@
ldif_read_free(ldif);
}
+ return count;
+}
+
+ int main(int argc, char * const argv[])
+{
+ struct ldb_context *ldb;
+ int count=0;
+ const char *ldb_url;
+ int opt, i;
+
+ ldb_url = getenv("LDB_URL");
+
+ while ((opt = getopt(argc, argv, "hH:")) != EOF) {
+ switch (opt) {
+ case 'H':
+ ldb_url = optarg;
+ break;
+
+ case 'h':
+ default:
+ usage();
+ break;
+ }
+ }
+
+ if (!ldb_url) {
+ fprintf(stderr, "You must specify a ldb URL\n");
+ exit(1);
+ }
+
+ argc -= optind;
+ argv += optind;
+
+ ldb = ldb_connect(ldb_url, 0, NULL);
+
+ if (!ldb) {
+ perror("ldb_connect");
+ exit(1);
+ }
+
+ if (argc == 0) {
+ usage();
+ exit(1);
+ }
+
+ 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) {
+ fclose(f);
+ }
+ }
+
ldb_close(ldb);
printf("Modified %d records with %d failures\n", count, failures);