/** * Initialize a domain structure * @param[in] mem_ctx memory context for the result * @param[in] domainname which domain is this for * @param[in] modulename which backend module * @param[in] params parameter to pass to the init function * @result The initialized structure */ static struct idmap_domain *idmap_init_domain(TALLOC_CTX *mem_ctx, const char *domainname, const char *modulename, const char *params) { struct idmap_domain *result; NTSTATUS status; result = talloc_zero(mem_ctx, struct idmap_domain); if (result == NULL) { DEBUG(0, ("talloc failed\n")); return NULL; } result->name = talloc_strdup(result, domainname); if (result->name == NULL) { DEBUG(0, ("talloc failed\n")); goto fail; } result->methods = get_methods(modulename); if (result->methods == NULL) { DEBUG(3, ("idmap backend %s not found\n", modulename)); status = smb_probe_module("idmap", modulename); if (!NT_STATUS_IS_OK(status)) { DEBUG(3, ("Could not probe idmap module %s\n", modulename)); goto fail; } result->methods = get_methods(modulename); } if (result->methods == NULL) { DEBUG(1, ("idmap backend %s not found\n", modulename)); goto fail; } status = result->methods->init(result, params); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("idmap initialization returned %s\n", nt_errstr(status))); goto fail; } talloc_set_destructor(result, close_domain_destructor); return result; fail: TALLOC_FREE(result); return NULL; }
BOOL idmap_init(const char **remote_backend) { if (!backends) static_init_idmap; if (!cache_map) { cache_map = get_methods("tdb", True); if (!cache_map) { DEBUG(0, ("idmap_init: could not find tdb cache backend!\n")); return False; } if (!NT_STATUS_IS_OK(cache_map->init( NULL ))) { DEBUG(0, ("idmap_init: could not initialise tdb cache backend!\n")); return False; } } if ((remote_map == NULL) && (remote_backend != NULL) && (*remote_backend != NULL) && (**remote_backend != '\0')) { char *rem_backend = smb_xstrdup(*remote_backend); fstring params = ""; char *pparams; /* get any mode parameters passed in */ if ( (pparams = strchr( rem_backend, ':' )) != NULL ) { *pparams = '\0'; pparams++; fstrcpy( params, pparams ); } DEBUG(3, ("idmap_init: using '%s' as remote backend\n", rem_backend)); if((remote_map = get_methods(rem_backend, False)) || (NT_STATUS_IS_OK(smb_probe_module("idmap", rem_backend)) && (remote_map = get_methods(rem_backend, False)))) { if (!NT_STATUS_IS_OK(remote_map->init(params))) { DEBUG(0, ("idmap_init: failed to initialize remote backend!\n")); return False; } } else { DEBUG(0, ("idmap_init: could not load remote backend '%s'\n", rem_backend)); SAFE_FREE(rem_backend); return False; } SAFE_FREE(rem_backend); } return True; }
NTSTATUS smb_register_idmap(int version, const char *name, struct idmap_methods *methods) { struct idmap_function_entry *entry; if ((version != SMB_IDMAP_INTERFACE_VERSION)) { DEBUG(0, ("smb_register_idmap: Failed to register idmap module.\n" "The module was compiled against SMB_IDMAP_INTERFACE_VERSION %d,\n" "current SMB_IDMAP_INTERFACE_VERSION is %d.\n" "Please recompile against the current version of samba!\n", version, SMB_IDMAP_INTERFACE_VERSION)); return NT_STATUS_OBJECT_TYPE_MISMATCH; } if (!name || !name[0] || !methods) { DEBUG(0,("smb_register_idmap: called with NULL pointer or empty name!\n")); return NT_STATUS_INVALID_PARAMETER; } if (get_methods(name, False)) { DEBUG(0,("smb_register_idmap: idmap module %s already registered!\n", name)); return NT_STATUS_OBJECT_NAME_COLLISION; } entry = SMB_XMALLOC_P(struct idmap_function_entry); entry->name = smb_xstrdup(name); entry->methods = methods; DLIST_ADD(backends, entry); DEBUG(5, ("smb_register_idmap: Successfully added idmap backend '%s'\n", name)); return NT_STATUS_OK; }
/** * Initialize a domain structure * @param[in] mem_ctx memory context for the result * @param[in] domainname which domain is this for * @param[in] modulename which backend module * @param[in] check_range whether range checking should be done * @result The initialized structure */ static struct idmap_domain *idmap_init_domain(TALLOC_CTX *mem_ctx, const char *domainname, const char *modulename, bool check_range) { struct idmap_domain *result; NTSTATUS status; char *config_option = NULL; const char *range; result = talloc_zero(mem_ctx, struct idmap_domain); if (result == NULL) { DEBUG(0, ("talloc failed\n")); return NULL; } result->name = talloc_strdup(result, domainname); if (result->name == NULL) { DEBUG(0, ("talloc failed\n")); goto fail; } /* * load ranges and read only information from the config */ config_option = talloc_asprintf(result, "idmap config %s", result->name); if (config_option == NULL) { DEBUG(0, ("Out of memory!\n")); goto fail; } range = lp_parm_const_string(-1, config_option, "range", NULL); if (range == NULL) { DEBUG(1, ("idmap range not specified for domain %s\n", result->name)); if (check_range) { goto fail; } } else if (sscanf(range, "%u - %u", &result->low_id, &result->high_id) != 2) { DEBUG(1, ("invalid range '%s' specified for domain " "'%s'\n", range, result->name)); if (check_range) { goto fail; } } result->read_only = lp_parm_bool(-1, config_option, "read only", false); talloc_free(config_option); if (result->low_id > result->high_id) { DEBUG(1, ("Error: invalid idmap range detected: %lu - %lu\n", (unsigned long)result->low_id, (unsigned long)result->high_id)); if (check_range) { goto fail; } } result->methods = get_methods(modulename); if (result->methods == NULL) { DEBUG(3, ("idmap backend %s not found\n", modulename)); status = smb_probe_module("idmap", modulename); if (!NT_STATUS_IS_OK(status)) { DEBUG(3, ("Could not probe idmap module %s\n", modulename)); goto fail; } result->methods = get_methods(modulename); } if (result->methods == NULL) { DEBUG(1, ("idmap backend %s not found\n", modulename)); goto fail; } status = result->methods->init(result); if (!NT_STATUS_IS_OK(status)) { DEBUG(1, ("idmap initialization returned %s\n", nt_errstr(status))); goto fail; } return result; fail: TALLOC_FREE(result); return NULL; }