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 "rpc_server/drsuapi/dcesrv_drsuapi.h"
29 #include "libcli/security/security.h"
30 #include "auth/auth.h"
32 #define DRSUAPI_UNSUPPORTED(fname) do { \
33 DEBUG(1,(__location__ ": Unsupported DRS call %s\n", #fname)); \
34 if (DEBUGLVL(2)) NDR_PRINT_IN_DEBUG(fname, r); \
35 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR); \
41 static WERROR
dcesrv_drsuapi_DsBind(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
42 struct drsuapi_DsBind
*r
)
44 struct drsuapi_bind_state
*b_state
;
45 struct dcesrv_handle
*handle
;
46 struct drsuapi_DsBindInfoCtr
*bind_info
;
47 struct GUID site_guid
;
48 struct ldb_result
*site_res
;
49 struct ldb_dn
*server_site_dn
;
50 static const char *site_attrs
[] = { "objectGUID", NULL
};
51 struct ldb_result
*ntds_res
;
52 struct ldb_dn
*ntds_dn
;
53 static const char *ntds_attrs
[] = { "ms-DS-ReplicationEpoch", NULL
};
57 struct auth_session_info
*auth_info
;
60 r
->out
.bind_info
= NULL
;
61 ZERO_STRUCTP(r
->out
.bind_handle
);
63 b_state
= talloc_zero(mem_ctx
, struct drsuapi_bind_state
);
64 W_ERROR_HAVE_NO_MEMORY(b_state
);
66 /* if this is a DC connecting, give them system level access */
67 werr
= drs_security_level_check(dce_call
, NULL
);
68 if (W_ERROR_IS_OK(werr
)) {
69 DEBUG(3,(__location__
": doing DsBind with system_session\n"));
70 auth_info
= system_session(dce_call
->conn
->dce_ctx
->lp_ctx
);
72 auth_info
= dce_call
->conn
->auth_state
.session_info
;
76 * connect to the samdb
78 b_state
->sam_ctx
= samdb_connect(b_state
, dce_call
->event_ctx
,
79 dce_call
->conn
->dce_ctx
->lp_ctx
, auth_info
);
80 if (!b_state
->sam_ctx
) {
85 * find out the guid of our own site
87 server_site_dn
= samdb_server_site_dn(b_state
->sam_ctx
, mem_ctx
);
88 W_ERROR_HAVE_NO_MEMORY(server_site_dn
);
90 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &site_res
,
91 server_site_dn
, LDB_SCOPE_BASE
, site_attrs
,
93 if (ret
!= LDB_SUCCESS
) {
94 return WERR_DS_DRA_INTERNAL_ERROR
;
96 if (site_res
->count
!= 1) {
97 return WERR_DS_DRA_INTERNAL_ERROR
;
99 site_guid
= samdb_result_guid(site_res
->msgs
[0], "objectGUID");
102 * lookup the local servers Replication Epoch
104 ntds_dn
= samdb_ntds_settings_dn(b_state
->sam_ctx
);
105 W_ERROR_HAVE_NO_MEMORY(ntds_dn
);
107 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &ntds_res
,
108 ntds_dn
, LDB_SCOPE_BASE
, ntds_attrs
,
110 if (ret
!= LDB_SUCCESS
) {
111 return WERR_DS_DRA_INTERNAL_ERROR
;
113 if (ntds_res
->count
!= 1) {
114 return WERR_DS_DRA_INTERNAL_ERROR
;
116 repl_epoch
= samdb_result_uint(ntds_res
->msgs
[0], "ms-DS-ReplicationEpoch", 0);
119 * The "process identifier" of the client.
120 * According to the WSPP docs, sectin 5.35, this is
121 * for informational and debugging purposes only.
122 * The assignment is implementation specific.
127 * store the clients bind_guid
129 if (r
->in
.bind_guid
) {
130 b_state
->remote_bind_guid
= *r
->in
.bind_guid
;
134 * store the clients bind_info
136 if (r
->in
.bind_info
) {
137 switch (r
->in
.bind_info
->length
) {
139 struct drsuapi_DsBindInfo24
*info24
;
140 info24
= &r
->in
.bind_info
->info
.info24
;
141 b_state
->remote_info28
.supported_extensions
= info24
->supported_extensions
;
142 b_state
->remote_info28
.site_guid
= info24
->site_guid
;
143 b_state
->remote_info28
.pid
= info24
->pid
;
144 b_state
->remote_info28
.repl_epoch
= 0;
148 b_state
->remote_info28
= r
->in
.bind_info
->info
.info28
;
154 * fill in our local bind info 28
156 b_state
->local_info28
.supported_extensions
= 0;
157 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_BASE
;
158 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION
;
159 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI
;
160 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2
;
161 #if 0 /* we don't support MSZIP compression (only decompression) */
162 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS
;
164 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1
;
165 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION
;
166 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE
;
167 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2
;
168 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION
;
169 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2
;
170 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD
;
171 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND
;
172 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO
;
173 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION
;
174 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01
;
175 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP
;
176 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY
;
177 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3
;
178 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_00100000
;
179 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2
;
180 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6
;
181 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS
;
182 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8
;
183 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5
;
184 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6
;
185 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3
;
186 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7
;
187 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT
;
188 #if 0 /* we don't support XPRESS compression yet */
189 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS
;
191 b_state
->local_info28
.site_guid
= site_guid
;
192 b_state
->local_info28
.pid
= pid
;
193 b_state
->local_info28
.repl_epoch
= repl_epoch
;
196 * allocate the return bind_info
198 bind_info
= talloc(mem_ctx
, struct drsuapi_DsBindInfoCtr
);
199 W_ERROR_HAVE_NO_MEMORY(bind_info
);
201 bind_info
->length
= 28;
202 bind_info
->info
.info28
= b_state
->local_info28
;
205 * allocate a bind handle
207 handle
= dcesrv_handle_new(dce_call
->context
, DRSUAPI_BIND_HANDLE
);
208 W_ERROR_HAVE_NO_MEMORY(handle
);
209 handle
->data
= talloc_steal(handle
, b_state
);
214 r
->out
.bind_info
= bind_info
;
215 *r
->out
.bind_handle
= handle
->wire_handle
;
224 static WERROR
dcesrv_drsuapi_DsUnbind(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
225 struct drsuapi_DsUnbind
*r
)
227 struct dcesrv_handle
*h
;
229 *r
->out
.bind_handle
= *r
->in
.bind_handle
;
231 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
235 ZERO_STRUCTP(r
->out
.bind_handle
);
242 drsuapi_DsReplicaSync
244 static WERROR
dcesrv_drsuapi_DsReplicaSync(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
245 struct drsuapi_DsReplicaSync
*r
)
249 status
= drs_security_level_check(dce_call
, "DsReplicaSync");
250 if (!W_ERROR_IS_OK(status
)) {
254 dcesrv_irpc_forward_rpc_call(dce_call
, mem_ctx
, r
, NDR_DRSUAPI_DSREPLICASYNC
,
256 "dreplsrv", "DsReplicaSync");
265 static WERROR
dcesrv_drsuapi_DsReplicaAdd(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
266 struct drsuapi_DsReplicaAdd
*r
)
268 DRSUAPI_UNSUPPORTED(drsuapi_DsReplicaAdd
);
275 static WERROR
dcesrv_drsuapi_DsReplicaDel(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
276 struct drsuapi_DsReplicaDel
*r
)
278 DRSUAPI_UNSUPPORTED(drsuapi_DsReplicaDel
);
283 drsuapi_DsReplicaModify
285 static WERROR
dcesrv_drsuapi_DsReplicaMod(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
286 struct drsuapi_DsReplicaMod
*r
)
288 DRSUAPI_UNSUPPORTED(drsuapi_DsReplicaMod
);
295 static WERROR
dcesrv_DRSUAPI_VERIFY_NAMES(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
296 struct DRSUAPI_VERIFY_NAMES
*r
)
298 DRSUAPI_UNSUPPORTED(DRSUAPI_VERIFY_NAMES
);
303 drsuapi_DsGetMemberships
305 static WERROR
dcesrv_drsuapi_DsGetMemberships(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
306 struct drsuapi_DsGetMemberships
*r
)
308 DRSUAPI_UNSUPPORTED(drsuapi_DsGetMemberships
);
313 DRSUAPI_INTER_DOMAIN_MOVE
315 static WERROR
dcesrv_DRSUAPI_INTER_DOMAIN_MOVE(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
316 struct DRSUAPI_INTER_DOMAIN_MOVE
*r
)
318 DRSUAPI_UNSUPPORTED(DRSUAPI_INTER_DOMAIN_MOVE
);
323 drsuapi_DsGetNT4ChangeLog
325 static WERROR
dcesrv_drsuapi_DsGetNT4ChangeLog(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
326 struct drsuapi_DsGetNT4ChangeLog
*r
)
328 DRSUAPI_UNSUPPORTED(drsuapi_DsGetNT4ChangeLog
);
335 static WERROR
dcesrv_drsuapi_DsCrackNames(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
336 struct drsuapi_DsCrackNames
*r
)
339 struct drsuapi_bind_state
*b_state
;
340 struct dcesrv_handle
*h
;
342 *r
->out
.level_out
= r
->in
.level
;
344 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
347 r
->out
.ctr
= talloc_zero(mem_ctx
, union drsuapi_DsNameCtr
);
348 W_ERROR_HAVE_NO_MEMORY(r
->out
.ctr
);
350 switch (r
->in
.level
) {
352 struct drsuapi_DsNameCtr1
*ctr1
;
353 struct drsuapi_DsNameInfo1
*names
;
357 ctr1
= talloc(mem_ctx
, struct drsuapi_DsNameCtr1
);
358 W_ERROR_HAVE_NO_MEMORY(ctr1
);
360 count
= r
->in
.req
->req1
.count
;
361 names
= talloc_array(mem_ctx
, struct drsuapi_DsNameInfo1
, count
);
362 W_ERROR_HAVE_NO_MEMORY(names
);
364 for (i
=0; i
< count
; i
++) {
365 status
= DsCrackNameOneName(b_state
->sam_ctx
, mem_ctx
,
366 r
->in
.req
->req1
.format_flags
,
367 r
->in
.req
->req1
.format_offered
,
368 r
->in
.req
->req1
.format_desired
,
369 r
->in
.req
->req1
.names
[i
].str
,
371 if (!W_ERROR_IS_OK(status
)) {
378 r
->out
.ctr
->ctr1
= ctr1
;
384 return WERR_UNKNOWN_LEVEL
;
389 drsuapi_DsRemoveDSServer
391 static WERROR
dcesrv_drsuapi_DsRemoveDSServer(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
392 struct drsuapi_DsRemoveDSServer
*r
)
394 struct drsuapi_bind_state
*b_state
;
395 struct dcesrv_handle
*h
;
396 struct ldb_dn
*ntds_dn
;
401 ZERO_STRUCT(r
->out
.res
);
402 *r
->out
.level_out
= 1;
404 status
= drs_security_level_check(dce_call
, "DsRemoveDSServer");
405 if (!W_ERROR_IS_OK(status
)) {
409 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
412 switch (r
->in
.level
) {
414 ntds_dn
= ldb_dn_new(mem_ctx
, b_state
->sam_ctx
, r
->in
.req
->req1
.server_dn
);
415 W_ERROR_HAVE_NO_MEMORY(ntds_dn
);
417 ok
= ldb_dn_validate(ntds_dn
);
422 /* TODO: it's likely that we need more checks here */
424 ok
= ldb_dn_add_child_fmt(ntds_dn
, "CN=NTDS Settings");
429 if (r
->in
.req
->req1
.commit
) {
430 ret
= ldb_delete(b_state
->sam_ctx
, ntds_dn
);
431 if (ret
!= LDB_SUCCESS
) {
446 DRSUAPI_REMOVE_DS_DOMAIN
448 static WERROR
dcesrv_DRSUAPI_REMOVE_DS_DOMAIN(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
449 struct DRSUAPI_REMOVE_DS_DOMAIN
*r
)
451 DRSUAPI_UNSUPPORTED(DRSUAPI_REMOVE_DS_DOMAIN
);
454 /* Obtain the site name from a server DN */
455 static const char *result_site_name(struct ldb_dn
*site_dn
)
457 /* Format is cn=<NETBIOS name>,cn=Servers,cn=<site>,cn=sites.... */
458 const struct ldb_val
*val
= ldb_dn_get_component_val(site_dn
, 2);
459 const char *name
= ldb_dn_get_component_name(site_dn
, 2);
461 if (!name
|| (ldb_attr_cmp(name
, "cn") != 0)) {
462 /* Ensure this matches the format. This gives us a
463 * bit more confidence that a 'cn' value will be a
468 return (char *)val
->data
;
474 drsuapi_DsGetDomainControllerInfo
476 static WERROR
dcesrv_drsuapi_DsGetDomainControllerInfo_1(struct drsuapi_bind_state
*b_state
,
478 struct drsuapi_DsGetDomainControllerInfo
*r
)
480 struct ldb_dn
*sites_dn
;
481 struct ldb_result
*res
;
483 const char *attrs_account_1
[] = { "cn", "dnsHostName", NULL
};
484 const char *attrs_account_2
[] = { "cn", "dnsHostName", "objectGUID", NULL
};
486 const char *attrs_none
[] = { NULL
};
488 const char *attrs_site
[] = { "objectGUID", NULL
};
490 const char *attrs_ntds
[] = { "options", "objectGUID", NULL
};
492 const char *attrs_1
[] = { "serverReference", "cn", "dnsHostName", NULL
};
493 const char *attrs_2
[] = { "serverReference", "cn", "dnsHostName", "objectGUID", NULL
};
496 struct drsuapi_DsGetDCInfoCtr1
*ctr1
;
497 struct drsuapi_DsGetDCInfoCtr2
*ctr2
;
501 *r
->out
.level_out
= r
->in
.req
->req1
.level
;
502 r
->out
.ctr
= talloc(mem_ctx
, union drsuapi_DsGetDCInfoCtr
);
503 W_ERROR_HAVE_NO_MEMORY(r
->out
.ctr
);
505 sites_dn
= samdb_sites_dn(b_state
->sam_ctx
, mem_ctx
);
507 return WERR_DS_OBJ_NOT_FOUND
;
510 switch (*r
->out
.level_out
) {
512 /* this level is not like the others */
513 return WERR_UNKNOWN_LEVEL
;
521 return WERR_UNKNOWN_LEVEL
;
524 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res
, sites_dn
, LDB_SCOPE_SUBTREE
, attrs
,
525 "objectClass=server");
528 DEBUG(1, ("searching for servers in sites DN %s failed: %s\n",
529 ldb_dn_get_linearized(sites_dn
), ldb_errstring(b_state
->sam_ctx
)));
530 return WERR_GENERAL_FAILURE
;
533 switch (*r
->out
.level_out
) {
535 ctr1
= &r
->out
.ctr
->ctr1
;
536 ctr1
->count
= res
->count
;
537 ctr1
->array
= talloc_zero_array(mem_ctx
,
538 struct drsuapi_DsGetDCInfo1
,
540 for (i
=0; i
< res
->count
; i
++) {
541 struct ldb_dn
*domain_dn
;
542 struct ldb_result
*res_domain
;
543 struct ldb_result
*res_account
;
544 struct ldb_dn
*ntds_dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[i
]->dn
);
546 struct ldb_dn
*ref_dn
547 = ldb_msg_find_attr_as_dn(b_state
->sam_ctx
,
548 mem_ctx
, res
->msgs
[i
],
551 if (!ntds_dn
|| !ldb_dn_add_child_fmt(ntds_dn
, "CN=NTDS Settings")) {
555 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_account
, ref_dn
,
556 LDB_SCOPE_BASE
, attrs_account_1
, "objectClass=computer");
557 if (ret
== LDB_SUCCESS
&& res_account
->count
== 1) {
559 ctr1
->array
[i
].dns_name
560 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "dNSHostName", NULL
);
561 ctr1
->array
[i
].netbios_name
562 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "cn", NULL
);
563 ctr1
->array
[i
].computer_dn
564 = ldb_dn_get_linearized(res_account
->msgs
[0]->dn
);
566 /* Determine if this is the PDC */
567 ret
= samdb_search_for_parent_domain(b_state
->sam_ctx
,
568 mem_ctx
, res_account
->msgs
[0]->dn
,
569 &domain_dn
, &errstr
);
571 if (ret
== LDB_SUCCESS
) {
572 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_domain
, domain_dn
,
573 LDB_SCOPE_BASE
, attrs_none
, "fSMORoleOwner=%s",
574 ldb_dn_get_linearized(ntds_dn
));
576 return WERR_GENERAL_FAILURE
;
578 if (res_domain
->count
== 1) {
579 ctr1
->array
[i
].is_pdc
= true;
583 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
584 DEBUG(5, ("warning: searching for computer DN %s failed: %s\n",
585 ldb_dn_get_linearized(ref_dn
), ldb_errstring(b_state
->sam_ctx
)));
588 /* Look at server DN and extract site component */
589 ctr1
->array
[i
].site_name
= result_site_name(res
->msgs
[i
]->dn
);
590 ctr1
->array
[i
].server_dn
= ldb_dn_get_linearized(res
->msgs
[i
]->dn
);
593 ctr1
->array
[i
].is_enabled
= true;
598 ctr2
= &r
->out
.ctr
->ctr2
;
599 ctr2
->count
= res
->count
;
600 ctr2
->array
= talloc_zero_array(mem_ctx
,
601 struct drsuapi_DsGetDCInfo2
,
603 for (i
=0; i
< res
->count
; i
++) {
604 struct ldb_dn
*domain_dn
;
605 struct ldb_result
*res_domain
;
606 struct ldb_result
*res_account
;
607 struct ldb_dn
*ntds_dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[i
]->dn
);
608 struct ldb_result
*res_ntds
;
609 struct ldb_dn
*site_dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[i
]->dn
);
610 struct ldb_result
*res_site
;
611 struct ldb_dn
*ref_dn
612 = ldb_msg_find_attr_as_dn(b_state
->sam_ctx
,
613 mem_ctx
, res
->msgs
[i
],
616 if (!ntds_dn
|| !ldb_dn_add_child_fmt(ntds_dn
, "CN=NTDS Settings")) {
620 /* Format is cn=<NETBIOS name>,cn=Servers,cn=<site>,cn=sites.... */
621 if (!site_dn
|| !ldb_dn_remove_child_components(site_dn
, 2)) {
625 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_ntds
, ntds_dn
,
626 LDB_SCOPE_BASE
, attrs_ntds
, "objectClass=nTDSDSA");
627 if (ret
== LDB_SUCCESS
&& res_ntds
->count
== 1) {
629 = (ldb_msg_find_attr_as_int(res_ntds
->msgs
[0], "options", 0) == 1);
630 ctr2
->array
[i
].ntds_guid
631 = samdb_result_guid(res_ntds
->msgs
[0], "objectGUID");
632 ctr2
->array
[i
].ntds_dn
= ldb_dn_get_linearized(res_ntds
->msgs
[0]->dn
);
634 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
635 DEBUG(5, ("warning: searching for NTDS DN %s failed: %s\n",
636 ldb_dn_get_linearized(ntds_dn
), ldb_errstring(b_state
->sam_ctx
)));
639 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_site
, site_dn
,
640 LDB_SCOPE_BASE
, attrs_site
, "objectClass=site");
641 if (ret
== LDB_SUCCESS
&& res_site
->count
== 1) {
642 ctr2
->array
[i
].site_guid
643 = samdb_result_guid(res_site
->msgs
[0], "objectGUID");
644 ctr2
->array
[i
].site_dn
= ldb_dn_get_linearized(res_site
->msgs
[0]->dn
);
646 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
647 DEBUG(5, ("warning: searching for site DN %s failed: %s\n",
648 ldb_dn_get_linearized(site_dn
), ldb_errstring(b_state
->sam_ctx
)));
651 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_account
, ref_dn
,
652 LDB_SCOPE_BASE
, attrs_account_2
, "objectClass=computer");
653 if (ret
== LDB_SUCCESS
&& res_account
->count
== 1) {
655 ctr2
->array
[i
].dns_name
656 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "dNSHostName", NULL
);
657 ctr2
->array
[i
].netbios_name
658 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "cn", NULL
);
659 ctr2
->array
[i
].computer_dn
= ldb_dn_get_linearized(res_account
->msgs
[0]->dn
);
660 ctr2
->array
[i
].computer_guid
661 = samdb_result_guid(res_account
->msgs
[0], "objectGUID");
663 /* Determine if this is the PDC */
664 ret
= samdb_search_for_parent_domain(b_state
->sam_ctx
,
665 mem_ctx
, res_account
->msgs
[0]->dn
,
666 &domain_dn
, &errstr
);
668 if (ret
== LDB_SUCCESS
) {
669 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_domain
, domain_dn
,
670 LDB_SCOPE_BASE
, attrs_none
, "fSMORoleOwner=%s",
671 ldb_dn_get_linearized(ntds_dn
));
672 if (ret
== LDB_SUCCESS
&& res_domain
->count
== 1) {
673 ctr2
->array
[i
].is_pdc
= true;
675 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
676 DEBUG(5, ("warning: searching for domain DN %s failed: %s\n",
677 ldb_dn_get_linearized(domain_dn
), ldb_errstring(b_state
->sam_ctx
)));
681 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
682 DEBUG(5, ("warning: searching for computer account DN %s failed: %s\n",
683 ldb_dn_get_linearized(ref_dn
), ldb_errstring(b_state
->sam_ctx
)));
686 /* Look at server DN and extract site component */
687 ctr2
->array
[i
].site_name
= result_site_name(res
->msgs
[i
]->dn
);
688 ctr2
->array
[i
].server_dn
= ldb_dn_get_linearized(res
->msgs
[i
]->dn
);
689 ctr2
->array
[i
].server_guid
690 = samdb_result_guid(res
->msgs
[i
], "objectGUID");
692 ctr2
->array
[i
].is_enabled
= true;
701 drsuapi_DsGetDomainControllerInfo
703 static WERROR
dcesrv_drsuapi_DsGetDomainControllerInfo(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
704 struct drsuapi_DsGetDomainControllerInfo
*r
)
706 struct dcesrv_handle
*h
;
707 struct drsuapi_bind_state
*b_state
;
708 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
711 switch (r
->in
.level
) {
713 return dcesrv_drsuapi_DsGetDomainControllerInfo_1(b_state
, mem_ctx
, r
);
716 return WERR_UNKNOWN_LEVEL
;
724 static WERROR
dcesrv_drsuapi_DsExecuteKCC(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
725 struct drsuapi_DsExecuteKCC
*r
)
728 status
= drs_security_level_check(dce_call
, "DsExecuteKCC");
730 if (!W_ERROR_IS_OK(status
)) {
734 dcesrv_irpc_forward_rpc_call(dce_call
, mem_ctx
, r
, NDR_DRSUAPI_DSEXECUTEKCC
,
735 &ndr_table_drsuapi
, "kccsrv", "DsExecuteKCC");
741 drsuapi_DsReplicaGetInfo
743 static WERROR
dcesrv_drsuapi_DsReplicaGetInfo(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
744 struct drsuapi_DsReplicaGetInfo
*r
)
746 DRSUAPI_UNSUPPORTED(drsuapi_DsReplicaGetInfo
);
751 DRSUAPI_ADD_SID_HISTORY
753 static WERROR
dcesrv_DRSUAPI_ADD_SID_HISTORY(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
754 struct DRSUAPI_ADD_SID_HISTORY
*r
)
756 DRSUAPI_UNSUPPORTED(DRSUAPI_ADD_SID_HISTORY
);
760 drsuapi_DsGetMemberships2
762 static WERROR
dcesrv_drsuapi_DsGetMemberships2(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
763 struct drsuapi_DsGetMemberships2
*r
)
765 DRSUAPI_UNSUPPORTED(drsuapi_DsGetMemberships2
);
769 DRSUAPI_REPLICA_VERIFY_OBJECTS
771 static WERROR
dcesrv_DRSUAPI_REPLICA_VERIFY_OBJECTS(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
772 struct DRSUAPI_REPLICA_VERIFY_OBJECTS
*r
)
774 DRSUAPI_UNSUPPORTED(DRSUAPI_REPLICA_VERIFY_OBJECTS
);
779 DRSUAPI_GET_OBJECT_EXISTENCE
781 static WERROR
dcesrv_DRSUAPI_GET_OBJECT_EXISTENCE(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
782 struct DRSUAPI_GET_OBJECT_EXISTENCE
*r
)
784 DRSUAPI_UNSUPPORTED(DRSUAPI_GET_OBJECT_EXISTENCE
);
789 drsuapi_QuerySitesByCost
791 static WERROR
dcesrv_drsuapi_QuerySitesByCost(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
792 struct drsuapi_QuerySitesByCost
*r
)
794 DRSUAPI_UNSUPPORTED(drsuapi_QuerySitesByCost
);
798 /* include the generated boilerplate */
799 #include "librpc/gen_ndr/ndr_drsuapi_s.c"