s3-auth: Simplify how we free the auth_context
[kai/samba.git] / source3 / include / auth.h
1 #ifndef _SMBAUTH_H_
2 #define _SMBAUTH_H_
3 /* 
4    Unix SMB/CIFS implementation.
5    Standardised Authentication types
6    Copyright (C) Andrew Bartlett 2001
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 struct auth_usersupplied_info {
23         DATA_BLOB lm_resp;
24         DATA_BLOB nt_resp;
25         DATA_BLOB lm_interactive_pwd;
26         DATA_BLOB nt_interactive_pwd;
27         DATA_BLOB plaintext_password;
28
29         bool encrypted;
30         struct {
31                 char *account_name;   /* username before/after mapping */
32                 char *domain_name;    /* username before/after mapping */
33         } client, mapped;
34
35         bool was_mapped;              /* Did the username map actually match? */
36         char *internal_username;      /* username after mapping */
37         const char *workstation_name; /* workstation name (netbios calling
38                                        * name) unicode string */
39
40         uint32 logon_parameters;
41
42 };
43
44 struct extra_auth_info {
45         struct dom_sid user_sid;
46         struct dom_sid pgid_sid;
47 };
48
49 struct auth_serversupplied_info {
50         bool guest;
51         bool system;
52
53         struct unix_user_token utok;
54
55         /* NT group information taken from the info3 structure */
56
57         NT_USER_TOKEN *ptok;
58
59         /* This is the final session key, as used by SMB signing, and
60          * (truncated to 16 bytes) encryption on the SAMR and LSA pipes
61          * when over ncacn_np.
62          * It is calculated by NTLMSSP from the session key in the info3,
63          * and is  set from the Kerberos session key using
64          * krb5_auth_con_getremotesubkey().
65          *
66          * Bootom line, it is not the same as the session keys in info3.
67          */
68
69         DATA_BLOB user_session_key;
70         DATA_BLOB lm_session_key;
71
72         struct netr_SamInfo3 *info3;
73
74         /* this structure is filled *only* in pathological cases where the user
75          * sid or the primary group sid are not sids of the domain. Normally
76          * this happens only for unix accounts that have unix domain sids.
77          * This is checked only when info3.rid and/or info3.primary_gid are set
78          * to the special invalid value of 0xFFFFFFFF */
79         struct extra_auth_info extra;
80
81         void *pam_handle;
82
83         /*
84          * This is a token from /etc/passwd and /etc/group
85          */
86         bool nss_token;
87
88         char *unix_name;
89
90         /*
91          * For performance reasons we keep an alpha_strcpy-sanitized version
92          * of the username around as long as the global variable current_user
93          * still exists. If we did not do keep this, we'd have to call
94          * alpha_strcpy whenever we do a become_user(), potentially on every
95          * smb request. See set_current_user_info.
96          */
97         char *sanitized_username;
98 };
99
100 struct auth_context {
101         DATA_BLOB challenge; 
102
103         /* Who set this up in the first place? */ 
104         const char *challenge_set_by; 
105
106         bool challenge_may_be_modified;
107
108         struct auth_methods *challenge_set_method; 
109         /* What order are the various methods in?   Try to stop it changing under us */ 
110         struct auth_methods *auth_method_list;  
111
112         NTSTATUS (*get_ntlm_challenge)(struct auth_context *auth_context,
113                                        uint8_t chal[8]);
114         NTSTATUS (*check_ntlm_password)(const struct auth_context *auth_context,
115                                         const struct auth_usersupplied_info *user_info, 
116                                         struct auth_serversupplied_info **server_info);
117         NTSTATUS (*nt_status_squash)(NTSTATUS nt_status);
118 };
119
120 typedef struct auth_methods
121 {
122         struct auth_methods *prev, *next;
123         const char *name; /* What name got this module */
124
125         NTSTATUS (*auth)(const struct auth_context *auth_context,
126                          void *my_private_data, 
127                          TALLOC_CTX *mem_ctx,
128                          const struct auth_usersupplied_info *user_info, 
129                          struct auth_serversupplied_info **server_info);
130
131         /* If you are using this interface, then you are probably
132          * getting something wrong.  This interface is only for
133          * security=server, and makes a number of compromises to allow
134          * that.  It is not compatible with being a PDC.  */
135         DATA_BLOB (*get_chal)(const struct auth_context *auth_context,
136                               void **my_private_data, 
137                               TALLOC_CTX *mem_ctx);
138
139         /* Used to keep tabs on things like the cli for SMB server authentication */
140         void *private_data;
141
142 } auth_methods;
143
144 typedef NTSTATUS (*auth_init_function)(struct auth_context *, const char *, struct auth_methods **);
145
146 struct auth_init_function_entry {
147         const char *name;
148         /* Function to create a member of the authmethods list */
149
150         auth_init_function init;
151
152         struct auth_init_function_entry *prev, *next;
153 };
154
155 struct auth_ntlmssp_state;
156
157 /* Changed from 1 -> 2 to add the logon_parameters field. */
158 #define AUTH_INTERFACE_VERSION 2
159
160 #endif /* _SMBAUTH_H_ */