2 Unix SMB/CIFS implementation.
3 Samba Active Directory authentication policy utility functions
5 Copyright (C) Catalyst.Net Ltd 2023
7 This program is free software; you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef KDC_AUTHN_POLICY_UTIL_H
22 #define KDC_AUTHN_POLICY_UTIL_H
24 #include "lib/replace/replace.h"
25 #include "auth/authn_policy.h"
26 #include "auth/session.h"
30 struct loadparm_context
;
33 bool authn_policy_silos_and_policies_in_effect(struct ldb_context
*samdb
);
35 bool authn_policy_allowed_ntlm_network_auth_in_effect(struct ldb_context
*samdb
);
38 * Look up the silo assigned to an account. If one exists, returns its details
39 * and whether it is enforced or not. ‘silo_attrs’ comprises the attributes to
40 * include in the search result, the relevant set of which can differ depending
41 * on the account’s objectClass.
43 int authn_policy_get_assigned_silo(struct ldb_context
*samdb
,
45 const struct ldb_message
*msg
,
46 const char *const *silo_attrs
,
47 const struct ldb_message
**silo_msg_out
,
50 struct auth_user_info_dc
;
52 /* Authentication policies for Kerberos clients. */
55 * Get the applicable authentication policy for an account acting as a Kerberos
58 int authn_policy_kerberos_client(struct ldb_context
*samdb
,
60 const struct ldb_message
*msg
,
61 const struct authn_kerberos_client_policy
**policy_out
);
64 * Perform an access check for the device with which the client is
65 * authenticating. ‘device_info’ must be talloc-allocated so that we can make a
68 NTSTATUS
authn_policy_authenticate_from_device(TALLOC_CTX
*mem_ctx
,
69 struct ldb_context
*samdb
,
70 struct loadparm_context
* lp_ctx
,
71 const struct auth_user_info_dc
*device_info
,
72 const struct auth_claims auth_claims
,
73 const struct authn_kerberos_client_policy
*client_policy
,
74 struct authn_audit_info
**client_audit_info_out
);
76 /* Return whether an authentication policy enforces device restrictions. */
77 bool authn_policy_device_restrictions_present(const struct authn_kerberos_client_policy
*policy
);
79 /* Authentication policies for NTLM clients. */
81 struct authn_ntlm_client_policy
;
84 * Get the applicable authentication policy for an account acting as an NTLM
87 int authn_policy_ntlm_client(struct ldb_context
*samdb
,
89 const struct ldb_message
*msg
,
90 const struct authn_ntlm_client_policy
**policy_out
);
92 /* Check whether the client is allowed to authenticate using NTLM. */
93 NTSTATUS
authn_policy_ntlm_apply_device_restriction(TALLOC_CTX
*mem_ctx
,
94 const struct authn_ntlm_client_policy
*client_policy
,
95 struct authn_audit_info
**client_audit_info_out
);
97 /* Authentication policies for servers. */
99 struct authn_server_policy
;
102 * Get the applicable authentication policy for an account acting as a
105 int authn_policy_server(struct ldb_context
*samdb
,
107 const struct ldb_message
*msg
,
108 const struct authn_server_policy
**policy_out
);
110 /* Return whether an authentication policy enforces restrictions. */
111 bool authn_policy_restrictions_present(const struct authn_server_policy
*policy
);
113 enum authn_policy_auth_type
{
114 AUTHN_POLICY_AUTH_TYPE_KERBEROS
,
115 AUTHN_POLICY_AUTH_TYPE_NTLM
,
118 struct authn_policy_flags
{
119 bool force_compounded_authentication
: 1;
123 * Perform an access check for the client attempting to authenticate to the
124 * server. ‘user_info’ must be talloc-allocated so that we can make a reference
127 NTSTATUS
authn_policy_authenticate_to_service(TALLOC_CTX
*mem_ctx
,
128 struct ldb_context
*samdb
,
129 struct loadparm_context
* lp_ctx
,
130 enum authn_policy_auth_type auth_type
,
131 const struct auth_user_info_dc
*user_info
,
132 const struct auth_user_info_dc
*device_info
,
133 const struct auth_claims auth_claims
,
134 const struct authn_server_policy
*server_policy
,
135 const struct authn_policy_flags authn_policy_flags
,
136 struct authn_audit_info
**server_audit_info_out
);
138 /* Create a structure containing auditing information. */
139 NTSTATUS
_authn_kerberos_client_policy_audit_info(
141 const struct authn_kerberos_client_policy
*client_policy
,
142 const struct auth_user_info_dc
*client_info
,
143 enum authn_audit_event event
,
144 enum authn_audit_reason reason
,
145 NTSTATUS policy_status
,
146 const char *location
,
147 struct authn_audit_info
**audit_info_out
);
149 /* Create a structure containing auditing information. */
150 #define authn_kerberos_client_policy_audit_info( \
158 _authn_kerberos_client_policy_audit_info( \
168 /* Create a structure containing auditing information. */
169 NTSTATUS
_authn_ntlm_client_policy_audit_info(
171 const struct authn_ntlm_client_policy
*policy
,
172 const struct auth_user_info_dc
*client_info
,
173 enum authn_audit_event event
,
174 enum authn_audit_reason reason
,
175 NTSTATUS policy_status
,
176 const char *location
,
177 struct authn_audit_info
**audit_info_out
);
179 /* Create a structure containing auditing information. */
180 #define authn_ntlm_client_policy_audit_info( \
188 _authn_ntlm_client_policy_audit_info( \
198 /* Create a structure containing auditing information. */
199 NTSTATUS
_authn_server_policy_audit_info(
201 const struct authn_server_policy
*policy
,
202 const struct auth_user_info_dc
*client_info
,
203 enum authn_audit_event event
,
204 enum authn_audit_reason reason
,
205 NTSTATUS policy_status
,
206 const char *location
,
207 struct authn_audit_info
**audit_info_out
);
209 /* Create a structure containing auditing information. */
210 #define authn_server_policy_audit_info( \
218 _authn_server_policy_audit_info( \