This commit was manufactured by cvs2svn to create branch 'SAMBA_3_0'.
[kai/samba-autobuild/.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 /**
24  * Return a guest logon for guest users (username = "")
25  *
26  * Typically used as the first module in the auth chain, this allows
27  * guest logons to be delt with in one place.  Non-gust logons 'fail'
28  * and pass onto the next module.
29  **/
30
31 static NTSTATUS check_guest_security(const struct auth_context *auth_context,
32                                      void *my_private_data, 
33                                      TALLOC_CTX *mem_ctx,
34                                      const auth_usersupplied_info *user_info, 
35                                      auth_serversupplied_info **server_info)
36 {
37         NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
38
39         if (!(user_info->internal_username.str 
40               && *user_info->internal_username.str)) { 
41                 if (make_server_info_guest(server_info)) {
42                         nt_status = NT_STATUS_OK;
43                 } else {
44                         nt_status = NT_STATUS_NO_SUCH_USER;
45                 }
46         }
47
48         return nt_status;
49 }
50
51 /* Guest modules initialisation */
52 BOOL auth_init_guest(struct auth_context *auth_context, auth_methods **auth_method) 
53 {
54         if (!make_auth_methods(auth_context, auth_method)) {
55                 return False;
56         }
57
58         (*auth_method)->auth = check_guest_security;
59         return True;
60 }
61
62 /** 
63  * Return an error based on username
64  *
65  * This function allows the testing of obsure errors, as well as the generation
66  * of NT_STATUS -> DOS error mapping tables.
67  *
68  * This module is of no value to end-users.
69  *
70  * The password is ignored.
71  *
72  * @return An NTSTATUS value based on the username
73  **/
74
75 static NTSTATUS check_name_to_ntstatus_security(const struct auth_context *auth_context,
76                                                 void *my_private_data, 
77                                                 TALLOC_CTX *mem_ctx,
78                                                 const auth_usersupplied_info *user_info, 
79                                                 auth_serversupplied_info **server_info)
80 {
81         NTSTATUS nt_status;
82         fstring user;
83         long error_num;
84         fstrcpy(user, user_info->smb_name.str);
85         
86         if (strncasecmp("NT_STATUS", user, strlen("NT_STATUS")) == 0) {
87                 strupper(user);
88                 return nt_status_string_to_code(user);
89         }
90
91         strlower(user);
92         error_num = strtoul(user, NULL, 16);
93         
94         DEBUG(5,("Error for user %s was %lx\n", user, error_num));
95
96         nt_status = NT_STATUS(error_num);
97         
98         return nt_status;
99 }
100
101 /** Module initailisation function */
102 BOOL auth_init_name_to_ntstatus(struct auth_context *auth_context, auth_methods **auth_method) 
103 {
104         if (!make_auth_methods(auth_context, auth_method)) {
105                 return False;
106         }
107
108         (*auth_method)->auth = check_name_to_ntstatus_security;
109         return True;
110 }
111