s4-dsdb: validate number of extended components
authorAndrew Tridgell <tridge@samba.org>
Thu, 13 Jan 2011 00:08:40 +0000 (11:08 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 14 Jan 2011 05:39:32 +0000 (16:39 +1100)
this checks that the number of extended components in a DN is valid,
to match MS AD behaviour. We need to do this to ensure that our tools
don't try to do operations that will be invalid when used against MS
servers

Pair-Programmed-With: Andrew Bartlett <abartlet@samba.org>

source4/dsdb/samdb/ldb_modules/extended_dn_in.c

index 39e69d9b1ed057b851fcfe64287524f78a7da88b..4071adda798b77e3c1ab1cbaf7b39a888b16e168 100644 (file)
@@ -273,6 +273,12 @@ static int extended_dn_in_fix(struct ldb_module *module, struct ldb_request *req
        } else {
                /* It looks like we need to map the DN */
                const struct ldb_val *sid_val, *guid_val, *wkguid_val;
+               int num_components = ldb_dn_get_comp_num(dn);
+               int num_ex_components = ldb_dn_get_extended_comp_num(dn);
+
+               if (num_components != 0 || num_ex_components != 1) {
+                       return ldb_error(ldb_module_get_ctx(module), LDB_ERR_INVALID_DN_SYNTAX, "invalid number of DN components");
+               }
 
                sid_val = ldb_dn_get_extended_component(dn, "SID");
                guid_val = ldb_dn_get_extended_component(dn, "GUID");
@@ -311,7 +317,8 @@ static int extended_dn_in_fix(struct ldb_module *module, struct ldb_request *req
 
                        p = strchr(wkguid_dup, ',');
                        if (!p) {
-                               return LDB_ERR_INVALID_DN_SYNTAX;
+                               return ldb_error(ldb_module_get_ctx(module), LDB_ERR_INVALID_DN_SYNTAX,
+                                                "Invalid WKGUID format");
                        }
 
                        p[0] = '\0';
@@ -336,7 +343,8 @@ static int extended_dn_in_fix(struct ldb_module *module, struct ldb_request *req
                        base_dn_scope = LDB_SCOPE_BASE;
                        base_dn_attrs = wkattr;
                } else {
-                       return LDB_ERR_INVALID_DN_SYNTAX;
+                       return ldb_error(ldb_module_get_ctx(module), LDB_ERR_INVALID_DN_SYNTAX,
+                                        "Invalid extended DN component");
                }
 
                ac = talloc_zero(req, struct extended_search_context);