ldb-samba: ldif-handlers: make ldif_comparison_objectSid() accurate
[samba.git] / auth / common_auth.h
blob1afb79eb5df573b2f07537a11abdbd79fa587f9d
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 */
43 #define AUTH_SESSION_INFO_FORCE_COMPOUNDED_AUTHENTICATION 0x20 /* The user authenticated with a device. */
44 #define AUTH_SESSION_INFO_DEVICE_DEFAULT_GROUPS 0x40 /* Add the device to the default world and network groups */
45 #define AUTH_SESSION_INFO_DEVICE_AUTHENTICATED 0x80 /* Add the device to the 'authenticated users' group */
47 struct auth_usersupplied_info
49 const char *workstation_name;
50 const struct tsocket_address *remote_host;
51 const struct tsocket_address *local_host;
53 uint32_t logon_parameters;
55 bool cracknames_called;
56 bool was_mapped;
57 uint64_t logon_id;
58 /* the values the client gives us */
59 struct {
60 const char *account_name;
61 const char *domain_name;
62 } client, mapped, orig_client;
64 enum auth_password_state password_state;
66 struct {
67 struct {
68 DATA_BLOB lanman;
69 DATA_BLOB nt;
70 } response;
71 struct {
72 struct samr_Password *lanman;
73 struct samr_Password *nt;
74 } hash;
76 char *plaintext;
77 } password;
78 uint32_t flags;
80 struct {
81 uint32_t negotiate_flags;
82 enum netr_SchannelType secure_channel_type;
83 const char *computer_name; /* [charset(UTF8)] */
84 const char *account_name; /* [charset(UTF8)] */
85 struct dom_sid *sid; /* [unique] */
86 } netlogon_trust_account;
88 const char *service_description;
89 const char *auth_description;
92 * for logging only, normally worked out from the password but
93 * for krb5 logging only (krb5 normally doesn't use this) we
94 * record the enc type here
96 const char *password_type;
99 struct auth_method_context;
100 struct tevent_context;
101 struct imessaging_context;
102 struct loadparm_context;
103 struct ldb_context;
104 struct smb_krb5_context;
106 struct auth4_context {
107 struct {
108 /* Who set this up in the first place? */
109 const char *set_by;
111 DATA_BLOB data;
112 } challenge;
114 /* methods, in the order they should be called */
115 struct auth_method_context *methods;
117 /* the event context to use for calls that can block */
118 struct tevent_context *event_ctx;
120 /* the messaging context which can be used by backends */
121 struct imessaging_context *msg_ctx;
123 /* loadparm context */
124 struct loadparm_context *lp_ctx;
126 /* SAM database for this local machine - to fill in local groups, or to authenticate local NTLM users */
127 struct ldb_context *sam_ctx;
129 /* The time this authentication started */
130 struct timeval start_time;
132 /* Private data for the callbacks on this auth context */
133 void *private_data;
135 /* Kerberos context, set up on demand */
136 struct smb_krb5_context *smb_krb5_context;
138 struct tevent_req *(*check_ntlm_password_send)(TALLOC_CTX *mem_ctx,
139 struct tevent_context *ev,
140 struct auth4_context *auth_ctx,
141 const struct auth_usersupplied_info *user_info);
142 NTSTATUS (*check_ntlm_password_recv)(struct tevent_req *req,
143 TALLOC_CTX *mem_ctx,
144 uint8_t *pauthoritative,
145 void **server_returned_info,
146 DATA_BLOB *nt_session_key,
147 DATA_BLOB *lm_session_key);
149 NTSTATUS (*get_ntlm_challenge)(struct auth4_context *auth_ctx, uint8_t chal[8]);
151 NTSTATUS (*set_ntlm_challenge)(struct auth4_context *auth_ctx, const uint8_t chal[8], const char *set_by);
153 NTSTATUS (*generate_session_info)(struct auth4_context *auth_context,
154 TALLOC_CTX *mem_ctx,
155 void *server_returned_info,
156 const char *original_user_name,
157 uint32_t session_info_flags,
158 struct auth_session_info **session_info);
160 NTSTATUS (*generate_session_info_pac)(struct auth4_context *auth_ctx,
161 TALLOC_CTX *mem_ctx,
162 struct smb_krb5_context *smb_krb5_context,
163 DATA_BLOB *pac_blob,
164 const char *principal_name,
165 const struct tsocket_address *remote_address,
166 uint32_t session_info_flags,
167 struct auth_session_info **session_info);
170 #define AUTHZ_TRANSPORT_PROTECTION_NONE "NONE"
171 #define AUTHZ_TRANSPORT_PROTECTION_SMB "SMB"
172 #define AUTHZ_TRANSPORT_PROTECTION_TLS "TLS"
173 #define AUTHZ_TRANSPORT_PROTECTION_SEAL "SEAL"
174 #define AUTHZ_TRANSPORT_PROTECTION_SIGN "SIGN"
177 * Log details of an authentication attempt.
178 * Successful and unsuccessful attempts are logged.
180 * NOTE: msg_ctx and lp_ctx is optional, but when supplied allows streaming the
181 * authentication events over the message bus.
183 struct authn_audit_info;
184 void log_authentication_event(struct imessaging_context *msg_ctx,
185 struct loadparm_context *lp_ctx,
186 const struct timeval *start_time,
187 const struct auth_usersupplied_info *ui,
188 NTSTATUS status,
189 const char *domain_name,
190 const char *account_name,
191 struct dom_sid *sid,
192 const struct authn_audit_info *client_audit_info,
193 const struct authn_audit_info *server_audit_info);
196 * Log details of a successful authorization to a service.
198 * Only successful authorizations are logged. For clarity:
199 * - NTLM bad passwords will be recorded by log_authentication_event
200 * - Kerberos decrypt failures need to be logged in gensec_gssapi et al
202 * The service may later refuse authorization due to an ACL.
205 * NOTE: msg_ctx and lp_ctx is optional, but when supplied allows streaming the
206 * authorization events over the message bus.
208 void log_successful_authz_event(struct imessaging_context *msg_ctx,
209 struct loadparm_context *lp_ctx,
210 const struct tsocket_address *remote,
211 const struct tsocket_address *local,
212 const char *service_description,
213 const char *auth_type,
214 const char *transport_protection,
215 struct auth_session_info *session_info,
216 const struct authn_audit_info *client_audit_info,
217 const struct authn_audit_info *server_audit_info);
220 * Log details of an authorization to a service.
222 * NOTE: msg_ctx and lp_ctx are optional, but when supplied, allow streaming the
223 * authorization events over the message bus.
225 void log_authz_event(
226 struct imessaging_context *msg_ctx,
227 struct loadparm_context *lp_ctx,
228 const struct tsocket_address *remote,
229 const struct tsocket_address *local,
230 const struct authn_audit_info *server_audit_info,
231 const char *service_description,
232 const char *auth_type,
233 const char *domain_name,
234 const char *account_name,
235 const struct dom_sid *sid,
236 const char *logon_server,
237 const struct timeval authtime,
238 NTSTATUS status);
240 #endif