45c5f9a7f6a76152c37f31afd0985eaf014cb6e7
[gd/samba-autobuild/.git] / source4 / auth / 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 2 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, write to the Free Software
20    Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 */
22
23 #include "includes.h"
24 #include "auth/auth.h"
25
26 /**
27  * Return a anonymous logon for anonymous users (username = "")
28  *
29  * Typically used as the first module in the auth chain, this allows
30  * anonymou logons to be dealt with in one place.  Non-anonymou logons 'fail'
31  * and pass onto the next module.
32  **/
33 static NTSTATUS anonymous_want_check(struct auth_method_context *ctx,
34                                      TALLOC_CTX *mem_ctx,
35                                      const struct auth_usersupplied_info *user_info)
36 {
37         if (user_info->client.account_name && *user_info->client.account_name) {
38                 return NT_STATUS_NOT_IMPLEMENTED;
39         }
40
41         return NT_STATUS_OK;
42 }
43
44 /**
45  * Return a anonymous logon for anonymous users (username = "")
46  *
47  * Typically used as the first module in the auth chain, this allows
48  * anonymou logons to be dealt with in one place.  Non-anonymou logons 'fail'
49  * and pass onto the next module.
50  **/
51 static NTSTATUS anonymous_check_password(struct auth_method_context *ctx,
52                                          TALLOC_CTX *mem_ctx,
53                                          const struct auth_usersupplied_info *user_info, 
54                                          struct auth_serversupplied_info **_server_info)
55 {
56         return auth_anonymous_server_info(mem_ctx, _server_info);
57 }
58
59 static struct auth_operations anonymous_auth_ops = {
60         .name           = "anonymous",
61         .get_challenge  = auth_get_challenge_not_implemented,
62         .want_check     = anonymous_want_check,
63         .check_password = anonymous_check_password
64 };
65
66 NTSTATUS auth_anonymous_init(void)
67 {
68         NTSTATUS ret;
69
70         ret = auth_register(&anonymous_auth_ops);
71         if (!NT_STATUS_IS_OK(ret)) {
72                 DEBUG(0,("Failed to register 'anonymous' auth backend!\n"));
73                 return ret;
74         }
75
76         return ret;
77 }