The branch, master has been updated
       via  a8e8a3161164ec469d65d7489d2f71fdc288a131 (commit)
       via  6d1d33319ced87c9741983302cf42a4841d688de (commit)
       via  237f720e6c116b0e07bd20fb90ce19680ad36d3c (commit)
       via  206d79ac514823f1c8f33489b740439df79189b6 (commit)
       via  29ba7765d90eda0b3d0f45f7a970272f0ef2ab2f (commit)
      from  5b2b5abf4f630c28dc5f018ecced3894ae66f491 (commit)

http://gitweb.samba.org/?p=samba.git;a=shortlog;h=master


- Log -----------------------------------------------------------------
commit a8e8a3161164ec469d65d7489d2f71fdc288a131
Author: Andrew Tridgell <[email protected]>
Date:   Tue Sep 8 21:55:56 2009 +1000

    s4/ldb: allow printing ntSecurityDescriptor in full
    
    print security descriptors in NDR format if --show-binary is
    given. This is easier to read than sddl format.

commit 6d1d33319ced87c9741983302cf42a4841d688de
Author: Andrew Tridgell <[email protected]>
Date:   Tue Sep 8 21:45:08 2009 +1000

    s4/ldb: added ldif handler for repsFrom/repsTo
    
    In normal usage this makes no difference, but if you add --show-binary
    then you can see the NDR printed out in the usual ndr_print_*() format

commit 237f720e6c116b0e07bd20fb90ce19680ad36d3c
Author: Andrew Tridgell <[email protected]>
Date:   Tue Sep 8 21:39:33 2009 +1000

    s4/ldb: expose the ldb flags with ldb_get_flags()

commit 206d79ac514823f1c8f33489b740439df79189b6
Author: Andrew Tridgell <[email protected]>
Date:   Tue Sep 8 21:39:09 2009 +1000

    s4/ldb: don't line wrap ldif when --show-binary is used

commit 29ba7765d90eda0b3d0f45f7a970272f0ef2ab2f
Author: Andrew Tridgell <[email protected]>
Date:   Tue Sep 8 20:57:31 2009 +1000

    s4/ldb: added --show-binary command line option
    
    This add --show-binary to ldbsearch. When this flag is set, binary
    blobs will be shown as-is, instead of base64 encoded. This is useful
    for some XML encoded attributes, and will also be used as part of some
    NDR print formatting for attributes like repsTo.

-----------------------------------------------------------------------

Summary of changes:
 source4/lib/ldb-samba/ldif_handlers.c |   66 +++++++++++++++++++++++++++++++-
 source4/lib/ldb-samba/ldif_handlers.h |    1 +
 source4/lib/ldb/common/ldb.c          |    6 +++
 source4/lib/ldb/common/ldb_ldif.c     |   21 +++++++---
 source4/lib/ldb/include/ldb.h         |   11 +++++
 source4/lib/ldb/include/ldb_module.h  |    2 +-
 source4/lib/ldb/ldb_tdb/ldb_index.c   |    2 +-
 source4/lib/ldb/tools/cmdline.c       |    5 ++
 source4/lib/ldb/tools/cmdline.h       |    1 +
 9 files changed, 104 insertions(+), 11 deletions(-)


Changeset truncated at 500 lines:

diff --git a/source4/lib/ldb-samba/ldif_handlers.c 
b/source4/lib/ldb-samba/ldif_handlers.c
index 7086430..6927576 100644
--- a/source4/lib/ldb-samba/ldif_handlers.c
+++ b/source4/lib/ldb-samba/ldif_handlers.c
@@ -30,10 +30,42 @@
 #include "librpc/gen_ndr/ndr_security.h"
 #include "librpc/gen_ndr/ndr_misc.h"
 #include "librpc/gen_ndr/ndr_drsblobs.h"
