📄 objectclass.c
字号:
return ldb_next_request(ac->module, ac->search_req);}static int objectclass_do_mod(struct ldb_handle *h) { const struct dsdb_schema *schema; struct oc_context *ac; struct ldb_message_element *objectclass_element; struct ldb_message *msg; TALLOC_CTX *mem_ctx; struct class_list *sorted, *current; int ret; ac = talloc_get_type(h->private_data, struct oc_context); schema = dsdb_get_schema(ac->module->ldb); mem_ctx = talloc_new(ac); if (mem_ctx == NULL) { return LDB_ERR_OPERATIONS_ERROR; } ac->mod_req = talloc(ac, struct ldb_request); if (ac->mod_req == NULL) { talloc_free(mem_ctx); return LDB_ERR_OPERATIONS_ERROR; } ac->mod_req->operation = LDB_MODIFY; ac->mod_req->controls = NULL; ac->mod_req->context = ac; ac->mod_req->callback = NULL; ldb_set_timeout_from_prev_req(ac->module->ldb, ac->orig_req, ac->mod_req); /* use a new message structure */ ac->mod_req->op.mod.message = msg = ldb_msg_new(ac->mod_req); if (msg == NULL) { ldb_set_errstring(ac->module->ldb, "objectclass: could not create new modify msg"); talloc_free(mem_ctx); return LDB_ERR_OPERATIONS_ERROR; } /* This is now the objectClass list from the database */ objectclass_element = ldb_msg_find_element(ac->search_res->message, "objectClass"); if (!objectclass_element) { /* Where did it go? bail now... */ talloc_free(mem_ctx); return LDB_ERR_OPERATIONS_ERROR; } /* modify dn */ msg->dn = ac->orig_req->op.mod.message->dn; ret = objectclass_sort(ac->module, schema, msg, mem_ctx, objectclass_element, &sorted); if (ret != LDB_SUCCESS) { return ret; } /* We must completely replace the existing objectClass entry. * We could do a constrained add/del, but we are meant to be * in a transaction... */ ret = ldb_msg_add_empty(msg, "objectClass", LDB_FLAG_MOD_REPLACE, NULL); if (ret != LDB_SUCCESS) { ldb_set_errstring(ac->module->ldb, "objectclass: could not clear objectclass in modify msg"); talloc_free(mem_ctx); return ret; } /* Move from the linked list back into an ldb msg */ for (current = sorted; current; current = current->next) { ret = ldb_msg_add_string(msg, "objectClass", current->objectclass->lDAPDisplayName); if (ret != LDB_SUCCESS) { ldb_set_errstring(ac->module->ldb, "objectclass: could not re-add sorted objectclass to modify msg"); talloc_free(mem_ctx); return ret; } } ret = ldb_msg_sanity_check(ac->module->ldb, msg); if (ret != LDB_SUCCESS) { talloc_free(mem_ctx); return ret; } h->state = LDB_ASYNC_INIT; h->status = LDB_SUCCESS; ac->step = OC_DO_MOD; talloc_free(mem_ctx); /* perform the search */ return ldb_next_request(ac->module, ac->mod_req);}static int objectclass_rename(struct ldb_module *module, struct ldb_request *req){ static const char * const attrs[] = { NULL }; struct ldb_handle *h; struct oc_context *ac; struct ldb_dn *parent_dn; int ret; ldb_debug(module->ldb, LDB_DEBUG_TRACE, "objectclass_rename\n"); if (ldb_dn_is_special(req->op.rename.newdn)) { /* do not manipulate our control entries */ return ldb_next_request(module, req); } /* Firstly ensure we are not trying to rename it to be a child of itself */ if ((ldb_dn_compare_base(req->op.rename.olddn, req->op.rename.newdn) == 0) && (ldb_dn_compare(req->op.rename.olddn, req->op.rename.newdn) != 0)) { ldb_asprintf_errstring(module->ldb, "Cannot rename %s to be a child of itself", ldb_dn_get_linearized(req->op.rename.olddn)); return LDB_ERR_UNWILLING_TO_PERFORM; } h = oc_init_handle(req, module); if (!h) { return LDB_ERR_OPERATIONS_ERROR; } ac = talloc_get_type(h->private_data, struct oc_context); /* return or own handle to deal with this call */ req->handle = h; parent_dn = ldb_dn_get_parent(ac, ac->orig_req->op.rename.newdn); if (parent_dn == NULL) { ldb_oom(module->ldb); return LDB_ERR_OPERATIONS_ERROR; } ret = ldb_build_search_req(&ac->search_req, module->ldb, ac, parent_dn, LDB_SCOPE_BASE, "(objectClass=*)", attrs, NULL, ac, get_search_callback); if (ret != LDB_SUCCESS) { return ret; } talloc_steal(ac->search_req, parent_dn); ldb_set_timeout_from_prev_req(ac->module->ldb, ac->orig_req, ac->search_req); ac->step = OC_SEARCH_RENAME_PARENT; return ldb_next_request(ac->module, ac->search_req);}static int objectclass_do_rename(struct ldb_handle *h) { struct oc_context *ac; int ret; ac = talloc_get_type(h->private_data, struct oc_context); ac->rename_req = talloc(ac, struct ldb_request); if (ac->rename_req == NULL) { return LDB_ERR_OPERATIONS_ERROR; } *ac->rename_req = *ac->orig_req; ldb_set_timeout_from_prev_req(ac->module->ldb, ac->orig_req, ac->rename_req); /* Check we have a valid parent */ if (ac->search_res == NULL) { ldb_asprintf_errstring(ac->module->ldb, "objectclass: Cannot rename %s, parent does not exist!", ldb_dn_get_linearized(ac->orig_req->op.rename.newdn)); return LDB_ERR_UNWILLING_TO_PERFORM; } /* Fix up the DN to be in the standard form, taking particular care to match the parent DN */ ret = fix_dn(ac->rename_req, ac->orig_req->op.rename.newdn, ac->search_res->message->dn, &ac->rename_req->op.rename.newdn); if (ret != LDB_SUCCESS) { return ret; } /* TODO: Check this is a valid child to this parent, * by reading the allowedChildClasses and * allowedChildClasssesEffective attributes */ h->state = LDB_ASYNC_INIT; h->status = LDB_SUCCESS; ac->step = OC_DO_RENAME; /* perform the rename */ return ldb_next_request(ac->module, ac->rename_req);}static int oc_wait(struct ldb_handle *handle) { struct oc_context *ac; int ret; if (!handle || !handle->private_data) { return LDB_ERR_OPERATIONS_ERROR; } if (handle->state == LDB_ASYNC_DONE) { return handle->status; } handle->state = LDB_ASYNC_PENDING; handle->status = LDB_SUCCESS; ac = talloc_get_type(handle->private_data, struct oc_context); switch (ac->step) { case OC_DO_REQ: ret = ldb_wait(ac->down_req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; } if (ac->down_req->handle->status != LDB_SUCCESS) { handle->status = ac->down_req->handle->status; goto done; } if (ac->down_req->handle->state != LDB_ASYNC_DONE) { return LDB_SUCCESS; } /* mods done, go on */ return objectclass_search_self(handle); case OC_SEARCH_SELF: ret = ldb_wait(ac->search_req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; } if (ac->search_req->handle->status != LDB_SUCCESS) { handle->status = ac->search_req->handle->status; goto done; } if (ac->search_req->handle->state != LDB_ASYNC_DONE) { return LDB_SUCCESS; } /* self search done, go on */ return objectclass_do_mod(handle); case OC_DO_MOD: ret = ldb_wait(ac->mod_req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; } if (ac->mod_req->handle->status != LDB_SUCCESS) { handle->status = ac->mod_req->handle->status; goto done; } if (ac->mod_req->handle->state != LDB_ASYNC_DONE) { return LDB_SUCCESS; } break; case OC_SEARCH_ADD_PARENT: ret = ldb_wait(ac->search_req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS && ret != LDB_ERR_NO_SUCH_OBJECT) { handle->status = ret; goto done; } if (ac->search_req->handle->status != LDB_SUCCESS && ac->search_req->handle->status != LDB_ERR_NO_SUCH_OBJECT) { handle->status = ac->search_req->handle->status; goto done; } if (ac->search_req->handle->state != LDB_ASYNC_DONE) { return LDB_SUCCESS; } /* parent search done, go on */ return objectclass_do_add(handle); case OC_DO_ADD: ret = ldb_wait(ac->add_req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; } if (ac->add_req->handle->status != LDB_SUCCESS) { handle->status = ac->add_req->handle->status; goto done; } if (ac->add_req->handle->state != LDB_ASYNC_DONE) { return LDB_SUCCESS; } break; case OC_SEARCH_RENAME_PARENT: ret = ldb_wait(ac->search_req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS && ret != LDB_ERR_NO_SUCH_OBJECT) { handle->status = ret; goto done; } if (ac->search_req->handle->status != LDB_SUCCESS && ac->search_req->handle->status != LDB_ERR_NO_SUCH_OBJECT) { handle->status = ac->search_req->handle->status; goto done; } if (ac->search_req->handle->state != LDB_ASYNC_DONE) { return LDB_SUCCESS; } /* parent search done, go on */ return objectclass_do_rename(handle); case OC_DO_RENAME: ret = ldb_wait(ac->rename_req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; } if (ac->rename_req->handle->status != LDB_SUCCESS) { handle->status = ac->rename_req->handle->status; goto done; } if (ac->rename_req->handle->state != LDB_ASYNC_DONE) { return LDB_SUCCESS; } break; default: ret = LDB_ERR_OPERATIONS_ERROR; goto done; } ret = LDB_SUCCESS;done: handle->state = LDB_ASYNC_DONE; return ret;}static int oc_wait_all(struct ldb_handle *handle) { int ret; while (handle->state != LDB_ASYNC_DONE) { ret = oc_wait(handle); if (ret != LDB_SUCCESS) { return ret; } } return handle->status;}static int objectclass_wait(struct ldb_handle *handle, enum ldb_wait_type type){ if (type == LDB_WAIT_ALL) { return oc_wait_all(handle); } else { return oc_wait(handle); }}_PUBLIC_ const struct ldb_module_ops ldb_objectclass_module_ops = { .name = "objectclass", .add = objectclass_add, .modify = objectclass_modify, .rename = objectclass_rename, .wait = objectclass_wait};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -