NTSTATUS pdb_init_plugin(PDB_CONTEXT *pdb_context, PDB_METHODS **pdb_method, const char *location) { void * dl_handle; char *plugin_location, *plugin_name, *p; pdb_init_function plugin_init; int (*plugin_version)(void); if (location == NULL) { DEBUG(0, ("The plugin module needs an argument!\n")); return NT_STATUS_UNSUCCESSFUL; } plugin_name = smb_xstrdup(location); p = strchr(plugin_name, ':'); if (p) { *p = 0; plugin_location = p+1; trim_char(plugin_location, ' ', ' '); } else { plugin_location = NULL; } trim_char(plugin_name, ' ', ' '); DEBUG(5, ("Trying to load sam plugin %s\n", plugin_name)); dl_handle = sys_dlopen(plugin_name, RTLD_NOW ); if (!dl_handle) { DEBUG(0, ("Failed to load sam plugin %s using sys_dlopen (%s)\n", plugin_name, sys_dlerror())); return NT_STATUS_UNSUCCESSFUL; } plugin_version = sys_dlsym(dl_handle, "pdb_version"); if (!plugin_version) { sys_dlclose(dl_handle); DEBUG(0, ("Failed to find function 'pdb_version' using sys_dlsym in sam plugin %s (%s)\n", plugin_name, sys_dlerror())); return NT_STATUS_UNSUCCESSFUL; } if (plugin_version() != PASSDB_INTERFACE_VERSION) { sys_dlclose(dl_handle); DEBUG(0, ("Wrong PASSDB_INTERFACE_VERSION! sam plugin has version %d and version %d is needed! Please update!\n", plugin_version(),PASSDB_INTERFACE_VERSION)); return NT_STATUS_UNSUCCESSFUL; } plugin_init = sys_dlsym(dl_handle, "pdb_init"); if (!plugin_init) { sys_dlclose(dl_handle); DEBUG(0, ("Failed to find function 'pdb_init' using sys_dlsym in sam plugin %s (%s)\n", plugin_name, sys_dlerror())); return NT_STATUS_UNSUCCESSFUL; } DEBUG(5, ("Starting sam plugin %s with location %s\n", plugin_name, plugin_location)); return plugin_init(pdb_context, pdb_method, plugin_location); }
static NTSTATUS do_smb_load_module(const char *module_name, bool is_probe) { void *handle; init_module_function *init; NTSTATUS status; const char *error; /* Always try to use LAZY symbol resolving; if the plugin has * backwards compatibility, there might be symbols in the * plugin referencing to old (removed) functions */ handle = sys_dlopen(module_name, RTLD_LAZY); /* This call should reset any possible non-fatal errors that occured since last call to dl* functions */ error = sys_dlerror(); if(!handle) { int level = is_probe ? 3 : 0; DEBUG(level, ("Error loading module '%s': %s\n", module_name, error ? error : "")); return NT_STATUS_UNSUCCESSFUL; } init = (init_module_function *)sys_dlsym(handle, "init_samba_module"); /* we must check sys_dlerror() to determine if it worked, because sys_dlsym() can validly return NULL */ error = sys_dlerror(); if (error) { DEBUG(0, ("Error trying to resolve symbol 'init_samba_module' " "in %s: %s\n", module_name, error)); sys_dlclose(handle); 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))); sys_dlclose(handle); } return status; }
static void *find_fn(const char *name) { char s[1024]; static void *h; void *res; snprintf(s,sizeof(s), "_nss_%s_%s", nss_name, name); if (!h) { h = sys_dlopen(so_path, RTLD_LAZY); } if (!h) { printf("Can't open shared library %s\n", so_path); exit(1); } res = sys_dlsym(h, s); if (!res) { printf("Can't find function %s\n", s); return NULL; } return res; }
static void *find_fn(const char *name) { pstring s; static void *h; void *res; pstr_sprintf(s, "_nss_%s_%s", nss_name, name); if (!h) { h = sys_dlopen(so_path, RTLD_LAZY); } if (!h) { printf("Can't open shared library %s\n", so_path); exit(1); } res = sys_dlsym(h, s); if (!res) { printf("Can't find function %s\n", s); total_errors++; return NULL; } return res; }