s4:auth Remove event context from anonymous_session()
[samba.git] / source4 / auth / session.c
1 /* 
2    Unix SMB/CIFS implementation.
3    Authentication utility functions
4    Copyright (C) Andrew Tridgell 1992-1998
5    Copyright (C) Andrew Bartlett 2001-2010
6    Copyright (C) Jeremy Allison 2000-2001
7    Copyright (C) Rafal Szczesniak 2002
8    Copyright (C) Stefan Metzmacher 2005
9
10    This program is free software; you can redistribute it and/or modify
11    it under the terms of the GNU General Public License as published by
12    the Free Software Foundation; either version 3 of the License, or
13    (at your option) any later version.
14    
15    This program is distributed in the hope that it will be useful,
16    but WITHOUT ANY WARRANTY; without even the implied warranty of
17    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18    GNU General Public License for more details.
19    
20    You should have received a copy of the GNU General Public License
21    along with this program.  If not, see <http://www.gnu.org/licenses/>.
22 */
23
24 #include "includes.h"
25 #include "auth/auth.h"
26 #include "libcli/security/security.h"
27 #include "libcli/auth/libcli_auth.h"
28 #include "dsdb/samdb/samdb.h"
29 #include "auth/credentials/credentials.h"
30 #include "param/param.h"
31 #include "auth/session_proto.h"
32
33 _PUBLIC_ struct auth_session_info *anonymous_session(TALLOC_CTX *mem_ctx, 
34                                             struct loadparm_context *lp_ctx) 
35 {
36         NTSTATUS nt_status;
37         struct auth_session_info *session_info = NULL;
38         nt_status = auth_anonymous_session_info(mem_ctx, lp_ctx, &session_info);
39         if (!NT_STATUS_IS_OK(nt_status)) {
40                 return NULL;
41         }
42         return session_info;
43 }
44
45 _PUBLIC_ NTSTATUS auth_generate_session_info(TALLOC_CTX *mem_ctx, 
46                                     struct tevent_context *event_ctx, 
47                                     struct loadparm_context *lp_ctx,
48                                     struct auth_serversupplied_info *server_info, 
49                                     struct auth_session_info **_session_info) 
50 {
51         struct auth_session_info *session_info;
52         NTSTATUS nt_status;
53
54         session_info = talloc(mem_ctx, struct auth_session_info);
55         NT_STATUS_HAVE_NO_MEMORY(session_info);
56
57         session_info->server_info = talloc_reference(session_info, server_info);
58
59         /* unless set otherwise, the session key is the user session
60          * key from the auth subsystem */ 
61         session_info->session_key = server_info->user_session_key;
62
63         nt_status = security_token_create(session_info,
64                                           event_ctx,
65                                           lp_ctx,
66                                           server_info->account_sid,
67                                           server_info->primary_group_sid,
68                                           server_info->n_domain_groups,
69                                           server_info->domain_groups,
70                                           server_info->authenticated,
71                                           &session_info->security_token);
72         NT_STATUS_NOT_OK_RETURN(nt_status);
73
74         session_info->credentials = NULL;
75
76         *_session_info = session_info;
77         return NT_STATUS_OK;
78 }
79
80 /**
81  * prints a struct auth_session_info security token to debug output.
82  */
83 void auth_session_info_debug(int dbg_lev, 
84                              const struct auth_session_info *session_info)
85 {
86         if (!session_info) {
87                 DEBUG(dbg_lev, ("Session Info: (NULL)\n"));
88                 return; 
89         }
90
91         security_token_debug(dbg_lev, session_info->security_token);
92 }
93