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"
29 format a drsuapi_DsReplicaObjectIdentifier naming context as a string
31 char *drs_ObjectIdentifier_to_string(TALLOC_CTX *mem_ctx,
32 struct drsuapi_DsReplicaObjectIdentifier *nc)
34 char *guid, *sid, *ret;
35 guid = GUID_string(mem_ctx, &nc->guid);
36 sid = dom_sid_string(mem_ctx, &nc->sid);
37 ret = talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
44 int drsuapi_search_with_extended_dn(struct ldb_context *ldb,
46 struct ldb_result **_res,
47 struct ldb_dn *basedn,
49 const char * const *attrs,
50 const char *sort_attrib,
54 struct ldb_request *req;
56 struct ldb_result *res;
58 tmp_ctx = talloc_new(mem_ctx);
60 res = talloc_zero(tmp_ctx, struct ldb_result);
62 return LDB_ERR_OPERATIONS_ERROR;
65 ret = ldb_build_search_req(&req, ldb, tmp_ctx,
72 ldb_search_default_callback,
74 if (ret != LDB_SUCCESS) {
79 ret = ldb_request_add_control(req, LDB_CONTROL_EXTENDED_DN_OID, true, NULL);
80 if (ret != LDB_SUCCESS) {
84 ret = ldb_request_add_control(req, LDB_CONTROL_SHOW_DELETED_OID, true, NULL);
85 if (ret != LDB_SUCCESS) {
89 ret = ldb_request_add_control(req, LDB_CONTROL_REVEAL_INTERNALS, false, NULL);
90 if (ret != LDB_SUCCESS) {
95 struct ldb_server_sort_control **sort_control;
96 sort_control = talloc_array(req, struct ldb_server_sort_control *, 2);
97 if (sort_control == NULL) {
99 return LDB_ERR_OPERATIONS_ERROR;
101 sort_control[0] = talloc(req, struct ldb_server_sort_control);
102 sort_control[0]->attributeName = sort_attrib;
103 sort_control[0]->orderingRule = NULL;
104 sort_control[0]->reverse = 0;
105 sort_control[1] = NULL;
107 ret = ldb_request_add_control(req, LDB_CONTROL_SERVER_SORT_OID, true, sort_control);
108 if (ret != LDB_SUCCESS) {
114 ret = ldb_request(ldb, req);
115 if (ret == LDB_SUCCESS) {
116 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
120 *_res = talloc_steal(mem_ctx, res);
124 WERROR drs_security_level_check(struct dcesrv_call_state *dce_call, const char* call)
126 if (lp_parm_bool(dce_call->conn->dce_ctx->lp_ctx, NULL,
127 "drs", "disable_sec_check", false)) {
131 if (security_session_user_level(dce_call->conn->auth_state.session_info) <
132 SECURITY_DOMAIN_CONTROLLER) {
134 DEBUG(0,("%s refused for security token\n", call));
136 return WERR_DS_DRA_ACCESS_DENIED;
142 void drsuapi_process_secret_attribute(struct drsuapi_DsReplicaAttribute *attr,
143 struct drsuapi_DsReplicaMetaData *meta_data)
145 if (attr->value_ctr.num_values == 0) {
149 switch (attr->attid) {
150 case DRSUAPI_ATTRIBUTE_dBCSPwd:
151 case DRSUAPI_ATTRIBUTE_unicodePwd:
152 case DRSUAPI_ATTRIBUTE_ntPwdHistory:
153 case DRSUAPI_ATTRIBUTE_lmPwdHistory:
154 case DRSUAPI_ATTRIBUTE_supplementalCredentials:
155 case DRSUAPI_ATTRIBUTE_priorValue:
156 case DRSUAPI_ATTRIBUTE_currentValue:
157 case DRSUAPI_ATTRIBUTE_trustAuthOutgoing:
158 case DRSUAPI_ATTRIBUTE_trustAuthIncoming:
159 case DRSUAPI_ATTRIBUTE_initialAuthOutgoing:
160 case DRSUAPI_ATTRIBUTE_initialAuthIncoming:
161 /*set value to null*/
162 attr->value_ctr.num_values = 0;
163 talloc_free(attr->value_ctr.values);
164 attr->value_ctr.values = NULL;
165 meta_data->originating_change_time = 0;