diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2003-05-29 19:08:40 +0000 |
---|---|---|
committer | Jelmer Vernooij <jelmer@samba.org> | 2003-05-29 19:08:40 +0000 |
commit | 69b50029f4472d29e823e2b541a59a420ab706cb (patch) | |
tree | af912650e07b1f0b9f8f33131e8081cc12ae675f /source3/sam | |
parent | 44fa85fd60baf1dba4e4858ee23b9ebbd7e13ef9 (diff) | |
download | samba-69b50029f4472d29e823e2b541a59a420ab706cb.tar.gz samba-69b50029f4472d29e823e2b541a59a420ab706cb.tar.bz2 samba-69b50029f4472d29e823e2b541a59a420ab706cb.zip |
Add smb_register_idmap(). Based on a patch from metze
(This used to be commit 7e352f5c62c4889bdf2662dded1e74a354890dc7)
Diffstat (limited to 'source3/sam')
-rw-r--r-- | source3/sam/idmap.c | 85 | ||||
-rw-r--r-- | source3/sam/idmap_tdb.c | 8 | ||||
-rw-r--r-- | source3/sam/idmap_winbind.c | 9 |
3 files changed, 64 insertions, 38 deletions
diff --git a/source3/sam/idmap.c b/source3/sam/idmap.c index e2796e0864..62377a9228 100644 --- a/source3/sam/idmap.c +++ b/source3/sam/idmap.c @@ -24,50 +24,69 @@ #undef DBGC_CLASS #define DBGC_CLASS DBGC_IDMAP -static struct { - +struct idmap_function_entry { const char *name; - /* Function to create a member of the idmap_methods list */ - NTSTATUS (*reg_meth)(struct idmap_methods **methods); struct idmap_methods *methods; - -} remote_idmap_functions[] = { - { "winbind", idmap_reg_winbind, NULL }, - { NULL, NULL, NULL } + struct idmap_function_entry *prev,*next; }; +static struct idmap_function_entry *backends = NULL; + static struct idmap_methods *local_map; static struct idmap_methods *remote_map; static void lazy_initialize_idmap(void) { static BOOL initialized = False; - if (initialized) return; - idmap_init(); - initialized = True; -} - + if(!initialized) { + idmap_init(); + initialized = True; + } +} static struct idmap_methods *get_methods(const char *name) { - int i = 0; - struct idmap_methods *ret = NULL; + struct idmap_function_entry *entry = backends; - while (remote_idmap_functions[i].name && strcmp(remote_idmap_functions[i].name, name)) { - i++; + while(entry) { + if (strcmp(entry->name, name) == 0) return entry->methods; + entry = entry->next; } - if (remote_idmap_functions[i].name) { + return NULL; +} - if (!remote_idmap_functions[i].methods) { - remote_idmap_functions[i].reg_meth(&remote_idmap_functions[i].methods); - } +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, ("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; + } - ret = remote_idmap_functions[i].methods; + if (get_methods(name)) { + DEBUG(0,("idmap module %s already registered!\n", name)); + return NT_STATUS_OBJECT_NAME_COLLISION; } - return ret; + entry = smb_xmalloc(sizeof(struct idmap_function_entry)); + entry->name = smb_xstrdup(name); + entry->methods = methods; + + DLIST_ADD(backends, entry); + DEBUG(5, ("Successfully added idmap backend '%s'\n", name)); + return NT_STATUS_OK; } /* Initialize backend */ @@ -75,8 +94,17 @@ BOOL idmap_init(void) { const char *remote_backend = lp_idmap_backend(); + if (!backends) + static_init_idmap; + if (!local_map) { - idmap_reg_tdb(&local_map); + local_map = get_methods("tdb"); + + if (!local_map) { + DEBUG(0, ("idmap_init: could not find tdb backend!\n")); + return False; + } + if (NT_STATUS_IS_ERR(local_map->init())) { DEBUG(0, ("idmap_init: could not load or create local backend!\n")); return False; @@ -86,12 +114,15 @@ BOOL idmap_init(void) if (!remote_map && remote_backend && *remote_backend != 0) { DEBUG(3, ("idmap_init: using '%s' as remote backend\n", remote_backend)); - remote_map = get_methods(remote_backend); - if (!remote_map) { + if((remote_map = get_methods(remote_backend)) || + (NT_STATUS_IS_OK(smb_probe_module("idmap", remote_backend)) && + (remote_map = get_methods(remote_backend)))) { + remote_map->init(); + } else { DEBUG(0, ("idmap_init: could not load remote backend '%s'\n", remote_backend)); return False; } - remote_map->init(); + } return True; diff --git a/source3/sam/idmap_tdb.c b/source3/sam/idmap_tdb.c index 31c12241bf..373fb66a1b 100644 --- a/source3/sam/idmap_tdb.c +++ b/source3/sam/idmap_tdb.c @@ -424,7 +424,7 @@ static void db_idmap_status(void) /* Display complete mapping of users and groups to rids */ } -struct idmap_methods db_methods = { +static struct idmap_methods db_methods = { db_idmap_init, db_get_sid_from_id, @@ -435,9 +435,7 @@ struct idmap_methods db_methods = { }; -NTSTATUS idmap_reg_tdb(struct idmap_methods **meth) +NTSTATUS idmap_tdb_init() { - *meth = &db_methods; - - return NT_STATUS_OK; + return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "tdb", &db_methods); } diff --git a/source3/sam/idmap_winbind.c b/source3/sam/idmap_winbind.c index bc3c8ad60c..bff870b8fc 100644 --- a/source3/sam/idmap_winbind.c +++ b/source3/sam/idmap_winbind.c @@ -135,8 +135,7 @@ static void db_status(void) { return; } -struct idmap_methods winbind_methods = { - +static struct idmap_methods winbind_methods = { db_init, db_get_sid_from_id, db_get_id_from_sid, @@ -146,10 +145,8 @@ struct idmap_methods winbind_methods = { }; -NTSTATUS idmap_reg_winbind(struct idmap_methods **meth) +NTSTATUS idmap_winbind_init(void) { - *meth = &winbind_methods; - - return NT_STATUS_OK; + return smb_register_idmap(SMB_IDMAP_INTERFACE_VERSION, "winbind", &winbind_methods); } |