r25446: Merge some changes I made on the way home from SFO:
[jelmer/samba4-debian.git] / source / auth / auth.c
index 9100891d5248d0dfb9c3327a06bb2fa39d3275f8..20524b34a4fe1e1b3e7268e5e465644e40bb0061 100644 (file)
@@ -6,7 +6,7 @@
    
    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
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
    
    This program is distributed in the hope that it will be useful,
@@ -15,8 +15,7 @@
    GNU General Public License for more details.
    
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.
 */
 
 #include "includes.h"
@@ -24,6 +23,7 @@
 #include "auth/auth.h"
 #include "lib/events/events.h"
 #include "build.h"
+#include "param/param.h"
 
 /***************************************************************************
  Set a fixed challenge
@@ -348,11 +348,12 @@ NTSTATUS auth_check_password_recv(struct auth_check_password_request *req,
 
 /***************************************************************************
  Make a auth_info struct for the auth subsystem
+ - Allow the caller to specify the methods to use
 ***************************************************************************/
-NTSTATUS auth_context_create(TALLOC_CTX *mem_ctx, const char **methods, 
-                            struct event_context *ev,
-                            struct messaging_context *msg,
-                            struct auth_context **auth_ctx)
+NTSTATUS auth_context_create_methods(TALLOC_CTX *mem_ctx, const char **methods, 
+                                    struct event_context *ev,
+                                    struct messaging_context *msg,
+                                    struct auth_context **auth_ctx)
 {
        int i;
        struct auth_context *ctx;
@@ -406,6 +407,30 @@ NTSTATUS auth_context_create(TALLOC_CTX *mem_ctx, const char **methods,
 
        return NT_STATUS_OK;
 }
+/***************************************************************************
+ Make a auth_info struct for the auth subsystem
+ - Uses default auth_methods, depending on server role and smb.conf settings
+***************************************************************************/
+NTSTATUS auth_context_create(TALLOC_CTX *mem_ctx, 
+                            struct event_context *ev,
+                            struct messaging_context *msg,
+                            struct auth_context **auth_ctx)
+{
+       const char **auth_methods = NULL;
+       switch (lp_server_role(global_loadparm)) {
+       case ROLE_STANDALONE:
+               auth_methods = lp_parm_string_list(global_loadparm, NULL, "auth methods", "standalone", NULL);
+               break;
+       case ROLE_DOMAIN_MEMBER:
+               auth_methods = lp_parm_string_list(global_loadparm, NULL, "auth methods", "member server", NULL);
+               break;
+       case ROLE_DOMAIN_CONTROLLER:
+               auth_methods = lp_parm_string_list(global_loadparm, NULL, "auth methods", "domain controller", NULL);
+               break;
+       }
+       return auth_context_create_methods(mem_ctx, auth_methods, ev, msg, auth_ctx);
+}
+
 
 /* the list of currently registered AUTH backends */
 static struct auth_backend {
@@ -419,9 +444,8 @@ static int num_backends;
   The 'name' can be later used by other backends to find the operations
   structure for this backend.
 */
-NTSTATUS auth_register(const void *_ops)
+NTSTATUS auth_register(const struct auth_operations *ops)
 {
-       const struct auth_operations *ops = _ops;
        struct auth_operations *new_ops;
        
        if (auth_backend_byname(ops->name) != NULL) {
@@ -431,13 +455,14 @@ NTSTATUS auth_register(const void *_ops)
                return NT_STATUS_OBJECT_NAME_COLLISION;
        }
 
-       backends = realloc_p(backends, struct auth_backend, num_backends+1);
-       if (!backends) {
-               return NT_STATUS_NO_MEMORY;
-       }
+       backends = talloc_realloc(talloc_autofree_context(), backends, 
+                                 struct auth_backend, num_backends+1);
+       NT_STATUS_HAVE_NO_MEMORY(backends);
 
-       new_ops = smb_xmemdup(ops, sizeof(*ops));
-       new_ops->name = smb_xstrdup(ops->name);
+       new_ops = talloc_memdup(backends, ops, sizeof(*ops));
+       NT_STATUS_HAVE_NO_MEMORY(new_ops);
+       new_ops->name = talloc_strdup(new_ops, ops->name);
+       NT_STATUS_HAVE_NO_MEMORY(new_ops->name);
 
        backends[num_backends].ops = new_ops;
 
@@ -494,7 +519,7 @@ NTSTATUS auth_init(void)
        if (initialized) return NT_STATUS_OK;
        initialized = True;
        
-       shared_init = load_samba_modules(NULL, "auth");
+       shared_init = load_samba_modules(NULL, global_loadparm, "auth");
 
        run_init_functions(static_init);
        run_init_functions(shared_init);