1
0
mirror of https://github.com/samba-team/samba.git synced 2025-01-28 17:47:29 +03:00

we don't need the unique checks in the samldb code now

These attributes now use the unique indexing flag
This commit is contained in:
Andrew Tridgell 2009-06-01 16:37:28 +10:00
parent ce1045983f
commit c0213308bb

View File

@ -466,91 +466,19 @@ static int samldb_generate_samAccountName(struct ldb_message *msg)
return ldb_msg_add_steal_string(msg, "samAccountName", name);
}
static int samldb_check_samAccountName_callback(struct ldb_request *req,
struct ldb_reply *ares)
{
struct samldb_ctx *ac;
int ret;
ac = talloc_get_type(req->context, struct samldb_ctx);
if (!ares) {
ret = LDB_ERR_OPERATIONS_ERROR;
goto done;
}
if (ares->error != LDB_SUCCESS) {
return ldb_module_done(ac->req, ares->controls,
ares->response, ares->error);
}
switch (ares->type) {
case LDB_REPLY_ENTRY:
/* if we get an entry it means this samAccountName
* already exists */
return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_ENTRY_ALREADY_EXISTS);
case LDB_REPLY_REFERRAL:
/* ignore */
talloc_free(ares);
ret = LDB_SUCCESS;
break;
case LDB_REPLY_DONE:
/* not found, go on */
talloc_free(ares);
ret = samldb_next_step(ac);
break;
}
done:
if (ret != LDB_SUCCESS) {
return ldb_module_done(ac->req, NULL, NULL, ret);
}
return LDB_SUCCESS;
}
static int samldb_check_samAccountName(struct samldb_ctx *ac)
{
struct ldb_context *ldb;
struct ldb_request *req;
const char *name;
char *filter;
int ret;
ldb = ldb_module_get_ctx(ac->module);
if (ldb_msg_find_element(ac->msg, "samAccountName") == NULL) {
ret = samldb_generate_samAccountName(ac->msg);
if (ret != LDB_SUCCESS) {
return ret;
}
}
name = ldb_msg_find_attr_as_string(ac->msg, "samAccountName", NULL);
if (name == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
filter = talloc_asprintf(ac, "samAccountName=%s", name);
if (filter == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
ret = ldb_build_search_req(&req, ldb, ac,
ac->domain_dn, LDB_SCOPE_SUBTREE,
filter, NULL,
NULL,
ac, samldb_check_samAccountName_callback,
ac->req);
talloc_free(filter);
if (ret != LDB_SUCCESS) {
return ret;
}
ac->ares = NULL;
return ldb_next_request(ac->module, req);
return samldb_next_step(ac);
}
static int samldb_check_samAccountType(struct samldb_ctx *ac)
@ -768,87 +696,6 @@ static int samldb_new_sid(struct samldb_ctx *ac)
return samldb_next_step(ac);
}
static int samldb_check_sid_callback(struct ldb_request *req,
struct ldb_reply *ares)
{
struct samldb_ctx *ac;
int ret;
ac = talloc_get_type(req->context, struct samldb_ctx);
if (!ares) {
ret = LDB_ERR_OPERATIONS_ERROR;
goto done;
}
if (ares->error != LDB_SUCCESS) {
return ldb_module_done(ac->req, ares->controls,
ares->response, ares->error);
}
switch (ares->type) {
case LDB_REPLY_ENTRY:
/* if we get an entry it means an object with the
* requested sid exists */
return ldb_module_done(ac->req, NULL, NULL,
LDB_ERR_CONSTRAINT_VIOLATION);
case LDB_REPLY_REFERRAL:
/* ignore */
talloc_free(ares);
break;
case LDB_REPLY_DONE:
/* not found, go on */
talloc_free(ares);
ret = samldb_next_step(ac);
break;
}
done:
if (ret != LDB_SUCCESS) {
return ldb_module_done(ac->req, NULL, NULL, ret);
}
return LDB_SUCCESS;
}
static int samldb_check_sid(struct samldb_ctx *ac)
{
struct ldb_context *ldb;
const char *const attrs[2] = { "objectSid", NULL };
struct ldb_request *req;
char *filter;
int ret;
if (ac->sid == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
ldb = ldb_module_get_ctx(ac->module);
filter = talloc_asprintf(ac, "(objectSid=%s)",
ldap_encode_ndr_dom_sid(ac, ac->sid));
if (filter == NULL) {
return LDB_ERR_OPERATIONS_ERROR;
}
ret = ldb_build_search_req(&req, ldb, ac,
ldb_get_default_basedn(ldb),
LDB_SCOPE_SUBTREE,
filter, attrs,
NULL,
ac, samldb_check_sid_callback,
ac->req);
if (ret != LDB_SUCCESS) {
return ret;
}
return ldb_next_request(ac->module, req);
}
static int samldb_notice_sid_callback(struct ldb_request *req,
struct ldb_reply *ares)
{
@ -1051,9 +898,6 @@ static int samldb_fill_object(struct samldb_ctx *ac, const char *type)
if (ret != LDB_SUCCESS) return ret;
}
ret = samldb_add_step(ac, samldb_check_sid);
if (ret != LDB_SUCCESS) return ret;
ret = samldb_add_step(ac, samldb_notice_sid);
if (ret != LDB_SUCCESS) return ret;
@ -1228,10 +1072,6 @@ static int samldb_fill_foreignSecurityPrincipal_object(struct samldb_ctx *ac)
ret = samldb_add_step(ac, samldb_apply_template);
if (ret != LDB_SUCCESS) return ret;
/* check we do not already have this SID */
ret = samldb_add_step(ac, samldb_check_sid);
if (ret != LDB_SUCCESS) return ret;
/* check if we need to notice this SID */
ret = samldb_add_step(ac, samldb_foreign_notice_sid);
if (ret != LDB_SUCCESS) return ret;