summaryrefslogtreecommitdiff
path: root/source4/lib
diff options
context:
space:
mode:
authorAndrew Tridgell <tridge@samba.org>2004-12-04 10:14:03 +0000
committerGerald (Jerry) Carter <jerry@samba.org>2007-10-10 13:06:20 -0500
commit9012a501533126c4c0ac25a16fd6439a45df3d9a (patch)
tree24e31070e5b34000a70d78ecbc019c0ff141bde2 /source4/lib
parent2f9e170f45e128eb6ab6bd97c9c8b40dcd9a97fa (diff)
downloadsamba-9012a501533126c4c0ac25a16fd6439a45df3d9a.tar.gz
samba-9012a501533126c4c0ac25a16fd6439a45df3d9a.tar.bz2
samba-9012a501533126c4c0ac25a16fd6439a45df3d9a.zip
r4059: moved the ldb -o option parsing to a common routine
(This used to be commit ee52c1e38c9bac852458196ffbd677cca62a3965)
Diffstat (limited to 'source4/lib')
-rw-r--r--source4/lib/ldb/common/util.c20
-rw-r--r--source4/lib/ldb/include/ldb_private.h2
-rw-r--r--source4/lib/ldb/tools/ldbadd.c14
-rw-r--r--source4/lib/ldb/tools/ldbdel.c14
-rw-r--r--source4/lib/ldb/tools/ldbedit.c14
-rw-r--r--source4/lib/ldb/tools/ldbmodify.c14
-rw-r--r--source4/lib/ldb/tools/ldbrename.c14
-rw-r--r--source4/lib/ldb/tools/ldbsearch.c14
-rw-r--r--source4/lib/ldb/tools/ldbtest.c14
9 files changed, 36 insertions, 84 deletions
diff --git a/source4/lib/ldb/common/util.c b/source4/lib/ldb/common/util.c
index af738f352a..0c9cf297c1 100644
--- a/source4/lib/ldb/common/util.c
+++ b/source4/lib/ldb/common/util.c
@@ -86,3 +86,23 @@ int ldb_list_find(const void *needle,
return -1;
}
+
+
+/*
+ common code for parsing -o options in ldb tools
+*/
+const char **ldb_options_parse(const char **options, int *ldbopts, const char *arg)
+{
+ if (*ldbopts == 0) {
+ options = malloc(sizeof(char *) * 2);
+ } else {
+ options = realloc(options, sizeof(char *)*((*ldbopts)+2));
+ }
+ if (options == NULL) {
+ fprintf(stderr, "Out of memory in options parsing!\n");
+ exit(-1);
+ }
+ options[(*ldbopts)++] = arg;
+ options[*ldbopts] = NULL;
+ return options;
+}
diff --git a/source4/lib/ldb/include/ldb_private.h b/source4/lib/ldb/include/ldb_private.h
index 720d8928dd..a2171162ad 100644
--- a/source4/lib/ldb/include/ldb_private.h
+++ b/source4/lib/ldb/include/ldb_private.h
@@ -127,4 +127,6 @@ struct ldb_context *lldb_connect(const char *url,
const char *options[]);
struct ldb_module *timestamps_module_init(struct ldb_context *ldb, const char *options[]);
+const char **ldb_options_parse(const char **options, int *ldbopts, const char *arg);
+
#endif
diff --git a/source4/lib/ldb/tools/ldbadd.c b/source4/lib/ldb/tools/ldbadd.c
index d7f890b155..9d19a1db0a 100644
--- a/source4/lib/ldb/tools/ldbadd.c
+++ b/source4/lib/ldb/tools/ldbadd.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
static int failures;
@@ -100,18 +101,7 @@ static int process_file(struct ldb_context *ldb, FILE *f)
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);
- }
- }
- options[ldbopts - 1] = optarg;
- options[ldbopts] = NULL;
+ options = ldb_options_parse(options, &ldbopts, optarg);
break;
case 'h':
diff --git a/source4/lib/ldb/tools/ldbdel.c b/source4/lib/ldb/tools/ldbdel.c
index dc1c734284..29d3b39730 100644
--- a/source4/lib/ldb/tools/ldbdel.c
+++ b/source4/lib/ldb/tools/ldbdel.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
static int ldb_delete_recursive(struct ldb_context *ldb, const char *dn)
{
@@ -95,18 +96,7 @@ static void usage(void)
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);
- }
- }
- options[ldbopts - 1] = optarg;
- options[ldbopts] = NULL;
+ options = ldb_options_parse(options, &ldbopts, optarg);
break;
case 'h':
diff --git a/source4/lib/ldb/tools/ldbedit.c b/source4/lib/ldb/tools/ldbedit.c
index fd45248c0e..f84d05440f 100644
--- a/source4/lib/ldb/tools/ldbedit.c
+++ b/source4/lib/ldb/tools/ldbedit.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
static int verbose;
@@ -358,18 +359,7 @@ static void usage(void)
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);
- }
- }
- options[ldbopts - 1] = optarg;
- options[ldbopts] = NULL;
+ options = ldb_options_parse(options, &ldbopts, optarg);
break;
case 'h':
diff --git a/source4/lib/ldb/tools/ldbmodify.c b/source4/lib/ldb/tools/ldbmodify.c
index a660b814da..5fabba57b7 100644
--- a/source4/lib/ldb/tools/ldbmodify.c
+++ b/source4/lib/ldb/tools/ldbmodify.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
static int failures;
@@ -102,18 +103,7 @@ static int process_file(struct ldb_context *ldb, FILE *f)
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);
- }
- }
- options[ldbopts - 1] = optarg;
- options[ldbopts] = NULL;
+ options = ldb_options_parse(options, &ldbopts, optarg);
break;
case 'h':
diff --git a/source4/lib/ldb/tools/ldbrename.c b/source4/lib/ldb/tools/ldbrename.c
index f702cbd7f2..3ee001cf23 100644
--- a/source4/lib/ldb/tools/ldbrename.c
+++ b/source4/lib/ldb/tools/ldbrename.c
@@ -36,6 +36,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
static void usage(void)
{
@@ -68,18 +69,7 @@ static void usage(void)
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);
- }
- }
- options[ldbopts - 1] = optarg;
- options[ldbopts] = NULL;
+ options = ldb_options_parse(options, &ldbopts, optarg);
break;
case 'h':
diff --git a/source4/lib/ldb/tools/ldbsearch.c b/source4/lib/ldb/tools/ldbsearch.c
index 9f6b2f617a..fced589572 100644
--- a/source4/lib/ldb/tools/ldbsearch.c
+++ b/source4/lib/ldb/tools/ldbsearch.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
static void usage(void)
{
@@ -125,18 +126,7 @@ static int do_search(struct ldb_context *ldb,
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);
- }
- }
- options[ldbopts - 1] = optarg;
- options[ldbopts] = NULL;
+ options = ldb_options_parse(options, &ldbopts, optarg);
break;
case 'h':
diff --git a/source4/lib/ldb/tools/ldbtest.c b/source4/lib/ldb/tools/ldbtest.c
index f3be8e1e5c..645bc93fd3 100644
--- a/source4/lib/ldb/tools/ldbtest.c
+++ b/source4/lib/ldb/tools/ldbtest.c
@@ -34,6 +34,7 @@
#include "includes.h"
#include "ldb/include/ldb.h"
+#include "ldb/include/ldb_private.h"
static const char *ldb_url;
static const char *base_dn = "ou=Ldb Test,ou=People,o=University of Michigan,c=US";
@@ -387,18 +388,7 @@ static void usage(void)
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);
- }
- }
- options[ldbopts - 1] = optarg;
- options[ldbopts] = NULL;
+ options = ldb_options_parse(options, &ldbopts, optarg);
break;
case 'h':