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"
31 #include "param/param.h"
33 #define DRSUAPI_UNSUPPORTED(fname) do { \
34 DEBUG(1,(__location__ ": Unsupported DRS call %s\n", #fname)); \
35 if (DEBUGLVL(2)) NDR_PRINT_IN_DEBUG(fname, r); \
36 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR); \
42 static WERROR
dcesrv_drsuapi_DsBind(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
43 struct drsuapi_DsBind
*r
)
45 struct drsuapi_bind_state
*b_state
;
46 struct dcesrv_handle
*handle
;
47 struct drsuapi_DsBindInfoCtr
*bind_info
;
48 struct GUID site_guid
;
49 struct ldb_result
*site_res
;
50 struct ldb_dn
*server_site_dn
;
51 static const char *site_attrs
[] = { "objectGUID", NULL
};
52 struct ldb_result
*ntds_res
;
53 struct ldb_dn
*ntds_dn
;
54 static const char *ntds_attrs
[] = { "ms-DS-ReplicationEpoch", NULL
};
58 struct auth_session_info
*auth_info
;
61 r
->out
.bind_info
= NULL
;
62 ZERO_STRUCTP(r
->out
.bind_handle
);
64 b_state
= talloc_zero(mem_ctx
, struct drsuapi_bind_state
);
65 W_ERROR_HAVE_NO_MEMORY(b_state
);
67 /* if this is a DC connecting, give them system level access */
68 werr
= drs_security_level_check(dce_call
, NULL
);
69 if (W_ERROR_IS_OK(werr
)) {
70 DEBUG(3,(__location__
": doing DsBind with system_session\n"));
71 auth_info
= system_session(dce_call
->conn
->dce_ctx
->lp_ctx
);
73 auth_info
= dce_call
->conn
->auth_state
.session_info
;
77 * connect to the samdb
79 b_state
->sam_ctx
= samdb_connect(b_state
, dce_call
->event_ctx
,
80 dce_call
->conn
->dce_ctx
->lp_ctx
, auth_info
);
81 if (!b_state
->sam_ctx
) {
86 * find out the guid of our own site
88 server_site_dn
= samdb_server_site_dn(b_state
->sam_ctx
, mem_ctx
);
89 W_ERROR_HAVE_NO_MEMORY(server_site_dn
);
91 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &site_res
,
92 server_site_dn
, LDB_SCOPE_BASE
, site_attrs
,
94 if (ret
!= LDB_SUCCESS
) {
95 return WERR_DS_DRA_INTERNAL_ERROR
;
97 if (site_res
->count
!= 1) {
98 return WERR_DS_DRA_INTERNAL_ERROR
;
100 site_guid
= samdb_result_guid(site_res
->msgs
[0], "objectGUID");
103 * lookup the local servers Replication Epoch
105 ntds_dn
= samdb_ntds_settings_dn(b_state
->sam_ctx
);
106 W_ERROR_HAVE_NO_MEMORY(ntds_dn
);
108 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &ntds_res
,
109 ntds_dn
, LDB_SCOPE_BASE
, ntds_attrs
,
111 if (ret
!= LDB_SUCCESS
) {
112 return WERR_DS_DRA_INTERNAL_ERROR
;
114 if (ntds_res
->count
!= 1) {
115 return WERR_DS_DRA_INTERNAL_ERROR
;
117 repl_epoch
= samdb_result_uint(ntds_res
->msgs
[0], "ms-DS-ReplicationEpoch", 0);
120 * The "process identifier" of the client.
121 * According to the WSPP docs, sectin 5.35, this is
122 * for informational and debugging purposes only.
123 * The assignment is implementation specific.
128 * store the clients bind_guid
130 if (r
->in
.bind_guid
) {
131 b_state
->remote_bind_guid
= *r
->in
.bind_guid
;
135 * store the clients bind_info
137 if (r
->in
.bind_info
) {
138 switch (r
->in
.bind_info
->length
) {
140 struct drsuapi_DsBindInfo24
*info24
;
141 info24
= &r
->in
.bind_info
->info
.info24
;
142 b_state
->remote_info28
.supported_extensions
= info24
->supported_extensions
;
143 b_state
->remote_info28
.site_guid
= info24
->site_guid
;
144 b_state
->remote_info28
.pid
= info24
->pid
;
145 b_state
->remote_info28
.repl_epoch
= 0;
149 b_state
->remote_info28
= r
->in
.bind_info
->info
.info28
;
155 * fill in our local bind info 28
157 b_state
->local_info28
.supported_extensions
= 0;
158 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_BASE
;
159 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION
;
160 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI
;
161 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2
;
162 #if 0 /* we don't support MSZIP compression (only decompression) */
163 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS
;
165 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1
;
166 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION
;
167 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE
;
168 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2
;
169 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION
;
170 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2
;
171 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD
;
172 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND
;
173 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO
;
174 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION
;
175 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01
;
176 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP
;
177 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY
;
178 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3
;
179 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V5
;
180 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2
;
181 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6
;
182 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS
;
183 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8
;
184 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5
;
185 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6
;
186 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3
;
187 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7
;
188 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT
;
189 #if 0 /* we don't support XPRESS compression yet */
190 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS
;
192 b_state
->local_info28
.site_guid
= site_guid
;
193 b_state
->local_info28
.pid
= pid
;
194 b_state
->local_info28
.repl_epoch
= repl_epoch
;
197 * allocate the return bind_info
199 bind_info
= talloc(mem_ctx
, struct drsuapi_DsBindInfoCtr
);
200 W_ERROR_HAVE_NO_MEMORY(bind_info
);
202 bind_info
->length
= 28;
203 bind_info
->info
.info28
= b_state
->local_info28
;
206 * allocate a bind handle
208 handle
= dcesrv_handle_new(dce_call
->context
, DRSUAPI_BIND_HANDLE
);
209 W_ERROR_HAVE_NO_MEMORY(handle
);
210 handle
->data
= talloc_steal(handle
, b_state
);
215 r
->out
.bind_info
= bind_info
;
216 *r
->out
.bind_handle
= handle
->wire_handle
;
225 static WERROR
dcesrv_drsuapi_DsUnbind(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
226 struct drsuapi_DsUnbind
*r
)
228 struct dcesrv_handle
*h
;
230 *r
->out
.bind_handle
= *r
->in
.bind_handle
;
232 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
236 ZERO_STRUCTP(r
->out
.bind_handle
);
243 drsuapi_DsReplicaSync
245 static WERROR
dcesrv_drsuapi_DsReplicaSync(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
246 struct drsuapi_DsReplicaSync
*r
)
250 status
= drs_security_level_check(dce_call
, "DsReplicaSync");
251 if (!W_ERROR_IS_OK(status
)) {
255 dcesrv_irpc_forward_rpc_call(dce_call
, mem_ctx
, r
, NDR_DRSUAPI_DSREPLICASYNC
,
257 "dreplsrv", "DsReplicaSync");
266 static WERROR
dcesrv_drsuapi_DsReplicaAdd(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
267 struct drsuapi_DsReplicaAdd
*r
)
269 DRSUAPI_UNSUPPORTED(drsuapi_DsReplicaAdd
);
276 static WERROR
dcesrv_drsuapi_DsReplicaDel(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
277 struct drsuapi_DsReplicaDel
*r
)
279 DRSUAPI_UNSUPPORTED(drsuapi_DsReplicaDel
);
284 drsuapi_DsReplicaModify
286 static WERROR
dcesrv_drsuapi_DsReplicaMod(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
287 struct drsuapi_DsReplicaMod
*r
)
289 DRSUAPI_UNSUPPORTED(drsuapi_DsReplicaMod
);
296 static WERROR
dcesrv_DRSUAPI_VERIFY_NAMES(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
297 struct DRSUAPI_VERIFY_NAMES
*r
)
299 DRSUAPI_UNSUPPORTED(DRSUAPI_VERIFY_NAMES
);
304 drsuapi_DsGetMemberships
306 static WERROR
dcesrv_drsuapi_DsGetMemberships(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
307 struct drsuapi_DsGetMemberships
*r
)
309 DRSUAPI_UNSUPPORTED(drsuapi_DsGetMemberships
);
314 DRSUAPI_INTER_DOMAIN_MOVE
316 static WERROR
dcesrv_DRSUAPI_INTER_DOMAIN_MOVE(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
317 struct DRSUAPI_INTER_DOMAIN_MOVE
*r
)
319 DRSUAPI_UNSUPPORTED(DRSUAPI_INTER_DOMAIN_MOVE
);
324 drsuapi_DsGetNT4ChangeLog
326 static WERROR
dcesrv_drsuapi_DsGetNT4ChangeLog(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
327 struct drsuapi_DsGetNT4ChangeLog
*r
)
329 DRSUAPI_UNSUPPORTED(drsuapi_DsGetNT4ChangeLog
);
336 static WERROR
dcesrv_drsuapi_DsCrackNames(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
337 struct drsuapi_DsCrackNames
*r
)
340 struct drsuapi_bind_state
*b_state
;
341 struct dcesrv_handle
*h
;
343 *r
->out
.level_out
= r
->in
.level
;
345 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
348 r
->out
.ctr
= talloc_zero(mem_ctx
, union drsuapi_DsNameCtr
);
349 W_ERROR_HAVE_NO_MEMORY(r
->out
.ctr
);
351 switch (r
->in
.level
) {
353 struct drsuapi_DsNameCtr1
*ctr1
;
354 struct drsuapi_DsNameInfo1
*names
;
358 ctr1
= talloc(mem_ctx
, struct drsuapi_DsNameCtr1
);
359 W_ERROR_HAVE_NO_MEMORY(ctr1
);
361 count
= r
->in
.req
->req1
.count
;
362 names
= talloc_array(mem_ctx
, struct drsuapi_DsNameInfo1
, count
);
363 W_ERROR_HAVE_NO_MEMORY(names
);
365 for (i
=0; i
< count
; i
++) {
366 status
= DsCrackNameOneName(b_state
->sam_ctx
, mem_ctx
,
367 r
->in
.req
->req1
.format_flags
,
368 r
->in
.req
->req1
.format_offered
,
369 r
->in
.req
->req1
.format_desired
,
370 r
->in
.req
->req1
.names
[i
].str
,
372 if (!W_ERROR_IS_OK(status
)) {
379 r
->out
.ctr
->ctr1
= ctr1
;
385 return WERR_UNKNOWN_LEVEL
;
390 drsuapi_DsRemoveDSServer
392 static WERROR
dcesrv_drsuapi_DsRemoveDSServer(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
393 struct drsuapi_DsRemoveDSServer
*r
)
395 struct drsuapi_bind_state
*b_state
;
396 struct dcesrv_handle
*h
;
397 struct ldb_dn
*ntds_dn
;
402 ZERO_STRUCT(r
->out
.res
);
403 *r
->out
.level_out
= 1;
405 status
= drs_security_level_check(dce_call
, "DsRemoveDSServer");
406 if (!W_ERROR_IS_OK(status
)) {
410 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
413 switch (r
->in
.level
) {
415 ntds_dn
= ldb_dn_new(mem_ctx
, b_state
->sam_ctx
, r
->in
.req
->req1
.server_dn
);
416 W_ERROR_HAVE_NO_MEMORY(ntds_dn
);
418 ok
= ldb_dn_validate(ntds_dn
);
423 /* TODO: it's likely that we need more checks here */
425 ok
= ldb_dn_add_child_fmt(ntds_dn
, "CN=NTDS Settings");
430 if (r
->in
.req
->req1
.commit
) {
431 ret
= ldb_delete(b_state
->sam_ctx
, ntds_dn
);
432 if (ret
!= LDB_SUCCESS
) {
447 DRSUAPI_REMOVE_DS_DOMAIN
449 static WERROR
dcesrv_DRSUAPI_REMOVE_DS_DOMAIN(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
450 struct DRSUAPI_REMOVE_DS_DOMAIN
*r
)
452 DRSUAPI_UNSUPPORTED(DRSUAPI_REMOVE_DS_DOMAIN
);
455 /* Obtain the site name from a server DN */
456 static const char *result_site_name(struct ldb_dn
*site_dn
)
458 /* Format is cn=<NETBIOS name>,cn=Servers,cn=<site>,cn=sites.... */
459 const struct ldb_val
*val
= ldb_dn_get_component_val(site_dn
, 2);
460 const char *name
= ldb_dn_get_component_name(site_dn
, 2);
462 if (!name
|| (ldb_attr_cmp(name
, "cn") != 0)) {
463 /* Ensure this matches the format. This gives us a
464 * bit more confidence that a 'cn' value will be a
469 return (char *)val
->data
;
475 drsuapi_DsGetDomainControllerInfo
477 static WERROR
dcesrv_drsuapi_DsGetDomainControllerInfo_1(struct drsuapi_bind_state
*b_state
,
479 struct drsuapi_DsGetDomainControllerInfo
*r
)
481 struct ldb_dn
*sites_dn
;
482 struct ldb_result
*res
;
484 const char *attrs_account_1
[] = { "cn", "dnsHostName", NULL
};
485 const char *attrs_account_2
[] = { "cn", "dnsHostName", "objectGUID", NULL
};
487 const char *attrs_none
[] = { NULL
};
489 const char *attrs_site
[] = { "objectGUID", NULL
};
491 const char *attrs_ntds
[] = { "options", "objectGUID", NULL
};
493 const char *attrs_1
[] = { "serverReference", "cn", "dnsHostName", NULL
};
494 const char *attrs_2
[] = { "serverReference", "cn", "dnsHostName", "objectGUID", NULL
};
497 struct drsuapi_DsGetDCInfoCtr1
*ctr1
;
498 struct drsuapi_DsGetDCInfoCtr2
*ctr2
;
502 *r
->out
.level_out
= r
->in
.req
->req1
.level
;
503 r
->out
.ctr
= talloc(mem_ctx
, union drsuapi_DsGetDCInfoCtr
);
504 W_ERROR_HAVE_NO_MEMORY(r
->out
.ctr
);
506 sites_dn
= samdb_sites_dn(b_state
->sam_ctx
, mem_ctx
);
508 return WERR_DS_OBJ_NOT_FOUND
;
511 switch (*r
->out
.level_out
) {
513 /* this level is not like the others */
514 return WERR_UNKNOWN_LEVEL
;
522 return WERR_UNKNOWN_LEVEL
;
525 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res
, sites_dn
, LDB_SCOPE_SUBTREE
, attrs
,
526 "objectClass=server");
529 DEBUG(1, ("searching for servers in sites DN %s failed: %s\n",
530 ldb_dn_get_linearized(sites_dn
), ldb_errstring(b_state
->sam_ctx
)));
531 return WERR_GENERAL_FAILURE
;
534 switch (*r
->out
.level_out
) {
536 ctr1
= &r
->out
.ctr
->ctr1
;
537 ctr1
->count
= res
->count
;
538 ctr1
->array
= talloc_zero_array(mem_ctx
,
539 struct drsuapi_DsGetDCInfo1
,
541 for (i
=0; i
< res
->count
; i
++) {
542 struct ldb_dn
*domain_dn
;
543 struct ldb_result
*res_domain
;
544 struct ldb_result
*res_account
;
545 struct ldb_dn
*ntds_dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[i
]->dn
);
547 struct ldb_dn
*ref_dn
548 = ldb_msg_find_attr_as_dn(b_state
->sam_ctx
,
549 mem_ctx
, res
->msgs
[i
],
552 if (!ntds_dn
|| !ldb_dn_add_child_fmt(ntds_dn
, "CN=NTDS Settings")) {
556 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_account
, ref_dn
,
557 LDB_SCOPE_BASE
, attrs_account_1
, "objectClass=computer");
558 if (ret
== LDB_SUCCESS
&& res_account
->count
== 1) {
560 ctr1
->array
[i
].dns_name
561 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "dNSHostName", NULL
);
562 ctr1
->array
[i
].netbios_name
563 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "cn", NULL
);
564 ctr1
->array
[i
].computer_dn
565 = ldb_dn_get_linearized(res_account
->msgs
[0]->dn
);
567 /* Determine if this is the PDC */
568 ret
= samdb_search_for_parent_domain(b_state
->sam_ctx
,
569 mem_ctx
, res_account
->msgs
[0]->dn
,
570 &domain_dn
, &errstr
);
572 if (ret
== LDB_SUCCESS
) {
573 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_domain
, domain_dn
,
574 LDB_SCOPE_BASE
, attrs_none
, "fSMORoleOwner=%s",
575 ldb_dn_get_linearized(ntds_dn
));
577 return WERR_GENERAL_FAILURE
;
579 if (res_domain
->count
== 1) {
580 ctr1
->array
[i
].is_pdc
= true;
584 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
585 DEBUG(5, ("warning: searching for computer DN %s failed: %s\n",
586 ldb_dn_get_linearized(ref_dn
), ldb_errstring(b_state
->sam_ctx
)));
589 /* Look at server DN and extract site component */
590 ctr1
->array
[i
].site_name
= result_site_name(res
->msgs
[i
]->dn
);
591 ctr1
->array
[i
].server_dn
= ldb_dn_get_linearized(res
->msgs
[i
]->dn
);
594 ctr1
->array
[i
].is_enabled
= true;
599 ctr2
= &r
->out
.ctr
->ctr2
;
600 ctr2
->count
= res
->count
;
601 ctr2
->array
= talloc_zero_array(mem_ctx
,
602 struct drsuapi_DsGetDCInfo2
,
604 for (i
=0; i
< res
->count
; i
++) {
605 struct ldb_dn
*domain_dn
;
606 struct ldb_result
*res_domain
;
607 struct ldb_result
*res_account
;
608 struct ldb_dn
*ntds_dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[i
]->dn
);
609 struct ldb_result
*res_ntds
;
610 struct ldb_dn
*site_dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[i
]->dn
);
611 struct ldb_result
*res_site
;
612 struct ldb_dn
*ref_dn
613 = ldb_msg_find_attr_as_dn(b_state
->sam_ctx
,
614 mem_ctx
, res
->msgs
[i
],
617 if (!ntds_dn
|| !ldb_dn_add_child_fmt(ntds_dn
, "CN=NTDS Settings")) {
621 /* Format is cn=<NETBIOS name>,cn=Servers,cn=<site>,cn=sites.... */
622 if (!site_dn
|| !ldb_dn_remove_child_components(site_dn
, 2)) {
626 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_ntds
, ntds_dn
,
627 LDB_SCOPE_BASE
, attrs_ntds
, "objectClass=nTDSDSA");
628 if (ret
== LDB_SUCCESS
&& res_ntds
->count
== 1) {
630 = (ldb_msg_find_attr_as_int(res_ntds
->msgs
[0], "options", 0) == 1);
631 ctr2
->array
[i
].ntds_guid
632 = samdb_result_guid(res_ntds
->msgs
[0], "objectGUID");
633 ctr2
->array
[i
].ntds_dn
= ldb_dn_get_linearized(res_ntds
->msgs
[0]->dn
);
635 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
636 DEBUG(5, ("warning: searching for NTDS DN %s failed: %s\n",
637 ldb_dn_get_linearized(ntds_dn
), ldb_errstring(b_state
->sam_ctx
)));
640 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_site
, site_dn
,
641 LDB_SCOPE_BASE
, attrs_site
, "objectClass=site");
642 if (ret
== LDB_SUCCESS
&& res_site
->count
== 1) {
643 ctr2
->array
[i
].site_guid
644 = samdb_result_guid(res_site
->msgs
[0], "objectGUID");
645 ctr2
->array
[i
].site_dn
= ldb_dn_get_linearized(res_site
->msgs
[0]->dn
);
647 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
648 DEBUG(5, ("warning: searching for site DN %s failed: %s\n",
649 ldb_dn_get_linearized(site_dn
), ldb_errstring(b_state
->sam_ctx
)));
652 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_account
, ref_dn
,
653 LDB_SCOPE_BASE
, attrs_account_2
, "objectClass=computer");
654 if (ret
== LDB_SUCCESS
&& res_account
->count
== 1) {
656 ctr2
->array
[i
].dns_name
657 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "dNSHostName", NULL
);
658 ctr2
->array
[i
].netbios_name
659 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "cn", NULL
);
660 ctr2
->array
[i
].computer_dn
= ldb_dn_get_linearized(res_account
->msgs
[0]->dn
);
661 ctr2
->array
[i
].computer_guid
662 = samdb_result_guid(res_account
->msgs
[0], "objectGUID");
664 /* Determine if this is the PDC */
665 ret
= samdb_search_for_parent_domain(b_state
->sam_ctx
,
666 mem_ctx
, res_account
->msgs
[0]->dn
,
667 &domain_dn
, &errstr
);
669 if (ret
== LDB_SUCCESS
) {
670 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_domain
, domain_dn
,
671 LDB_SCOPE_BASE
, attrs_none
, "fSMORoleOwner=%s",
672 ldb_dn_get_linearized(ntds_dn
));
673 if (ret
== LDB_SUCCESS
&& res_domain
->count
== 1) {
674 ctr2
->array
[i
].is_pdc
= true;
676 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
677 DEBUG(5, ("warning: searching for domain DN %s failed: %s\n",
678 ldb_dn_get_linearized(domain_dn
), ldb_errstring(b_state
->sam_ctx
)));
682 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
683 DEBUG(5, ("warning: searching for computer account DN %s failed: %s\n",
684 ldb_dn_get_linearized(ref_dn
), ldb_errstring(b_state
->sam_ctx
)));
687 /* Look at server DN and extract site component */
688 ctr2
->array
[i
].site_name
= result_site_name(res
->msgs
[i
]->dn
);
689 ctr2
->array
[i
].server_dn
= ldb_dn_get_linearized(res
->msgs
[i
]->dn
);
690 ctr2
->array
[i
].server_guid
691 = samdb_result_guid(res
->msgs
[i
], "objectGUID");
693 ctr2
->array
[i
].is_enabled
= true;
702 drsuapi_DsGetDomainControllerInfo
704 static WERROR
dcesrv_drsuapi_DsGetDomainControllerInfo(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
705 struct drsuapi_DsGetDomainControllerInfo
*r
)
707 struct dcesrv_handle
*h
;
708 struct drsuapi_bind_state
*b_state
;
709 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
712 switch (r
->in
.level
) {
714 return dcesrv_drsuapi_DsGetDomainControllerInfo_1(b_state
, mem_ctx
, r
);
717 return WERR_UNKNOWN_LEVEL
;
725 static WERROR
dcesrv_drsuapi_DsExecuteKCC(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
726 struct drsuapi_DsExecuteKCC
*r
)
729 status
= drs_security_level_check(dce_call
, "DsExecuteKCC");
731 if (!W_ERROR_IS_OK(status
)) {
735 dcesrv_irpc_forward_rpc_call(dce_call
, mem_ctx
, r
, NDR_DRSUAPI_DSEXECUTEKCC
,
736 &ndr_table_drsuapi
, "kccsrv", "DsExecuteKCC");
742 drsuapi_DsReplicaGetInfo
744 static WERROR
dcesrv_drsuapi_DsReplicaGetInfo(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
745 struct drsuapi_DsReplicaGetInfo
*r
)
747 enum security_user_level level
;
749 if (!lp_parm_bool(dce_call
->conn
->dce_ctx
->lp_ctx
, NULL
,
750 "drs", "disable_sec_check", false)) {
751 level
= security_session_user_level(dce_call
->conn
->auth_state
.session_info
);
752 if (level
< SECURITY_ADMINISTRATOR
) {
753 DEBUG(1,(__location__
": Administrator access required for DsReplicaGetInfo\n"));
754 security_token_debug(2, dce_call
->conn
->auth_state
.session_info
->security_token
);
755 return WERR_DS_DRA_ACCESS_DENIED
;
759 dcesrv_irpc_forward_rpc_call(dce_call
, mem_ctx
, r
, NDR_DRSUAPI_DSREPLICAGETINFO
,
760 &ndr_table_drsuapi
, "kccsrv", "DsReplicaGetInfo");
767 DRSUAPI_ADD_SID_HISTORY
769 static WERROR
dcesrv_DRSUAPI_ADD_SID_HISTORY(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
770 struct DRSUAPI_ADD_SID_HISTORY
*r
)
772 DRSUAPI_UNSUPPORTED(DRSUAPI_ADD_SID_HISTORY
);
776 drsuapi_DsGetMemberships2
778 static WERROR
dcesrv_drsuapi_DsGetMemberships2(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
779 struct drsuapi_DsGetMemberships2
*r
)
781 DRSUAPI_UNSUPPORTED(drsuapi_DsGetMemberships2
);
785 DRSUAPI_REPLICA_VERIFY_OBJECTS
787 static WERROR
dcesrv_DRSUAPI_REPLICA_VERIFY_OBJECTS(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
788 struct DRSUAPI_REPLICA_VERIFY_OBJECTS
*r
)
790 DRSUAPI_UNSUPPORTED(DRSUAPI_REPLICA_VERIFY_OBJECTS
);
795 DRSUAPI_GET_OBJECT_EXISTENCE
797 static WERROR
dcesrv_DRSUAPI_GET_OBJECT_EXISTENCE(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
798 struct DRSUAPI_GET_OBJECT_EXISTENCE
*r
)
800 DRSUAPI_UNSUPPORTED(DRSUAPI_GET_OBJECT_EXISTENCE
);
805 drsuapi_QuerySitesByCost
807 static WERROR
dcesrv_drsuapi_QuerySitesByCost(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
808 struct drsuapi_QuerySitesByCost
*r
)
810 DRSUAPI_UNSUPPORTED(drsuapi_QuerySitesByCost
);
814 /* include the generated boilerplate */
815 #include "librpc/gen_ndr/ndr_drsuapi_s.c"