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 "lib/ldb/include/ldb.h"
25 #include "lib/ldb/include/ldb_errors.h"
26 #include "lib/ldb_wrap.h"
27 #include "dsdb/samdb/samdb.h"
28 #include "dsdb/common/flags.h"
29 #include "librpc/gen_ndr/ndr_drsuapi_c.h"
30 #include "param/param.h"
32 /*****************************************************************************
33 * Windows 2003 (w2k3) does the following steps when changing the server role
34 * from domain controller back to domain member
36 * We mostly do the same.
37 *****************************************************************************/
41 * - using nbt name<1C> request and a samlogon mailslot request
43 * - using a DNS SRV _ldap._tcp.dc._msdcs. request and a CLDAP netlogon request
45 * see: unbecomeDC_send_cldap() and unbecomeDC_recv_cldap()
49 * Open 1st LDAP connection to the DC using admin credentials
51 * see: unbecomeDC_ldap_connect()
55 * LDAP search 1st LDAP connection:
57 * see: unbecomeDC_ldap_rootdse()
62 * filter: (objectClass=*)
63 * attrs: defaultNamingContext
64 * configurationNamingContext
67 * defaultNamingContext: <domain_partition>
68 * configurationNamingContext:CN=Configuration,<domain_partition>
72 * LDAP search 1st LDAP connection:
74 * see: unbecomeDC_ldap_computer_object()
77 * basedn: <domain_partition>
79 * filter: (&(|(objectClass=user)(objectClass=computer))(sAMAccountName=<new_dc_account_name>))
80 * attrs: distinguishedName
83 * CN=<new_dc_netbios_name>,CN=Domain Controllers,<domain_partition>
84 * distinguishedName: CN=<new_dc_netbios_name>,CN=Domain Controllers,<domain_partition>
85 * userAccoountControl: 532480 <0x82000>
89 * LDAP search 1st LDAP connection:
91 * see: unbecomeDC_ldap_modify_computer()
94 * basedn: CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
96 * filter: (objectClass=*)
97 * attrs: userAccountControl
99 * CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
100 * userAccoountControl: 532480 <0x82000>
104 * LDAP modify 1st LDAP connection:
106 * see: unbecomeDC_ldap_modify_computer()
109 * CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
110 * userAccoountControl: 4096 <0x1000>
116 * LDAP search 1st LDAP connection:
118 * see: unbecomeDC_ldap_move_computer()
121 * basedn: <WKGUID=aa312825768811d1aded00c04fd8d5cd,<domain_partition>>
123 * filter: (objectClass=*)
126 * CN=Computers,<domain_partition>
130 * LDAP search 1st LDAP connection:
132 * not implemented because it doesn't give any new information
135 * basedn: CN=Computers,<domain_partition>
137 * filter: (objectClass=*)
138 * attrs: distinguishedName
140 * CN=Computers,<domain_partition>
141 * distinguishedName: CN=Computers,<domain_partition>
145 * LDAP modifyRDN 1st LDAP connection:
147 * see: unbecomeDC_ldap_move_computer()
150 * entry: CN=<new_dc_netbios_name>,CN=Domain Controllers,<domain_partition>
151 * newrdn: CN=<new_dc_netbios_name>
153 * newparent: CN=Computers,<domain_partition>
159 * LDAP unbind on the 1st LDAP connection
161 * not implemented, because it's not needed...
165 * Open 1st DRSUAPI connection to the DC using admin credentials
166 * DsBind with DRSUAPI_DS_BIND_GUID ("e24d201a-4fd6-11d1-a3da-0000f875ae0d")
168 * see: unbecomeDC_drsuapi_connect_send(), unbecomeDC_drsuapi_connect_recv(),
169 * unbecomeDC_drsuapi_bind_send() and unbecomeDC_drsuapi_bind_recv()
173 * DsRemoveDsServer to remove the
174 * CN=<machine_name>,CN=Servers,CN=<site_name>,CN=Configuration,<domain_partition>
175 * and CN=NTDS Settings,CN=<machine_name>,CN=Servers,CN=<site_name>,CN=Configuration,<domain_partition>
176 * on the 1st DRSUAPI connection
178 * see: unbecomeDC_drsuapi_remove_ds_server_send() and unbecomeDC_drsuapi_remove_ds_server_recv()
182 * DsUnbind on the 1st DRSUAPI connection
184 * not implemented, because it's not needed...
188 struct libnet_UnbecomeDC_state
{
189 struct composite_context
*creq
;
191 struct libnet_context
*libnet
;
194 struct cldap_socket
*sock
;
195 struct cldap_netlogon io
;
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 drsuapi_DsBind bind_r
;
207 struct GUID bind_guid
;
208 struct drsuapi_DsBindInfoCtr bind_info_ctr
;
209 struct drsuapi_DsBindInfo28 local_info28
;
210 struct drsuapi_DsBindInfo28 remote_info28
;
211 struct policy_handle bind_handle
;
212 struct drsuapi_DsRemoveDSServer rm_ds_srv_r
;
217 const char *dns_name
;
218 const char *netbios_name
;
227 const char *config_dn_str
;
235 const char *dns_name
;
236 const char *netbios_name
;
237 const char *site_name
;
242 const char *netbios_name
;
245 const char *dns_name
;
246 const char *site_name
;
247 const char *computer_dn_str
;
248 const char *server_dn_str
;
249 uint32_t user_account_control
;
253 static void unbecomeDC_recv_cldap(struct cldap_request
*req
);
255 static void unbecomeDC_send_cldap(struct libnet_UnbecomeDC_state
*s
)
257 struct composite_context
*c
= s
->creq
;
258 struct cldap_request
*req
;
260 s
->cldap
.io
.in
.dest_address
= s
->source_dsa
.address
;
261 s
->cldap
.io
.in
.dest_port
= lp_cldap_port(s
->libnet
->lp_ctx
);
262 s
->cldap
.io
.in
.realm
= s
->domain
.dns_name
;
263 s
->cldap
.io
.in
.host
= s
->dest_dsa
.netbios_name
;
264 s
->cldap
.io
.in
.user
= NULL
;
265 s
->cldap
.io
.in
.domain_guid
= NULL
;
266 s
->cldap
.io
.in
.domain_sid
= NULL
;
267 s
->cldap
.io
.in
.acct_control
= -1;
268 s
->cldap
.io
.in
.version
= NETLOGON_NT_VERSION_5
| NETLOGON_NT_VERSION_5EX
;
269 s
->cldap
.io
.in
.map_response
= true;
271 s
->cldap
.sock
= cldap_socket_init(s
, s
->libnet
->event_ctx
,
272 lp_iconv_convenience(s
->libnet
->lp_ctx
));
273 if (composite_nomem(s
->cldap
.sock
, c
)) return;
275 req
= cldap_netlogon_send(s
->cldap
.sock
, &s
->cldap
.io
);
276 if (composite_nomem(req
, c
)) return;
277 req
->async
.fn
= unbecomeDC_recv_cldap
;
278 req
->async
.private = s
;
281 static void unbecomeDC_connect_ldap(struct libnet_UnbecomeDC_state
*s
);
283 static void unbecomeDC_recv_cldap(struct cldap_request
*req
)
285 struct libnet_UnbecomeDC_state
*s
= talloc_get_type(req
->async
.private,
286 struct libnet_UnbecomeDC_state
);
287 struct composite_context
*c
= s
->creq
;
289 c
->status
= cldap_netlogon_recv(req
, s
, &s
->cldap
.io
);
290 if (!composite_is_ok(c
)) return;
292 s
->cldap
.netlogon
= s
->cldap
.io
.out
.netlogon
.data
.nt5_ex
;
294 s
->domain
.dns_name
= s
->cldap
.netlogon
.dns_domain
;
295 s
->domain
.netbios_name
= s
->cldap
.netlogon
.domain
;
296 s
->domain
.guid
= s
->cldap
.netlogon
.domain_uuid
;
298 s
->source_dsa
.dns_name
= s
->cldap
.netlogon
.pdc_dns_name
;
299 s
->source_dsa
.netbios_name
= s
->cldap
.netlogon
.pdc_name
;
300 s
->source_dsa
.site_name
= s
->cldap
.netlogon
.server_site
;
302 s
->dest_dsa
.site_name
= s
->cldap
.netlogon
.client_site
;
304 unbecomeDC_connect_ldap(s
);
307 static NTSTATUS
unbecomeDC_ldap_connect(struct libnet_UnbecomeDC_state
*s
)
311 url
= talloc_asprintf(s
, "ldap://%s/", s
->source_dsa
.dns_name
);
312 NT_STATUS_HAVE_NO_MEMORY(url
);
314 s
->ldap
.ldb
= ldb_wrap_connect(s
, s
->libnet
->event_ctx
, s
->libnet
->lp_ctx
, url
,
319 if (s
->ldap
.ldb
== NULL
) {
320 return NT_STATUS_UNEXPECTED_NETWORK_ERROR
;
326 static NTSTATUS
unbecomeDC_ldap_rootdse(struct libnet_UnbecomeDC_state
*s
)
329 struct ldb_result
*r
;
330 struct ldb_dn
*basedn
;
331 static const char *attrs
[] = {
332 "defaultNamingContext",
333 "configurationNamingContext",
337 basedn
= ldb_dn_new(s
, s
->ldap
.ldb
, NULL
);
338 NT_STATUS_HAVE_NO_MEMORY(basedn
);
340 ret
= ldb_search(s
->ldap
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
, attrs
,
343 if (ret
!= LDB_SUCCESS
) {
344 return NT_STATUS_LDAP(ret
);
345 } else if (r
->count
!= 1) {
347 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
350 s
->domain
.dn_str
= ldb_msg_find_attr_as_string(r
->msgs
[0], "defaultNamingContext", NULL
);
351 if (!s
->domain
.dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
352 talloc_steal(s
, s
->domain
.dn_str
);
354 s
->forest
.config_dn_str
= ldb_msg_find_attr_as_string(r
->msgs
[0], "configurationNamingContext", NULL
);
355 if (!s
->forest
.config_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
356 talloc_steal(s
, s
->forest
.config_dn_str
);
358 s
->dest_dsa
.server_dn_str
= talloc_asprintf(s
, "CN=%s,CN=Servers,CN=%s,CN=Sites,%s",
359 s
->dest_dsa
.netbios_name
,
360 s
->dest_dsa
.site_name
,
361 s
->forest
.config_dn_str
);
362 NT_STATUS_HAVE_NO_MEMORY(s
->dest_dsa
.server_dn_str
);
368 static NTSTATUS
unbecomeDC_ldap_computer_object(struct libnet_UnbecomeDC_state
*s
)
371 struct ldb_result
*r
;
372 struct ldb_dn
*basedn
;
373 static const char *attrs
[] = {
375 "userAccountControl",
379 basedn
= ldb_dn_new(s
, s
->ldap
.ldb
, s
->domain
.dn_str
);
380 NT_STATUS_HAVE_NO_MEMORY(basedn
);
382 ret
= ldb_search(s
->ldap
.ldb
, s
, &r
, basedn
, LDB_SCOPE_SUBTREE
, attrs
,
383 "(&(|(objectClass=user)(objectClass=computer))(sAMAccountName=%s$))",
384 s
->dest_dsa
.netbios_name
);
386 if (ret
!= LDB_SUCCESS
) {
387 return NT_STATUS_LDAP(ret
);
388 } else if (r
->count
!= 1) {
390 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
393 s
->dest_dsa
.computer_dn_str
= samdb_result_string(r
->msgs
[0], "distinguishedName", NULL
);
394 if (!s
->dest_dsa
.computer_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
395 talloc_steal(s
, s
->dest_dsa
.computer_dn_str
);
397 s
->dest_dsa
.user_account_control
= samdb_result_uint(r
->msgs
[0], "userAccountControl", 0);
403 static NTSTATUS
unbecomeDC_ldap_modify_computer(struct libnet_UnbecomeDC_state
*s
)
406 struct ldb_message
*msg
;
407 uint32_t user_account_control
= UF_WORKSTATION_TRUST_ACCOUNT
;
410 /* as the value is already as we want it to be, we're done */
411 if (s
->dest_dsa
.user_account_control
== user_account_control
) {
415 /* make a 'modify' msg, and only for serverReference */
416 msg
= ldb_msg_new(s
);
417 NT_STATUS_HAVE_NO_MEMORY(msg
);
418 msg
->dn
= ldb_dn_new(msg
, s
->ldap
.ldb
, s
->dest_dsa
.computer_dn_str
);
419 NT_STATUS_HAVE_NO_MEMORY(msg
->dn
);
421 ret
= ldb_msg_add_fmt(msg
, "userAccountControl", "%u", user_account_control
);
424 return NT_STATUS_NO_MEMORY
;
427 /* mark all the message elements (should be just one)
428 as LDB_FLAG_MOD_REPLACE */
429 for (i
=0;i
<msg
->num_elements
;i
++) {
430 msg
->elements
[i
].flags
= LDB_FLAG_MOD_REPLACE
;
433 ret
= ldb_modify(s
->ldap
.ldb
, msg
);
435 if (ret
!= LDB_SUCCESS
) {
436 return NT_STATUS_LDAP(ret
);
439 s
->dest_dsa
.user_account_control
= user_account_control
;
444 static NTSTATUS
unbecomeDC_ldap_move_computer(struct libnet_UnbecomeDC_state
*s
)
447 struct ldb_result
*r
;
448 struct ldb_dn
*basedn
;
449 struct ldb_dn
*old_dn
;
450 struct ldb_dn
*new_dn
;
451 static const char *_1_1_attrs
[] = {
456 basedn
= ldb_dn_new_fmt(s
, s
->ldap
.ldb
, "<WKGUID=aa312825768811d1aded00c04fd8d5cd,%s>",
458 NT_STATUS_HAVE_NO_MEMORY(basedn
);
460 ret
= ldb_search(s
->ldap
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
,
461 _1_1_attrs
, "(objectClass=*)");
463 if (ret
!= LDB_SUCCESS
) {
464 return NT_STATUS_LDAP(ret
);
465 } else if (r
->count
!= 1) {
467 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
470 old_dn
= ldb_dn_new(r
, s
->ldap
.ldb
, s
->dest_dsa
.computer_dn_str
);
471 NT_STATUS_HAVE_NO_MEMORY(old_dn
);
473 new_dn
= r
->msgs
[0]->dn
;
475 if (!ldb_dn_add_child_fmt(new_dn
, "CN=%s", s
->dest_dsa
.netbios_name
)) {
477 return NT_STATUS_NO_MEMORY
;
480 if (ldb_dn_compare(old_dn
, new_dn
) == 0) {
481 /* we don't need to rename if the old and new dn match */
486 ret
= ldb_rename(s
->ldap
.ldb
, old_dn
, new_dn
);
487 if (ret
!= LDB_SUCCESS
) {
489 return NT_STATUS_LDAP(ret
);
492 s
->dest_dsa
.computer_dn_str
= ldb_dn_alloc_linearized(s
, new_dn
);
493 NT_STATUS_HAVE_NO_MEMORY(s
->dest_dsa
.computer_dn_str
);
500 static void unbecomeDC_drsuapi_connect_send(struct libnet_UnbecomeDC_state
*s
);
502 static void unbecomeDC_connect_ldap(struct libnet_UnbecomeDC_state
*s
)
504 struct composite_context
*c
= s
->creq
;
506 c
->status
= unbecomeDC_ldap_connect(s
);
507 if (!composite_is_ok(c
)) return;
509 c
->status
= unbecomeDC_ldap_rootdse(s
);
510 if (!composite_is_ok(c
)) return;
512 c
->status
= unbecomeDC_ldap_computer_object(s
);
513 if (!composite_is_ok(c
)) return;
515 c
->status
= unbecomeDC_ldap_modify_computer(s
);
516 if (!composite_is_ok(c
)) return;
518 c
->status
= unbecomeDC_ldap_move_computer(s
);
519 if (!composite_is_ok(c
)) return;
521 unbecomeDC_drsuapi_connect_send(s
);
524 static void unbecomeDC_drsuapi_connect_recv(struct composite_context
*creq
);
526 static void unbecomeDC_drsuapi_connect_send(struct libnet_UnbecomeDC_state
*s
)
528 struct composite_context
*c
= s
->creq
;
529 struct composite_context
*creq
;
532 binding_str
= talloc_asprintf(s
, "ncacn_ip_tcp:%s[seal]", s
->source_dsa
.dns_name
);
533 if (composite_nomem(binding_str
, c
)) return;
535 c
->status
= dcerpc_parse_binding(s
, binding_str
, &s
->drsuapi
.binding
);
536 talloc_free(binding_str
);
537 if (!composite_is_ok(c
)) return;
539 creq
= dcerpc_pipe_connect_b_send(s
, s
->drsuapi
.binding
, &ndr_table_drsuapi
,
540 s
->libnet
->cred
, s
->libnet
->event_ctx
,
542 composite_continue(c
, creq
, unbecomeDC_drsuapi_connect_recv
, s
);
545 static void unbecomeDC_drsuapi_bind_send(struct libnet_UnbecomeDC_state
*s
);
547 static void unbecomeDC_drsuapi_connect_recv(struct composite_context
*req
)
549 struct libnet_UnbecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
550 struct libnet_UnbecomeDC_state
);
551 struct composite_context
*c
= s
->creq
;
553 c
->status
= dcerpc_pipe_connect_b_recv(req
, s
, &s
->drsuapi
.pipe
);
554 if (!composite_is_ok(c
)) return;
556 unbecomeDC_drsuapi_bind_send(s
);
559 static void unbecomeDC_drsuapi_bind_recv(struct rpc_request
*req
);
561 static void unbecomeDC_drsuapi_bind_send(struct libnet_UnbecomeDC_state
*s
)
563 struct composite_context
*c
= s
->creq
;
564 struct rpc_request
*req
;
565 struct drsuapi_DsBindInfo28
*bind_info28
;
567 GUID_from_string(DRSUAPI_DS_BIND_GUID
, &s
->drsuapi
.bind_guid
);
569 bind_info28
= &s
->drsuapi
.local_info28
;
570 bind_info28
->supported_extensions
= 0;
571 bind_info28
->site_guid
= GUID_zero();
572 bind_info28
->pid
= 0;
573 bind_info28
->repl_epoch
= 0;
575 s
->drsuapi
.bind_info_ctr
.length
= 28;
576 s
->drsuapi
.bind_info_ctr
.info
.info28
= *bind_info28
;
578 s
->drsuapi
.bind_r
.in
.bind_guid
= &s
->drsuapi
.bind_guid
;
579 s
->drsuapi
.bind_r
.in
.bind_info
= &s
->drsuapi
.bind_info_ctr
;
580 s
->drsuapi
.bind_r
.out
.bind_handle
= &s
->drsuapi
.bind_handle
;
582 req
= dcerpc_drsuapi_DsBind_send(s
->drsuapi
.pipe
, s
, &s
->drsuapi
.bind_r
);
583 composite_continue_rpc(c
, req
, unbecomeDC_drsuapi_bind_recv
, s
);
586 static void unbecomeDC_drsuapi_remove_ds_server_send(struct libnet_UnbecomeDC_state
*s
);
588 static void unbecomeDC_drsuapi_bind_recv(struct rpc_request
*req
)
590 struct libnet_UnbecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
591 struct libnet_UnbecomeDC_state
);
592 struct composite_context
*c
= s
->creq
;
594 c
->status
= dcerpc_ndr_request_recv(req
);
595 if (!composite_is_ok(c
)) return;
597 if (!W_ERROR_IS_OK(s
->drsuapi
.bind_r
.out
.result
)) {
598 composite_error(c
, werror_to_ntstatus(s
->drsuapi
.bind_r
.out
.result
));
602 ZERO_STRUCT(s
->drsuapi
.remote_info28
);
603 if (s
->drsuapi
.bind_r
.out
.bind_info
) {
604 switch (s
->drsuapi
.bind_r
.out
.bind_info
->length
) {
606 struct drsuapi_DsBindInfo24
*info24
;
607 info24
= &s
->drsuapi
.bind_r
.out
.bind_info
->info
.info24
;
608 s
->drsuapi
.remote_info28
.supported_extensions
= info24
->supported_extensions
;
609 s
->drsuapi
.remote_info28
.site_guid
= info24
->site_guid
;
610 s
->drsuapi
.remote_info28
.pid
= info24
->pid
;
611 s
->drsuapi
.remote_info28
.repl_epoch
= 0;
615 struct drsuapi_DsBindInfo48
*info48
;
616 info48
= &s
->drsuapi
.bind_r
.out
.bind_info
->info
.info48
;
617 s
->drsuapi
.remote_info28
.supported_extensions
= info48
->supported_extensions
;
618 s
->drsuapi
.remote_info28
.site_guid
= info48
->site_guid
;
619 s
->drsuapi
.remote_info28
.pid
= info48
->pid
;
620 s
->drsuapi
.remote_info28
.repl_epoch
= info48
->repl_epoch
;
624 s
->drsuapi
.remote_info28
= s
->drsuapi
.bind_r
.out
.bind_info
->info
.info28
;
629 unbecomeDC_drsuapi_remove_ds_server_send(s
);
632 static void unbecomeDC_drsuapi_remove_ds_server_recv(struct rpc_request
*req
);
634 static void unbecomeDC_drsuapi_remove_ds_server_send(struct libnet_UnbecomeDC_state
*s
)
636 struct composite_context
*c
= s
->creq
;
637 struct rpc_request
*req
;
638 struct drsuapi_DsRemoveDSServer
*r
= &s
->drsuapi
.rm_ds_srv_r
;
640 r
->in
.bind_handle
= &s
->drsuapi
.bind_handle
;
642 r
->in
.req
= talloc(s
, union drsuapi_DsRemoveDSServerRequest
);
643 r
->in
.req
->req1
.server_dn
= s
->dest_dsa
.server_dn_str
;
644 r
->in
.req
->req1
.domain_dn
= s
->domain
.dn_str
;
645 r
->in
.req
->req1
.commit
= true;
647 r
->out
.level_out
= talloc(s
, int32_t);
648 r
->out
.res
= talloc(s
, union drsuapi_DsRemoveDSServerResult
);
650 req
= dcerpc_drsuapi_DsRemoveDSServer_send(s
->drsuapi
.pipe
, s
, r
);
651 composite_continue_rpc(c
, req
, unbecomeDC_drsuapi_remove_ds_server_recv
, s
);
654 static void unbecomeDC_drsuapi_remove_ds_server_recv(struct rpc_request
*req
)
656 struct libnet_UnbecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
657 struct libnet_UnbecomeDC_state
);
658 struct composite_context
*c
= s
->creq
;
659 struct drsuapi_DsRemoveDSServer
*r
= &s
->drsuapi
.rm_ds_srv_r
;
661 c
->status
= dcerpc_ndr_request_recv(req
);
662 if (!composite_is_ok(c
)) return;
664 if (!W_ERROR_IS_OK(r
->out
.result
)) {
665 composite_error(c
, werror_to_ntstatus(r
->out
.result
));
669 if (*r
->out
.level_out
!= 1) {
670 composite_error(c
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
677 struct composite_context
*libnet_UnbecomeDC_send(struct libnet_context
*ctx
, TALLOC_CTX
*mem_ctx
, struct libnet_UnbecomeDC
*r
)
679 struct composite_context
*c
;
680 struct libnet_UnbecomeDC_state
*s
;
683 c
= composite_create(mem_ctx
, ctx
->event_ctx
);
684 if (c
== NULL
) return NULL
;
686 s
= talloc_zero(c
, struct libnet_UnbecomeDC_state
);
687 if (composite_nomem(s
, c
)) return c
;
693 s
->domain
.dns_name
= talloc_strdup(s
, r
->in
.domain_dns_name
);
694 if (composite_nomem(s
->domain
.dns_name
, c
)) return c
;
695 s
->domain
.netbios_name
= talloc_strdup(s
, r
->in
.domain_netbios_name
);
696 if (composite_nomem(s
->domain
.netbios_name
, c
)) return c
;
698 /* Source DSA input */
699 s
->source_dsa
.address
= talloc_strdup(s
, r
->in
.source_dsa_address
);
700 if (composite_nomem(s
->source_dsa
.address
, c
)) return c
;
702 /* Destination DSA input */
703 s
->dest_dsa
.netbios_name
= talloc_strdup(s
, r
->in
.dest_dsa_netbios_name
);
704 if (composite_nomem(s
->dest_dsa
.netbios_name
, c
)) return c
;
706 /* Destination DSA dns_name construction */
707 tmp_name
= strlower_talloc(s
, s
->dest_dsa
.netbios_name
);
708 if (composite_nomem(tmp_name
, c
)) return c
;
709 s
->dest_dsa
.dns_name
= talloc_asprintf_append_buffer(tmp_name
, ".%s",
711 if (composite_nomem(s
->dest_dsa
.dns_name
, c
)) return c
;
713 unbecomeDC_send_cldap(s
);
717 NTSTATUS
libnet_UnbecomeDC_recv(struct composite_context
*c
, TALLOC_CTX
*mem_ctx
, struct libnet_UnbecomeDC
*r
)
721 status
= composite_wait(c
);
729 NTSTATUS
libnet_UnbecomeDC(struct libnet_context
*ctx
, TALLOC_CTX
*mem_ctx
, struct libnet_UnbecomeDC
*r
)
732 struct composite_context
*c
;
733 c
= libnet_UnbecomeDC_send(ctx
, mem_ctx
, r
);
734 status
= libnet_UnbecomeDC_recv(c
, mem_ctx
, r
);