s4-ldb: added a new "reveal" control
authorAndrew Tridgell <tridge@samba.org>
Thu, 10 Dec 2009 12:44:05 +0000 (23:44 +1100)
committerAndrew Tridgell <tridge@samba.org>
Mon, 14 Dec 2009 11:29:57 +0000 (22:29 +1100)
This control will allow inspection of internal ldb values, which would
normally be stripped before being presented to users. The first use
will be stripping linked attribute meta data extended components.

source4/lib/ldb/common/ldb_controls.c
source4/lib/ldb/include/ldb.h
source4/lib/ldb/tools/cmdline.c

index f2ab61bde602f92a5ed2707647dc1f2f974dd39c..8da43ab9b1aec317655c8434d3d281f3657cff28 100644 (file)
@@ -775,6 +775,33 @@ struct ldb_control **ldb_parse_control_strings(struct ldb_context *ldb, void *me
                        continue;
                }
 
+               if (strncmp(control_strings[i], "reveal_internals:", 17) == 0) {
+                       const char *p;
+                       int crit, ret;
+
+                       p = &(control_strings[i][17]);
+                       ret = sscanf(p, "%d", &crit);
+                       if ((ret != 1) || (crit < 0) || (crit > 1)) {
+                               error_string = talloc_asprintf(mem_ctx, "invalid reveal_internals control syntax\n");
+                               error_string = talloc_asprintf_append(error_string, " syntax: crit(b)\n");
+                               error_string = talloc_asprintf_append(error_string, "   note: b = boolean");
+                               ldb_set_errstring(ldb, error_string);
+                               talloc_free(error_string);
+                               return NULL;
+                       }
+
+                       ctrl[i] = talloc(ctrl, struct ldb_control);
+                       if (!ctrl[i]) {
+                               ldb_oom(ldb);
+                               return NULL;
+                       }
+                       ctrl[i]->oid = LDB_CONTROL_REVEAL_INTERNALS;
+                       ctrl[i]->critical = crit;
+                       ctrl[i]->data = NULL;
+
+                       continue;
+               }
+
                /* no controls matched, throw an error */
                ldb_asprintf_errstring(ldb, "Invalid control name: '%s'", control_strings[i]);
                return NULL;
index 88ac29d943c409e09fa5696d3e5faccb8a113acd..2b80e42cb30e2a8621666bc7689554627b802e68 100644 (file)
@@ -470,6 +470,14 @@ typedef int (*ldb_qsort_cmp_fn_t) (void *v1, void *v2, void *opaque);
 
 */
 #define LDB_CONTROL_RECALCULATE_SD_OID "1.3.6.1.4.1.7165.4.3.5"
+
+/**
+   REVEAL_INTERNALS is used to reveal internal attributes and DN
+   components which are not normally shown to the user
+*/
+#define LDB_CONTROL_REVEAL_INTERNALS "1.3.6.1.4.1.7165.4.3.6"
+
+
 /**
    OID for the paged results control. This control is included in the
    searchRequest and searchResultDone messages as part of the controls
@@ -1617,7 +1625,7 @@ char *ldb_dn_alloc_linearized(TALLOC_CTX *mem_ctx, struct ldb_dn *dn);
 char *ldb_dn_get_extended_linearized(void *mem_ctx, struct ldb_dn *dn, int mode);
 const struct ldb_val *ldb_dn_get_extended_component(struct ldb_dn *dn, const char *name);
 int ldb_dn_set_extended_component(struct ldb_dn *dn, const char *name, const struct ldb_val *val);
-
+void ldb_dn_extended_filter(struct ldb_dn *dn, const char * const *accept);
 void ldb_dn_remove_extended_components(struct ldb_dn *dn);
 bool ldb_dn_has_extended(struct ldb_dn *dn);
 
index e27ca5b6a6c25cad2d83a48c462326410fbb6f6c..5204215778957049c683906a412261e35f8a5028 100644 (file)
@@ -61,6 +61,7 @@ static struct poptOption popt_options[] = {
        { "paged", 0, POPT_ARG_NONE, NULL, 'P', "use a paged search", NULL },
        { "show-deleted", 0, POPT_ARG_NONE, NULL, 'D', "show deleted objects", NULL },
        { "show-recycled", 0, POPT_ARG_NONE, NULL, 'R', "show recycled objects", NULL },
+       { "reveal", 0, POPT_ARG_NONE, NULL, 'r', "reveal ldb internals", NULL },
        { "cross-ncs", 0, POPT_ARG_NONE, NULL, 'N', "search across NC boundaries", NULL },
        { "extended-dn", 0, POPT_ARG_NONE, NULL, 'E', "show extended DNs", NULL },
 #if (_SAMBA_BUILD_ >= 4)
@@ -225,6 +226,12 @@ struct ldb_cmdline *ldb_cmdline_process(struct ldb_context *ldb,
                                goto failed;
                        }
                        break;
+               case 'r':
+                       if (!add_control(ret, "reveal_internals:0")) {
+                               fprintf(stderr, __location__ ": out of memory\n");
+                               goto failed;
+                       }
+                       break;
                case 'N':
                        if (!add_control(ret, "search_options:1:2")) {
                                fprintf(stderr, __location__ ": out of memory\n");