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