Add the PDC end of the smbtorture test for creating an NT_STATUS -> DOS error
[ira/wip.git] / source3 / smbd / 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  Check for a guest logon (username = "") and if so create the required 
26  structure.
27 ****************************************************************************/
28
29 static NTSTATUS check_guest_security(void *my_private_data, 
30                               const auth_usersupplied_info *user_info, 
31                               const auth_authsupplied_info *auth_info,
32                               auth_serversupplied_info **server_info)
33 {
34         NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
35
36         if (!(user_info->internal_username.str 
37               && *user_info->internal_username.str)) { 
38                 if (make_server_info_guest(server_info)) {
39                         nt_status = NT_STATUS_OK;
40                 } else {
41                         nt_status = NT_STATUS_NO_SUCH_USER;
42                 }
43         }
44
45         return nt_status;
46 }
47
48 BOOL auth_init_guest(auth_methods **auth_method) 
49 {
50         if (!make_auth_methods(auth_method)) {
51                 return False;
52         }
53
54         (*auth_method)->auth = check_guest_security;
55         return True;
56 }
57
58 /****************************************************************************
59  Check against either sam or unix, depending on encryption.
60 ****************************************************************************/
61
62 static NTSTATUS check_local_security(void *my_private_data,
63                               const auth_usersupplied_info *user_info, 
64                               const auth_authsupplied_info *auth_info,
65                               auth_serversupplied_info **server_info)
66 {
67         NTSTATUS nt_status = NT_STATUS_LOGON_FAILURE;
68
69         if (user_info->encrypted) {
70                 nt_status = check_sam_security(my_private_data, user_info, auth_info, server_info);
71         } else {
72                 nt_status = check_unix_security(my_private_data, user_info, auth_info, server_info);
73         }
74         
75         return nt_status;
76 }
77
78 BOOL auth_init_local(auth_methods **auth_method) 
79 {
80         if (!make_auth_methods(auth_method)) {
81                 return False;
82         }
83
84         (*auth_method)->auth = check_local_security;
85         return True;
86 }
87
88 /****************************************************************************
89  Return an error based on username
90 ****************************************************************************/
91
92 static NTSTATUS check_name_to_ntstatus_security(void *my_private_data,
93                                                 const auth_usersupplied_info *user_info, 
94                                                 const auth_authsupplied_info *auth_info,
95                                                 auth_serversupplied_info **server_info)
96 {
97         NTSTATUS nt_status;
98         fstring user;
99         long error_num;
100         fstrcpy(user, user_info->smb_name.str);
101         strlower(user);
102         error_num = strtoul(user, NULL, 16);
103         
104         DEBUG(5,("Error for user %s was %lx\n", user, error_num));
105
106         nt_status = NT_STATUS(error_num);
107         
108         return nt_status;
109 }
110
111 BOOL auth_init_name_to_ntstatus(auth_methods **auth_method) 
112 {
113         if (!make_auth_methods(auth_method)) {
114                 return False;
115         }
116
117         (*auth_method)->auth = check_name_to_ntstatus_security;
118         return True;
119 }
120