I've decided to move the auth code around a bit more...
[kai/samba-autobuild/.git] / source3 / auth / auth_builtin.c
1 /* 
2    Unix SMB/Netbios implementation.
3    Version 3.0.
4    Generic authenticaion types
5    Copyright (C) Andrew Bartlett              2001
6    
7    This program is free software; you can redistribute it and/or modify
8    it under the terms of the GNU General Public License as published by
9    the Free Software Foundation; either version 2 of the License, or
10    (at your option) any later version.
11    
12    This program is distributed in the hope that it will be useful,
13    but WITHOUT ANY WARRANTY; without even the implied warranty of
14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15    GNU General Public License for more details.
16    
17    You should have received a copy of the GNU General Public License
18    along with this program; if not, write to the Free Software
19    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
20 */
21
22 #include "includes.h"
23
24 /**
25  * Return a guest logon for guest users (username = "")
26  *
27  * Typically used as the first module in the auth chain, this allows
28  * guest logons to be delt with in one place.  Non-gust logons 'fail'
29  * and pass onto the next module.
30  **/
31
32 static NTSTATUS check_guest_security(const struct auth_context *auth_context,
33                                      void *my_private_data, 
34                                      TALLOC_CTX *mem_ctx,
35                                      const auth_usersupplied_info *user_info, 
36                                      auth_serversupplied_info **server_info)
37 {
38         NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
39
40         if (!(user_info->internal_username.str 
41               && *user_info->internal_username.str)) { 
42                 if (make_server_info_guest(server_info)) {
43                         nt_status = NT_STATUS_OK;
44                 } else {
45                         nt_status = NT_STATUS_NO_SUCH_USER;
46                 }
47         }
48
49         return nt_status;
50 }
51
52 /* Guest modules initialisation */
53 BOOL auth_init_guest(struct auth_context *auth_context, auth_methods **auth_method) 
54 {
55         if (!make_auth_methods(auth_context, auth_method)) {
56                 return False;
57         }
58
59         (*auth_method)->auth = check_guest_security;
60         return True;
61 }
62
63 /** 
64  * Return an error based on username
65  *
66  * This function allows the testing of obsure errors, as well as the generation
67  * of NT_STATUS -> DOS error mapping tables.
68  *
69  * This module is of no value to end-users.
70  *
71  * The password is ignored.
72  *
73  * @return An NTSTATUS value based on the username
74  **/
75
76 static NTSTATUS check_name_to_ntstatus_security(const struct auth_context *auth_context,
77                                                 void *my_private_data, 
78                                                 TALLOC_CTX *mem_ctx,
79                                                 const auth_usersupplied_info *user_info, 
80                                                 auth_serversupplied_info **server_info)
81 {
82         NTSTATUS nt_status;
83         fstring user;
84         long error_num;
85         fstrcpy(user, user_info->smb_name.str);
86         
87         if (strncasecmp("NT_STATUS", user, strlen("NT_STATUS")) == 0) {
88                 strupper(user);
89                 return nt_status_string_to_code(user);
90         }
91
92         strlower(user);
93         error_num = strtoul(user, NULL, 16);
94         
95         DEBUG(5,("Error for user %s was %lx\n", user, error_num));
96
97         nt_status = NT_STATUS(error_num);
98         
99         return nt_status;
100 }
101
102 /** Module initailisation function */
103 BOOL auth_init_name_to_ntstatus(struct auth_context *auth_context, auth_methods **auth_method) 
104 {
105         if (!make_auth_methods(auth_context, auth_method)) {
106                 return False;
107         }
108
109         (*auth_method)->auth = check_name_to_ntstatus_security;
110         return True;
111 }
112