ldb/tools: only use LDB_FLG_SHOW_BINARY for 'ldbsearch'
authorStefan Metzmacher <metze@samba.org>
Thu, 19 Jan 2017 03:29:13 +0000 (04:29 +0100)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 24 Feb 2017 02:59:01 +0000 (03:59 +0100)
--show-binary is only useful for ldbseach in all other cases
it will destroy data.

Signed-off-by: Stefan Metzmacher <metze@samba.org>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
Autobuild-User(master): Andrew Bartlett <abartlet@samba.org>
Autobuild-Date(master): Fri Feb 24 03:59:01 CET 2017 on sn-devel-144

lib/ldb/tools/cmdline.c
lib/ldb/tools/cmdline.h
lib/ldb/tools/ldbsearch.c

index 6d0a40643df82b737e5519822dc30212c8a2a25f..8baa12087172b9dd9b70caac300b340833dd41d4 100644 (file)
@@ -93,9 +93,10 @@ static bool add_control(TALLOC_CTX *mem_ctx, const char *control)
 /**
   process command line options
 */
-struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, 
+static struct ldb_cmdline *ldb_cmdline_process_internal(struct ldb_context *ldb,
                                        int argc, const char **argv,
-                                       void (*usage)(struct ldb_context *))
+                                       void (*usage)(struct ldb_context *),
+                                       bool search)
 {
        struct ldb_cmdline *ret=NULL;
        poptContext pc;
@@ -278,8 +279,15 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb,
                flags |= LDB_FLG_NOSYNC;
        }
 
-       if (options.show_binary) {
-               flags |= LDB_FLG_SHOW_BINARY;
+       if (search) {
+               /*
+                * For now we're not adding LDB_FLG_RDONLY,
+                * as that would result in no tdb locking.
+                */
+
+               if (options.show_binary) {
+                       flags |= LDB_FLG_SHOW_BINARY;
+               }
        }
 
        if (options.tracing) {
@@ -317,6 +325,20 @@ failed:
        return NULL;
 }
 
+struct ldb_cmdline *ldb_cmdline_process_search(struct ldb_context *ldb,
+                                              int argc, const char **argv,
+                                              void (*usage)(struct ldb_context *))
+{
+       return ldb_cmdline_process_internal(ldb, argc, argv, usage, true);
+}
+
+struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb,
+                                       int argc, const char **argv,
+                                       void (*usage)(struct ldb_context *))
+{
+       return ldb_cmdline_process_internal(ldb, argc, argv, usage, false);
+}
+
 /* this function check controls reply and determines if more
  * processing is needed setting up the request controls correctly
  *
index 416bf51d228a978b2dc72c8233c786a694b22e30..9af0ea168b79e200cc8c3c98112579ae6aee6a9e 100644 (file)
@@ -46,6 +46,9 @@ struct ldb_cmdline {
        int tracing;
 };
 
+struct ldb_cmdline *ldb_cmdline_process_search(struct ldb_context *ldb,
+                                              int argc, const char **argv,
+                                              void (*usage)(struct ldb_context *));
 struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc,
                                        const char **argv,
                                        void (*usage)(struct ldb_context *));
index a030a5abda663c05ec590243a6c0c15dc600bd42..5eae6242a9977104d56bc28b95356f187f1470c9 100644 (file)
@@ -300,7 +300,7 @@ int main(int argc, const char **argv)
                return LDB_ERR_OPERATIONS_ERROR;
        }
 
-       options = ldb_cmdline_process(ldb, argc, argv, usage);
+       options = ldb_cmdline_process_search(ldb, argc, argv, usage);
 
        /* the check for '=' is for compatibility with ldapsearch */
        if (!options->interactive &&