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 "lib/ldb/include/ldb_errors.h"
29 #include "param/param.h"
30 #include "librpc/gen_ndr/ndr_drsblobs.h"
31 #include "messaging/irpc.h"
32 #include "rpc_server/drsuapi/dcesrv_drsuapi.h"
37 static WERROR
dcesrv_drsuapi_DsBind(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
38 struct drsuapi_DsBind
*r
)
40 struct drsuapi_bind_state
*b_state
;
41 struct dcesrv_handle
*handle
;
42 struct drsuapi_DsBindInfoCtr
*bind_info
;
43 struct GUID site_guid
;
44 struct ldb_result
*site_res
;
45 struct ldb_dn
*server_site_dn
;
46 static const char *site_attrs
[] = { "objectGUID", NULL
};
47 struct ldb_result
*ntds_res
;
48 struct ldb_dn
*ntds_dn
;
49 static const char *ntds_attrs
[] = { "ms-DS-ReplicationEpoch", NULL
};
54 r
->out
.bind_info
= NULL
;
55 ZERO_STRUCTP(r
->out
.bind_handle
);
57 b_state
= talloc_zero(mem_ctx
, struct drsuapi_bind_state
);
58 W_ERROR_HAVE_NO_MEMORY(b_state
);
61 * connect to the samdb
63 b_state
->sam_ctx
= samdb_connect(b_state
, dce_call
->event_ctx
, dce_call
->conn
->dce_ctx
->lp_ctx
, dce_call
->conn
->auth_state
.session_info
);
64 if (!b_state
->sam_ctx
) {
69 * find out the guid of our own site
71 server_site_dn
= samdb_server_site_dn(b_state
->sam_ctx
, mem_ctx
);
72 W_ERROR_HAVE_NO_MEMORY(server_site_dn
);
74 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &site_res
,
75 server_site_dn
, LDB_SCOPE_BASE
, site_attrs
,
77 if (ret
!= LDB_SUCCESS
) {
78 return WERR_DS_DRA_INTERNAL_ERROR
;
80 if (site_res
->count
!= 1) {
81 return WERR_DS_DRA_INTERNAL_ERROR
;
83 site_guid
= samdb_result_guid(site_res
->msgs
[0], "objectGUID");
86 * lookup the local servers Replication Epoch
88 ntds_dn
= samdb_ntds_settings_dn(b_state
->sam_ctx
);
89 W_ERROR_HAVE_NO_MEMORY(ntds_dn
);
91 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &ntds_res
,
92 ntds_dn
, LDB_SCOPE_BASE
, ntds_attrs
,
94 if (ret
!= LDB_SUCCESS
) {
95 return WERR_DS_DRA_INTERNAL_ERROR
;
97 if (ntds_res
->count
!= 1) {
98 return WERR_DS_DRA_INTERNAL_ERROR
;
100 repl_epoch
= samdb_result_uint(ntds_res
->msgs
[0], "ms-DS-ReplicationEpoch", 0);
103 * The "process identifier" of the client.
104 * According to the WSPP docs, sectin 5.35, this is
105 * for informational and debugging purposes only.
106 * The assignment is implementation specific.
111 * store the clients bind_guid
113 if (r
->in
.bind_guid
) {
114 b_state
->remote_bind_guid
= *r
->in
.bind_guid
;
118 * store the clients bind_info
120 if (r
->in
.bind_info
) {
121 switch (r
->in
.bind_info
->length
) {
123 struct drsuapi_DsBindInfo24
*info24
;
124 info24
= &r
->in
.bind_info
->info
.info24
;
125 b_state
->remote_info28
.supported_extensions
= info24
->supported_extensions
;
126 b_state
->remote_info28
.site_guid
= info24
->site_guid
;
127 b_state
->remote_info28
.pid
= info24
->pid
;
128 b_state
->remote_info28
.repl_epoch
= 0;
132 b_state
->remote_info28
= r
->in
.bind_info
->info
.info28
;
138 * fill in our local bind info 28
140 b_state
->local_info28
.supported_extensions
= 0;
141 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_BASE
;
142 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION
;
143 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI
;
144 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2
;
145 #if 0 /* we don't support MSZIP compression (only decompression) */
146 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS
;
148 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1
;
149 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION
;
150 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE
;
151 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2
;
152 if (0 /*domain.behavior_version == 2*/) {
153 /* TODO: find out how this is really triggered! */
154 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION
;
156 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2
;
157 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD
;
158 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND
;
159 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO
;
160 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION
;
161 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01
;
162 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP
;
163 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY
;
164 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3
;
165 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_00100000
;
166 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2
;
167 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6
;
168 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS
;
169 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8
;
170 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5
;
171 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6
;
172 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3
;
173 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7
;
174 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT
;
175 #if 0 /* we don't support XPRESS compression yet */
176 b_state
->local_info28
.supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS
;
178 b_state
->local_info28
.site_guid
= site_guid
;
179 b_state
->local_info28
.pid
= pid
;
180 b_state
->local_info28
.repl_epoch
= repl_epoch
;
183 * allocate the return bind_info
185 bind_info
= talloc(mem_ctx
, struct drsuapi_DsBindInfoCtr
);
186 W_ERROR_HAVE_NO_MEMORY(bind_info
);
188 bind_info
->length
= 28;
189 bind_info
->info
.info28
= b_state
->local_info28
;
192 * allocate a bind handle
194 handle
= dcesrv_handle_new(dce_call
->context
, DRSUAPI_BIND_HANDLE
);
195 W_ERROR_HAVE_NO_MEMORY(handle
);
196 handle
->data
= talloc_steal(handle
, b_state
);
201 r
->out
.bind_info
= bind_info
;
202 *r
->out
.bind_handle
= handle
->wire_handle
;
211 static WERROR
dcesrv_drsuapi_DsUnbind(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
212 struct drsuapi_DsUnbind
*r
)
214 struct dcesrv_handle
*h
;
216 *r
->out
.bind_handle
= *r
->in
.bind_handle
;
218 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
222 ZERO_STRUCTP(r
->out
.bind_handle
);
229 drsuapi_DsReplicaSync
231 static WERROR
dcesrv_drsuapi_DsReplicaSync(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
232 struct drsuapi_DsReplicaSync
*r
)
234 struct server_id
*repld
;
235 struct irpc_request
*ireq
;
238 NDR_PRINT_IN_DEBUG(drsuapi_DsReplicaSync
, r
);
241 repld
= irpc_servers_byname(dce_call
->msg_ctx
, mem_ctx
, "dreplsrv");
242 if (repld
== NULL
|| repld
[0].id
== 0) {
243 DEBUG(0,("DsReplicaSync: Unable to find dreplsrv task\n"));
244 return WERR_DS_DRA_INTERNAL_ERROR
;
247 ireq
= IRPC_CALL_SEND(dce_call
->msg_ctx
, repld
[0],
248 drsuapi
, DRSUAPI_DSREPLICASYNC
,
251 DEBUG(0,("DsReplicaSync: Failed to forward request to dreplsrv task\n"));
252 return WERR_DS_DRA_INTERNAL_ERROR
;
255 /* we are not interested in a reply */
264 static WERROR
dcesrv_drsuapi_DsReplicaAdd(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
265 struct drsuapi_DsReplicaAdd
*r
)
267 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
274 static WERROR
dcesrv_drsuapi_DsReplicaDel(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
275 struct drsuapi_DsReplicaDel
*r
)
277 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
282 drsuapi_DsReplicaModify
284 static WERROR
dcesrv_drsuapi_DsReplicaMod(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
285 struct drsuapi_DsReplicaMod
*r
)
287 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
294 static WERROR
dcesrv_DRSUAPI_VERIFY_NAMES(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
295 struct DRSUAPI_VERIFY_NAMES
*r
)
297 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
302 drsuapi_DsGetMemberships
304 static WERROR
dcesrv_drsuapi_DsGetMemberships(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
305 struct drsuapi_DsGetMemberships
*r
)
307 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
312 DRSUAPI_INTER_DOMAIN_MOVE
314 static WERROR
dcesrv_DRSUAPI_INTER_DOMAIN_MOVE(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
315 struct DRSUAPI_INTER_DOMAIN_MOVE
*r
)
317 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
322 drsuapi_DsGetNT4ChangeLog
324 static WERROR
dcesrv_drsuapi_DsGetNT4ChangeLog(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
325 struct drsuapi_DsGetNT4ChangeLog
*r
)
327 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
334 static WERROR
dcesrv_drsuapi_DsCrackNames(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
335 struct drsuapi_DsCrackNames
*r
)
338 struct drsuapi_bind_state
*b_state
;
339 struct dcesrv_handle
*h
;
341 *r
->out
.level_out
= r
->in
.level
;
343 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
346 r
->out
.ctr
= talloc_zero(mem_ctx
, union drsuapi_DsNameCtr
);
347 W_ERROR_HAVE_NO_MEMORY(r
->out
.ctr
);
349 switch (r
->in
.level
) {
351 struct drsuapi_DsNameCtr1
*ctr1
;
352 struct drsuapi_DsNameInfo1
*names
;
356 ctr1
= talloc(mem_ctx
, struct drsuapi_DsNameCtr1
);
357 W_ERROR_HAVE_NO_MEMORY(ctr1
);
359 count
= r
->in
.req
->req1
.count
;
360 names
= talloc_array(mem_ctx
, struct drsuapi_DsNameInfo1
, count
);
361 W_ERROR_HAVE_NO_MEMORY(names
);
363 for (i
=0; i
< count
; i
++) {
364 status
= DsCrackNameOneName(b_state
->sam_ctx
, mem_ctx
,
365 r
->in
.req
->req1
.format_flags
,
366 r
->in
.req
->req1
.format_offered
,
367 r
->in
.req
->req1
.format_desired
,
368 r
->in
.req
->req1
.names
[i
].str
,
370 if (!W_ERROR_IS_OK(status
)) {
377 r
->out
.ctr
->ctr1
= ctr1
;
383 return WERR_UNKNOWN_LEVEL
;
387 drsuapi_DsWriteAccountSpn
389 static WERROR
dcesrv_drsuapi_DsWriteAccountSpn(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
390 struct drsuapi_DsWriteAccountSpn
*r
)
392 struct drsuapi_bind_state
*b_state
;
393 struct dcesrv_handle
*h
;
395 *r
->out
.level_out
= r
->in
.level
;
397 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
400 r
->out
.res
= talloc(mem_ctx
, union drsuapi_DsWriteAccountSpnResult
);
401 W_ERROR_HAVE_NO_MEMORY(r
->out
.res
);
403 switch (r
->in
.level
) {
405 struct drsuapi_DsWriteAccountSpnRequest1
*req
;
406 struct ldb_message
*msg
;
408 req
= &r
->in
.req
->req1
;
411 msg
= ldb_msg_new(mem_ctx
);
416 msg
->dn
= ldb_dn_new(msg
, b_state
->sam_ctx
, req
->object_dn
);
417 if ( ! ldb_dn_validate(msg
->dn
)) {
418 r
->out
.res
->res1
.status
= WERR_OK
;
423 for (i
= 0; i
< count
; i
++) {
424 samdb_msg_add_string(b_state
->sam_ctx
,
425 msg
, msg
, "servicePrincipalName",
426 req
->spn_names
[i
].str
);
428 for (i
=0;i
<msg
->num_elements
;i
++) {
429 switch (req
->operation
) {
430 case DRSUAPI_DS_SPN_OPERATION_ADD
:
431 msg
->elements
[i
].flags
= LDB_FLAG_MOD_ADD
;
433 case DRSUAPI_DS_SPN_OPERATION_REPLACE
:
434 msg
->elements
[i
].flags
= LDB_FLAG_MOD_REPLACE
;
436 case DRSUAPI_DS_SPN_OPERATION_DELETE
:
437 msg
->elements
[i
].flags
= LDB_FLAG_MOD_DELETE
;
442 /* Apply to database */
444 ret
= ldb_modify(b_state
->sam_ctx
, msg
);
446 DEBUG(0,("Failed to modify SPNs on %s: %s\n",
447 ldb_dn_get_linearized(msg
->dn
),
448 ldb_errstring(b_state
->sam_ctx
)));
449 r
->out
.res
->res1
.status
= WERR_ACCESS_DENIED
;
451 r
->out
.res
->res1
.status
= WERR_OK
;
458 return WERR_UNKNOWN_LEVEL
;
463 drsuapi_DsRemoveDSServer
465 static WERROR
dcesrv_drsuapi_DsRemoveDSServer(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
466 struct drsuapi_DsRemoveDSServer
*r
)
468 struct drsuapi_bind_state
*b_state
;
469 struct dcesrv_handle
*h
;
470 struct ldb_dn
*ntds_dn
;
474 ZERO_STRUCT(r
->out
.res
);
475 *r
->out
.level_out
= 1;
477 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
480 switch (r
->in
.level
) {
482 ntds_dn
= ldb_dn_new(mem_ctx
, b_state
->sam_ctx
, r
->in
.req
->req1
.server_dn
);
483 W_ERROR_HAVE_NO_MEMORY(ntds_dn
);
485 ok
= ldb_dn_validate(ntds_dn
);
490 /* TODO: it's likely that we need more checks here */
492 ok
= ldb_dn_add_child_fmt(ntds_dn
, "CN=NTDS Settings");
497 if (r
->in
.req
->req1
.commit
) {
498 ret
= ldb_delete(b_state
->sam_ctx
, ntds_dn
);
499 if (ret
!= LDB_SUCCESS
) {
514 DRSUAPI_REMOVE_DS_DOMAIN
516 static WERROR
dcesrv_DRSUAPI_REMOVE_DS_DOMAIN(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
517 struct DRSUAPI_REMOVE_DS_DOMAIN
*r
)
519 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
522 /* Obtain the site name from a server DN */
523 static const char *result_site_name(struct ldb_dn
*site_dn
)
525 /* Format is cn=<NETBIOS name>,cn=Servers,cn=<site>,cn=sites.... */
526 const struct ldb_val
*val
= ldb_dn_get_component_val(site_dn
, 2);
527 const char *name
= ldb_dn_get_component_name(site_dn
, 2);
529 if (!name
|| (ldb_attr_cmp(name
, "cn") != 0)) {
530 /* Ensure this matches the format. This gives us a
531 * bit more confidence that a 'cn' value will be a
536 return (char *)val
->data
;
542 drsuapi_DsGetDomainControllerInfo
544 static WERROR
dcesrv_drsuapi_DsGetDomainControllerInfo_1(struct drsuapi_bind_state
*b_state
,
546 struct drsuapi_DsGetDomainControllerInfo
*r
)
548 struct ldb_dn
*sites_dn
;
549 struct ldb_result
*res
;
551 const char *attrs_account_1
[] = { "cn", "dnsHostName", NULL
};
552 const char *attrs_account_2
[] = { "cn", "dnsHostName", "objectGUID", NULL
};
554 const char *attrs_none
[] = { NULL
};
556 const char *attrs_site
[] = { "objectGUID", NULL
};
558 const char *attrs_ntds
[] = { "options", "objectGUID", NULL
};
560 const char *attrs_1
[] = { "serverReference", "cn", "dnsHostName", NULL
};
561 const char *attrs_2
[] = { "serverReference", "cn", "dnsHostName", "objectGUID", NULL
};
564 struct drsuapi_DsGetDCInfoCtr1
*ctr1
;
565 struct drsuapi_DsGetDCInfoCtr2
*ctr2
;
569 *r
->out
.level_out
= r
->in
.req
->req1
.level
;
570 r
->out
.ctr
= talloc(mem_ctx
, union drsuapi_DsGetDCInfoCtr
);
571 W_ERROR_HAVE_NO_MEMORY(r
->out
.ctr
);
573 sites_dn
= samdb_sites_dn(b_state
->sam_ctx
, mem_ctx
);
575 return WERR_DS_OBJ_NOT_FOUND
;
578 switch (*r
->out
.level_out
) {
580 /* this level is not like the others */
581 return WERR_UNKNOWN_LEVEL
;
589 return WERR_UNKNOWN_LEVEL
;
592 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res
, sites_dn
, LDB_SCOPE_SUBTREE
, attrs
,
593 "objectClass=server");
596 DEBUG(1, ("searching for servers in sites DN %s failed: %s\n",
597 ldb_dn_get_linearized(sites_dn
), ldb_errstring(b_state
->sam_ctx
)));
598 return WERR_GENERAL_FAILURE
;
601 switch (*r
->out
.level_out
) {
603 ctr1
= &r
->out
.ctr
->ctr1
;
604 ctr1
->count
= res
->count
;
605 ctr1
->array
= talloc_zero_array(mem_ctx
,
606 struct drsuapi_DsGetDCInfo1
,
608 for (i
=0; i
< res
->count
; i
++) {
609 struct ldb_dn
*domain_dn
;
610 struct ldb_result
*res_domain
;
611 struct ldb_result
*res_account
;
612 struct ldb_dn
*ntds_dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[i
]->dn
);
614 struct ldb_dn
*ref_dn
615 = ldb_msg_find_attr_as_dn(b_state
->sam_ctx
,
616 mem_ctx
, res
->msgs
[i
],
619 if (!ntds_dn
|| !ldb_dn_add_child_fmt(ntds_dn
, "CN=NTDS Settings")) {
623 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_account
, ref_dn
,
624 LDB_SCOPE_BASE
, attrs_account_1
, "objectClass=computer");
625 if (ret
== LDB_SUCCESS
&& res_account
->count
== 1) {
627 ctr1
->array
[i
].dns_name
628 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "dNSHostName", NULL
);
629 ctr1
->array
[i
].netbios_name
630 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "cn", NULL
);
631 ctr1
->array
[i
].computer_dn
632 = ldb_dn_get_linearized(res_account
->msgs
[0]->dn
);
634 /* Determine if this is the PDC */
635 ret
= samdb_search_for_parent_domain(b_state
->sam_ctx
,
636 mem_ctx
, res_account
->msgs
[0]->dn
,
637 &domain_dn
, &errstr
);
639 if (ret
== LDB_SUCCESS
) {
640 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_domain
, domain_dn
,
641 LDB_SCOPE_BASE
, attrs_none
, "fSMORoleOwner=%s",
642 ldb_dn_get_linearized(ntds_dn
));
644 return WERR_GENERAL_FAILURE
;
646 if (res_domain
->count
== 1) {
647 ctr1
->array
[i
].is_pdc
= true;
651 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
652 DEBUG(5, ("warning: searching for computer DN %s failed: %s\n",
653 ldb_dn_get_linearized(ref_dn
), ldb_errstring(b_state
->sam_ctx
)));
656 /* Look at server DN and extract site component */
657 ctr1
->array
[i
].site_name
= result_site_name(res
->msgs
[i
]->dn
);
658 ctr1
->array
[i
].server_dn
= ldb_dn_get_linearized(res
->msgs
[i
]->dn
);
661 ctr1
->array
[i
].is_enabled
= true;
666 ctr2
= &r
->out
.ctr
->ctr2
;
667 ctr2
->count
= res
->count
;
668 ctr2
->array
= talloc_zero_array(mem_ctx
,
669 struct drsuapi_DsGetDCInfo2
,
671 for (i
=0; i
< res
->count
; i
++) {
672 struct ldb_dn
*domain_dn
;
673 struct ldb_result
*res_domain
;
674 struct ldb_result
*res_account
;
675 struct ldb_dn
*ntds_dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[i
]->dn
);
676 struct ldb_result
*res_ntds
;
677 struct ldb_dn
*site_dn
= ldb_dn_copy(mem_ctx
, res
->msgs
[i
]->dn
);
678 struct ldb_result
*res_site
;
679 struct ldb_dn
*ref_dn
680 = ldb_msg_find_attr_as_dn(b_state
->sam_ctx
,
681 mem_ctx
, res
->msgs
[i
],
684 if (!ntds_dn
|| !ldb_dn_add_child_fmt(ntds_dn
, "CN=NTDS Settings")) {
688 /* Format is cn=<NETBIOS name>,cn=Servers,cn=<site>,cn=sites.... */
689 if (!site_dn
|| !ldb_dn_remove_child_components(site_dn
, 2)) {
693 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_ntds
, ntds_dn
,
694 LDB_SCOPE_BASE
, attrs_ntds
, "objectClass=nTDSDSA");
695 if (ret
== LDB_SUCCESS
&& res_ntds
->count
== 1) {
697 = (ldb_msg_find_attr_as_int(res_ntds
->msgs
[0], "options", 0) == 1);
698 ctr2
->array
[i
].ntds_guid
699 = samdb_result_guid(res_ntds
->msgs
[0], "objectGUID");
700 ctr2
->array
[i
].ntds_dn
= ldb_dn_get_linearized(res_ntds
->msgs
[0]->dn
);
702 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
703 DEBUG(5, ("warning: searching for NTDS DN %s failed: %s\n",
704 ldb_dn_get_linearized(ntds_dn
), ldb_errstring(b_state
->sam_ctx
)));
707 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_site
, site_dn
,
708 LDB_SCOPE_BASE
, attrs_site
, "objectClass=site");
709 if (ret
== LDB_SUCCESS
&& res_site
->count
== 1) {
710 ctr2
->array
[i
].site_guid
711 = samdb_result_guid(res_site
->msgs
[0], "objectGUID");
712 ctr2
->array
[i
].site_dn
= ldb_dn_get_linearized(res_site
->msgs
[0]->dn
);
714 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
715 DEBUG(5, ("warning: searching for site DN %s failed: %s\n",
716 ldb_dn_get_linearized(site_dn
), ldb_errstring(b_state
->sam_ctx
)));
719 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_account
, ref_dn
,
720 LDB_SCOPE_BASE
, attrs_account_2
, "objectClass=computer");
721 if (ret
== LDB_SUCCESS
&& res_account
->count
== 1) {
723 ctr2
->array
[i
].dns_name
724 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "dNSHostName", NULL
);
725 ctr2
->array
[i
].netbios_name
726 = ldb_msg_find_attr_as_string(res_account
->msgs
[0], "cn", NULL
);
727 ctr2
->array
[i
].computer_dn
= ldb_dn_get_linearized(res_account
->msgs
[0]->dn
);
728 ctr2
->array
[i
].computer_guid
729 = samdb_result_guid(res_account
->msgs
[0], "objectGUID");
731 /* Determine if this is the PDC */
732 ret
= samdb_search_for_parent_domain(b_state
->sam_ctx
,
733 mem_ctx
, res_account
->msgs
[0]->dn
,
734 &domain_dn
, &errstr
);
736 if (ret
== LDB_SUCCESS
) {
737 ret
= ldb_search(b_state
->sam_ctx
, mem_ctx
, &res_domain
, domain_dn
,
738 LDB_SCOPE_BASE
, attrs_none
, "fSMORoleOwner=%s",
739 ldb_dn_get_linearized(ntds_dn
));
740 if (ret
== LDB_SUCCESS
&& res_domain
->count
== 1) {
741 ctr2
->array
[i
].is_pdc
= true;
743 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
744 DEBUG(5, ("warning: searching for domain DN %s failed: %s\n",
745 ldb_dn_get_linearized(domain_dn
), ldb_errstring(b_state
->sam_ctx
)));
749 if ((ret
!= LDB_SUCCESS
) && (ret
!= LDB_ERR_NO_SUCH_OBJECT
)) {
750 DEBUG(5, ("warning: searching for computer account DN %s failed: %s\n",
751 ldb_dn_get_linearized(ref_dn
), ldb_errstring(b_state
->sam_ctx
)));
754 /* Look at server DN and extract site component */
755 ctr2
->array
[i
].site_name
= result_site_name(res
->msgs
[i
]->dn
);
756 ctr2
->array
[i
].server_dn
= ldb_dn_get_linearized(res
->msgs
[i
]->dn
);
757 ctr2
->array
[i
].server_guid
758 = samdb_result_guid(res
->msgs
[i
], "objectGUID");
760 ctr2
->array
[i
].is_enabled
= true;
769 drsuapi_DsGetDomainControllerInfo
771 static WERROR
dcesrv_drsuapi_DsGetDomainControllerInfo(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
772 struct drsuapi_DsGetDomainControllerInfo
*r
)
774 struct dcesrv_handle
*h
;
775 struct drsuapi_bind_state
*b_state
;
776 DCESRV_PULL_HANDLE_WERR(h
, r
->in
.bind_handle
, DRSUAPI_BIND_HANDLE
);
779 switch (r
->in
.level
) {
781 return dcesrv_drsuapi_DsGetDomainControllerInfo_1(b_state
, mem_ctx
, r
);
784 return WERR_UNKNOWN_LEVEL
;
792 static WERROR
dcesrv_DRSUAPI_EXECUTE_KCC(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
793 struct DRSUAPI_EXECUTE_KCC
*r
)
795 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
800 drsuapi_DsReplicaGetInfo
802 static WERROR
dcesrv_drsuapi_DsReplicaGetInfo(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
803 struct drsuapi_DsReplicaGetInfo
*r
)
805 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
810 DRSUAPI_ADD_SID_HISTORY
812 static WERROR
dcesrv_DRSUAPI_ADD_SID_HISTORY(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
813 struct DRSUAPI_ADD_SID_HISTORY
*r
)
815 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
819 drsuapi_DsGetMemberships2
821 static WERROR
dcesrv_drsuapi_DsGetMemberships2(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
822 struct drsuapi_DsGetMemberships2
*r
)
824 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
828 DRSUAPI_REPLICA_VERIFY_OBJECTS
830 static WERROR
dcesrv_DRSUAPI_REPLICA_VERIFY_OBJECTS(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
831 struct DRSUAPI_REPLICA_VERIFY_OBJECTS
*r
)
833 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
838 DRSUAPI_GET_OBJECT_EXISTENCE
840 static WERROR
dcesrv_DRSUAPI_GET_OBJECT_EXISTENCE(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
841 struct DRSUAPI_GET_OBJECT_EXISTENCE
*r
)
843 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
848 drsuapi_QuerySitesByCost
850 static WERROR
dcesrv_drsuapi_QuerySitesByCost(struct dcesrv_call_state
*dce_call
, TALLOC_CTX
*mem_ctx
,
851 struct drsuapi_QuerySitesByCost
*r
)
853 DCESRV_FAULT(DCERPC_FAULT_OP_RNG_ERROR
);
857 /* include the generated boilerplate */
858 #include "librpc/gen_ndr/ndr_drsuapi_s.c"