WHATSNEW: Add release notes for Samba 4.19.1.
[Samba.git] / auth / common_auth.h
blob24b7b14f51a0a0b44bf97bb521079acbfd1c292e
1 /*
2 Unix SMB/CIFS implementation.
3 Standardised Authentication types
4 Copyright (C) Andrew Bartlett 2001-2010
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
20 #ifndef AUTH_COMMON_AUTH_H
21 #define AUTH_COMMON_AUTH_H
23 #include "librpc/gen_ndr/auth.h"
25 #define USER_INFO_CASE_INSENSITIVE_USERNAME 0x01 /* username may be in any case */
26 #define USER_INFO_CASE_INSENSITIVE_PASSWORD 0x02 /* password may be in any case */
27 #define USER_INFO_DONT_CHECK_UNIX_ACCOUNT 0x04 /* don't check unix account status */
28 #define USER_INFO_INTERACTIVE_LOGON 0x08 /* Interactive logon */
29 /*unused #define USER_INFO_LOCAL_SAM_ONLY 0x10 Only authenticate against the local SAM, do not map missing passwords to NO_SUCH_USER */
30 #define USER_INFO_INFO3_AND_NO_AUTHZ 0x20 /* Only fill in server_info->info3 and do not do any authorization steps */
32 enum auth_password_state {
33 AUTH_PASSWORD_PLAIN = 1,
34 AUTH_PASSWORD_HASH = 2,
35 AUTH_PASSWORD_RESPONSE = 3
38 #define AUTH_SESSION_INFO_DEFAULT_GROUPS 0x01 /* Add the user to the default world and network groups */
39 #define AUTH_SESSION_INFO_AUTHENTICATED 0x02 /* Add the user to the 'authenticated users' group */
40 #define AUTH_SESSION_INFO_SIMPLE_PRIVILEGES 0x04 /* Use a trivial map between users and privileges, rather than a DB */
41 #define AUTH_SESSION_INFO_UNIX_TOKEN 0x08 /* The returned token must have the unix_token and unix_info elements provided */
42 #define AUTH_SESSION_INFO_NTLM 0x10 /* The returned token must have authenticated-with-NTLM flag set */
44 struct auth_usersupplied_info
46 const char *workstation_name;
47 const struct tsocket_address *remote_host;
48 const struct tsocket_address *local_host;
50 uint32_t logon_parameters;
52 bool cracknames_called;
53 bool was_mapped;
54 uint64_t logon_id;
55 /* the values the client gives us */
56 struct {
57 const char *account_name;
58 const char *domain_name;
59 } client, mapped, orig_client;
61 enum auth_password_state password_state;
63 struct {
64 struct {
65 DATA_BLOB lanman;
66 DATA_BLOB nt;
67 } response;
68 struct {
69 struct samr_Password *lanman;
70 struct samr_Password *nt;
71 } hash;
73 char *plaintext;
74 } password;
75 uint32_t flags;
77 struct {
78 uint32_t negotiate_flags;
79 enum netr_SchannelType secure_channel_type;
80 const char *computer_name; /* [charset(UTF8)] */
81 const char *account_name; /* [charset(UTF8)] */
82 struct dom_sid *sid; /* [unique] */
83 } netlogon_trust_account;
85 const char *service_description;
86 const char *auth_description;
89 * for logging only, normally worked out from the password but
90 * for krb5 logging only (krb5 normally doesn't use this) we
91 * record the enc type here
93 const char *password_type;
96 struct auth_method_context;
97 struct tevent_context;
98 struct imessaging_context;
99 struct loadparm_context;
100 struct ldb_context;
101 struct smb_krb5_context;
103 struct auth4_context {
104 struct {
105 /* Who set this up in the first place? */
106 const char *set_by;
108 DATA_BLOB data;
109 } challenge;
111 /* methods, in the order they should be called */
112 struct auth_method_context *methods;
114 /* the event context to use for calls that can block */
115 struct tevent_context *event_ctx;
117 /* the messaging context which can be used by backends */
118 struct imessaging_context *msg_ctx;
120 /* loadparm context */
121 struct loadparm_context *lp_ctx;
123 /* SAM database for this local machine - to fill in local groups, or to authenticate local NTLM users */
124 struct ldb_context *sam_ctx;
126 /* The time this authentication started */
127 struct timeval start_time;
129 /* Private data for the callbacks on this auth context */
130 void *private_data;
132 /* Kerberos context, set up on demand */
133 struct smb_krb5_context *smb_krb5_context;
135 struct tevent_req *(*check_ntlm_password_send)(TALLOC_CTX *mem_ctx,
136 struct tevent_context *ev,
137 struct auth4_context *auth_ctx,
138 const struct auth_usersupplied_info *user_info);
139 NTSTATUS (*check_ntlm_password_recv)(struct tevent_req *req,
140 TALLOC_CTX *mem_ctx,
141 uint8_t *pauthoritative,
142 void **server_returned_info,
143 DATA_BLOB *nt_session_key,
144 DATA_BLOB *lm_session_key);
146 NTSTATUS (*get_ntlm_challenge)(struct auth4_context *auth_ctx, uint8_t chal[8]);
148 NTSTATUS (*set_ntlm_challenge)(struct auth4_context *auth_ctx, const uint8_t chal[8], const char *set_by);
150 NTSTATUS (*generate_session_info)(struct auth4_context *auth_context,
151 TALLOC_CTX *mem_ctx,
152 void *server_returned_info,
153 const char *original_user_name,
154 uint32_t session_info_flags,
155 struct auth_session_info **session_info);
157 NTSTATUS (*generate_session_info_pac)(struct auth4_context *auth_ctx,
158 TALLOC_CTX *mem_ctx,
159 struct smb_krb5_context *smb_krb5_context,
160 DATA_BLOB *pac_blob,
161 const char *principal_name,
162 const struct tsocket_address *remote_address,
163 uint32_t session_info_flags,
164 struct auth_session_info **session_info);
167 #define AUTHZ_TRANSPORT_PROTECTION_NONE "NONE"
168 #define AUTHZ_TRANSPORT_PROTECTION_SMB "SMB"
169 #define AUTHZ_TRANSPORT_PROTECTION_TLS "TLS"
170 #define AUTHZ_TRANSPORT_PROTECTION_SEAL "SEAL"
171 #define AUTHZ_TRANSPORT_PROTECTION_SIGN "SIGN"
174 * Log details of an authentication attempt.
175 * Successful and unsuccessful attempts are logged.
177 * NOTE: msg_ctx and lp_ctx is optional, but when supplied allows streaming the
178 * authentication events over the message bus.
180 struct authn_audit_info;
181 void log_authentication_event(struct imessaging_context *msg_ctx,
182 struct loadparm_context *lp_ctx,
183 const struct timeval *start_time,
184 const struct auth_usersupplied_info *ui,
185 NTSTATUS status,
186 const char *domain_name,
187 const char *account_name,
188 struct dom_sid *sid,
189 const struct authn_audit_info *client_audit_info,
190 const struct authn_audit_info *server_audit_info);
193 * Log details of a successful authorization to a service.
195 * Only successful authorizations are logged. For clarity:
196 * - NTLM bad passwords will be recorded by log_authentication_event
197 * - Kerberos decrypt failures need to be logged in gensec_gssapi et al
199 * The service may later refuse authorization due to an ACL.
202 * NOTE: msg_ctx and lp_ctx is optional, but when supplied allows streaming the
203 * authorization events over the message bus.
205 void log_successful_authz_event(struct imessaging_context *msg_ctx,
206 struct loadparm_context *lp_ctx,
207 const struct tsocket_address *remote,
208 const struct tsocket_address *local,
209 const char *service_description,
210 const char *auth_type,
211 const char *transport_protection,
212 struct auth_session_info *session_info,
213 const struct authn_audit_info *client_audit_info,
214 const struct authn_audit_info *server_audit_info);
217 * Log details of an authorization to a service.
219 * NOTE: msg_ctx and lp_ctx are optional, but when supplied, allow streaming the
220 * authorization events over the message bus.
222 void log_authz_event(
223 struct imessaging_context *msg_ctx,
224 struct loadparm_context *lp_ctx,
225 const struct tsocket_address *remote,
226 const struct tsocket_address *local,
227 const struct authn_audit_info *server_audit_info,
228 const char *service_description,
229 const char *auth_type,
230 const char *domain_name,
231 const char *account_name,
232 const struct dom_sid *sid,
233 const char *logon_server,
234 const struct timeval authtime,
235 NTSTATUS status);
237 #endif