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