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