2 Unix SMB/CIFS implementation.
4 useful utilities for the DRS server
6 Copyright (C) Andrew Tridgell 2009
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.
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.
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/>.
23 #include "rpc_server/dcerpc_server.h"
24 #include "dsdb/samdb/samdb.h"
25 #include "libcli/security/security.h"
26 #include "param/param.h"
27 #include "auth/session.h"
29 int drsuapi_search_with_extended_dn(struct ldb_context *ldb,
31 struct ldb_result **_res,
32 struct ldb_dn *basedn,
34 const char * const *attrs,
38 struct ldb_request *req;
40 struct ldb_result *res;
42 tmp_ctx = talloc_new(mem_ctx);
44 res = talloc_zero(tmp_ctx, struct ldb_result);
46 return LDB_ERR_OPERATIONS_ERROR;
49 ret = ldb_build_search_req(&req, ldb, tmp_ctx,
56 ldb_search_default_callback,
58 if (ret != LDB_SUCCESS) {
63 ret = ldb_request_add_control(req, LDB_CONTROL_EXTENDED_DN_OID, true, NULL);
64 if (ret != LDB_SUCCESS) {
68 ret = ldb_request_add_control(req, LDB_CONTROL_SHOW_RECYCLED_OID, true, NULL);
69 if (ret != LDB_SUCCESS) {
73 ret = ldb_request_add_control(req, LDB_CONTROL_REVEAL_INTERNALS, false, NULL);
74 if (ret != LDB_SUCCESS) {
78 ret = ldb_request(ldb, req);
79 if (ret == LDB_SUCCESS) {
80 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
84 *_res = talloc_steal(mem_ctx, res);
88 WERROR drs_security_level_check(struct dcesrv_call_state *dce_call,
90 enum security_user_level minimum_level,
91 const struct dom_sid *domain_sid)
93 enum security_user_level level;
95 if (lpcfg_parm_bool(dce_call->conn->dce_ctx->lp_ctx, NULL,
96 "drs", "disable_sec_check", false)) {
100 level = security_session_user_level(dce_call->conn->auth_state.session_info, domain_sid);
101 if (level < minimum_level) {
103 DEBUG(0,("%s refused for security token (level=%u)\n",
104 call, (unsigned)level));
105 security_token_debug(2, dce_call->conn->auth_state.session_info->security_token);
107 return WERR_DS_DRA_ACCESS_DENIED;
113 void drsuapi_process_secret_attribute(struct drsuapi_DsReplicaAttribute *attr,
114 struct drsuapi_DsReplicaMetaData *meta_data)
116 if (attr->value_ctr.num_values == 0) {
120 switch (attr->attid) {
121 case DRSUAPI_ATTRIBUTE_dBCSPwd:
122 case DRSUAPI_ATTRIBUTE_unicodePwd:
123 case DRSUAPI_ATTRIBUTE_ntPwdHistory:
124 case DRSUAPI_ATTRIBUTE_lmPwdHistory:
125 case DRSUAPI_ATTRIBUTE_supplementalCredentials:
126 case DRSUAPI_ATTRIBUTE_priorValue:
127 case DRSUAPI_ATTRIBUTE_currentValue:
128 case DRSUAPI_ATTRIBUTE_trustAuthOutgoing:
129 case DRSUAPI_ATTRIBUTE_trustAuthIncoming:
130 case DRSUAPI_ATTRIBUTE_initialAuthOutgoing:
131 case DRSUAPI_ATTRIBUTE_initialAuthIncoming:
132 /*set value to null*/
133 attr->value_ctr.num_values = 0;
134 talloc_free(attr->value_ctr.values);
135 attr->value_ctr.values = NULL;
136 meta_data->originating_change_time = 0;
145 check security on a DN, with logging of errors
147 static WERROR drs_security_access_check_log(struct ldb_context *sam_ctx,
149 struct security_token *token,
151 const char *ext_right)
155 DEBUG(3,("drs_security_access_check: Null dn provided, access is denied for %s\n",
157 return WERR_DS_DRA_ACCESS_DENIED;
159 ret = dsdb_check_access_on_dn(sam_ctx,
163 SEC_ADS_CONTROL_ACCESS,
165 if (ret == LDB_ERR_INSUFFICIENT_ACCESS_RIGHTS) {
166 DEBUG(3,("%s refused for security token on %s\n",
167 ext_right, ldb_dn_get_linearized(dn)));
168 security_token_debug(2, token);
169 return WERR_DS_DRA_ACCESS_DENIED;
170 } else if (ret != LDB_SUCCESS) {
171 DEBUG(1,("Failed to perform access check on %s\n", ldb_dn_get_linearized(dn)));
172 return WERR_DS_DRA_INTERNAL_ERROR;
179 check security on a object identifier
181 WERROR drs_security_access_check(struct ldb_context *sam_ctx,
183 struct security_token *token,
184 struct drsuapi_DsReplicaObjectIdentifier *nc,
185 const char *ext_right)
187 struct ldb_dn *dn = drs_ObjectIdentifier_to_dn(mem_ctx, sam_ctx, nc);
189 werr = drs_security_access_check_log(sam_ctx, mem_ctx, token, dn, ext_right);
195 check security on the NC root of a object identifier
197 WERROR drs_security_access_check_nc_root(struct ldb_context *sam_ctx,
199 struct security_token *token,
200 struct drsuapi_DsReplicaObjectIdentifier *nc,
201 const char *ext_right)
203 struct ldb_dn *dn, *nc_root;
207 dn = drs_ObjectIdentifier_to_dn(mem_ctx, sam_ctx, nc);
208 W_ERROR_HAVE_NO_MEMORY(dn);
209 ret = dsdb_find_nc_root(sam_ctx, dn, dn, &nc_root);
210 if (ret != LDB_SUCCESS) {
211 return WERR_DS_CANT_FIND_EXPECTED_NC;
213 werr = drs_security_access_check_log(sam_ctx, mem_ctx, token, nc_root, ext_right);