+#include "librpc/ndr/libndr.h"
 #include "libcli/security/security.h"
 #include "param/param.h"
 
 /*
+  use ndr_print_* to convert a NDR formatted blob to a ldif formatted blob
+*/
+static int ldif_write_NDR(struct ldb_context *ldb, void *mem_ctx,
+                         const struct ldb_val *in, struct ldb_val *out,
+                         size_t struct_size,
+                         ndr_pull_flags_fn_t pull_fn,
+                         ndr_print_fn_t print_fn)
+{
+       uint8_t *p;
+       enum ndr_err_code err;
+       if (!(ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY)) {
+               return ldb_handler_copy(ldb, mem_ctx, in, out);
+       }
+       p = talloc_size(mem_ctx, struct_size);
+       err = ndr_pull_struct_blob(in, mem_ctx, 
+                                  lp_iconv_convenience(ldb_get_opaque(ldb, 
"loadparm")), 
+                                  p, pull_fn);
+       if (err != NDR_ERR_SUCCESS) {
+               talloc_free(p);
+               return ldb_handler_copy(ldb, mem_ctx, in, out);
+       }
+       out->data = (uint8_t *)ndr_print_struct_string(mem_ctx, print_fn, 
"NDR", p);
+       talloc_free(p);
+       if (out->data == NULL) {
+               return ldb_handler_copy(ldb, mem_ctx, in, out);         
+       }
+       out->length = strlen((char *)out->data);
+       return 0;
+}
+
+/*
   convert a ldif formatted objectSid to a NDR formatted blob
 */
 static int ldif_read_objectSid(struct ldb_context *ldb, void *mem_ctx,
@@ -314,7 +346,6 @@ static int ldif_read_ntSecurityDescriptor(struct 
ldb_context *ldb, void *mem_ctx
                                          const struct ldb_val *in, struct 
ldb_val *out)
 {
        struct security_descriptor *sd;
-
        enum ndr_err_code ndr_err;
 
        sd = talloc(mem_ctx, struct security_descriptor);
@@ -354,6 +385,14 @@ static int ldif_write_ntSecurityDescriptor(struct 
ldb_context *ldb, void *mem_ct
        struct security_descriptor *sd;
        enum ndr_err_code ndr_err;
 
+       if (ldb_get_flags(ldb) & LDB_FLG_SHOW_BINARY) {
+               return ldif_write_NDR(ldb, mem_ctx, in, out, 
+                                     sizeof(struct security_descriptor),
+                                     
(ndr_pull_flags_fn_t)ndr_pull_security_descriptor,
+                                     
(ndr_print_fn_t)ndr_print_security_descriptor);
+                                     
+       }
+
        sd = talloc(mem_ctx, struct security_descriptor);
        if (sd == NULL) {
                return -1;
@@ -673,6 +712,19 @@ static int ldif_comparison_int32(struct ldb_context *ldb, 
void *mem_ctx,
         - (int32_t) strtoll((char *)v2->data, NULL, 0);
 }
 
+/*
+  convert a NDR formatted blob to a ldif formatted repsFromTo
+*/
+static int ldif_write_repsFromTo(struct ldb_context *ldb, void *mem_ctx,
+                                const struct ldb_val *in, struct ldb_val *out)
+{
+       return ldif_write_NDR(ldb, mem_ctx, in, out, 
+                             sizeof(struct repsFromToBlob),
+                             (ndr_pull_flags_fn_t)ndr_pull_repsFromToBlob,
+                             (ndr_print_fn_t)ndr_print_repsFromToBlob);
+}
+
+
 static int extended_dn_write_hex(struct ldb_context *ldb, void *mem_ctx,
                                 const struct ldb_val *in, struct ldb_val *out)
 {
@@ -720,7 +772,13 @@ static const struct ldb_schema_syntax samba_syntaxes[] = {
                .ldif_write_fn    = ldb_handler_copy,
                .canonicalise_fn  = ldif_canonicalise_int32,
                .comparison_fn    = ldif_comparison_int32
-       }
+       },{
+               .name             = LDB_SYNTAX_SAMBA_REPSFROMTO,
+               .ldif_read_fn     = ldb_handler_copy,
+               .ldif_write_fn    = ldif_write_repsFromTo,
+               .canonicalise_fn  = ldb_handler_copy,
+               .comparison_fn    = ldb_comparison_binary
+       },
 };
 
 static const struct ldb_dn_extended_syntax samba_dn_syntax[] = {
@@ -761,7 +819,9 @@ static const struct {
        { "fRSReplicaSetGUID",          LDB_SYNTAX_SAMBA_GUID },
        { "netbootGUID",                LDB_SYNTAX_SAMBA_GUID },
        { "objectCategory",             LDB_SYNTAX_SAMBA_OBJECT_CATEGORY },
-       { "prefixMap",                  LDB_SYNTAX_SAMBA_PREFIX_MAP }
+       { "prefixMap",                  LDB_SYNTAX_SAMBA_PREFIX_MAP },
+       { "repsFrom",                   LDB_SYNTAX_SAMBA_REPSFROMTO },
+       { "repsTo",                     LDB_SYNTAX_SAMBA_REPSFROMTO },
 };
 
 const struct ldb_schema_syntax *ldb_samba_syntax_by_name(struct ldb_context 
*ldb, const char *name)
diff --git a/source4/lib/ldb-samba/ldif_handlers.h 
b/source4/lib/ldb-samba/ldif_handlers.h
index 3e1f17e..839525e 100644
--- a/source4/lib/ldb-samba/ldif_handlers.h
+++ b/source4/lib/ldb-samba/ldif_handlers.h
@@ -7,6 +7,7 @@
 #define LDB_SYNTAX_SAMBA_OBJECT_CATEGORY       
"LDB_SYNTAX_SAMBA_OBJECT_CATEGORY"
 #define LDB_SYNTAX_SAMBA_PREFIX_MAP            "LDB_SYNTAX_SAMBA_PREFIX_MAP"
 #define LDB_SYNTAX_SAMBA_INT32                 "LDB_SYNTAX_SAMBA_INT32"
+#define LDB_SYNTAX_SAMBA_REPSFROMTO            "LDB_SYNTAX_SAMBA_REPSFROMTO"
 
 #include "lib/ldb-samba/ldif_handlers_proto.h"
 
diff --git a/source4/lib/ldb/common/ldb.c b/source4/lib/ldb/common/ldb.c
index dc30326..6939cef 100644
--- a/source4/lib/ldb/common/ldb.c
+++ b/source4/lib/ldb/common/ldb.c
@@ -1467,3 +1467,9 @@ int ldb_global_init(void)
        /* Provided for compatibility with some older versions of ldb */
        return 0;
 }
+
+/* return the ldb flags */
+unsigned int ldb_get_flags(struct ldb_context *ldb)
+{
+       return ldb->flags;
+}
diff --git a/source4/lib/ldb/common/ldb_ldif.c 
b/source4/lib/ldb/common/ldb_ldif.c
index 83f08b6..cde2132 100644
--- a/source4/lib/ldb/common/ldb_ldif.c
+++ b/source4/lib/ldb/common/ldb_ldif.c
@@ -185,11 +185,15 @@ char *ldb_base64_encode(void *mem_ctx, const char *buf, 
int len)
 /*
   see if a buffer should be base64 encoded
 */
-int ldb_should_b64_encode(const struct ldb_val *val)
+int ldb_should_b64_encode(struct ldb_context *ldb, const struct ldb_val *val)
 {
        unsigned int i;
        uint8_t *p = val->data;
 
+       if (ldb->flags & LDB_FLG_SHOW_BINARY) {
+               return 0;
+       }
+
        if (val->length == 0) {
                return 0;
        }
@@ -333,7 +337,7 @@ int ldb_ldif_write(struct ldb_context *ldb,
                        if (ret != LDB_SUCCESS) {
                                v = msg->elements[i].values[j];
                        }
-                       if (ret != LDB_SUCCESS || ldb_should_b64_encode(&v)) {
+                       if (ret != LDB_SUCCESS || ldb_should_b64_encode(ldb, 
&v)) {
                                ret = fprintf_fn(private_data, "%s:: ", 
                                                 msg->elements[i].name);
                                CHECK_RET;
@@ -346,9 +350,14 @@ int ldb_ldif_write(struct ldb_context *ldb,
                        } else {
                                ret = fprintf_fn(private_data, "%s: ", 
msg->elements[i].name);
                                CHECK_RET;
-                               ret = fold_string(fprintf_fn, private_data,
-                                                 (char *)v.data, v.length,
-                                                 
strlen(msg->elements[i].name)+2);
+                               if (ldb->flags & LDB_FLG_SHOW_BINARY) {
+                                       ret = fprintf_fn(private_data, "%*.*s", 
+                                                        v.length, v.length, 
(char *)v.data);
+                               } else {
+                                       ret = fold_string(fprintf_fn, 
private_data,
+                                                         (char *)v.data, 
v.length,
+                                                         
strlen(msg->elements[i].name)+2);
+                               }
                                CHECK_RET;
                                ret = fprintf_fn(private_data, "\n");
                                CHECK_RET;
@@ -811,7 +820,7 @@ char *ldb_ldif_message_string(struct ldb_context *ldb, 
TALLOC_CTX *mem_ctx,
        struct ldb_ldif ldif;
 
        ldif.changetype = changetype;
-       ldif.msg = msg;
+       ldif.msg = discard_const_p(struct ldb_message, msg);
 
        return ldb_ldif_write_string(ldb, mem_ctx, &ldif);
 }
diff --git a/source4/lib/ldb/include/ldb.h b/source4/lib/ldb/include/ldb.h
index f38dc8f..04b0a22 100644
--- a/source4/lib/ldb/include/ldb.h
+++ b/source4/lib/ldb/include/ldb.h
@@ -240,6 +240,12 @@ struct ldb_utf8_fns {
 */
 #define LDB_FLG_NOMMAP 8
 
+/**
+   Flag to tell ldif handlers not to force encoding of binary
+   structures in base64   
+*/
+#define LDB_FLG_SHOW_BINARY 16
+
 /*
    structures for ldb_parse_tree handling code
 */
@@ -1892,4 +1898,9 @@ void ldb_qsort (void *const pbase, size_t total_elems, 
size_t size, void *opaque
 */
 struct ldb_control **ldb_parse_control_strings(struct ldb_context *ldb, 
TALLOC_CTX *mem_ctx, const char **control_strings);
 
+/**
+   return the ldb flags 
+*/
+unsigned int ldb_get_flags(struct ldb_context *ldb);
+
 #endif
diff --git a/source4/lib/ldb/include/ldb_module.h 
b/source4/lib/ldb/include/ldb_module.h
index 1d6329c..199c0bb 100644
--- a/source4/lib/ldb/include/ldb_module.h
+++ b/source4/lib/ldb/include/ldb_module.h
@@ -102,7 +102,7 @@ int save_controls(struct ldb_control *exclude, struct 
ldb_request *req, struct l
 int check_critical_controls(struct ldb_control **controls);
 
 /* The following definitions come from lib/ldb/common/ldb_ldif.c  */
-int ldb_should_b64_encode(const struct ldb_val *val);
+int ldb_should_b64_encode(struct ldb_context *ldb, const struct ldb_val *val);
 
 /* The following definitions come from lib/ldb/common/ldb_match.c  */
 int ldb_match_msg(struct ldb_context *ldb,
diff --git a/source4/lib/ldb/ldb_tdb/ldb_index.c 
b/source4/lib/ldb/ldb_tdb/ldb_index.c
index 7db22de..85fbfa0 100644
--- a/source4/lib/ldb/ldb_tdb/ldb_index.c
+++ b/source4/lib/ldb/ldb_tdb/ldb_index.c
@@ -455,7 +455,7 @@ static struct ldb_dn *ltdb_index_key(struct ldb_context 
*ldb,
                talloc_free(attr_folded);
                return NULL;
        }
-       if (ldb_should_b64_encode(&v)) {
+       if (ldb_should_b64_encode(ldb, &v)) {
                char *vstr = ldb_base64_encode(ldb, (char *)v.data, v.length);
                if (!vstr) return NULL;
                ret = ldb_dn_new_fmt(ldb, ldb, "%s:%s::%s", LTDB_INDEX, 
attr_folded, vstr);
diff --git a/source4/lib/ldb/tools/cmdline.c b/source4/lib/ldb/tools/cmdline.c
index b6c1de3..8541106 100644
--- a/source4/lib/ldb/tools/cmdline.c
+++ b/source4/lib/ldb/tools/cmdline.c
@@ -56,6 +56,7 @@ static struct poptOption popt_options[] = {
        { "output", 'O', POPT_ARG_STRING, &options.output, 0, "Output File", 
"Output" },
        { NULL,    'o', POPT_ARG_STRING, NULL, 'o', "ldb_connect option", 
"OPTION" },
        { "controls", 0, POPT_ARG_STRING, NULL, 'c', "controls", NULL },
+       { "show-binary", 0, POPT_ARG_NONE, &options.show_binary, 0, "display 
binary LDIF", NULL },
 #if (_SAMBA_BUILD_ >= 4)
        POPT_COMMON_SAMBA
        POPT_COMMON_CREDENTIALS
@@ -215,6 +216,10 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context 
*ldb,
                flags |= LDB_FLG_NOSYNC;
        }
 
+       if (options.show_binary) {
+               flags |= LDB_FLG_SHOW_BINARY;
+       }
+
 #if (_SAMBA_BUILD_ >= 4)
        /* Must be after we have processed command line options */
        gensec_init(cmdline_lp_ctx); 
diff --git a/source4/lib/ldb/tools/cmdline.h b/source4/lib/ldb/tools/cmdline.h
index 4decf45..9f728fb 100644
--- a/source4/lib/ldb/tools/cmdline.h
+++ b/source4/lib/ldb/tools/cmdline.h
@@ -44,6 +44,7 @@ struct ldb_cmdline {
        const char *input;
        const char *output;
        char **controls;
+       int show_binary;
 };
 
 struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb, int argc, 
const char **argv,


-- 
Samba Shared Repository

Reply via email to