Move the authenticaion subsystem over to the same 'module:options' syntax
authorAndrew Bartlett <abartlet@samba.org>
Fri, 24 May 2002 03:43:52 +0000 (03:43 +0000)
committerAndrew Bartlett <abartlet@samba.org>
Fri, 24 May 2002 03:43:52 +0000 (03:43 +0000)
that the passdb code now uses.  Similarly, move the 'pluggable' stuff
over from passdb as well, allowing runtime loading of new authenticaion
modules.

(NOTE:  The interfaces here can *and do* change - module writers are
not assured source-level compatibilty, and certainly not binary
compatibility).

source/auth/auth.c
source/auth/auth_builtin.c
source/auth/auth_domain.c
source/auth/auth_rhosts.c
source/auth/auth_sam.c
source/auth/auth_server.c
source/auth/auth_unix.c
source/auth/auth_winbind.c
source/include/auth.h

index c40cef551911e9b12822bfb8d3e0277a96e7fc63..55695fa9c283d11c0ef6323f30d20a0fa7c872fd 100644 (file)
@@ -25,7 +25,7 @@
 
 /** List of various built-in authenticaion modules */
 
-const struct auth_init_function builtin_auth_init_functions[] = {
+const struct auth_init_function_entry builtin_auth_init_functions[] = {
        { "guest", auth_init_guest },
        { "rhosts", auth_init_rhosts },
        { "hostsequiv", auth_init_hostsequiv },
@@ -340,14 +340,31 @@ static NTSTATUS make_auth_context_text_list(struct auth_context **auth_context,
                {
                        if (strequal(builtin_auth_init_functions[i].name, *text_list))
                        {
+                               
+                               char *module_name = smb_xstrdup(*text_list);
+                               char *module_params = NULL;
+                               char *p;
+                               
+                               p = strchr(module_name, ':');
+                               
+                               if (p) {
+                                       *p = 0;
+                                       
+                                       module_params = p+1;
+                                       
+                                       trim_string(module_params, " ", " ");
+                               }
+                               
+                               trim_string(module_name, " ", " ");
+
                                DEBUG(5,("Found auth method %s (at pos %d)\n", *text_list, i));
-                               if (builtin_auth_init_functions[i].init(*auth_context, &t)) {
+                               if (NT_STATUS_IS_OK(builtin_auth_init_functions[i].init(*auth_context, module_params, &t))) {
                                        DEBUG(5,("auth method %s has a valid init\n", *text_list));
-                                       t->name = builtin_auth_init_functions[i].name;
                                        DLIST_ADD_END(list, t, tmp);
                                } else {
                                        DEBUG(0,("auth method %s did not correctly init\n", *text_list));
                                }
+                               SAFE_FREE(module_name);
                                break;
                        }
                }
index 0cca6b8e15cbef05116c80be85727d1d5b076b0e..d2c60ae64f8b3c08aae66a3244110be6ec45e8ec 100644 (file)
@@ -1,7 +1,8 @@
 /* 
    Unix SMB/CIFS implementation.
    Generic authenticaion types
-   Copyright (C) Andrew Bartlett              2001
+   Copyright (C) Andrew Bartlett         2001-2002
+   Copyright (C) Jelmer Vernooij              2002
    
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
@@ -52,14 +53,15 @@ static NTSTATUS check_guest_security(const struct auth_context *auth_context,
 }
 
 /* Guest modules initialisation */
-BOOL auth_init_guest(struct auth_context *auth_context, auth_methods **auth_method) 
+NTSTATUS auth_init_guest(struct auth_context *auth_context, const char *options, auth_methods **auth_method) 
 {
        if (!make_auth_methods(auth_context, auth_method)) {
-               return False;
+               return NT_STATUS_NO_MEMORY;
        }
 
        (*auth_method)->auth = check_guest_security;
-       return True;
+       (*auth_method)->name = "guest";
+       return NT_STATUS_OK;
 }
 
 /** 
@@ -102,13 +104,60 @@ static NTSTATUS check_name_to_ntstatus_security(const struct auth_context *auth_
 }
 
 /** Module initailisation function */
-BOOL auth_init_name_to_ntstatus(struct auth_context *auth_context, auth_methods **auth_method) 
+NTSTATUS auth_init_name_to_ntstatus(struct auth_context *auth_context, const char *param, auth_methods **auth_method) 
 {
        if (!make_auth_methods(auth_context, auth_method)) {
-               return False;
+               return NT_STATUS_NO_MEMORY;
        }
 
        (*auth_method)->auth = check_name_to_ntstatus_security;
-       return True;
+       (*auth_method)->name = "name_to_ntstatus";
+       return NT_STATUS_OK;
 }
 
+/**
+ * Outsorce an auth module to an external loadable .so
+ *
+ * Only works on systems with dlopen() etc.
+ **/
+
+/* Plugin modules initialisation */
+NTSTATUS auth_init_plugin(struct auth_context *auth_context, const char *param, auth_methods **auth_method) 
+{
+       void * dl_handle;
+       char *plugin_param, *plugin_name, *p;
+       auth_init_function plugin_init;
+
+       if (param == NULL) {
+               DEBUG(0, ("The plugin module needs an argument!\n"));
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+
+       plugin_name = smb_xstrdup(param);
+       p = strchr(plugin_name, ':');
+       if (p) {
+               *p = 0;
+               plugin_param = p+1;
+               trim_string(plugin_param, " ", " ");
+       } else plugin_param = NULL;
+
+       trim_string(plugin_name, " ", " ");
+
+       DEBUG(5, ("Trying to load auth plugin %s\n", plugin_name));
+       dl_handle = sys_dlopen(plugin_name, RTLD_NOW | RTLD_GLOBAL );
+       if (!dl_handle) {
+               DEBUG(0, ("Failed to load auth plugin %s using sys_dlopen (%s)\n", plugin_name, sys_dlerror()));
+               return NT_STATUS_UNSUCCESSFUL;
+       }
+    
+       plugin_init = sys_dlsym(dl_handle, "auth_init");
+       if (!plugin_init){
+               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 paramater %s\n", plugin_name, plugin_param?plugin_param:"(null)"));
+       return plugin_init(auth_context, plugin_param, auth_method);
+}
+
+
index d520dabbb26ff8f181e3eaaa24c20656b8054eac..91c111b557b16467d06b4b58c4fa1839e1e91d2f 100644 (file)
@@ -511,14 +511,14 @@ static NTSTATUS check_ntdomain_security(const struct auth_context *auth_context,
 }
 
 /* module initialisation */
-BOOL auth_init_ntdomain(struct auth_context *auth_context, auth_methods **auth_method) 
+NTSTATUS auth_init_ntdomain(struct auth_context *auth_context, const char* param, auth_methods **auth_method) 
 {
        if (!make_auth_methods(auth_context, auth_method)) {
-               return False;
+               return NT_STATUS_NO_MEMORY;
        }
 
        (*auth_method)->auth = check_ntdomain_security;
-       return True;
+       return NT_STATUS_OK;
 }
 
 
@@ -598,12 +598,12 @@ static NTSTATUS check_trustdomain_security(const struct auth_context *auth_conte
 }
 
 /* module initialisation */
-BOOL auth_init_trustdomain(struct auth_context *auth_context, auth_methods **auth_method) 
+NTSTATUS auth_init_trustdomain(struct auth_context *auth_context, const char* param, auth_methods **auth_method) 
 {
        if (!make_auth_methods(auth_context, auth_method)) {
-               return False;
+               return NT_STATUS_NO_MEMORY;
        }
 
        (*auth_method)->auth = check_trustdomain_security;
-       return True;
+       return NT_STATUS_OK;
 }
index 7730f50a3ceee3286cde245152296ace12b8147b..4ed0e6bbc43a0fce1cef8848b6aeb8655162431d 100644 (file)
@@ -179,14 +179,14 @@ static NTSTATUS check_hostsequiv_security(const struct auth_context *auth_contex
 }
 
 /* module initialisation */
-BOOL auth_init_hostsequiv(struct auth_context *auth_context, auth_methods **auth_method) 
+NTSTATUS auth_init_hostsequiv(struct auth_context *auth_context, const char* param, auth_methods **auth_method) 
 {
        if (!make_auth_methods(auth_context, auth_method)) {
-               return False;
+               return NT_STATUS_NO_MEMORY;
        }
 
        (*auth_method)->auth = check_hostsequiv_security;
-       return True;
+       return NT_STATUS_OK;
 }
 
 
@@ -223,12 +223,12 @@ static NTSTATUS check_rhosts_security(const struct auth_context *auth_context,
 }
 
 /* module initialisation */
-BOOL auth_init_rhosts(struct auth_context *auth_context, auth_methods **auth_method) 
+NTSTATUS auth_init_rhosts(struct auth_context *auth_context, const char *param, auth_methods **auth_method) 
 {
        if (!make_auth_methods(auth_context, auth_method)) {
-               return False;
+               return NT_STATUS_NO_MEMORY;
        }
 
        (*auth_method)->auth = check_rhosts_security;
-       return True;
+       return NT_STATUS_OK;
 }
index 7e0cd513da6ced5e3fcb954f367d0a8abfd406d9..76579150ce9da4918f91c38c08a93852d961c512 100644 (file)
@@ -404,14 +404,15 @@ static NTSTATUS check_sam_security(const struct auth_context *auth_context,
 }
 
 /* module initialisation */
-BOOL auth_init_sam(struct auth_context *auth_context, auth_methods **auth_method) 
+NTSTATUS auth_init_sam(struct auth_context *auth_context, const char *param, auth_methods **auth_method) 
 {
        if (!make_auth_methods(auth_context, auth_method)) {
-               return False;
+               return NT_STATUS_NO_MEMORY;
        }
 
-       (*auth_method)->auth = check_sam_security;
-       return True;
+       (*auth_method)->auth = check_sam_security;      
+       (*auth_method)->name = "sam";
+       return NT_STATUS_OK;
 }
 
 
@@ -442,14 +443,15 @@ static NTSTATUS check_samstrict_security(const struct auth_context *auth_context
 }
 
 /* module initialisation */
-BOOL auth_init_samstrict(struct auth_context *auth_context, auth_methods **auth_method) 
+NTSTATUS auth_init_samstrict(struct auth_context *auth_context, const char *param, auth_methods **auth_method) 
 {
        if (!make_auth_methods(auth_context, auth_method)) {
-               return False;
+               return NT_STATUS_NO_MEMORY;
        }
 
        (*auth_method)->auth = check_samstrict_security;
-       return True;
+       (*auth_method)->name = "samstrict";
+       return NT_STATUS_OK;
 }
 
 
index bcb7d5059bf59a5c667af578e6ed372a02f3320d..0d366a4c0d0d0643204544cde823213080c731da 100644 (file)
@@ -357,14 +357,14 @@ use this machine as the password server.\n"));
        return(nt_status);
 }
 
-BOOL auth_init_smbserver(struct auth_context *auth_context, auth_methods **auth_method) 
+NTSTATUS auth_init_smbserver(struct auth_context *auth_context, const char* param, auth_methods **auth_method) 
 {
        if (!make_auth_methods(auth_context, auth_method)) {
-               return False;
+               return NT_STATUS_NO_MEMORY;
        }
        (*auth_method)->auth = check_smbserver_security;
        (*auth_method)->get_chal = auth_get_challenge_server;
        (*auth_method)->send_keepalive = send_server_keepalive;
        (*auth_method)->free_private_data = free_server_private_data;
-       return True;
+       return NT_STATUS_OK;
 }
index d624cb12614b8bb20f56602b8e17bbd3546c15ba..9f85bf11fed2b7275912cd4579b23cc36e497172 100644 (file)
@@ -119,12 +119,12 @@ static NTSTATUS check_unix_security(const struct auth_context *auth_context,
 }
 
 /* module initialisation */
-BOOL auth_init_unix(struct auth_context *auth_context, auth_methods **auth_method) 
+NTSTATUS auth_init_unix(struct auth_context *auth_context, const char* param, auth_methods **auth_method) 
 {
        if (!make_auth_methods(auth_context, auth_method)) {
-               return False;
+               return NT_STATUS_NO_MEMORY;
        }
 
        (*auth_method)->auth = check_unix_security;
-       return True;
+       return NT_STATUS_OK;
 }
index 1a72c2df0fa234060ffdbfca833b208027d33027..2d214c7acac1be03c35f6e800e7dfb8b3e784137 100644 (file)
@@ -103,12 +103,12 @@ static NTSTATUS check_winbind_security(const struct auth_context *auth_context,
 }
 
 /* module initialisation */
-BOOL auth_init_winbind(struct auth_context *auth_context, auth_methods **auth_method) 
+NTSTATUS auth_init_winbind(struct auth_context *auth_context, const char *param, auth_methods **auth_method) 
 {
        if (!make_auth_methods(auth_context, auth_method)) {
-               return False;
+               return NT_STATUS_NO_MEMORY;
        }
 
        (*auth_method)->auth = check_winbind_security;
-       return True;
+       return NT_STATUS_OK;
 }
index 5c8bc8edfe6d1417932a72d69413f7ef19f7a272..66b317d64337e3bb90183ea73c6477e40125a0b7 100644 (file)
@@ -141,11 +141,12 @@ typedef struct auth_methods
 
 } auth_methods;
 
-struct auth_init_function {
+typedef NTSTATUS (*auth_init_function)(struct auth_context *, const char *, struct auth_methods **);
+
+struct auth_init_function_entry {
        char *name;
        /* Function to create a member of the authmethods list */
-       BOOL (*init)(struct auth_context *auth_context, struct auth_methods **auth_method);
-};
-
 
+       auth_init_function init;
+};
 #endif /* _SMBAUTH_H_ */