2 Unix SMB/CIFS implementation.
4 Copyright (C) Stefan Metzmacher <metze@samba.org> 2006
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #include "libnet/libnet.h"
22 #include "libcli/composite/composite.h"
23 #include "libcli/cldap/cldap.h"
24 #include "source3/libads/netlogon_ping.h"
26 #include <ldb_errors.h>
28 #include "dsdb/samdb/samdb.h"
29 #include "../libds/common/flags.h"
30 #include "librpc/gen_ndr/ndr_drsuapi_c.h"
31 #include "param/param.h"
32 #include "lib/tsocket/tsocket.h"
34 /*****************************************************************************
35 * Windows 2003 (w2k3) does the following steps when changing the server role
36 * from domain controller back to domain member
38 * We mostly do the same.
39 *****************************************************************************/
43 * - using nbt name<1C> request and a samlogon mailslot request
45 * - using a DNS SRV _ldap._tcp.dc._msdcs. request and a CLDAP netlogon request
47 * see: unbecomeDC_send_cldap() and unbecomeDC_recv_cldap()
51 * Open 1st LDAP connection to the DC using admin credentials
53 * see: unbecomeDC_ldap_connect()
57 * LDAP search 1st LDAP connection:
59 * see: unbecomeDC_ldap_rootdse()
64 * filter: (objectClass=*)
65 * attrs: defaultNamingContext
66 * configurationNamingContext
69 * defaultNamingContext: <domain_partition>
70 * configurationNamingContext:CN=Configuration,<domain_partition>
74 * LDAP search 1st LDAP connection:
76 * see: unbecomeDC_ldap_computer_object()
79 * basedn: <domain_partition>
81 * filter: (&(|(objectClass=user)(objectClass=computer))(sAMAccountName=<new_dc_account_name>))
82 * attrs: distinguishedName
85 * CN=<new_dc_netbios_name>,CN=Domain Controllers,<domain_partition>
86 * distinguishedName: CN=<new_dc_netbios_name>,CN=Domain Controllers,<domain_partition>
87 * userAccoountControl: 532480 <0x82000>
91 * LDAP search 1st LDAP connection:
93 * see: unbecomeDC_ldap_modify_computer()
96 * basedn: CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
98 * filter: (objectClass=*)
99 * attrs: userAccountControl
101 * CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
102 * userAccoountControl: 532480 <0x82000>
106 * LDAP modify 1st LDAP connection:
108 * see: unbecomeDC_ldap_modify_computer()
111 * CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
112 * userAccoountControl: 4096 <0x1000>
118 * LDAP search 1st LDAP connection:
120 * see: unbecomeDC_ldap_move_computer()
123 * basedn: <WKGUID=aa312825768811d1aded00c04fd8d5cd,<domain_partition>>
125 * filter: (objectClass=*)
128 * CN=Computers,<domain_partition>
132 * LDAP search 1st LDAP connection:
134 * not implemented because it doesn't give any new information
137 * basedn: CN=Computers,<domain_partition>
139 * filter: (objectClass=*)
140 * attrs: distinguishedName
142 * CN=Computers,<domain_partition>
143 * distinguishedName: CN=Computers,<domain_partition>
147 * LDAP modifyRDN 1st LDAP connection:
149 * see: unbecomeDC_ldap_move_computer()
152 * entry: CN=<new_dc_netbios_name>,CN=Domain Controllers,<domain_partition>
153 * newrdn: CN=<new_dc_netbios_name>
155 * newparent: CN=Computers,<domain_partition>
161 * LDAP unbind on the 1st LDAP connection
163 * not implemented, because it's not needed...
167 * Open 1st DRSUAPI connection to the DC using admin credentials
168 * DsBind with DRSUAPI_DS_BIND_GUID ("e24d201a-4fd6-11d1-a3da-0000f875ae0d")
170 * see: unbecomeDC_drsuapi_connect_send(), unbecomeDC_drsuapi_connect_recv(),
171 * unbecomeDC_drsuapi_bind_send() and unbecomeDC_drsuapi_bind_recv()
175 * DsRemoveDsServer to remove the
176 * CN=<machine_name>,CN=Servers,CN=<site_name>,CN=Configuration,<domain_partition>
177 * and CN=NTDS Settings,CN=<machine_name>,CN=Servers,CN=<site_name>,CN=Configuration,<domain_partition>
178 * on the 1st DRSUAPI connection
180 * see: unbecomeDC_drsuapi_remove_ds_server_send() and unbecomeDC_drsuapi_remove_ds_server_recv()
184 * DsUnbind on the 1st DRSUAPI connection
186 * not implemented, because it's not needed...
190 struct libnet_UnbecomeDC_state
{
191 struct composite_context
*creq
;
193 struct libnet_context
*libnet
;
196 struct NETLOGON_SAM_LOGON_RESPONSE_EX netlogon
;
200 struct ldb_context
*ldb
;
204 struct dcerpc_binding
*binding
;
205 struct dcerpc_pipe
*pipe
;
206 struct dcerpc_binding_handle
*drsuapi_handle
;
207 struct drsuapi_DsBind bind_r
;
208 struct GUID bind_guid
;
209 struct drsuapi_DsBindInfoCtr bind_info_ctr
;
210 struct drsuapi_DsBindInfo28 local_info28
;
211 struct drsuapi_DsBindInfo28 remote_info28
;
212 struct policy_handle bind_handle
;
213 struct drsuapi_DsRemoveDSServer rm_ds_srv_r
;
218 const char *dns_name
;
219 const char *netbios_name
;
228 const char *config_dn_str
;
236 const char *dns_name
;
237 const char *netbios_name
;
238 const char *site_name
;
243 const char *netbios_name
;
246 const char *dns_name
;
247 const char *site_name
;
248 const char *computer_dn_str
;
249 const char *server_dn_str
;
250 uint32_t user_account_control
;
254 static void unbecomeDC_recv_cldap(struct tevent_req
*req
);
256 static void unbecomeDC_send_cldap(struct libnet_UnbecomeDC_state
*s
)
258 struct composite_context
*c
= s
->creq
;
259 struct libnet_context
*libnet
= s
->libnet
;
260 struct tevent_req
*req
;
261 struct tsocket_address
*dest_address
;
264 ret
= tsocket_address_inet_from_strings(
265 s
, "ip", s
->source_dsa
.address
, 389, &dest_address
);
267 c
->status
= map_nt_error_from_unix_common(errno
);
268 if (!composite_is_ok(c
)) return;
271 req
= netlogon_pings_send(s
, /* mem_ctx */
272 libnet
->event_ctx
, /* ev */
273 lpcfg_client_netlogon_ping_protocol(
274 libnet
->lp_ctx
), /* proto */
275 &dest_address
, /* servers*/
277 (struct netlogon_ping_filter
){
278 .ntversion
= NETLOGON_NT_VERSION_5
|
279 NETLOGON_NT_VERSION_5EX
,
281 .domain
= s
->domain
.dns_name
,
282 .hostname
= s
->dest_dsa
.netbios_name
,
285 tevent_timeval_current_ofs(2,
288 if (composite_nomem(req
, c
)) return;
289 tevent_req_set_callback(req
, unbecomeDC_recv_cldap
, s
);
292 static void unbecomeDC_connect_ldap(struct libnet_UnbecomeDC_state
*s
);
294 static void unbecomeDC_recv_cldap(struct tevent_req
*req
)
296 struct libnet_UnbecomeDC_state
*s
= tevent_req_callback_data(req
,
297 struct libnet_UnbecomeDC_state
);
298 struct composite_context
*c
= s
->creq
;
299 struct netlogon_samlogon_response
**responses
= NULL
;
300 struct netlogon_samlogon_response
*resp
= NULL
;
302 c
->status
= netlogon_pings_recv(req
, s
, &responses
);
304 if (!composite_is_ok(c
)) {
305 DBG_ERR("Failed to send, receive or parse CLDAP reply "
306 "for our host %s: %s\n",
307 s
->dest_dsa
.netbios_name
,
308 nt_errstr(c
->status
));
313 map_netlogon_samlogon_response(resp
);
314 s
->cldap
.netlogon
= resp
->data
.nt5_ex
;
316 s
->domain
.dns_name
= s
->cldap
.netlogon
.dns_domain
;
317 s
->domain
.netbios_name
= s
->cldap
.netlogon
.domain_name
;
318 s
->domain
.guid
= s
->cldap
.netlogon
.domain_uuid
;
320 s
->source_dsa
.dns_name
= s
->cldap
.netlogon
.pdc_dns_name
;
321 s
->source_dsa
.netbios_name
= s
->cldap
.netlogon
.pdc_name
;
322 s
->source_dsa
.site_name
= s
->cldap
.netlogon
.server_site
;
324 s
->dest_dsa
.site_name
= s
->cldap
.netlogon
.client_site
;
326 unbecomeDC_connect_ldap(s
);
329 static NTSTATUS
unbecomeDC_ldap_connect(struct libnet_UnbecomeDC_state
*s
)
333 url
= talloc_asprintf(s
, "ldap://%s/", s
->source_dsa
.dns_name
);
334 NT_STATUS_HAVE_NO_MEMORY(url
);
336 s
->ldap
.ldb
= ldb_wrap_connect(s
, s
->libnet
->event_ctx
, s
->libnet
->lp_ctx
, url
,
341 if (s
->ldap
.ldb
== NULL
) {
342 return NT_STATUS_UNEXPECTED_NETWORK_ERROR
;
348 static NTSTATUS
unbecomeDC_ldap_rootdse(struct libnet_UnbecomeDC_state
*s
)
351 struct ldb_result
*r
;
352 struct ldb_dn
*basedn
;
353 static const char *attrs
[] = {
354 "defaultNamingContext",
355 "configurationNamingContext",
359 basedn
= ldb_dn_new(s
, s
->ldap
.ldb
, NULL
);
360 NT_STATUS_HAVE_NO_MEMORY(basedn
);
362 ret
= ldb_search(s
->ldap
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
, attrs
,
365 if (ret
!= LDB_SUCCESS
) {
366 return NT_STATUS_LDAP(ret
);
367 } else if (r
->count
!= 1) {
369 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
372 s
->domain
.dn_str
= ldb_msg_find_attr_as_string(r
->msgs
[0], "defaultNamingContext", NULL
);
373 if (!s
->domain
.dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
374 talloc_steal(s
, s
->domain
.dn_str
);
376 s
->forest
.config_dn_str
= ldb_msg_find_attr_as_string(r
->msgs
[0], "configurationNamingContext", NULL
);
377 if (!s
->forest
.config_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
378 talloc_steal(s
, s
->forest
.config_dn_str
);
380 s
->dest_dsa
.server_dn_str
= talloc_asprintf(s
, "CN=%s,CN=Servers,CN=%s,CN=Sites,%s",
381 s
->dest_dsa
.netbios_name
,
382 s
->dest_dsa
.site_name
,
383 s
->forest
.config_dn_str
);
384 NT_STATUS_HAVE_NO_MEMORY(s
->dest_dsa
.server_dn_str
);
390 static NTSTATUS
unbecomeDC_ldap_computer_object(struct libnet_UnbecomeDC_state
*s
)
393 struct ldb_result
*r
;
394 struct ldb_dn
*basedn
;
395 static const char *attrs
[] = {
397 "userAccountControl",
401 basedn
= ldb_dn_new(s
, s
->ldap
.ldb
, s
->domain
.dn_str
);
402 NT_STATUS_HAVE_NO_MEMORY(basedn
);
404 ret
= ldb_search(s
->ldap
.ldb
, s
, &r
, basedn
, LDB_SCOPE_SUBTREE
, attrs
,
405 "(&(|(objectClass=user)(objectClass=computer))(sAMAccountName=%s$))",
406 s
->dest_dsa
.netbios_name
);
408 if (ret
!= LDB_SUCCESS
) {
409 return NT_STATUS_LDAP(ret
);
410 } else if (r
->count
!= 1) {
412 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
415 s
->dest_dsa
.computer_dn_str
= ldb_msg_find_attr_as_string(r
->msgs
[0], "distinguishedName", NULL
);
416 if (!s
->dest_dsa
.computer_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
417 talloc_steal(s
, s
->dest_dsa
.computer_dn_str
);
419 s
->dest_dsa
.user_account_control
= ldb_msg_find_attr_as_uint(r
->msgs
[0], "userAccountControl", 0);
425 static NTSTATUS
unbecomeDC_ldap_modify_computer(struct libnet_UnbecomeDC_state
*s
)
428 struct ldb_message
*msg
;
429 uint32_t user_account_control
= UF_WORKSTATION_TRUST_ACCOUNT
;
432 /* as the value is already as we want it to be, we're done */
433 if (s
->dest_dsa
.user_account_control
== user_account_control
) {
437 /* make a 'modify' msg, and only for serverReference */
438 msg
= ldb_msg_new(s
);
439 NT_STATUS_HAVE_NO_MEMORY(msg
);
440 msg
->dn
= ldb_dn_new(msg
, s
->ldap
.ldb
, s
->dest_dsa
.computer_dn_str
);
441 NT_STATUS_HAVE_NO_MEMORY(msg
->dn
);
443 ret
= samdb_msg_add_uint(s
->ldap
.ldb
, msg
, msg
, "userAccountControl",
444 user_account_control
);
445 if (ret
!= LDB_SUCCESS
) {
447 return NT_STATUS_NO_MEMORY
;
450 /* mark all the message elements (should be just one)
451 as LDB_FLAG_MOD_REPLACE */
452 for (i
=0;i
<msg
->num_elements
;i
++) {
453 msg
->elements
[i
].flags
= LDB_FLAG_MOD_REPLACE
;
456 ret
= ldb_modify(s
->ldap
.ldb
, msg
);
458 if (ret
!= LDB_SUCCESS
) {
459 return NT_STATUS_LDAP(ret
);
462 s
->dest_dsa
.user_account_control
= user_account_control
;
467 static NTSTATUS
unbecomeDC_ldap_move_computer(struct libnet_UnbecomeDC_state
*s
)
470 struct ldb_result
*r
;
471 struct ldb_dn
*basedn
;
472 struct ldb_dn
*old_dn
;
473 struct ldb_dn
*new_dn
;
474 static const char *_1_1_attrs
[] = {
479 basedn
= ldb_dn_new_fmt(s
, s
->ldap
.ldb
, "<WKGUID=aa312825768811d1aded00c04fd8d5cd,%s>",
481 NT_STATUS_HAVE_NO_MEMORY(basedn
);
483 ret
= ldb_search(s
->ldap
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
,
484 _1_1_attrs
, "(objectClass=*)");
486 if (ret
!= LDB_SUCCESS
) {
487 return NT_STATUS_LDAP(ret
);
488 } else if (r
->count
!= 1) {
490 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
493 old_dn
= ldb_dn_new(r
, s
->ldap
.ldb
, s
->dest_dsa
.computer_dn_str
);
494 NT_STATUS_HAVE_NO_MEMORY(old_dn
);
496 new_dn
= r
->msgs
[0]->dn
;
498 if (!ldb_dn_add_child_fmt(new_dn
, "CN=%s", s
->dest_dsa
.netbios_name
)) {
500 return NT_STATUS_NO_MEMORY
;
503 if (ldb_dn_compare(old_dn
, new_dn
) == 0) {
504 /* we don't need to rename if the old and new dn match */
509 ret
= ldb_rename(s
->ldap
.ldb
, old_dn
, new_dn
);
510 if (ret
!= LDB_SUCCESS
) {
512 return NT_STATUS_LDAP(ret
);
515 s
->dest_dsa
.computer_dn_str
= ldb_dn_alloc_linearized(s
, new_dn
);
516 NT_STATUS_HAVE_NO_MEMORY(s
->dest_dsa
.computer_dn_str
);
523 static void unbecomeDC_drsuapi_connect_send(struct libnet_UnbecomeDC_state
*s
);
525 static void unbecomeDC_connect_ldap(struct libnet_UnbecomeDC_state
*s
)
527 struct composite_context
*c
= s
->creq
;
529 c
->status
= unbecomeDC_ldap_connect(s
);
530 if (!composite_is_ok(c
)) return;
532 c
->status
= unbecomeDC_ldap_rootdse(s
);
533 if (!composite_is_ok(c
)) return;
535 c
->status
= unbecomeDC_ldap_computer_object(s
);
536 if (!composite_is_ok(c
)) return;
538 c
->status
= unbecomeDC_ldap_modify_computer(s
);
539 if (!composite_is_ok(c
)) return;
541 c
->status
= unbecomeDC_ldap_move_computer(s
);
542 if (!composite_is_ok(c
)) return;
544 unbecomeDC_drsuapi_connect_send(s
);
547 static void unbecomeDC_drsuapi_connect_recv(struct composite_context
*creq
);
549 static void unbecomeDC_drsuapi_connect_send(struct libnet_UnbecomeDC_state
*s
)
551 struct composite_context
*c
= s
->creq
;
552 struct composite_context
*creq
;
555 binding_str
= talloc_asprintf(s
, "ncacn_ip_tcp:%s[seal,target_hostname=%s]",
556 s
->source_dsa
.address
,
557 s
->source_dsa
.dns_name
);
558 if (composite_nomem(binding_str
, c
)) return;
560 c
->status
= dcerpc_parse_binding(s
, binding_str
, &s
->drsuapi
.binding
);
561 talloc_free(binding_str
);
562 if (!composite_is_ok(c
)) return;
564 if (DEBUGLEVEL
>= 10) {
565 c
->status
= dcerpc_binding_set_flags(s
->drsuapi
.binding
,
566 DCERPC_DEBUG_PRINT_BOTH
,
568 if (!composite_is_ok(c
)) return;
571 creq
= dcerpc_pipe_connect_b_send(s
, s
->drsuapi
.binding
, &ndr_table_drsuapi
,
572 s
->libnet
->cred
, s
->libnet
->event_ctx
,
574 composite_continue(c
, creq
, unbecomeDC_drsuapi_connect_recv
, s
);
577 static void unbecomeDC_drsuapi_bind_send(struct libnet_UnbecomeDC_state
*s
);
579 static void unbecomeDC_drsuapi_connect_recv(struct composite_context
*req
)
581 struct libnet_UnbecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
582 struct libnet_UnbecomeDC_state
);
583 struct composite_context
*c
= s
->creq
;
585 c
->status
= dcerpc_pipe_connect_b_recv(req
, s
, &s
->drsuapi
.pipe
);
586 if (!composite_is_ok(c
)) return;
588 s
->drsuapi
.drsuapi_handle
= s
->drsuapi
.pipe
->binding_handle
;
590 unbecomeDC_drsuapi_bind_send(s
);
593 static void unbecomeDC_drsuapi_bind_recv(struct tevent_req
*subreq
);
595 static void unbecomeDC_drsuapi_bind_send(struct libnet_UnbecomeDC_state
*s
)
597 struct composite_context
*c
= s
->creq
;
598 struct drsuapi_DsBindInfo28
*bind_info28
;
599 struct tevent_req
*subreq
;
601 GUID_from_string(DRSUAPI_DS_BIND_GUID
, &s
->drsuapi
.bind_guid
);
603 bind_info28
= &s
->drsuapi
.local_info28
;
604 bind_info28
->supported_extensions
= 0;
605 bind_info28
->site_guid
= GUID_zero();
606 bind_info28
->pid
= 0;
607 bind_info28
->repl_epoch
= 0;
609 s
->drsuapi
.bind_info_ctr
.length
= 28;
610 s
->drsuapi
.bind_info_ctr
.info
.info28
= *bind_info28
;
612 s
->drsuapi
.bind_r
.in
.bind_guid
= &s
->drsuapi
.bind_guid
;
613 s
->drsuapi
.bind_r
.in
.bind_info
= &s
->drsuapi
.bind_info_ctr
;
614 s
->drsuapi
.bind_r
.out
.bind_handle
= &s
->drsuapi
.bind_handle
;
616 subreq
= dcerpc_drsuapi_DsBind_r_send(s
, c
->event_ctx
,
617 s
->drsuapi
.drsuapi_handle
,
619 if (composite_nomem(subreq
, c
)) return;
620 tevent_req_set_callback(subreq
, unbecomeDC_drsuapi_bind_recv
, s
);
623 static void unbecomeDC_drsuapi_remove_ds_server_send(struct libnet_UnbecomeDC_state
*s
);
625 static void unbecomeDC_drsuapi_bind_recv(struct tevent_req
*subreq
)
627 struct libnet_UnbecomeDC_state
*s
= tevent_req_callback_data(subreq
,
628 struct libnet_UnbecomeDC_state
);
629 struct composite_context
*c
= s
->creq
;
631 c
->status
= dcerpc_drsuapi_DsBind_r_recv(subreq
, s
);
633 if (!composite_is_ok(c
)) return;
635 if (!W_ERROR_IS_OK(s
->drsuapi
.bind_r
.out
.result
)) {
636 composite_error(c
, werror_to_ntstatus(s
->drsuapi
.bind_r
.out
.result
));
640 ZERO_STRUCT(s
->drsuapi
.remote_info28
);
641 if (s
->drsuapi
.bind_r
.out
.bind_info
) {
642 switch (s
->drsuapi
.bind_r
.out
.bind_info
->length
) {
644 struct drsuapi_DsBindInfo24
*info24
;
645 info24
= &s
->drsuapi
.bind_r
.out
.bind_info
->info
.info24
;
646 s
->drsuapi
.remote_info28
.supported_extensions
= info24
->supported_extensions
;
647 s
->drsuapi
.remote_info28
.site_guid
= info24
->site_guid
;
648 s
->drsuapi
.remote_info28
.pid
= info24
->pid
;
649 s
->drsuapi
.remote_info28
.repl_epoch
= 0;
653 s
->drsuapi
.remote_info28
= s
->drsuapi
.bind_r
.out
.bind_info
->info
.info28
;
657 struct drsuapi_DsBindInfo32
*info32
;
658 info32
= &s
->drsuapi
.bind_r
.out
.bind_info
->info
.info32
;
659 s
->drsuapi
.remote_info28
.supported_extensions
= info32
->supported_extensions
;
660 s
->drsuapi
.remote_info28
.site_guid
= info32
->site_guid
;
661 s
->drsuapi
.remote_info28
.pid
= info32
->pid
;
662 s
->drsuapi
.remote_info28
.repl_epoch
= info32
->repl_epoch
;
666 struct drsuapi_DsBindInfo48
*info48
;
667 info48
= &s
->drsuapi
.bind_r
.out
.bind_info
->info
.info48
;
668 s
->drsuapi
.remote_info28
.supported_extensions
= info48
->supported_extensions
;
669 s
->drsuapi
.remote_info28
.site_guid
= info48
->site_guid
;
670 s
->drsuapi
.remote_info28
.pid
= info48
->pid
;
671 s
->drsuapi
.remote_info28
.repl_epoch
= info48
->repl_epoch
;
675 struct drsuapi_DsBindInfo52
*info52
;
676 info52
= &s
->drsuapi
.bind_r
.out
.bind_info
->info
.info52
;
677 s
->drsuapi
.remote_info28
.supported_extensions
= info52
->supported_extensions
;
678 s
->drsuapi
.remote_info28
.site_guid
= info52
->site_guid
;
679 s
->drsuapi
.remote_info28
.pid
= info52
->pid
;
680 s
->drsuapi
.remote_info28
.repl_epoch
= info52
->repl_epoch
;
684 DEBUG(1, ("Warning: invalid info length in bind info: %d\n",
685 s
->drsuapi
.bind_r
.out
.bind_info
->length
));
690 unbecomeDC_drsuapi_remove_ds_server_send(s
);
693 static void unbecomeDC_drsuapi_remove_ds_server_recv(struct tevent_req
*subreq
);
695 static void unbecomeDC_drsuapi_remove_ds_server_send(struct libnet_UnbecomeDC_state
*s
)
697 struct composite_context
*c
= s
->creq
;
698 struct drsuapi_DsRemoveDSServer
*r
= &s
->drsuapi
.rm_ds_srv_r
;
699 struct tevent_req
*subreq
;
701 r
->in
.bind_handle
= &s
->drsuapi
.bind_handle
;
703 r
->in
.req
= talloc(s
, union drsuapi_DsRemoveDSServerRequest
);
704 r
->in
.req
->req1
.server_dn
= s
->dest_dsa
.server_dn_str
;
705 r
->in
.req
->req1
.domain_dn
= s
->domain
.dn_str
;
706 r
->in
.req
->req1
.commit
= true;
708 r
->out
.level_out
= talloc(s
, uint32_t);
709 r
->out
.res
= talloc(s
, union drsuapi_DsRemoveDSServerResult
);
711 subreq
= dcerpc_drsuapi_DsRemoveDSServer_r_send(s
, c
->event_ctx
,
712 s
->drsuapi
.drsuapi_handle
,
714 if (composite_nomem(subreq
, c
)) return;
715 tevent_req_set_callback(subreq
, unbecomeDC_drsuapi_remove_ds_server_recv
, s
);
718 static void unbecomeDC_drsuapi_remove_ds_server_recv(struct tevent_req
*subreq
)
720 struct libnet_UnbecomeDC_state
*s
= tevent_req_callback_data(subreq
,
721 struct libnet_UnbecomeDC_state
);
722 struct composite_context
*c
= s
->creq
;
723 struct drsuapi_DsRemoveDSServer
*r
= &s
->drsuapi
.rm_ds_srv_r
;
725 c
->status
= dcerpc_drsuapi_DsRemoveDSServer_r_recv(subreq
, s
);
727 if (!composite_is_ok(c
)) return;
729 if (!W_ERROR_IS_OK(r
->out
.result
)) {
730 composite_error(c
, werror_to_ntstatus(r
->out
.result
));
734 if (*r
->out
.level_out
!= 1) {
735 composite_error(c
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
742 struct composite_context
*libnet_UnbecomeDC_send(struct libnet_context
*ctx
, TALLOC_CTX
*mem_ctx
, struct libnet_UnbecomeDC
*r
)
744 struct composite_context
*c
;
745 struct libnet_UnbecomeDC_state
*s
;
748 c
= composite_create(mem_ctx
, ctx
->event_ctx
);
749 if (c
== NULL
) return NULL
;
751 s
= talloc_zero(c
, struct libnet_UnbecomeDC_state
);
752 if (composite_nomem(s
, c
)) return c
;
758 s
->domain
.dns_name
= talloc_strdup(s
, r
->in
.domain_dns_name
);
759 if (composite_nomem(s
->domain
.dns_name
, c
)) return c
;
760 s
->domain
.netbios_name
= talloc_strdup(s
, r
->in
.domain_netbios_name
);
761 if (composite_nomem(s
->domain
.netbios_name
, c
)) return c
;
763 /* Source DSA input */
764 s
->source_dsa
.address
= talloc_strdup(s
, r
->in
.source_dsa_address
);
765 if (composite_nomem(s
->source_dsa
.address
, c
)) return c
;
767 /* Destination DSA input */
768 s
->dest_dsa
.netbios_name
= talloc_strdup(s
, r
->in
.dest_dsa_netbios_name
);
769 if (composite_nomem(s
->dest_dsa
.netbios_name
, c
)) return c
;
771 /* Destination DSA dns_name construction */
772 tmp_name
= strlower_talloc(s
, s
->dest_dsa
.netbios_name
);
773 if (composite_nomem(tmp_name
, c
)) return c
;
774 s
->dest_dsa
.dns_name
= talloc_asprintf_append_buffer(tmp_name
, ".%s",
776 if (composite_nomem(s
->dest_dsa
.dns_name
, c
)) return c
;
778 unbecomeDC_send_cldap(s
);
782 NTSTATUS
libnet_UnbecomeDC_recv(struct composite_context
*c
, TALLOC_CTX
*mem_ctx
, struct libnet_UnbecomeDC
*r
)
786 status
= composite_wait(c
);
794 NTSTATUS
libnet_UnbecomeDC(struct libnet_context
*ctx
, TALLOC_CTX
*mem_ctx
, struct libnet_UnbecomeDC
*r
)
797 struct composite_context
*c
;
798 c
= libnet_UnbecomeDC_send(ctx
, mem_ctx
, r
);
799 status
= libnet_UnbecomeDC_recv(c
, mem_ctx
, r
);