s4:dsdb Do less allocation when searching for partitions modules
authorAndrew Bartlett <abartlet@samba.org>
Thu, 22 Oct 2009 23:08:27 +0000 (10:08 +1100)
committerAndrew Tridgell <tridge@samba.org>
Fri, 23 Oct 2009 04:42:14 +0000 (15:42 +1100)
(it didn't help that the previous allocation was on the wrong long-term context)

Andrew Bartlett

source4/dsdb/samdb/ldb_modules/partition_init.c

index 2a1f34e9bcb15b64d2cf06fca841a7c519991371..7d5c1307786105bcc0ee3c1fc71c3072e8dcf8c9 100644 (file)
@@ -89,32 +89,34 @@ static int partition_load_modules(struct ldb_context *ldb,
        }
        
        for (i=0; i < modules_attributes->num_values; i++) {
        }
        
        for (i=0; i < modules_attributes->num_values; i++) {
-               char *base;
                char *p;
                char *p;
-
+               DATA_BLOB dn_blob;
                data->modules[i] = talloc(data->modules, struct partition_module);
                if (!data->modules[i]) {
                        ldb_oom(ldb);
                        return LDB_ERR_OPERATIONS_ERROR;
                }
 
                data->modules[i] = talloc(data->modules, struct partition_module);
                if (!data->modules[i]) {
                        ldb_oom(ldb);
                        return LDB_ERR_OPERATIONS_ERROR;
                }
 
-               base = talloc_strdup(data->partitions, (char *)modules_attributes->values[i].data);
-               p = strchr(base, ':');
+               dn_blob = modules_attributes->values[i];
+
+               p = strchr((const char *)dn_blob.data, ':');
                if (!p) {
                        ldb_asprintf_errstring(ldb, 
                                               "partition_load_modules: "
                if (!p) {
                        ldb_asprintf_errstring(ldb, 
                                               "partition_load_modules: "
-                                              "invalid form for partition module record (missing ':'): %s", base);
+                                              "invalid form for partition module record (missing ':'): %s", (const char *)dn_blob.data);
                        return LDB_ERR_CONSTRAINT_VIOLATION;
                }
                        return LDB_ERR_CONSTRAINT_VIOLATION;
                }
-               p[0] = '\0';
+               /* Now trim off the filename */
+               dn_blob.length = ((uint8_t *)p - dn_blob.data);
+
                p++;
                data->modules[i]->modules = ldb_modules_list_from_string(ldb, data->modules[i],
                                                                         p);
                
                p++;
                data->modules[i]->modules = ldb_modules_list_from_string(ldb, data->modules[i],
                                                                         p);
                
-               if (strcmp(base, "*") == 0) {
+               if (dn_blob.length == 1 && dn_blob.data[0] == '*') {
                        data->modules[i]->dn = NULL;
                } else {
                        data->modules[i]->dn = NULL;
                } else {
-                       data->modules[i]->dn = ldb_dn_new(data->modules[i], ldb, base);
+                       data->modules[i]->dn = ldb_dn_from_ldb_val(data->modules[i], ldb, &dn_blob);
                        if (!data->modules[i]->dn || !ldb_dn_validate(data->modules[i]->dn)) {
                                return LDB_ERR_OPERATIONS_ERROR;
                        }
                        if (!data->modules[i]->dn || !ldb_dn_validate(data->modules[i]->dn)) {
                                return LDB_ERR_OPERATIONS_ERROR;
                        }