2 Unix SMB/CIFS implementation.
4 endpoint server for the drsuapi pipe
6 Copyright (C) Stefan Metzmacher 2004
7 Copyright (C) Andrew Bartlett <abartlet@samba.org> 2006
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "librpc/gen_ndr/ndr_drsuapi.h"
25 #include "rpc_server/dcerpc_server.h"
26 #include "rpc_server/common/common.h"
27 #include "dsdb/samdb/samdb.h"
28 #include "dsdb/common/util.h"
29 #include "libcli/security/security.h"
30 #include "libcli/security/session.h"
31 #include "rpc_server/drsuapi/dcesrv_drsuapi.h"
32 #include "auth/auth.h"
33 #include "param/param.h"
34 #include "lib/messaging/irpc.h"
36 #define DRSUAPI_UNSUPPORTED(fname) do { \
37 DEBUG(1,(__location__ ": Unsupported DRS call %s\n", #fname)); \
38 if (DEBUGLVL(2)) NDR_PRINT_IN_DEBUG(fname, r); \
39 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR); \
45 static WERROR
dcesrv_drsuapi_DsBind(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
46 struct drsuapi_DsBind
*r
)
48 struct drsuapi_bind_state
*b_state
;
49 struct dcesrv_handle
*handle
;
50 struct drsuapi_DsBindInfoCtr
*bind_info
;
51 struct GUID site_guid
;
52 struct ldb_result
*site_res
;
53 struct ldb_dn
*server_site_dn
;
54 static const char *site_attrs
[] = { "objectGUID", NULL
};
55 struct ldb_result
*ntds_res
;
56 struct ldb_dn
*ntds_dn
;
57 static const char *ntds_attrs
[] = { "ms-DS-ReplicationEpoch", NULL
};
61 struct auth_session_info
*auth_info
;
63 bool connected_as_system
= false;
65 r
->out
.bind_info
= NULL
;
66 ZERO_STRUCTP(r
->out
.bind_handle
);
68 b_state
= talloc_zero(mem_ctx
, struct drsuapi_bind_state
);
69 W_ERROR_HAVE_NO_MEMORY(b_state
);
71 /* if this is a DC connecting, give them system level access */
72 werr
= drs_security_level_check(dce_call
, NULL
, SECURITY_DOMAIN_CONTROLLER
, NULL
);
73 if (W_ERROR_IS_OK(werr
)) {
74 DEBUG(3,(__location__
": doing DsBind with system_session\n"));
75 auth_info
= system_session(dce_call
->conn
->dce_ctx
->lp_ctx
);
76 connected_as_system
= true;
78 auth_info
= dce_call
->conn
->auth_state
.session_info
;
82 * connect to the samdb
84 b_state
->sam_ctx
= samdb_connect(b_state
, dce_call
->event_ctx
,
85 dce_call
->conn
->dce_ctx
->lp_ctx
, auth_info
, 0);
86 if (!b_state
->sam_ctx
) {
90 if (connected_as_system
) {
91 b_state
->sam_ctx_system
= b_state
->sam_ctx
;
93 /* an RODC also needs system samdb access for secret
94 attribute replication */
95 werr
= drs_security_level_check(dce_call
, NULL
, SECURITY_RO_DOMAIN_CONTROLLER
,
96 samdb_domain_sid(b_state
->sam_ctx
));
97 if (W_ERROR_IS_OK(werr
)) {
98 b_state
->sam_ctx_system
= samdb_connect(b_state
, dce_call
->event_ctx
,
99 dce_call
->conn
->dce_ctx
->lp_ctx
,
100 system_session(dce_call
->conn
->dce_ctx
->lp_ctx
), 0);
101 if (!b_state
->sam_ctx_system
) {
108 * find out the guid of our own site
110 server_site_dn
= samdb_server_site_dn(b_state
->sam_ctx
, mem_ctx
);
111 W_ERROR_HAVE_NO_MEMORY(server_site_dn
);
113 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &site_res
,
114 server_site_dn
, LDB_SCOPE_BASE
, site_attrs
,
116 if (ret
!= LDB_SUCCESS
) {
117 return WERR_DS_DRA_INTERNAL_ERROR
;
119 if (site_res
->count
!= 1) {
120 return WERR_DS_DRA_INTERNAL_ERROR
;
122 site_guid
= samdb_result_guid(site_res
->msgs
[0], "objectGUID");
125 * lookup the local servers Replication Epoch
127 ntds_dn
= samdb_ntds_settings_dn(b_state
->sam_ctx
, mem_ctx
);
128 W_ERROR_HAVE_NO_MEMORY(ntds_dn
);
130 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &ntds_res
,
131 ntds_dn
, LDB_SCOPE_BASE
, ntds_attrs
,
133 if (ret
!= LDB_SUCCESS
) {
134 return WERR_DS_DRA_INTERNAL_ERROR
;
136 if (ntds_res
->count
!= 1) {
137 return WERR_DS_DRA_INTERNAL_ERROR
;
139 repl_epoch
= ldb_msg_find_attr_as_uint(ntds_res
->msgs
[0],
140 "ms-DS-ReplicationEpoch", 0);
143 * The "process identifier" of the client.
144 * According to the WSPP docs, sectin 5.35, this is
145 * for informational and debugging purposes only.
146 * The assignment is implementation specific.
151 * store the clients bind_guid
153 if (r
->in
.bind_guid
) {
154 b_state
->remote_bind_guid
= *r
->in
.bind_guid
;
158 * store the clients bind_info
160 if (r
->in
.bind_info
) {
161 switch (r
->in
.bind_info
->length
) {
163 struct drsuapi_DsBindInfo24
*info24
;
164 info24
= &r
->in
.bind_info
->info
.info24
;
165 b_state
->remote_info28
.supported_extensions
= info24
->supported_extensions
;
166 b_state
->remote_info28
.site_guid
= info24
->site_guid
;
167 b_state
->remote_info28
.pid
= info24
->pid
;
168 b_state
->remote_info28
.repl_epoch
= 0;
172 b_state
->remote_info28
= r
->in
.bind_info
->info
.info28
;
178 * fill in our local bind info 28
180 b_state
->local_info28
.supported_extensions
= 0;
181 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_BASE
;
182 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION
;
183 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI
;
184 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2
;
185 #if 0 /* we don't support MSZIP compression (only decompression) */
186 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS
;
188 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1
;
189 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION
;
190 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE
;
191 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2
;
192 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION
;
193 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2
;
194 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD
;
195 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND
;
196 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO
;
197 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION
;
198 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01
;
199 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP
;
200 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY
;
201 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3
;
202 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V5
;
203 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2
;
204 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6
;
205 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS
;
206 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8
;
207 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5
;
208 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6
;
209 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3
;
210 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7
;
211 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT
;
212 #if 0 /* we don't support XPRESS compression yet */
213 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS
;
215 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V10
;
216 b_state
->local_info28
.site_guid
= site_guid
;
217 b_state
->local_info28
.pid
= pid
;
218 b_state
->local_info28
.repl_epoch
= repl_epoch
;
221 * allocate the return bind_info
223 bind_info
= talloc_zero(mem_ctx
, struct drsuapi_DsBindInfoCtr
);
224 W_ERROR_HAVE_NO_MEMORY(bind_info
);
226 bind_info
->length
= 28;
227 bind_info
->info
.info28
= b_state
->local_info28
;
230 * allocate a bind handle
232 handle
= dcesrv_handle_new(dce_call
->context
, DRSUAPI_BIND_HANDLE
);
233 W_ERROR_HAVE_NO_MEMORY(handle
);
234 handle
->data
= talloc_steal(handle
, b_state
);
239 r
->out
.bind_info
= bind_info
;
240 *r
->out
.bind_handle
= handle
->wire_handle
;
249 static WERROR
dcesrv_drsuapi_DsUnbind(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
250 struct drsuapi_DsUnbind
*r
)
252 struct dcesrv_handle
*h
;
254 *r
->out
.bind_handle
= *r
->in
.bind_handle
;
256 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
260 ZERO_STRUCTP(r
->out
.bind_handle
);
267 drsuapi_DsReplicaSync
269 static WERROR
dcesrv_drsuapi_DsReplicaSync(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
270 struct drsuapi_DsReplicaSync
*r
)
275 status
= drs_security_level_check(dce_call
, "DsReplicaSync", SECURITY_DOMAIN_CONTROLLER
, NULL
);
276 if (!W_ERROR_IS_OK(status
)) {
280 if (r
->in
.level
!= 1) {
281 DEBUG(0,("DsReplicaSync called with unsupported level %d\n", r
->in
.level
));
282 return WERR_DS_DRA_INVALID_PARAMETER
;
285 if (r
->in
.req
->req1
.options
& DRSUAPI_DRS_ASYNC_OP
) {
286 timeout
= IRPC_CALL_TIMEOUT
;
289 * use Infinite time for timeout in case
290 * the caller made a sync call
292 timeout
= IRPC_CALL_TIMEOUT_INF
;
295 dcesrv_irpc_forward_rpc_call(dce_call
, mem_ctx
,
296 r
, NDR_DRSUAPI_DSREPLICASYNC
,
298 "dreplsrv", "DsReplicaSync",
308 static WERROR
dcesrv_drsuapi_DsReplicaAdd(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
309 struct drsuapi_DsReplicaAdd
*r
)
313 status
= drs_security_level_check(dce_call
, "DsReplicaAdd", SECURITY_DOMAIN_CONTROLLER
, NULL
);
314 if (!W_ERROR_IS_OK(status
)) {
318 dcesrv_irpc_forward_rpc_call(dce_call
, mem_ctx
,
319 r
, NDR_DRSUAPI_DSREPLICAADD
,
321 "dreplsrv", "DsReplicaAdd",
331 static WERROR
dcesrv_drsuapi_DsReplicaDel(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
332 struct drsuapi_DsReplicaDel
*r
)
336 status
= drs_security_level_check(dce_call
, "DsReplicaDel", SECURITY_DOMAIN_CONTROLLER
, NULL
);
337 if (!W_ERROR_IS_OK(status
)) {
341 dcesrv_irpc_forward_rpc_call(dce_call
, mem_ctx
,
342 r
, NDR_DRSUAPI_DSREPLICADEL
,
344 "dreplsrv", "DsReplicaDel",
352 drsuapi_DsReplicaModify
354 static WERROR
dcesrv_drsuapi_DsReplicaMod(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
355 struct drsuapi_DsReplicaMod
*r
)
359 status
= drs_security_level_check(dce_call
, "DsReplicaMod", SECURITY_DOMAIN_CONTROLLER
, NULL
);
360 if (!W_ERROR_IS_OK(status
)) {
364 dcesrv_irpc_forward_rpc_call(dce_call
, mem_ctx
,
365 r
, NDR_DRSUAPI_DSREPLICAMOD
,
367 "dreplsrv", "DsReplicaMod",
377 static WERROR
dcesrv_DRSUAPI_VERIFY_NAMES(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
378 struct DRSUAPI_VERIFY_NAMES
*r
)
380 DRSUAPI_UNSUPPORTED(DRSUAPI_VERIFY_NAMES
);
385 drsuapi_DsGetMemberships
387 static WERROR
dcesrv_drsuapi_DsGetMemberships(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
388 struct drsuapi_DsGetMemberships
*r
)
390 DRSUAPI_UNSUPPORTED(drsuapi_DsGetMemberships
);
395 DRSUAPI_INTER_DOMAIN_MOVE
397 static WERROR
dcesrv_DRSUAPI_INTER_DOMAIN_MOVE(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
398 struct DRSUAPI_INTER_DOMAIN_MOVE
*r
)
400 DRSUAPI_UNSUPPORTED(DRSUAPI_INTER_DOMAIN_MOVE
);
405 drsuapi_DsGetNT4ChangeLog
407 static WERROR
dcesrv_drsuapi_DsGetNT4ChangeLog(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
408 struct drsuapi_DsGetNT4ChangeLog
*r
)
410 DRSUAPI_UNSUPPORTED(drsuapi_DsGetNT4ChangeLog
);
416 static WERROR
dcesrv_drsuapi_DsCrackNames(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
417 struct drsuapi_DsCrackNames
*r
)
419 struct drsuapi_bind_state
*b_state
;
420 struct dcesrv_handle
*h
;
422 *r
->out
.level_out
= r
->in
.level
;
424 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
427 r
->out
.ctr
= talloc_zero(mem_ctx
, union drsuapi_DsNameCtr
);
428 W_ERROR_HAVE_NO_MEMORY(r
->out
.ctr
);
430 switch (r
->in
.level
) {
432 switch(r
->in
.req
->req1
.format_offered
){
433 case DRSUAPI_DS_NAME_FORMAT_UPN_AND_ALTSECID
:
434 case DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT_NAME_SANS_DOMAIN_EX
:
435 case DRSUAPI_DS_NAME_FORMAT_LIST_GLOBAL_CATALOG_SERVERS
:
436 case DRSUAPI_DS_NAME_FORMAT_UPN_FOR_LOGON
:
437 case DRSUAPI_DS_NAME_FORMAT_LIST_SERVERS_WITH_DCS_IN_SITE
:
438 case DRSUAPI_DS_NAME_FORMAT_STRING_SID_NAME
:
439 case DRSUAPI_DS_NAME_FORMAT_ALT_SECURITY_IDENTITIES_NAME
:
440 case DRSUAPI_DS_NAME_FORMAT_LIST_NCS
:
441 case DRSUAPI_DS_NAME_FORMAT_LIST_DOMAINS
:
442 case DRSUAPI_DS_NAME_FORMAT_MAP_SCHEMA_GUID
:
443 case DRSUAPI_DS_NAME_FORMAT_NT4_ACCOUNT_NAME_SANS_DOMAIN
:
444 case DRSUAPI_DS_NAME_FORMAT_LIST_INFO_FOR_SERVER
:
445 case DRSUAPI_DS_NAME_FORMAT_LIST_SERVERS_FOR_DOMAIN_IN_SITE
:
446 case DRSUAPI_DS_NAME_FORMAT_LIST_DOMAINS_IN_SITE
:
447 case DRSUAPI_DS_NAME_FORMAT_LIST_SERVERS_IN_SITE
:
448 case DRSUAPI_DS_NAME_FORMAT_LIST_SITES
:
449 DEBUG(0, ("DsCrackNames: Unsupported operation requested: %X",
450 r
->in
.req
->req1
.format_offered
));
452 case DRSUAPI_DS_NAME_FORMAT_LIST_ROLES
:
453 return dcesrv_drsuapi_ListRoles(b_state
->sam_ctx
, mem_ctx
,
454 &r
->in
.req
->req1
, &r
->out
.ctr
->ctr1
);
455 default:/* format_offered is in the enum drsuapi_DsNameFormat*/
456 return dcesrv_drsuapi_CrackNamesByNameFormat(b_state
->sam_ctx
, mem_ctx
,
457 &r
->in
.req
->req1
, &r
->out
.ctr
->ctr1
);
461 return WERR_UNKNOWN_LEVEL
;
466 drsuapi_DsRemoveDSServer
468 static WERROR
dcesrv_drsuapi_DsRemoveDSServer(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
469 struct drsuapi_DsRemoveDSServer
*r
)
471 struct drsuapi_bind_state
*b_state
;
472 struct dcesrv_handle
*h
;
473 struct ldb_dn
*ntds_dn
;
478 *r
->out
.level_out
= 1;
480 status
= drs_security_level_check(dce_call
, "DsRemoveDSServer", SECURITY_DOMAIN_CONTROLLER
, NULL
);
481 if (!W_ERROR_IS_OK(status
)) {
485 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
488 switch (r
->in
.level
) {
490 ntds_dn
= ldb_dn_new(mem_ctx
, b_state
->sam_ctx
, r
->in
.req
->req1
.server_dn
);
491 W_ERROR_HAVE_NO_MEMORY(ntds_dn
);
493 ok
= ldb_dn_validate(ntds_dn
);
498 /* TODO: it's likely that we need more checks here */
500 ok
= ldb_dn_add_child_fmt(ntds_dn
, "CN=NTDS Settings");
505 if (r
->in
.req
->req1
.commit
) {
506 ret
= dsdb_delete(b_state
->sam_ctx
, ntds_dn
, DSDB_TREE_DELETE
);
507 if (ret
!= LDB_SUCCESS
) {
522 DRSUAPI_REMOVE_DS_DOMAIN
524 static WERROR
dcesrv_DRSUAPI_REMOVE_DS_DOMAIN(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
525 struct DRSUAPI_REMOVE_DS_DOMAIN
*r
)
527 DRSUAPI_UNSUPPORTED(DRSUAPI_REMOVE_DS_DOMAIN
);
530 /* Obtain the site name from a server DN */
531 static const char *result_site_name(struct ldb_dn
*server_dn
)
533 /* Format is cn=<NETBIOS name>,cn=Servers,cn=<site>,cn=sites.... */
534 const struct ldb_val
*val
= ldb_dn_get_component_val(server_dn
, 2);
535 const char *name
= ldb_dn_get_component_name(server_dn
, 2);
537 if (!name
|| (ldb_attr_cmp(name
, "cn") != 0)) {
538 /* Ensure this matches the format. This gives us a
539 * bit more confidence that a 'cn' value will be a
544 return (char *)val
->data
;
550 drsuapi_DsGetDomainControllerInfo
552 static WERROR
dcesrv_drsuapi_DsGetDomainControllerInfo_1(struct drsuapi_bind_state
*b_state
,
554 struct drsuapi_DsGetDomainControllerInfo
*r
)
556 struct ldb_dn
*sites_dn
;
557 struct ldb_result
*res
;
559 const char *attrs_account_1
[] = { "cn", "dnsHostName", NULL
};
560 const char *attrs_account_2
[] = { "cn", "dnsHostName", "objectGUID", NULL
};
562 const char *attrs_none
[] = { NULL
};
564 const char *attrs_site
[] = { "objectGUID", NULL
};
566 const char *attrs_ntds
[] = { "options", "objectGUID", NULL
};
568 const char *attrs_1
[] = { "serverReference", "cn", "dnsHostName", NULL
};
569 const char *attrs_2
[] = { "serverReference", "cn", "dnsHostName", "objectGUID", NULL
};
572 struct drsuapi_DsGetDCInfoCtr1
*ctr1
;
573 struct drsuapi_DsGetDCInfoCtr2
*ctr2
;
578 *r
->out
.level_out
= r
->in
.req
->req1
.level
;
579 r
->out
.ctr
= talloc_zero(mem_ctx
, union drsuapi_DsGetDCInfoCtr
);
580 W_ERROR_HAVE_NO_MEMORY(r
->out
.ctr
);
582 switch (*r
->out
.level_out
) {
584 /* this level is not like the others */
585 return WERR_UNKNOWN_LEVEL
;
593 return WERR_UNKNOWN_LEVEL
;
596 sites_dn
= samdb_sites_dn(b_state
->sam_ctx
, mem_ctx
);
598 return WERR_DS_OBJ_NOT_FOUND
;
601 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res
, sites_dn
, LDB_SCOPE_SUBTREE
, attrs
,
602 "(&(objectClass=server)(serverReference=*))");
605 DEBUG(1, ("searching for servers in sites DN %s failed: %s\n",
606 ldb_dn_get_linearized(sites_dn
), ldb_errstring(b_state
->sam_ctx
)));
607 return WERR_GENERAL_FAILURE
;
610 switch (*r
->out
.level_out
) {
612 ctr1
= &r
->out
.ctr
->ctr1
;
613 ctr1
->count
= res
->count
;
614 ctr1
->array
= talloc_zero_array(mem_ctx
,
615 struct drsuapi_DsGetDCInfo1
,
617 for (i
=0; i
< res
->count
; i
++) {
618 struct ldb_dn
*domain_dn
;
619 struct ldb_result
*res_domain
;
620 struct ldb_result
*res_account
;
621 struct ldb_dn
*ntds_dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[i
]->dn
);
623 struct ldb_dn
*ref_dn
624 = ldb_msg_find_attr_as_dn(b_state
->sam_ctx
,
625 mem_ctx
, res
->msgs
[i
],
628 if (!ntds_dn
|| !ldb_dn_add_child_fmt(ntds_dn
, "CN=NTDS Settings")) {
632 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_account
, ref_dn
,
633 LDB_SCOPE_BASE
, attrs_account_1
,
634 "(&(objectClass=computer)(userAccountControl:1.2.840.113556.1.4.803:=%u)",
635 UF_SERVER_TRUST_ACCOUNT
);
636 if (ret
== LDB_SUCCESS
&& res_account
->count
== 1) {
638 ctr1
->array
[i
].dns_name
639 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "dNSHostName", NULL
);
640 ctr1
->array
[i
].netbios_name
641 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "cn", NULL
);
642 ctr1
->array
[i
].computer_dn
643 = ldb_dn_get_linearized(res_account
->msgs
[0]->dn
);
645 /* Determine if this is the PDC */
646 ret
= samdb_search_for_parent_domain(b_state
->sam_ctx
,
647 mem_ctx
, res_account
->msgs
[0]->dn
,
648 &domain_dn
, &errstr
);
650 if (ret
== LDB_SUCCESS
) {
651 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_domain
, domain_dn
,
652 LDB_SCOPE_BASE
, attrs_none
, "fSMORoleOwner=%s",
653 ldb_dn_get_linearized(ntds_dn
));
655 return WERR_GENERAL_FAILURE
;
657 if (res_domain
->count
== 1) {
658 ctr1
->array
[i
].is_pdc
= true;
662 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
663 DEBUG(5, ("warning: searching for computer DN %s failed: %s\n",
664 ldb_dn_get_linearized(ref_dn
), ldb_errstring(b_state
->sam_ctx
)));
667 /* Look at server DN and extract site component */
668 ctr1
->array
[i
].site_name
= result_site_name(res
->msgs
[i
]->dn
);
669 ctr1
->array
[i
].server_dn
= ldb_dn_get_linearized(res
->msgs
[i
]->dn
);
672 ctr1
->array
[i
].is_enabled
= true;
677 ctr2
= &r
->out
.ctr
->ctr2
;
678 ctr2
->count
= res
->count
;
679 ctr2
->array
= talloc_zero_array(mem_ctx
,
680 struct drsuapi_DsGetDCInfo2
,
682 for (i
=0; i
< res
->count
; i
++) {
683 struct ldb_dn
*domain_dn
;
684 struct ldb_result
*res_domain
;
685 struct ldb_result
*res_account
;
686 struct ldb_dn
*ntds_dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[i
]->dn
);
687 struct ldb_result
*res_ntds
;
688 struct ldb_dn
*site_dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[i
]->dn
);
689 struct ldb_result
*res_site
;
690 struct ldb_dn
*ref_dn
691 = ldb_msg_find_attr_as_dn(b_state
->sam_ctx
,
692 mem_ctx
, res
->msgs
[i
],
695 if (!ntds_dn
|| !ldb_dn_add_child_fmt(ntds_dn
, "CN=NTDS Settings")) {
699 /* Format is cn=<NETBIOS name>,cn=Servers,cn=<site>,cn=sites.... */
700 if (!site_dn
|| !ldb_dn_remove_child_components(site_dn
, 2)) {
704 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_ntds
, ntds_dn
,
705 LDB_SCOPE_BASE
, attrs_ntds
, "objectClass=nTDSDSA");
706 if (ret
== LDB_SUCCESS
&& res_ntds
->count
== 1) {
708 = (ldb_msg_find_attr_as_uint(res_ntds
->msgs
[0], "options", 0) & DS_NTDSDSA_OPT_IS_GC
);
709 ctr2
->array
[i
].ntds_guid
710 = samdb_result_guid(res_ntds
->msgs
[0], "objectGUID");
711 ctr2
->array
[i
].ntds_dn
= ldb_dn_get_linearized(res_ntds
->msgs
[0]->dn
);
713 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
714 DEBUG(5, ("warning: searching for NTDS DN %s failed: %s\n",
715 ldb_dn_get_linearized(ntds_dn
), ldb_errstring(b_state
->sam_ctx
)));
718 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_site
, site_dn
,
719 LDB_SCOPE_BASE
, attrs_site
, "objectClass=site");
720 if (ret
== LDB_SUCCESS
&& res_site
->count
== 1) {
721 ctr2
->array
[i
].site_guid
722 = samdb_result_guid(res_site
->msgs
[0], "objectGUID");
723 ctr2
->array
[i
].site_dn
= ldb_dn_get_linearized(res_site
->msgs
[0]->dn
);
725 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
726 DEBUG(5, ("warning: searching for site DN %s failed: %s\n",
727 ldb_dn_get_linearized(site_dn
), ldb_errstring(b_state
->sam_ctx
)));
730 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_account
, ref_dn
,
731 LDB_SCOPE_BASE
, attrs_account_2
, "objectClass=computer");
732 if (ret
== LDB_SUCCESS
&& res_account
->count
== 1) {
734 ctr2
->array
[i
].dns_name
735 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "dNSHostName", NULL
);
736 ctr2
->array
[i
].netbios_name
737 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "cn", NULL
);
738 ctr2
->array
[i
].computer_dn
= ldb_dn_get_linearized(res_account
->msgs
[0]->dn
);
739 ctr2
->array
[i
].computer_guid
740 = samdb_result_guid(res_account
->msgs
[0], "objectGUID");
742 /* Determine if this is the PDC */
743 ret
= samdb_search_for_parent_domain(b_state
->sam_ctx
,
744 mem_ctx
, res_account
->msgs
[0]->dn
,
745 &domain_dn
, &errstr
);
747 if (ret
== LDB_SUCCESS
) {
748 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_domain
, domain_dn
,
749 LDB_SCOPE_BASE
, attrs_none
, "fSMORoleOwner=%s",
750 ldb_dn_get_linearized(ntds_dn
));
751 if (ret
== LDB_SUCCESS
&& res_domain
->count
== 1) {
752 ctr2
->array
[i
].is_pdc
= true;
754 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
755 DEBUG(5, ("warning: searching for domain DN %s failed: %s\n",
756 ldb_dn_get_linearized(domain_dn
), ldb_errstring(b_state
->sam_ctx
)));
760 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
761 DEBUG(5, ("warning: searching for computer account DN %s failed: %s\n",
762 ldb_dn_get_linearized(ref_dn
), ldb_errstring(b_state
->sam_ctx
)));
765 /* Look at server DN and extract site component */
766 ctr2
->array
[i
].site_name
= result_site_name(res
->msgs
[i
]->dn
);
767 ctr2
->array
[i
].server_dn
= ldb_dn_get_linearized(res
->msgs
[i
]->dn
);
768 ctr2
->array
[i
].server_guid
769 = samdb_result_guid(res
->msgs
[i
], "objectGUID");
771 ctr2
->array
[i
].is_enabled
= true;
780 drsuapi_DsGetDomainControllerInfo
782 static WERROR
dcesrv_drsuapi_DsGetDomainControllerInfo(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
783 struct drsuapi_DsGetDomainControllerInfo
*r
)
785 struct dcesrv_handle
*h
;
786 struct drsuapi_bind_state
*b_state
;
787 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
790 switch (r
->in
.level
) {
792 return dcesrv_drsuapi_DsGetDomainControllerInfo_1(b_state
, mem_ctx
, r
);
795 return WERR_UNKNOWN_LEVEL
;
803 static WERROR
dcesrv_drsuapi_DsExecuteKCC(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
804 struct drsuapi_DsExecuteKCC
*r
)
807 status
= drs_security_level_check(dce_call
, "DsExecuteKCC", SECURITY_DOMAIN_CONTROLLER
, NULL
);
809 if (!W_ERROR_IS_OK(status
)) {
813 dcesrv_irpc_forward_rpc_call(dce_call
, mem_ctx
, r
, NDR_DRSUAPI_DSEXECUTEKCC
,
814 &ndr_table_drsuapi
, "kccsrv", "DsExecuteKCC",
821 drsuapi_DsReplicaGetInfo
823 static WERROR
dcesrv_drsuapi_DsReplicaGetInfo(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
824 struct drsuapi_DsReplicaGetInfo
*r
)
826 enum security_user_level level
;
828 if (!lpcfg_parm_bool(dce_call
->conn
->dce_ctx
->lp_ctx
, NULL
,
829 "drs", "disable_sec_check", false)) {
830 level
= security_session_user_level(dce_call
->conn
->auth_state
.session_info
, NULL
);
831 if (level
< SECURITY_DOMAIN_CONTROLLER
) {
832 DEBUG(1,(__location__
": Administrator access required for DsReplicaGetInfo\n"));
833 security_token_debug(0, 2, dce_call
->conn
->auth_state
.session_info
->security_token
);
834 return WERR_DS_DRA_ACCESS_DENIED
;
838 dcesrv_irpc_forward_rpc_call(dce_call
, mem_ctx
, r
, NDR_DRSUAPI_DSREPLICAGETINFO
,
839 &ndr_table_drsuapi
, "kccsrv", "DsReplicaGetInfo",
847 DRSUAPI_ADD_SID_HISTORY
849 static WERROR
dcesrv_DRSUAPI_ADD_SID_HISTORY(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
850 struct DRSUAPI_ADD_SID_HISTORY
*r
)
852 DRSUAPI_UNSUPPORTED(DRSUAPI_ADD_SID_HISTORY
);
856 drsuapi_DsGetMemberships2
858 static WERROR
dcesrv_drsuapi_DsGetMemberships2(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
859 struct drsuapi_DsGetMemberships2
*r
)
861 DRSUAPI_UNSUPPORTED(drsuapi_DsGetMemberships2
);
865 DRSUAPI_REPLICA_VERIFY_OBJECTS
867 static WERROR
dcesrv_DRSUAPI_REPLICA_VERIFY_OBJECTS(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
868 struct DRSUAPI_REPLICA_VERIFY_OBJECTS
*r
)
870 DRSUAPI_UNSUPPORTED(DRSUAPI_REPLICA_VERIFY_OBJECTS
);
875 DRSUAPI_GET_OBJECT_EXISTENCE
877 static WERROR
dcesrv_DRSUAPI_GET_OBJECT_EXISTENCE(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
878 struct DRSUAPI_GET_OBJECT_EXISTENCE
*r
)
880 DRSUAPI_UNSUPPORTED(DRSUAPI_GET_OBJECT_EXISTENCE
);
885 drsuapi_QuerySitesByCost
887 static WERROR
dcesrv_drsuapi_QuerySitesByCost(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
888 struct drsuapi_QuerySitesByCost
*r
)
890 DRSUAPI_UNSUPPORTED(drsuapi_QuerySitesByCost
);
894 /* include the generated boilerplate */
895 #include "librpc/gen_ndr/ndr_drsuapi_s.c"