ab1aac2693fbce7514f50443c91501f3170c7f9b
[sfrench/samba-autobuild/.git] / source4 / auth / ntlm / auth_anonymous.c
1 /* 
2    Unix SMB/CIFS implementation.
3
4    Anonymous Authentification
5
6    Copyright (C) Stefan Metzmacher            2004-2005
7    
8    This program is free software; you can redistribute it and/or modify
9    it under the terms of the GNU General Public License as published by
10    the Free Software Foundation; either version 3 of the License, or
11    (at your option) any later version.
12    
13    This program is distributed in the hope that it will be useful,
14    but WITHOUT ANY WARRANTY; without even the implied warranty of
15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16    GNU General Public License for more details.
17    
18    You should have received a copy of the GNU General Public License
19    along with this program.  If not, see <http://www.gnu.org/licenses/>.
20 */
21
22 #include "includes.h"
23 #include "auth/auth.h"
24 #include "auth/ntlm/auth_proto.h"
25 #include "param/param.h"
26
27 _PUBLIC_ NTSTATUS auth4_anonymous_init(void);
28
29 /**
30  * Return a anonymous logon for anonymous users (username = "")
31  *
32  * Typically used as the first module in the auth chain, this allows
33  * anonymou logons to be dealt with in one place.  Non-anonymou logons 'fail'
34  * and pass onto the next module.
35  **/
36 static NTSTATUS anonymous_want_check(struct auth_method_context *ctx,
37                                      TALLOC_CTX *mem_ctx,
38                                      const struct auth_usersupplied_info *user_info)
39 {
40         if (user_info->client.account_name && *user_info->client.account_name) {
41                 return NT_STATUS_NOT_IMPLEMENTED;
42         }
43
44         switch (user_info->password_state) {
45         case AUTH_PASSWORD_PLAIN:
46                 if (user_info->password.plaintext != NULL &&
47                     strlen(user_info->password.plaintext) > 0)
48                 {
49                         return NT_STATUS_NOT_IMPLEMENTED;
50                 }
51                 break;
52         case AUTH_PASSWORD_HASH:
53                 if (user_info->password.hash.lanman != NULL) {
54                         return NT_STATUS_NOT_IMPLEMENTED;
55                 }
56                 if (user_info->password.hash.nt != NULL) {
57                         return NT_STATUS_NOT_IMPLEMENTED;
58                 }
59                 break;
60         case AUTH_PASSWORD_RESPONSE:
61                 if (user_info->password.response.lanman.length == 1) {
62                         if (user_info->password.response.lanman.data[0] != '\0') {
63                                 return NT_STATUS_NOT_IMPLEMENTED;
64                         }
65                 } else if (user_info->password.response.lanman.length > 1) {
66                         return NT_STATUS_NOT_IMPLEMENTED;
67                 }
68                 if (user_info->password.response.nt.length > 0) {
69                         return NT_STATUS_NOT_IMPLEMENTED;
70                 }
71                 break;
72         }
73
74         return NT_STATUS_OK;
75 }
76
77 /**
78  * Return a anonymous logon for anonymous users (username = "")
79  *
80  * Typically used as the first module in the auth chain, this allows
81  * anonymou logons to be dealt with in one place.  Non-anonymou logons 'fail'
82  * and pass onto the next module.
83  **/
84 static NTSTATUS anonymous_check_password(struct auth_method_context *ctx,
85                                          TALLOC_CTX *mem_ctx,
86                                          const struct auth_usersupplied_info *user_info, 
87                                          struct auth_user_info_dc **_user_info_dc)
88 {
89         return auth_anonymous_user_info_dc(mem_ctx, lpcfg_netbios_name(ctx->auth_ctx->lp_ctx), _user_info_dc);
90 }
91
92 static const struct auth_operations anonymous_auth_ops = {
93         .name           = "anonymous",
94         .want_check     = anonymous_want_check,
95         .check_password = anonymous_check_password
96 };
97
98 _PUBLIC_ NTSTATUS auth4_anonymous_init(void)
99 {
100         NTSTATUS ret;
101
102         ret = auth_register(&anonymous_auth_ops);
103         if (!NT_STATUS_IS_OK(ret)) {
104                 DEBUG(0,("Failed to register 'anonymous' auth backend!\n"));
105                 return ret;
106         }
107
108         return ret;
109 }