r7714: enable samba credentials handling in ldb tools. So you can now do a
authorAndrew Tridgell <tridge@samba.org>
Sat, 18 Jun 2005 09:01:09 +0000 (09:01 +0000)
committerGerald (Jerry) Carter <jerry@samba.org>
Wed, 10 Oct 2007 18:18:25 +0000 (13:18 -0500)
encrypted ldbedit against w2k3

source/lib/ldb/ldb_ildap/ldb_ildap.c
source/lib/ldb/tools/cmdline.c
source/lib/ldb/tools/cmdline.h
source/lib/ldb/tools/ldbadd.c
source/lib/ldb/tools/ldbdel.c
source/lib/ldb/tools/ldbedit.c
source/lib/ldb/tools/ldbmodify.c
source/lib/ldb/tools/ldbrename.c
source/lib/ldb/tools/ldbsearch.c
source/lib/ldb/tools/ldbtest.c

index aa0efee481048d125b5360f2b54f9bbe8397db1e..9cccec03136c291648a5d0abc4a2a84526240901 100644 (file)
@@ -34,6 +34,7 @@
 #include "ldb/include/ldb_private.h"
 #include "libcli/ldap/ldap.h"
 #include "libcli/ldap/ldap_client.h"
+#include "lib/cmdline/popt_common.h"
 
 struct ildb_private {
        const char *basedn;
@@ -110,6 +111,10 @@ static int ildb_search(struct ldb_module *module, const char *base,
        int count, i;
        struct ldap_message **ldapres, *msg;
 
+       if (scope == LDB_SCOPE_DEFAULT) {
+               scope = LDB_SCOPE_SUBTREE;
+       }
+       
        if (base == NULL) {
                base = "";
        }
@@ -384,6 +389,15 @@ int ildb_connect(struct ldb_context *ldb, const char *url,
        ldb->modules->private_data = ildb;
        ldb->modules->ops = &ildb_ops;
 
+       if (cmdline_credentials->username_obtained > CRED_GUESSED) {
+               status = ldap_bind_sasl(ildb->ldap, cmdline_credentials);
+               if (!NT_STATUS_IS_OK(status)) {
+                       ldb_debug(ldb, LDB_DEBUG_ERROR, "Failed to bind - %s\n",
+                                 ldap_errstr(ildb->ldap, status));
+                       goto failed;
+               }
+       }
+
        return 0;
 
 failed:
index a7bfac8bb428a8f43caf013fe1d8f6cf8538c0fc..1f4a7544a5e1fc651e519394163390b175e5b042 100644 (file)
@@ -26,6 +26,9 @@
 #include "ldb/include/ldb.h"
 #include "ldb/include/ldb_private.h"
 #include "ldb/tools/cmdline.h"
+#ifdef _SAMBA_BUILD_
+#include "lib/cmdline/popt_common.h"
+#endif
 
 /*
   process command line options
@@ -50,10 +53,20 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
                { "num-records", 0, POPT_ARG_INT, &options.num_records, 0, "number of test records", NULL },
                { "all", 'a',    POPT_ARG_NONE, &options.all_records, 0, "dn=*", NULL },
                { "sorted", 'S', POPT_ARG_NONE, &options.sorted, 0, "sort attributes", NULL },
+               { "sasl-mechanism", 0, POPT_ARG_STRING, &options.sasl_mechanism, 0, "choose SASL mechanism", "MECHANISM" },
                { NULL,    'o', POPT_ARG_STRING, NULL, 'o', "ldb_connect option", "OPTION" },
+#ifdef _SAMBA_BUILD_
+               POPT_COMMON_SAMBA
+               POPT_COMMON_CREDENTIALS
+               POPT_COMMON_VERSION
+#endif
                POPT_TABLEEND
        };
 
+#ifdef _SAMBA_BUILD_
+       ldbsearch_init_subsystems;
+#endif
+
        ret = talloc_zero(ldb, struct ldb_cmdline);
        if (ret == NULL) {
                ldb_oom(ldb);
@@ -74,6 +87,8 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
                options.editor = "vi";
        }
 
+       options.scope = LDB_SCOPE_DEFAULT;
+
        pc = poptGetContext(argv[0], argc, argv, popt_options, 
                            POPT_CONTEXT_KEEP_FIRST);
 
@@ -133,6 +148,12 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const
                goto failed;
        }
 
+       if (ldb_connect(ldb, ret->url, 0, ret->options) != 0) {
+               fprintf(stderr, "Failed to connect to %s - %s\n", 
+                       ret->url, ldb_errstring(ldb));
+               goto failed;
+       }
+
        return ret;
 
 failed:
index f3eae26cce9fbf04713bfe8454348003dc9adf9a..8e479c5538c4f0164f688d1ebb36aa3e54f1ccb8 100644 (file)
@@ -39,6 +39,7 @@ struct ldb_cmdline {
        const char **argv;
        int num_records;
        int num_searches;
+       const char *sasl_mechanism;
 };
 
 struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, const char **argv,
index 35a41527bef328fd6685b48cc5de39c596539a0c..7794b9de392922c24b3d90150c1cb6115975454b 100644 (file)
@@ -90,21 +90,13 @@ static int process_file(struct ldb_context *ldb, FILE *f)
  int main(int argc, const char **argv)
 {
        struct ldb_context *ldb;
-       int i, ret, count=0;
+       int i, count=0;
        struct ldb_cmdline *options;
 
        ldb = ldb_init(NULL);
 
        options = ldb_cmdline_process(ldb, argc, argv, usage);
 
-       ret = ldb_connect(ldb, options->url, 0, options->options);
-       if (ret != 0) {
-               fprintf(stderr, "Failed to connect to %s - %s\n", 
-                       options->url, ldb_errstring(ldb));
-               talloc_free(ldb);
-               exit(1);
-       }
-
        if (options->argc == 0) {
                count += process_file(ldb, stdin);
        } else {
index fcf1d26d5394c1430f3efd44309a5fee759f5551..fdb1f7ef3b28ad9efb51dc53a66df9deb7f4147a 100644 (file)
@@ -93,14 +93,6 @@ static void usage(void)
                exit(1);
        }
 
-       ret = ldb_connect(ldb, options->url, 0, options->options);
-       if (ret != 0) {
-               fprintf(stderr, "Failed to connect to %s - %s\n", 
-                       options->url, ldb_errstring(ldb));
-               talloc_free(ldb);
-               exit(1);
-       }
-
        for (i=0;i<options->argc;i++) {
                const char *dn = options->argv[i];
                if (options->recursive) {
index 6c599ee2ec2f3fc684f80793d6d1528ec7b32d63..73fb77dfd1cab7928de2d77172c70647ce53df74 100644 (file)
@@ -303,14 +303,6 @@ static void usage(void)
                attrs = (const char * const *)options->argv;
        }
 
-       ret = ldb_connect(ldb, options->url, LDB_FLG_RDONLY, options->options);
-       if (ret != 0) {
-               fprintf(stderr, "Failed to connect to %s - %s\n", 
-                       options->url, ldb_errstring(ldb));
-               talloc_free(ldb);
-               exit(1);
-       }
-
        ret = ldb_search(ldb, options->basedn, options->scope, expression, attrs, &msgs);
        if (ret == -1) {
                printf("search failed - %s\n", ldb_errstring(ldb));
index c54c573ab0efdebee79821f1f3d193d63c1a12f0..39725b195d79a618324cc6526d1a9619c1f0f30a 100644 (file)
@@ -100,14 +100,6 @@ static int process_file(struct ldb_context *ldb, FILE *f)
 
        options = ldb_cmdline_process(ldb, argc, argv, usage);
 
-       ret = ldb_connect(ldb, options->url, 0, options->options);
-       if (ret != 0) {
-               fprintf(stderr, "Failed to connect to %s - %s\n", 
-                       options->url, ldb_errstring(ldb));
-               talloc_free(ldb);
-               exit(1);
-       }
-
        if (options->argc == 0) {
                usage();
                exit(1);
index 5566c3d7d7f2d4b4e07e1ea3fbada7a18efde933..c74516869eefad82c42ab867efa1c5df32ef9efd 100644 (file)
@@ -67,14 +67,6 @@ static void usage(void)
 
        options = ldb_cmdline_process(ldb, argc, argv, usage);
 
-       ret = ldb_connect(ldb, options->url, 0, options->options);
-       if (ret != 0) {
-               fprintf(stderr, "Failed to connect to %s - %s\n", 
-                       options->url, ldb_errstring(ldb));
-               talloc_free(ldb);
-               exit(1);
-       }
-
        if (options->argc < 2) {
                usage();
        }
index 04f83ca36685c945d44a23f59b9f4a10bab686c4..0e81da5de345c2fc1246ccf2751b66d107809601 100644 (file)
@@ -119,7 +119,7 @@ static int do_search(struct ldb_context *ldb,
        struct ldb_context *ldb;
        const char * const * attrs = NULL;
        struct ldb_cmdline *options;
-       int ret;
+       int ret = -1;
 
        ldb = ldb_init(NULL);
 
@@ -134,14 +134,6 @@ static int do_search(struct ldb_context *ldb,
                attrs = (const char * const *)(options->argv+1);
        }
 
-       ret = ldb_connect(ldb, options->url, LDB_FLG_RDONLY, options->options);
-       if (ret != 0) {
-               fprintf(stderr, "Failed to connect to %s - %s\n", 
-                       options->url, ldb_errstring(ldb));
-               talloc_free(ldb);
-               exit(1);
-       }
-
        if (options->interactive) {
                char line[1024];
                while (fgets(line, sizeof(line), stdin)) {
index a7c9a3123ace67d83f9c957f2e83d09648b11f2a..28ac7545a4eb0f15d28b4c7227393235df9b82c5 100644 (file)
@@ -365,14 +365,6 @@ static void usage(void)
                options->basedn = "ou=Ldb Test,ou=People,o=University of Michigan,c=US";
        }
 
-       ret = ldb_connect(ldb, options->url, 0, options->options);
-       if (ret != 0) {
-               fprintf(stderr, "Failed to connect to %s - %s\n", 
-                       options->url, ldb_errstring(ldb));
-               talloc_free(ldb);
-               exit(1);
-       }
-
        srandom(1);
 
        start_test(ldb, options->num_records, options->num_searches);