📄 schema.c
字号:
if (ret != LDB_SUCCESS) { return LDB_ERR_OPERATIONS_ERROR; } } } for (j = 0; parent_classes[i]->aux && parent_classes[i]->aux[j]; j++) { if (parent_classes[i]->aux[j]->possinf) { ret = schema_merge_class_list(sctx, &parent_possinf, parent_classes[i]->aux[j]->possinf); if (ret != LDB_SUCCESS) { return LDB_ERR_OPERATIONS_ERROR; } } } } /* foreach parent objectclass, * check parent possible inferiors match all of the child objectclasses * and that * poss Superiors of the child objectclasses mathes one of the parent classes */ temp = sctx->class_list->next; /* skip top it is special */ while (temp) { for (i = 0; parent_possinf[i]; i++) { if (temp->class == parent_possinf[i]) { break; } } if (parent_possinf[i] == NULL) { /* class not found in possible inferiors */ return LDB_ERR_NAMING_VIOLATION; } temp = temp->next; } for (i = 0; parent_classes[i]; i++) { for (j = 0; sctx->sup_list[j]; j++) { if (sctx->sup_list[j] == parent_classes[i]) { break; } } if (sctx->sup_list[j]) { /* possible Superiors match one of the parent classes */ return LDB_SUCCESS; } } /* no parent classes matched superiors */ return LDB_ERR_NAMING_VIOLATION;}static int schema_add_build_down_req(struct schema_context *sctx){ struct schema_class_dlist *temp; struct ldb_message *msg; int ret; sctx->down_req = talloc(sctx, struct ldb_request); if (!sctx->down_req) { ldb_set_errstring(sctx->module->ldb, "Out of memory!"); return LDB_ERR_OPERATIONS_ERROR; } *(sctx->down_req) = *(sctx->orig_req); /* copy the request */ msg = ldb_msg_copy_shallow(sctx->down_req, sctx->orig_req->op.add.message); if (!msg) { ldb_set_errstring(sctx->module->ldb, "Out of memory!"); return LDB_ERR_OPERATIONS_ERROR; } /* rebuild the objectclass list */ ldb_msg_remove_attr(msg, "objectClass"); ret = ldb_msg_add_empty(msg, "objectClass", 0, NULL); if (ret != LDB_SUCCESS) { return ret; } /* Add the complete list of classes back to the message */ for (temp = sctx->class_list; temp; temp = temp->next) { ret = ldb_msg_add_string(msg, "objectClass", temp->class->name); if (ret != LDB_SUCCESS) { return ret; } } /* objectCategory can be set only by the system */ if (ldb_msg_find_element(msg, "objectCategory")) { return LDB_ERR_CONSTRAINT_VIOLATION; } /* the OC is mandatory, every class defines it */ /* use the one defined in the structural class that defines the object */ for (temp = sctx->class_list->next; temp; temp = temp->next) { if (!temp->next) break; if (temp->next->role != SCHEMA_CT_STRUCTURAL) break; }/* oc = talloc_strdup(msg, temp->class->defobjcat); ret = ldb_msg_add_string(msg, "objectCategory", oc);*/ sctx->down_req->op.add.message = msg; return LDB_SUCCESS;}static int schema_check_attributes_syntax(struct schema_context *sctx){ struct ldb_message *msg; struct schema_attribute *attr; int i, ret; msg = sctx->orig_req->op.add.message; for (i = 0; i < msg->num_elements; i++) { attr = schema_store_find(sctx->data->attrs_store, msg->elements[i].name); if (attr == NULL) { return LDB_ERR_NO_SUCH_ATTRIBUTE; } ret = schema_validate(sctx->module->ldb, &msg->elements[i], attr->syntax, attr->single, attr->min, attr->max); if (ret != LDB_SUCCESS) { return ret; } } return LDB_SUCCESS;}static int schema_add_continue(struct ldb_handle *h){ struct schema_context *sctx; int ret; sctx = talloc_get_type(h->private_data, struct schema_context); switch (sctx->step) { case SC_INIT: /* First of all check that a parent exists for this entry */ ret = schema_add_build_parent_req(sctx); if (ret != LDB_SUCCESS) { break; } sctx->step = SC_ADD_CHECK_PARENT; return ldb_next_request(sctx->module, sctx->parent_req); case SC_ADD_CHECK_PARENT: /* parent search done, check result and go on */ if (sctx->parent_res == NULL) { /* we must have a parent */ ret = LDB_ERR_NO_SUCH_OBJECT; break; } /* Check objectclasses are ok */ ret = schema_add_build_objectclass_list(sctx); if (ret != LDB_SUCCESS) { break; } /* check the parent is of the right type for this object */ ret = schema_add_check_container_constraints(sctx); if (ret != LDB_SUCCESS) { break; } /* check attributes syntax */ ret = schema_check_attributes_syntax(sctx); if (ret != LDB_SUCCESS) { break; } ret = schema_add_build_down_req(sctx); if (ret != LDB_SUCCESS) { break; } sctx->step = SC_ADD_TEMP; return ldb_next_request(sctx->module, sctx->down_req); default: ret = LDB_ERR_OPERATIONS_ERROR; break; } /* this is reached only in case of error */ /* FIXME: fire an async reply ? */ h->status = ret; h->state = LDB_ASYNC_DONE; return ret;}static int schema_add(struct ldb_module *module, struct ldb_request *req){ struct schema_context *sctx; struct ldb_handle *h; if (ldb_dn_is_special(req->op.add.message->dn)) { /* do not manipulate our control entries */ return ldb_next_request(module, req); } h = schema_init_handle(req, module, SC_ADD); if (!h) { return LDB_ERR_OPERATIONS_ERROR; } sctx = talloc_get_type(h->private_data, struct schema_context); sctx->orig_req->handle = h; return schema_add_continue(h);}static int schema_modify(struct ldb_module *module, struct ldb_request *req){ if (ldb_dn_is_special(req->op.mod.message->dn)) { /* do not manipulate our control entries */ return ldb_next_request(module, req); } return ldb_next_request(module, req); }static int schema_delete(struct ldb_module *module, struct ldb_request *req){ if (ldb_dn_is_special(req->op.del.dn)) { /* do not manipulate our control entries */ return ldb_next_request(module, req); } /* First of all check no children exists for this entry */ return ldb_next_request(module, req);}static int schema_rename(struct ldb_module *module, struct ldb_request *req){ if (ldb_dn_is_special(req->op.rename.olddn) && ldb_dn_is_special(req->op.rename.newdn)) { /* do not manipulate our control entries */ return ldb_next_request(module, req); } return ldb_next_request(module, req);}static int schema_wait_loop(struct ldb_handle *handle) { struct schema_context *sctx; 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; sctx = talloc_get_type(handle->private_data, struct schema_context); switch (sctx->step) { case SC_ADD_CHECK_PARENT: ret = ldb_wait(sctx->parent_req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; } if (sctx->parent_req->handle->status != LDB_SUCCESS) { handle->status = sctx->parent_req->handle->status; goto done; } if (sctx->parent_req->handle->state != LDB_ASYNC_DONE) { return LDB_SUCCESS; } return schema_add_continue(handle); case SC_ADD_TEMP: ret = ldb_wait(sctx->down_req->handle, LDB_WAIT_NONE); if (ret != LDB_SUCCESS) { handle->status = ret; goto done; } if (sctx->down_req->handle->status != LDB_SUCCESS) { handle->status = sctx->down_req->handle->status; goto done; } if (sctx->down_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 schema_wait_all(struct ldb_handle *handle) { int ret; while (handle->state != LDB_ASYNC_DONE) { ret = schema_wait_loop(handle); if (ret != LDB_SUCCESS) { return ret; } } return handle->status;}static int schema_wait(struct ldb_handle *handle, enum ldb_wait_type type){ if (type == LDB_WAIT_ALL) { return schema_wait_all(handle); } else { return schema_wait_loop(handle); }}static int schema_init(struct ldb_module *module){ static const char *schema_attrs[] = { "schemaNamingContext", NULL }; struct schema_private_data *data; struct ldb_result *res; int ret; /* need to let the partition module to register first */ ret = ldb_next_init(module); if (ret != LDB_SUCCESS) { return ret; } data = ldb_get_opaque(module->ldb, "schema_instance"); if (data) { module->private_data = data; return LDB_SUCCESS; } data = talloc_zero(module->ldb, struct schema_private_data); if (data == NULL) { return LDB_ERR_OPERATIONS_ERROR; } /* find the schema partition */ ret = ldb_search(module->ldb, ldb_dn_new(module, module->ldb, NULL), LDB_SCOPE_BASE, "(objectClass=*)", schema_attrs, &res); if (res->count != 1) { /* FIXME: return a clear error string */ talloc_free(data); talloc_free(res); return LDB_ERR_OPERATIONS_ERROR; } data->schema_dn = ldb_msg_find_attr_as_dn(module->ldb, data, res->msgs[0], "schemaNamingContext"); if (data->schema_dn == NULL) { /* FIXME: return a clear error string */ talloc_free(data); talloc_free(res); return LDB_ERR_OPERATIONS_ERROR; } talloc_free(res); ret = schema_init_attrs(module, data); if (ret != LDB_SUCCESS) { talloc_free(data); return ret; } ret = schema_init_classes(module, data); if (ret != LDB_SUCCESS) { talloc_free(data); return ret; } module->private_data = data; ldb_set_opaque(module->ldb, "schema_instance", data); return LDB_SUCCESS;}_PUBLIC_ const struct ldb_module_ops ldb_schema_module_ops = { .name = "schema", .init_context = schema_init, .add = schema_add, .modify = schema_modify, .del = schema_delete, .rename = schema_rename, .wait = schema_wait};
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -