diff options
author | Andrew Bartlett <abartlet@samba.org> | 2005-07-21 05:24:02 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 13:29:51 -0500 |
commit | 8191f2cc800228e1e0d7378370f12bf6d3fca1e9 (patch) | |
tree | 49abf5df378553fdda9519f171c15e0a2533cf97 /source4/dsdb/samdb/ldb_modules | |
parent | 1211496eba93ee7578d0f72eed2b71f83f1cd202 (diff) | |
download | samba-8191f2cc800228e1e0d7378370f12bf6d3fca1e9.tar.gz samba-8191f2cc800228e1e0d7378370f12bf6d3fca1e9.tar.bz2 samba-8191f2cc800228e1e0d7378370f12bf6d3fca1e9.zip |
r8663: Since simo constructed the samdb module, he and tridge have worked on
a DN parsing system. Leverage that in the dsdb module.
Andrew Bartlett
(This used to be commit 2408f322765fc1b1769d5c8ea69eae4d968cd195)
Diffstat (limited to 'source4/dsdb/samdb/ldb_modules')
-rw-r--r-- | source4/dsdb/samdb/ldb_modules/samldb.c | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/source4/dsdb/samdb/ldb_modules/samldb.c b/source4/dsdb/samdb/ldb_modules/samldb.c index 40b6b72713..6d6c1eb660 100644 --- a/source4/dsdb/samdb/ldb_modules/samldb.c +++ b/source4/dsdb/samdb/ldb_modules/samldb.c @@ -243,29 +243,29 @@ static char *samldb_generate_samAccountName(const void *mem_ctx) { return name; } -static BOOL samldb_get_rdn_and_basedn(const void *mem_ctx, const char *dn, char **rdn, char **basedn) +static BOOL samldb_get_rdn_and_basedn(void *mem_ctx, const char *dn, struct ldb_dn_component **rdn, char **base_dn) { - char *p; + struct ldb_dn *dn_exploded = ldb_dn_explode(mem_ctx, dn); + struct ldb_dn base_dn_exploded; - p = strchr(dn, ','); - if ( ! p ) { + if (!dn_exploded) { return False; } - - *rdn = talloc_strndup(mem_ctx, dn, p - dn); - - if ( ! *rdn) { + + if (dn_exploded->comp_num < 1) { return False; } - - *basedn = talloc_strdup(mem_ctx, p + 1); - - if ( ! *basedn) { - talloc_free(*rdn); - *rdn = NULL; - return False; + + if (dn_exploded->comp_num < 2) { + *base_dn = NULL; + } else { + base_dn_exploded.comp_num = dn_exploded->comp_num - 1; + base_dn_exploded.components = &dn_exploded->components[1]; + + *base_dn = ldb_dn_linearize(mem_ctx, &base_dn_exploded); } + *rdn = &dn_exploded->components[0]; return True; } @@ -380,7 +380,8 @@ static struct ldb_message *samldb_fill_group_object(struct ldb_module *module, c { struct ldb_message *msg2; struct ldb_message_element *attribute; - char *rdn, *basedn; + struct ldb_dn_component *rdn; + char *basedn; if (samldb_find_attribute(msg, "objectclass", "group") == NULL) { return NULL; @@ -404,28 +405,29 @@ static struct ldb_message *samldb_fill_group_object(struct ldb_module *module, c ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_group_object: Bad DN (%s)!\n", msg2->dn); return NULL; } - if (strncasecmp(rdn, "cn", 2) != 0) { - ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_group_object: Bad RDN (%s) for group!\n", rdn); + if (strcasecmp(rdn->name, "cn") != 0) { + ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_group_object: Bad RDN (%s) for group!\n", rdn->name); return NULL; } if ((attribute = samldb_find_attribute(msg2, "cn", NULL)) != NULL) { - if (strcasecmp(&rdn[3], attribute->values[0].data) != 0) { + if (strcasecmp(rdn->value.data, attribute->values[0].data) != 0) { ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_group_object: Bad Attribute Syntax for CN\n"); return NULL; } } else { /* FIXME: remove this if ldb supports natively aliasing between the rdn and the "cn" attribute */ - if ( ! samldb_msg_add_string(module, msg2, "cn", &rdn[3])) { + if ( ! ldb_msg_add_value(module->ldb, msg2, "cn", &rdn->value)) { return NULL; } } if ((attribute = samldb_find_attribute(msg2, "name", NULL)) != NULL) { - if (strcasecmp(&rdn[3], attribute->values[0].data) != 0) { + if (strcasecmp(rdn->value.data, attribute->values[0].data) != 0) { + return NULL; } } else { /* FIXME: remove this if ldb supports natively aliasing between the rdn and the "name" attribute */ - if ( ! samldb_msg_add_string(module, msg2, "name", &rdn[3])) { + if ( !ldb_msg_add_value(module->ldb, msg2, "name", &rdn->value)) { return NULL; } } @@ -457,7 +459,8 @@ static struct ldb_message *samldb_fill_user_or_computer_object(struct ldb_module { struct ldb_message *msg2; struct ldb_message_element *attribute; - char *rdn, *basedn; + struct ldb_dn_component *rdn; + char *basedn; if ((samldb_find_attribute(msg, "objectclass", "user") == NULL) && (samldb_find_attribute(msg, "objectclass", "computer") == NULL)) { @@ -473,7 +476,7 @@ static struct ldb_message *samldb_fill_user_or_computer_object(struct ldb_module return NULL; } - if (samldb_find_attribute(msg, "objectclass", "computer") == NULL) { + if (samldb_find_attribute(msg, "objectclass", "computer") != NULL) { if (samldb_copy_template(module, msg2, "(&(CN=TemplateMemberServer)(objectclass=userTemplate))") != 0) { ldb_debug(module->ldb, LDB_DEBUG_WARNING, "samldb_fill_user_or_computer_object: Error copying computer template!\n"); return NULL; @@ -488,8 +491,8 @@ static struct ldb_message *samldb_fill_user_or_computer_object(struct ldb_module if ( ! samldb_get_rdn_and_basedn(msg2, msg2->dn, &rdn, &basedn)) { return NULL; } - if (strncasecmp(rdn, "cn", 2) != 0) { - ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_user_or_computer_object: Bad RDN (%s) for group!\n", rdn); + if (strcasecmp(rdn->name, "cn") != 0) { + ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_user_or_computer_object: Bad RDN (%s) for group!\n", rdn->name); return NULL; } @@ -499,23 +502,23 @@ static struct ldb_message *samldb_fill_user_or_computer_object(struct ldb_module } if ((attribute = samldb_find_attribute(msg2, "cn", NULL)) != NULL) { - if (strcasecmp(&rdn[3], attribute->values[0].data) != 0) { - ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_user_or_computer_object: Bad Attribute Syntax for CN\n"); + if (strcasecmp(rdn->value.data, attribute->values[0].data) != 0) { + ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_group_object: Bad Attribute Syntax for CN\n"); return NULL; } } else { /* FIXME: remove this if ldb supports natively aliasing between the rdn and the "cn" attribute */ - if ( ! samldb_msg_add_string(module, msg2, "cn", &rdn[3])) { + if ( !ldb_msg_add_value(module->ldb, msg2, "cn", &rdn->value)) { return NULL; } } if ((attribute = samldb_find_attribute(msg2, "name", NULL)) != NULL) { - if (strcasecmp(&rdn[3], attribute->values[0].data) != 0) { + if (strcasecmp(rdn->value.data, attribute->values[0].data) != 0) { ldb_debug(module->ldb, LDB_DEBUG_FATAL, "samldb_fill_user_or_computer_object: Bad Attribute Syntax for name\n"); return NULL; } } else { /* FIXME: remove this if ldb supports natively aliasing between the rdn and the "name" attribute */ - if ( ! samldb_msg_add_string(module, msg2, "name", &rdn[3])) { + if ( !ldb_msg_add_value(module->ldb, msg2, "name", &rdn->value)) { return NULL; } } |