static int samba_secrets_init(struct ldb_module *module) { struct ldb_context *ldb = ldb_module_get_ctx(module); int ret, len, i; TALLOC_CTX *tmp_ctx = talloc_new(module); struct ldb_module *backend_module, *module_chain; const char **reverse_module_list; /* Add modules to the list to activate them by default beware often order is important The list is presented here as a set of declarations to show the stack visually */ static const char *modules_list[] = {"update_keytab", "secrets_tdb_sync", "objectguid", "rdn_name", NULL }; if (!tmp_ctx) { return ldb_oom(ldb); } /* Now prepare the module chain. Oddly, we must give it to ldb_load_modules_list in REVERSE */ for (len = 0; modules_list[len]; len++) { /* noop */}; reverse_module_list = talloc_array(tmp_ctx, const char *, len+1); if (!reverse_module_list) { talloc_free(tmp_ctx); return ldb_oom(ldb); } for (i=0; i < len; i++) { reverse_module_list[i] = modules_list[(len - 1) - i]; } reverse_module_list[i] = NULL; /* The backend (at least until the partitions module * reconfigures things) is the next module in the currently * loaded chain */ backend_module = ldb_module_next(module); ret = ldb_module_load_list(ldb, reverse_module_list, backend_module, &module_chain); if (ret != LDB_SUCCESS) { talloc_free(tmp_ctx); return ret; } talloc_free(tmp_ctx); /* Set this as the 'next' module, so that we effectivly append it to module chain */ ldb_module_set_next(module, module_chain); return ldb_next_init(module); }
static int subtree_delete_init(struct ldb_module *module) { struct ldb_context *ldb; int ret; ldb = ldb_module_get_ctx(module); ret = ldb_mod_register_control(module, LDB_CONTROL_TREE_DELETE_OID); if (ret != LDB_SUCCESS) { ldb_debug(ldb, LDB_DEBUG_ERROR, "subtree_delete: Unable to register control with rootdse!\n"); return ldb_operr(ldb); } return ldb_next_init(module); }
static int skel_init(struct ldb_module *ctx) { struct private_data *data; data = talloc(ctx, struct private_data); if (data == NULL) { return 1; } data->some_private_data = NULL; ctx->private_data = data; talloc_set_destructor (ctx, skel_destructor); return ldb_next_init(ctx); }
static int pdc_fsmo_init(struct ldb_module *module) { struct ldb_context *ldb; TALLOC_CTX *mem_ctx; struct ldb_dn *pdc_dn; struct dsdb_pdc_fsmo *pdc_fsmo; struct ldb_result *pdc_res; int ret; static const char *pdc_attrs[] = { "fSMORoleOwner", NULL }; ldb = ldb_module_get_ctx(module); mem_ctx = talloc_new(module); if (!mem_ctx) { return ldb_oom(ldb); } pdc_dn = ldb_get_default_basedn(ldb); if (!pdc_dn) { ldb_debug_set(ldb, LDB_DEBUG_FATAL, "pdc_fsmo_init: could not determine default basedn"); talloc_free(mem_ctx); return LDB_ERR_OPERATIONS_ERROR; } pdc_fsmo = talloc_zero(mem_ctx, struct dsdb_pdc_fsmo); if (!pdc_fsmo) { return ldb_oom(ldb); } ldb_module_set_private(module, pdc_fsmo); ret = dsdb_module_search_dn(module, mem_ctx, &pdc_res, pdc_dn, pdc_attrs, DSDB_FLAG_NEXT_MODULE, NULL); if (ret == LDB_ERR_NO_SUCH_OBJECT) { ldb_debug(ldb, LDB_DEBUG_TRACE, "pdc_fsmo_init: no domain object present: (skip loading of domain details)"); talloc_free(mem_ctx); return ldb_next_init(module); } else if (ret != LDB_SUCCESS) { ldb_debug_set(ldb, LDB_DEBUG_FATAL, "pdc_fsmo_init: failed to search the domain object: %d:%s: %s", ret, ldb_strerror(ret), ldb_errstring(ldb)); talloc_free(mem_ctx); return ret; } pdc_fsmo->master_dn = ldb_msg_find_attr_as_dn(ldb, mem_ctx, pdc_res->msgs[0], "fSMORoleOwner"); if (ldb_dn_compare(samdb_ntds_settings_dn(ldb), pdc_fsmo->master_dn) == 0) { pdc_fsmo->we_are_master = true; } else { pdc_fsmo->we_are_master = false; } if (ldb_set_opaque(ldb, "dsdb_pdc_fsmo", pdc_fsmo) != LDB_SUCCESS) { return ldb_oom(ldb); } talloc_steal(module, pdc_fsmo); ldb_debug(ldb, LDB_DEBUG_TRACE, "pdc_fsmo_init: we are master: %s\n", (pdc_fsmo->we_are_master?"yes":"no")); talloc_free(mem_ctx); return ldb_next_init(module); }
static int acl_module_init(struct ldb_module *module) { struct ldb_context *ldb; struct acl_private *data; int ret, i; TALLOC_CTX *mem_ctx = talloc_new(module); static const char *attrs[] = { "passwordAttribute", NULL }; struct ldb_result *res; struct ldb_message *msg; struct ldb_message_element *password_attributes; ldb = ldb_module_get_ctx(module); ret = ldb_mod_register_control(module, LDB_CONTROL_SD_FLAGS_OID); if (ret != LDB_SUCCESS) { ldb_debug(ldb, LDB_DEBUG_ERROR, "acl_module_init: Unable to register control with rootdse!\n"); return LDB_ERR_OPERATIONS_ERROR; } data = talloc(module, struct acl_private); if (data == NULL) { ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } data->password_attrs = NULL; data->acl_perform = lp_parm_bool(ldb_get_opaque(ldb, "loadparm"), NULL, "acl", "perform", false); ldb_module_set_private(module, data); if (!mem_ctx) { ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } ret = ldb_search(ldb, mem_ctx, &res, ldb_dn_new(mem_ctx, ldb, "@KLUDGEACL"), LDB_SCOPE_BASE, attrs, NULL); if (ret != LDB_SUCCESS) { goto done; } if (res->count == 0) { goto done; } if (res->count > 1) { talloc_free(mem_ctx); return LDB_ERR_CONSTRAINT_VIOLATION; } msg = res->msgs[0]; password_attributes = ldb_msg_find_element(msg, "passwordAttribute"); if (!password_attributes) { goto done; } data->password_attrs = talloc_array(data, const char *, password_attributes->num_values + 1); if (!data->password_attrs) { talloc_free(mem_ctx); ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } for (i=0; i < password_attributes->num_values; i++) { data->password_attrs[i] = (const char *)password_attributes->values[i].data; talloc_steal(data->password_attrs, password_attributes->values[i].data); } data->password_attrs[i] = NULL; done: talloc_free(mem_ctx); return ldb_next_init(module); }
static int samldb_init(struct ldb_module *module) { return ldb_next_init(module); }
static int samba_dsdb_init(struct ldb_module *module) { struct ldb_context *ldb = ldb_module_get_ctx(module); int ret, len, i; TALLOC_CTX *tmp_ctx = talloc_new(module); struct ldb_result *res; struct ldb_message *rootdse_msg = NULL, *partition_msg; struct ldb_dn *samba_dsdb_dn, *partition_dn; struct ldb_module *backend_module, *module_chain; const char **final_module_list, **reverse_module_list; /* Add modules to the list to activate them by default beware often order is important Some Known ordering constraints: - rootdse must be first, as it makes redirects from "" -> cn=rootdse - extended_dn_in must be before objectclass.c, as it resolves the DN - objectclass must be before password_hash and samldb since these LDB modules require the expanded "objectClass" list - objectclass must be before descriptor and acl, as both assume that objectClass values are sorted - objectclass_attrs must be behind operational in order to see all attributes (the operational module protects and therefore suppresses per default some important ones) - partition must be last - each partition has its own module list then The list is presented here as a set of declarations to show the stack visually - the code below then handles the creation of the list based on the parameters loaded from the database. */ static const char *modules_list1[] = {"resolve_oids", "rootdse", "schema_load", "lazy_commit", "dirsync", "paged_results", "ranged_results", "anr", "server_sort", "asq", "extended_dn_store", NULL }; /* extended_dn_in or extended_dn_in_openldap goes here */ static const char *modules_list1a[] = {"objectclass", "descriptor", "acl", "aclread", "samldb", "password_hash", "operational", "instancetype", "objectclass_attrs", NULL }; const char **link_modules; static const char *fedora_ds_modules[] = { "rdn_name", NULL }; static const char *openldap_modules[] = { NULL }; static const char *tdb_modules_list[] = { "rdn_name", "subtree_delete", "repl_meta_data", "subtree_rename", "linked_attributes", NULL}; const char *extended_dn_module; const char *extended_dn_module_ldb = "extended_dn_out_ldb"; const char *extended_dn_module_fds = "extended_dn_out_fds"; const char *extended_dn_module_openldap = "extended_dn_out_openldap"; const char *extended_dn_in_module = "extended_dn_in"; static const char *modules_list2[] = {"show_deleted", "new_partition", "partition", NULL }; const char **backend_modules; static const char *fedora_ds_backend_modules[] = { "nsuniqueid", "paged_searches", "simple_dn", NULL }; static const char *openldap_backend_modules[] = { "entryuuid", "simple_dn", NULL }; static const char *samba_dsdb_attrs[] = { "backendType", NULL }; static const char *partition_attrs[] = { "ldapBackend", NULL }; const char *backendType, *backendUrl; bool use_sasl_external = false; if (!tmp_ctx) { return ldb_oom(ldb); } ret = ldb_register_samba_handlers(ldb); if (ret != LDB_SUCCESS) { talloc_free(tmp_ctx); return ret; } samba_dsdb_dn = ldb_dn_new(tmp_ctx, ldb, "@SAMBA_DSDB"); if (!samba_dsdb_dn) { talloc_free(tmp_ctx); return ldb_oom(ldb); } partition_dn = ldb_dn_new(tmp_ctx, ldb, DSDB_PARTITION_DN); if (!partition_dn) { talloc_free(tmp_ctx); return ldb_oom(ldb); } #define CHECK_LDB_RET(check_ret) \ do { \ if (check_ret != LDB_SUCCESS) { \ talloc_free(tmp_ctx); \ return check_ret; \ } \ } while (0) ret = dsdb_module_search_dn(module, tmp_ctx, &res, samba_dsdb_dn, samba_dsdb_attrs, DSDB_FLAG_NEXT_MODULE, NULL); if (ret == LDB_ERR_NO_SUCH_OBJECT) { backendType = "ldb"; } else if (ret == LDB_SUCCESS) { backendType = ldb_msg_find_attr_as_string(res->msgs[0], "backendType", "ldb"); } else { talloc_free(tmp_ctx); return ret; } backend_modules = NULL; if (strcasecmp(backendType, "ldb") == 0) { extended_dn_module = extended_dn_module_ldb; link_modules = tdb_modules_list; } else { struct cli_credentials *cred; bool is_ldapi = false; ret = dsdb_module_search_dn(module, tmp_ctx, &res, partition_dn, partition_attrs, DSDB_FLAG_NEXT_MODULE, NULL); if (ret == LDB_SUCCESS) { backendUrl = ldb_msg_find_attr_as_string(res->msgs[0], "ldapBackend", "ldapi://"); if (!strncasecmp(backendUrl, "ldapi://", sizeof("ldapi://")-1)) { is_ldapi = true; } } else if (ret != LDB_ERR_NO_SUCH_OBJECT) { talloc_free(tmp_ctx); return ret; } if (strcasecmp(backendType, "fedora-ds") == 0) { link_modules = fedora_ds_modules; backend_modules = fedora_ds_backend_modules; extended_dn_module = extended_dn_module_fds; } else if (strcasecmp(backendType, "openldap") == 0) { link_modules = openldap_modules; backend_modules = openldap_backend_modules; extended_dn_module = extended_dn_module_openldap; extended_dn_in_module = "extended_dn_in_openldap"; if (is_ldapi) { use_sasl_external = true; } } else { return ldb_error(ldb, LDB_ERR_OPERATIONS_ERROR, "invalid backend type"); } ret = ldb_set_opaque(ldb, "readOnlySchema", (void*)1); if (ret != LDB_SUCCESS) { ldb_set_errstring(ldb, "Failed to set readOnlySchema opaque"); } cred = ldb_get_opaque(ldb, "credentials"); if (!cred || !cli_credentials_authentication_requested(cred)) { ret = set_ldap_credentials(ldb, use_sasl_external); if (ret != LDB_SUCCESS) { return ret; } } } #define CHECK_MODULE_LIST \ do { \ if (!final_module_list) { \ talloc_free(tmp_ctx); \ return ldb_oom(ldb); \ } \ } while (0) final_module_list = str_list_copy_const(tmp_ctx, modules_list1); CHECK_MODULE_LIST; final_module_list = str_list_add_const(final_module_list, extended_dn_in_module); CHECK_MODULE_LIST; final_module_list = str_list_append_const(final_module_list, modules_list1a); CHECK_MODULE_LIST; final_module_list = str_list_append_const(final_module_list, link_modules); CHECK_MODULE_LIST; final_module_list = str_list_add_const(final_module_list, extended_dn_module); CHECK_MODULE_LIST; final_module_list = str_list_append_const(final_module_list, modules_list2); CHECK_MODULE_LIST; ret = read_at_rootdse_record(ldb, module, tmp_ctx, &rootdse_msg, NULL); CHECK_LDB_RET(ret); partition_msg = ldb_msg_new(tmp_ctx); partition_msg->dn = ldb_dn_new(partition_msg, ldb, "@" DSDB_OPAQUE_PARTITION_MODULE_MSG_OPAQUE_NAME); ret = prepare_modules_line(ldb, tmp_ctx, rootdse_msg, partition_msg, "schemaNamingContext", "schema_data", backend_modules); CHECK_LDB_RET(ret); ret = prepare_modules_line(ldb, tmp_ctx, rootdse_msg, partition_msg, NULL, NULL, backend_modules); CHECK_LDB_RET(ret); ret = ldb_set_opaque(ldb, DSDB_OPAQUE_PARTITION_MODULE_MSG_OPAQUE_NAME, partition_msg); CHECK_LDB_RET(ret); talloc_steal(ldb, partition_msg); /* Now prepare the module chain. Oddly, we must give it to ldb_load_modules_list in REVERSE */ for (len = 0; final_module_list[len]; len++) { /* noop */}; reverse_module_list = talloc_array(tmp_ctx, const char *, len+1); if (!reverse_module_list) { talloc_free(tmp_ctx); return ldb_oom(ldb); } for (i=0; i < len; i++) { reverse_module_list[i] = final_module_list[(len - 1) - i]; } reverse_module_list[i] = NULL; /* The backend (at least until the partitions module * reconfigures things) is the next module in the currently * loaded chain */ backend_module = ldb_module_next(module); ret = ldb_module_load_list(ldb, reverse_module_list, backend_module, &module_chain); CHECK_LDB_RET(ret); talloc_free(tmp_ctx); /* Set this as the 'next' module, so that we effectivly append it to module chain */ ldb_module_set_next(module, module_chain); return ldb_next_init(module); }
static int samba_dsdb_init(struct ldb_module *module) { struct ldb_context *ldb = ldb_module_get_ctx(module); int ret, len, i; TALLOC_CTX *tmp_ctx = talloc_new(module); struct ldb_result *res; struct ldb_message *rootdse_msg, *partition_msg; struct ldb_dn *samba_dsdb_dn; struct ldb_module *backend_module, *module_chain; const char **final_module_list, **reverse_module_list; /* Add modules to the list to activate them by default beware often order is important Some Known ordering constraints: - rootdse must be first, as it makes redirects from "" -> cn=rootdse - extended_dn_in must be before objectclass.c, as it resolves the DN - objectclass must be before password_hash, because password_hash checks that the objectclass is of type person (filled in by objectclass module when expanding the objectclass list) - partition must be last - each partition has its own module list then The list is presented here as a set of declarations to show the stack visually - the code below then handles the creation of the list based on the parameters loaded from the database. */ static const char *modules_list[] = {"resolve_oids", "rootdse", "lazy_commit", "paged_results", "ranged_results", "anr", "server_sort", "asq", "extended_dn_store", "extended_dn_in", "rdn_name", "objectclass", "descriptor", "acl", "samldb", "password_hash", "operational", "kludge_acl", "schema_load", "instancetype", NULL }; const char *objectguid_module; /* if serverrole == "domain controller": */ const char *repl_meta_data = "repl_meta_data"; /* else: */ const char *objectguid = "objectguid"; const char **link_modules; static const char *tdb_modules_list[] = { "subtree_rename", "subtree_delete", "linked_attributes", NULL}; const char *extended_dn_module; const char *extended_dn_module_ldb = "extended_dn_out_ldb"; const char *extended_dn_module_fds = "extended_dn_out_fds"; const char *extended_dn_module_openldap = "extended_dn_out_openldap"; static const char *modules_list2[] = {"show_deleted", "new_partition", "partition", NULL }; const char **backend_modules; static const char *fedora_ds_backend_modules[] = { "nsuniqueid", "paged_searches", NULL }; static const char *openldap_backend_modules[] = { "entryuuid", "paged_searches", NULL }; static const char *samba_dsdb_attrs[] = { "backendType", "serverRole", NULL }; const char *backendType, *serverRole; if (!tmp_ctx) { ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } samba_dsdb_dn = ldb_dn_new(tmp_ctx, ldb, "@SAMBA_DSDB"); if (!samba_dsdb_dn) { talloc_free(tmp_ctx); ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } #define CHECK_LDB_RET(check_ret) \ do { \ if (check_ret != LDB_SUCCESS) { \ talloc_free(tmp_ctx); \ return check_ret; \ } \ } while (0) ret = dsdb_module_search_dn(module, tmp_ctx, &res, samba_dsdb_dn, samba_dsdb_attrs, 0); if (ret == LDB_ERR_NO_SUCH_OBJECT) { backendType = "ldb"; serverRole = "domain controller"; } else if (ret == LDB_SUCCESS) { backendType = ldb_msg_find_attr_as_string(res->msgs[0], "backendType", "ldb"); serverRole = ldb_msg_find_attr_as_string(res->msgs[0], "serverRole", "domain controller"); } else { talloc_free(tmp_ctx); return ret; } backend_modules = NULL; if (strcasecmp(backendType, "ldb") == 0) { if (strcasecmp(serverRole, "dc") == 0 || strcasecmp(serverRole, "domain controller") == 0) { objectguid_module = repl_meta_data; } else { objectguid_module = objectguid; } extended_dn_module = extended_dn_module_ldb; link_modules = tdb_modules_list; } else { objectguid_module = NULL; link_modules = NULL; if (strcasecmp(backendType, "fedora-ds") == 0) { backend_modules = fedora_ds_backend_modules; extended_dn_module = extended_dn_module_fds; } else if (strcasecmp(backendType, "openldap") == 0) { backend_modules = openldap_backend_modules; extended_dn_module = extended_dn_module_openldap; } } #define CHECK_MODULE_LIST \ do { \ if (!final_module_list) { \ talloc_free(tmp_ctx); \ ldb_oom(ldb); \ return LDB_ERR_OPERATIONS_ERROR; \ } \ } while (0) final_module_list = str_list_copy_const(tmp_ctx, modules_list); CHECK_MODULE_LIST; final_module_list = str_list_add_const(final_module_list, objectguid_module); CHECK_MODULE_LIST; final_module_list = str_list_append_const(final_module_list, link_modules); CHECK_MODULE_LIST; final_module_list = str_list_add_const(final_module_list, extended_dn_module); CHECK_MODULE_LIST; final_module_list = str_list_append_const(final_module_list, modules_list2); CHECK_MODULE_LIST; ret = read_at_rootdse_record(ldb, module, tmp_ctx, &rootdse_msg); CHECK_LDB_RET(ret); partition_msg = ldb_msg_new(tmp_ctx); partition_msg->dn = ldb_dn_new(partition_msg, ldb, "@" DSDB_OPAQUE_PARTITION_MODULE_MSG_OPAQUE_NAME); ret = prepare_modules_line(ldb, tmp_ctx, rootdse_msg, partition_msg, "defaultNamingContext", "pdc_fsmo", backend_modules); CHECK_LDB_RET(ret); ret = prepare_modules_line(ldb, tmp_ctx, rootdse_msg, partition_msg, "configurationNamingContext", "naming_fsmo", backend_modules); CHECK_LDB_RET(ret); ret = prepare_modules_line(ldb, tmp_ctx, rootdse_msg, partition_msg, "schemaNamingContext", "schema_data", backend_modules); CHECK_LDB_RET(ret); ret = prepare_modules_line(ldb, tmp_ctx, rootdse_msg, partition_msg, NULL, NULL, backend_modules); CHECK_LDB_RET(ret); ret = ldb_set_opaque(ldb, DSDB_OPAQUE_PARTITION_MODULE_MSG_OPAQUE_NAME, partition_msg); CHECK_LDB_RET(ret); talloc_steal(ldb, partition_msg); /* Now prepare the module chain. Oddly, we must give it to ldb_load_modules_list in REVERSE */ for (len = 0; final_module_list[len]; len++) { /* noop */}; reverse_module_list = talloc_array(tmp_ctx, const char *, len+1); if (!reverse_module_list) { talloc_free(tmp_ctx); ldb_oom(ldb); return LDB_ERR_OPERATIONS_ERROR; } for (i=0; i < len; i++) { reverse_module_list[i] = final_module_list[(len - 1) - i]; } reverse_module_list[i] = NULL; /* The backend (at least until the partitions module * reconfigures things) is the next module in the currently * loaded chain */ backend_module = module->next; ret = ldb_load_modules_list(ldb, reverse_module_list, backend_module, &module_chain); CHECK_LDB_RET(ret); talloc_free(tmp_ctx); /* Set this as the 'next' module, so that we effectivly append it to module chain */ module->next = module_chain; return ldb_next_init(module); }
static int dsdb_cache_init(struct ldb_module *module) { /* TODO: load the schema */ return ldb_next_init(module); }