diff options
author | Andrew Bartlett <abartlet@samba.org> | 2007-09-03 04:14:54 +0200 |
---|---|---|
committer | Stefan Metzmacher <metze@samba.org> | 2007-12-21 03:32:23 +0100 |
commit | 34e3445c60dba4638e21042ac8356007c1d27f4a (patch) | |
tree | b5241ff297c86f25d75f214c0736e4b996058fad /source4/dsdb/samdb/samdb.c | |
parent | 3afdc12b96c0e249a9e4ff665c3b2147a99381a9 (diff) | |
download | samba-34e3445c60dba4638e21042ac8356007c1d27f4a.tar.gz samba-34e3445c60dba4638e21042ac8356007c1d27f4a.tar.bz2 samba-34e3445c60dba4638e21042ac8356007c1d27f4a.zip |
r24916: (merge to release branch)
In response to bug #4892 by Matthias Wallnöfer <mwallnoefer@yahoo.de>
allow the objectclass module to reconstruct the objectclass hierarchy,
rather than using templates.
The issue being fixed in particular is that 'top' was not being set on
containers.
This should ensure we do this right for all objects.
Andrew Bartlett
(This used to be commit eeaa6f82492f2ec5f6595d93451c1429c4f6947e)
Diffstat (limited to 'source4/dsdb/samdb/samdb.c')
-rw-r--r-- | source4/dsdb/samdb/samdb.c | 55 |
1 files changed, 21 insertions, 34 deletions
diff --git a/source4/dsdb/samdb/samdb.c b/source4/dsdb/samdb/samdb.c index 7a20ea8665..18669a2ae7 100644 --- a/source4/dsdb/samdb/samdb.c +++ b/source4/dsdb/samdb/samdb.c @@ -680,7 +680,7 @@ int samdb_find_or_add_attribute(struct ldb_context *ldb, struct ldb_message *msg copy from a template record to a message */ int samdb_copy_template(struct ldb_context *ldb, - struct ldb_message *msg, const char *filter, + struct ldb_message *msg, const char *name, const char **errstring) { struct ldb_result *res; @@ -690,15 +690,20 @@ int samdb_copy_template(struct ldb_context *ldb, *errstring = NULL; + if (!ldb_dn_add_child_fmt(basedn, "CN=Template%s", name)) { + return LDB_ERR_OPERATIONS_ERROR; + } + /* pull the template record */ - ret = ldb_search(ldb, basedn, LDB_SCOPE_SUBTREE, filter, NULL, &res); + ret = ldb_search(ldb, basedn, LDB_SCOPE_BASE, "cn=*", NULL, &res); talloc_free(basedn); if (ret != LDB_SUCCESS) { *errstring = talloc_steal(msg, ldb_errstring(ldb)); return ret; } if (res->count != 1) { - *errstring = talloc_asprintf(msg, "samdb_copy_template: ERROR: template '%s' matched %d records, expected 1\n", filter, + *errstring = talloc_asprintf(msg, "samdb_copy_template: ERROR: template '%s' matched %d records, expected 1\n", + name, res->count); talloc_free(res); return LDB_ERR_OPERATIONS_ERROR; @@ -708,40 +713,22 @@ int samdb_copy_template(struct ldb_context *ldb, for (i = 0; i < t->num_elements; i++) { struct ldb_message_element *el = &t->elements[i]; /* some elements should not be copied from the template */ - if (strcasecmp(el->name, "cn") == 0 || - strcasecmp(el->name, "name") == 0 || - strcasecmp(el->name, "sAMAccountName") == 0 || - strcasecmp(el->name, "sAMAccountName") == 0 || - strcasecmp(el->name, "distinguishedName") == 0 || - strcasecmp(el->name, "objectGUID") == 0) { + if (ldb_attr_cmp(el->name, "cn") == 0 || + ldb_attr_cmp(el->name, "name") == 0 || + ldb_attr_cmp(el->name, "objectClass") == 0 || + ldb_attr_cmp(el->name, "sAMAccountName") == 0 || + ldb_attr_cmp(el->name, "sAMAccountName") == 0 || + ldb_attr_cmp(el->name, "distinguishedName") == 0 || + ldb_attr_cmp(el->name, "objectGUID") == 0) { continue; } for (j = 0; j < el->num_values; j++) { - if (strcasecmp(el->name, "objectClass") == 0) { - if (strcasecmp((char *)el->values[j].data, "Template") == 0 || - strcasecmp((char *)el->values[j].data, "userTemplate") == 0 || - strcasecmp((char *)el->values[j].data, "groupTemplate") == 0 || - strcasecmp((char *)el->values[j].data, "foreignSecurityPrincipalTemplate") == 0 || - strcasecmp((char *)el->values[j].data, "aliasTemplate") == 0 || - strcasecmp((char *)el->values[j].data, "trustedDomainTemplate") == 0 || - strcasecmp((char *)el->values[j].data, "secretTemplate") == 0) { - continue; - } - ret = samdb_find_or_add_value(ldb, msg, el->name, - (char *)el->values[j].data); - if (ret) { - *errstring = talloc_asprintf(msg, "Adding objectClass %s failed.\n", el->values[j].data); - talloc_free(res); - return ret; - } - } else { - ret = samdb_find_or_add_attribute(ldb, msg, el->name, - (char *)el->values[j].data); - if (ret) { - *errstring = talloc_asprintf(msg, "Adding attribute %s failed.\n", el->name); - talloc_free(res); - return ret; - } + ret = samdb_find_or_add_attribute(ldb, msg, el->name, + (char *)el->values[j].data); + if (ret) { + *errstring = talloc_asprintf(msg, "Adding attribute %s failed.\n", el->name); + talloc_free(res); + return ret; } } } |