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/dom_sid.h"
26 #include "rpc_server/drsuapi/dcesrv_drsuapi.h"
27 #include "libcli/security/security.h"
28 #include "param/param.h"
31 format a drsuapi_DsReplicaObjectIdentifier naming context as a string
33 char *drs_ObjectIdentifier_to_string(TALLOC_CTX *mem_ctx,
34 struct drsuapi_DsReplicaObjectIdentifier *nc)
36 char *guid, *sid, *ret;
37 guid = GUID_string(mem_ctx, &nc->guid);
38 sid = dom_sid_string(mem_ctx, &nc->sid);
39 ret = talloc_asprintf(mem_ctx, "<GUID=%s>;<SID=%s>;%s",
46 int drsuapi_search_with_extended_dn(struct ldb_context *ldb,
48 struct ldb_result **_res,
49 struct ldb_dn *basedn,
51 const char * const *attrs,
52 const char *sort_attrib,
53 const char *format, ...)
57 struct ldb_request *req;
60 struct ldb_result *res;
62 tmp_ctx = talloc_new(mem_ctx);
64 res = talloc_zero(tmp_ctx, struct ldb_result);
66 return LDB_ERR_OPERATIONS_ERROR;
70 filter = talloc_vasprintf(tmp_ctx, format, ap);
75 return LDB_ERR_OPERATIONS_ERROR;
78 ret = ldb_build_search_req(&req, ldb, tmp_ctx,
85 ldb_search_default_callback,
87 if (ret != LDB_SUCCESS) {
92 ret = ldb_request_add_control(req, LDB_CONTROL_EXTENDED_DN_OID, true, NULL);
93 if (ret != LDB_SUCCESS) {
98 struct ldb_server_sort_control *sort_control;
99 sort_control = talloc(req, struct ldb_server_sort_control);
100 if (sort_control == NULL) {
101 talloc_free(tmp_ctx);
102 return LDB_ERR_OPERATIONS_ERROR;
104 sort_control->attributeName = sort_attrib;
105 sort_control->orderingRule = NULL;
106 sort_control->reverse = 1;
108 ret = ldb_request_add_control(req, LDB_CONTROL_SERVER_SORT_OID, true, sort_control);
109 if (ret != LDB_SUCCESS) {
115 ret = ldb_request(ldb, req);
116 if (ret == LDB_SUCCESS) {
117 ret = ldb_wait(req->handle, LDB_WAIT_ALL);
125 WERROR drs_security_level_check(struct dcesrv_call_state *dce_call, const char* call)
127 if (lp_parm_bool(dce_call->conn->dce_ctx->lp_ctx, NULL,
128 "drs", "disable_sec_check", false)) {
132 if (security_session_user_level(dce_call->conn->auth_state.session_info) <
133 SECURITY_DOMAIN_CONTROLLER) {
134 DEBUG(0,("DsReplicaGetInfo refused for security token\n"));
135 return WERR_DS_DRA_ACCESS_DENIED;