struct ldb_context *samba_ldb_init(TALLOC_CTX *mem_ctx, struct tevent_context *ev, struct loadparm_context *lp_ctx, struct auth_session_info *session_info, struct cli_credentials *credentials) { struct ldb_context *ldb; int ret; ldb = ldb_init(mem_ctx, ev); if (ldb == NULL) { return NULL; } ldb_set_modules_dir(ldb, modules_path(ldb, "ldb")); ldb_set_debug(ldb, ldb_wrap_debug, NULL); ldb_set_utf8_fns(ldb, NULL, wrap_casefold); if (session_info) { if (ldb_set_opaque(ldb, "sessionInfo", session_info)) { talloc_free(ldb); return NULL; } } if (credentials) { if (ldb_set_opaque(ldb, "credentials", credentials)) { talloc_free(ldb); return NULL; } } if (ldb_set_opaque(ldb, "loadparm", lp_ctx)) { talloc_free(ldb); return NULL; } /* This must be done before we load the schema, as these * handlers for objectSid and objectGUID etc must take * precedence over the 'binary attribute' declaration in the * schema */ ret = ldb_register_samba_handlers(ldb); if (ret != LDB_SUCCESS) { talloc_free(ldb); return NULL; } /* we usually want Samba databases to be private. If we later find we need one public, we will need to add a parameter to ldb_wrap_connect() */ ldb_set_create_perms(ldb, 0600); return ldb; }
init_module_fn *load_samba_modules(TALLOC_CTX *mem_ctx, const char *subsystem) { char *path = modules_path(mem_ctx, subsystem); init_module_fn *ret; ret = load_modules(mem_ctx, path); talloc_free(path); return ret; }
static NTSTATUS do_smb_load_module(const char *subsystem, const char *module_name, bool is_probe) { void *handle; init_module_fn init; NTSTATUS status; char *full_path = NULL; TALLOC_CTX *ctx = talloc_stackframe(); /* Check for absolute path */ DEBUG(5, ("%s module '%s'\n", is_probe ? "Probing" : "Loading", module_name)); if (subsystem && module_name[0] != '/') { full_path = talloc_asprintf(ctx, "%s/%s.%s", modules_path(ctx, subsystem), module_name, shlib_ext()); if (!full_path) { TALLOC_FREE(ctx); return NT_STATUS_NO_MEMORY; } DEBUG(5, ("%s module '%s': Trying to load from %s\n", is_probe ? "Probing": "Loading", module_name, full_path)); init = load_module(full_path, is_probe, &handle); } else { init = load_module(module_name, is_probe, &handle); } if (!init) { return NT_STATUS_UNSUCCESSFUL; } DEBUG(2, ("Module '%s' loaded\n", module_name)); status = init(); if (!NT_STATUS_IS_OK(status)) { DEBUG(0, ("Module '%s' initialization failed: %s\n", module_name, get_friendly_nt_error_msg(status))); dlclose(handle); } return status; }
/* return the default DN for a ldap server given a connected RPC pipe to the server */ static const char *torture_get_ldap_base_dn(struct torture_context *tctx, struct dcerpc_pipe *p) { const char *hostname = p->binding->host; struct ldb_context *ldb; const char *ldap_url = talloc_asprintf(p, "ldap://%s", hostname); const char *attrs[] = { "defaultNamingContext", NULL }; const char *dnstr; TALLOC_CTX *tmp_ctx = talloc_new(tctx); int ret; struct ldb_result *res; ldb = ldb_init(tmp_ctx, tctx->ev); if (ldb == NULL) { talloc_free(tmp_ctx); return NULL; } if (ldb_set_opaque(ldb, "loadparm", tctx->lp_ctx)) { talloc_free(ldb); return NULL; } ldb_set_modules_dir(ldb, modules_path(ldb, "ldb")); ret = ldb_connect(ldb, ldap_url, 0, NULL); if (ret != LDB_SUCCESS) { torture_comment(tctx, "Failed to make LDB connection to target"); talloc_free(tmp_ctx); return NULL; } ret = dsdb_search_dn(ldb, tmp_ctx, &res, ldb_dn_new(tmp_ctx, ldb, ""), attrs, 0); if (ret != LDB_SUCCESS) { torture_comment(tctx, "Failed to get defaultNamingContext"); talloc_free(tmp_ctx); return NULL; } dnstr = ldb_msg_find_attr_as_string(res->msgs[0], "defaultNamingContext", NULL); dnstr = talloc_strdup(tctx, dnstr); talloc_free(tmp_ctx); return dnstr; }
NTSTATUS smb_probe_module(const char *subsystem, const char *module) { char *full_path = NULL; TALLOC_CTX *ctx = talloc_stackframe(); NTSTATUS status; /* Check for absolute path */ /* if we make any 'samba multibyte string' calls here, we break for loading string modules */ DEBUG(5, ("Probing module '%s'\n", module)); if (module[0] == '/') { status = do_smb_load_module(module, True); TALLOC_FREE(ctx); return status; } full_path = talloc_asprintf(ctx, "%s/%s.%s", modules_path(subsystem), module, shlib_ext()); if (!full_path) { TALLOC_FREE(ctx); return NT_STATUS_NO_MEMORY; } DEBUG(5, ("Probing module '%s': Trying to load from %s\n", module, full_path)); status = do_smb_load_module(full_path, True); TALLOC_FREE(ctx); return status; }