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 "../libds/common/flags.h"
29 #include "librpc/gen_ndr/ndr_drsuapi_c.h"
30 #include "libcli/security/security.h"
31 #include "librpc/gen_ndr/ndr_misc.h"
32 #include "librpc/gen_ndr/ndr_security.h"
33 #include "librpc/gen_ndr/ndr_nbt.h"
34 #include "librpc/gen_ndr/ndr_drsuapi.h"
35 #include "auth/gensec/gensec.h"
36 #include "param/param.h"
37 #include "lib/tsocket/tsocket.h"
39 /*****************************************************************************
40 * Windows 2003 (w2k3) does the following steps when changing the server role
41 * from domain member to domain controller
43 * We mostly do the same.
44 *****************************************************************************/
48 * - using nbt name<1C> request and a samlogon mailslot request
50 * - using a DNS SRV _ldap._tcp.dc._msdcs. request and a CLDAP netlogon request
52 * see: becomeDC_recv_cldap() and becomeDC_send_cldap()
56 * Open 1st LDAP connection to the DC using admin credentials
58 * see: becomeDC_connect_ldap1() and becomeDC_ldap_connect()
62 * LDAP search 1st LDAP connection:
64 * see: becomeDC_ldap1_rootdse()
69 * filter: (objectClass=*)
73 * currentTime: 20061202155100.0Z
74 * subschemaSubentry: CN=Aggregate,CN=Schema,CN=Configuration,<domain_partition>
75 * dsServiceName: CN=<netbios_name>,CN=Servers,CN=<site_name>,CN=Sites,CN=Configuration,<domain_partition>
76 * namingContexts: <domain_partition>
77 * CN=Configuration,<domain_partition>
78 * CN=Schema,CN=Configuration,<domain_partition>
79 * defaultNamingContext: <domain_partition>
80 * schemaNamingContext: CN=Schema,CN=Configuration,<domain_partition>
81 * configurationNamingContext:CN=Configuration,<domain_partition>
82 * rootDomainNamingContext:<domain_partition>
83 * supportedControl: ...
84 * supportedLDAPVersion: 3
86 * supportedLDAPPolicies: ...
87 * highestCommitedUSN: ...
88 * supportedSASLMechanisms:GSSAPI
92 * dnsHostName: <dns_host_name>
93 * ldapServiceName: <domain_dns_name>:<netbios_name>$@<REALM>
94 * serverName: CN=Servers,CN=<site_name>,CN=Sites,CN=Configuration,<domain_partition>
95 * supportedCapabilities: ...
97 * isGlobalCatalogReady: TRUE
98 * domainFunctionality: 0
99 * forestFunctionality: 0
100 * domainControllerFunctionality: 2
104 * LDAP search 1st LDAP connection:
106 * see: becomeDC_ldap1_crossref_behavior_version()
109 * basedn: CN=Configuration,<domain_partition>
111 * filter: (cn=Partitions)
112 * attrs: msDS-Behavior-Version
114 * CN=Partitions,CN=Configuration,<domain_partition>
115 * msDS-Behavior-Version: 0
119 * LDAP search 1st LDAP connection:
121 * NOTE: this seems to be a bug! as the messageID of the LDAP message is corrupted!
123 * not implemented here
126 * basedn: CN=Schema,CN=Configuration,<domain_partition>
128 * filter: (cn=Partitions)
129 * attrs: msDS-Behavior-Version
136 * LDAP search 1st LDAP connection:
138 * see: becomeDC_ldap1_domain_behavior_version()
141 * basedn: <domain_partition>
143 * filter: (objectClass=*)
144 * attrs: msDS-Behavior-Version
147 * msDS-Behavior-Version: 0
151 * LDAP search 1st LDAP connection:
153 * see: becomeDC_ldap1_schema_object_version()
156 * basedn: CN=Schema,CN=Configuration,<domain_partition>
158 * filter: (objectClass=*)
159 * attrs: objectVersion
161 * CN=Schema,CN=Configuration,<domain_partition>
166 * LDAP search 1st LDAP connection:
168 * not implemented, because the information is already there
173 * filter: (objectClass=*)
174 * attrs: defaultNamingContext
178 * defaultNamingContext: <domain_partition>
179 * dnsHostName: <dns_host_name>
183 * LDAP search 1st LDAP connection:
185 * see: becomeDC_ldap1_infrastructure_fsmo()
188 * basedn: <WKGUID=2fbac1870ade11d297c400c04fd8d5cd,domain_partition>
190 * filter: (objectClass=*)
193 * CN=Infrastructure,<domain_partition>
197 * LDAP search 1st LDAP connection:
199 * see: becomeDC_ldap1_w2k3_update_revision()
202 * basedn: CN=Windows2003Update,CN=DomainUpdates,CN=System,<domain_partition>
204 * filter: (objectClass=*)
207 * CN=Windows2003Update,CN=DomainUpdates,CN=System,<domain_partition>
212 * LDAP search 1st LDAP connection:
214 * see: becomeDC_ldap1_infrastructure_fsmo()
217 * basedn: CN=Infrastructure,<domain_partition>
219 * filter: (objectClass=*)
220 * attrs: fSMORoleOwner
222 * CN=Infrastructure,<domain_partition>
223 * fSMORoleOwner: CN=NTDS Settings,<infrastructure_fsmo_server_object>
227 * LDAP search 1st LDAP connection:
229 * see: becomeDC_ldap1_infrastructure_fsmo()
232 * basedn: <infrastructure_fsmo_server_object>
234 * filter: (objectClass=*)
237 * <infrastructure_fsmo_server_object>
238 * dnsHostName: <dns_host_name>
242 * LDAP search 1st LDAP connection:
244 * see: becomeDC_ldap1_infrastructure_fsmo()
247 * basedn: CN=NTDS Settings,<infrastructure_fsmo_server_object>
249 * filter: (objectClass=*)
252 * CN=NTDS Settings,<infrastructure_fsmo_server_object>
253 * objectGUID: <object_guid>
257 * LDAP search 1st LDAP connection:
259 * see: becomeDC_ldap1_rid_manager_fsmo()
262 * basedn: <domain_partition>
264 * filter: (objectClass=*)
265 * attrs: rIDManagerReference
268 * rIDManagerReference: CN=RID Manager$,CN=System,<domain_partition>
272 * LDAP search 1st LDAP connection:
274 * see: becomeDC_ldap1_rid_manager_fsmo()
277 * basedn: CN=RID Manager$,CN=System,<domain_partition>
279 * filter: (objectClass=*)
280 * attrs: fSMORoleOwner
282 * CN=Infrastructure,<domain_partition>
283 * fSMORoleOwner: CN=NTDS Settings,<rid_manager_fsmo_server_object>
287 * LDAP search 1st LDAP connection:
289 * see: becomeDC_ldap1_rid_manager_fsmo()
292 * basedn: <rid_manager_fsmo_server_object>
294 * filter: (objectClass=*)
297 * <rid_manager_fsmo_server_object>
298 * dnsHostName: <dns_host_name>
302 * LDAP search 1st LDAP connection:
304 * see: becomeDC_ldap1_rid_manager_fsmo()
307 * basedn: CN=NTDS Settings,<rid_manager_fsmo_server_object>
309 * filter: (objectClass=*)
310 * attrs: msDs-ReplicationEpoch
312 * CN=NTDS Settings,<rid_manager_fsmo_server_object>
316 * LDAP search 1st LDAP connection:
318 * see: becomeDC_ldap1_site_object()
321 * basedn: CN=<new_dc_site_name>,CN=Sites,CN=Configuration,<domain_partition>
323 * filter: (objectClass=*)
326 * CN=<new_dc_site_name>,CN=Sites,CN=Configuration,<domain_partition>
329 * cn: <new_dc_site_name>
330 * distinguishedName:CN=<new_dc_site_name>,CN=Sites,CN=Configuration,<domain_partition>
336 * showInAdvancedViewOnly: TRUE
337 * name: <new_dc_site_name>
338 * objectGUID: <object_guid>
339 * systemFlags: 1107296256 <0x42000000>
340 * objectCategory: CN=Site,CN=Schema,CN=Configuration,<domain_partition>
343 /***************************************************************
344 * Add this stage we call the check_options() callback function
345 * of the caller, to see if he wants us to continue
347 * see: becomeDC_check_options()
348 ***************************************************************/
351 * LDAP search 1st LDAP connection:
353 * see: becomeDC_ldap1_computer_object()
356 * basedn: <domain_partition>
358 * filter: (&(|(objectClass=user)(objectClass=computer))(sAMAccountName=<new_dc_account_name>))
359 * attrs: distinguishedName
362 * CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
363 * distinguishedName: CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
364 * userAccoountControl: 4096 <0x1000>
368 * LDAP search 1st LDAP connection:
370 * see: becomeDC_ldap1_server_object_1()
373 * basedn: CN=<new_dc_netbios_name>,CN=Servers,CN=<new_dc_site_name>,CN=Sites,CN=Configuration,<domain_partition>
375 * filter: (objectClass=*)
379 * <matchedDN:CN=Servers,CN=<new_dc_site_name>,CN=Sites,CN=Configuration,<domain_partition>>
383 * LDAP search 1st LDAP connection:
385 * see: becomeDC_ldap1_server_object_2()
388 * basedn: CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
390 * filter: (objectClass=*)
391 * attrs: serverReferenceBL
394 * CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
398 * LDAP add 1st LDAP connection:
400 * see: becomeDC_ldap1_server_object_add()
403 * CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
404 * objectClass: server
405 * systemFlags: 50000000 <0x2FAF080>
406 * serverReference:CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
412 * LDAP search 1st LDAP connection:
414 * not implemented, maybe we can add that later
417 * basedn: CN=NTDS Settings,CN=<new_dc_netbios_name>,CN=Servers,CN=<new_dc_site_name>,CN=Sites,CN=Configuration,<domain_partition>
419 * filter: (objectClass=*)
423 * <matchedDN:CN=<new_dc_netbios_name>,CN=Servers,CN=<new_dc_site_name>,CN=Sites,CN=Configuration,<domain_partition>>
427 * LDAP search 1st LDAP connection:
429 * not implemented because it gives no new information
432 * basedn: CN=Partitions,CN=Configuration,<domain_partition>
434 * filter: (nCName=<domain_partition>)
437 * controls: LDAP_SERVER_EXTENDED_DN_OID:critical=false
439 * <GUID=<hex_guid>>;CN=<domain_netbios_name>,CN=Partitions,<domain_partition>>
440 * nCName: <GUID=<hex_guid>>;<SID=<hex_sid>>;<domain_partition>>
441 * dnsRoot: <domain_dns_name>
445 * LDAP modify 1st LDAP connection:
447 * see: becomeDC_ldap1_server_object_modify()
450 * CN=<new_dc_netbios_name>,CN=Servers,CN=<new_dc_site_name>,CN=Sites,CN=Configuration,<domain_partition>>
451 * serverReference:CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
453 * <attributeOrValueExist>
457 * LDAP modify 1st LDAP connection:
459 * see: becomeDC_ldap1_server_object_modify()
462 * CN=<new_dc_netbios_name>,CN=Servers,CN=<new_dc_site_name>,CN=Sites,CN=Configuration,<domain_partition>>
463 * serverReference:CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
469 * Open 1st DRSUAPI connection to the DC using admin credentials
470 * DsBind with DRSUAPI_DS_BIND_GUID_W2K3 ("6afab99c-6e26-464a-975f-f58f105218bc")
471 * (w2k3 does 2 DsBind() calls here..., where is first is unused and contains garbage at the end)
473 * see: becomeDC_drsuapi_connect_send(), becomeDC_drsuapi1_connect_recv(),
474 * becomeDC_drsuapi_bind_send(), becomeDC_drsuapi_bind_recv() and becomeDC_drsuapi1_bind_recv()
478 * DsAddEntry to create the CN=NTDS Settings,CN=<machine_name>,CN=Servers,CN=Default-First-Site-Name, ...
479 * on the 1st DRSUAPI connection
481 * see: becomeDC_drsuapi1_add_entry_send() and becomeDC_drsuapi1_add_entry_recv()
484 /***************************************************************
485 * Add this stage we call the prepare_db() callback function
486 * of the caller, to see if he wants us to continue
488 * see: becomeDC_prepare_db()
489 ***************************************************************/
492 * Open 2nd and 3rd DRSUAPI connection to the DC using admin credentials
493 * - a DsBind with DRSUAPI_DS_BIND_GUID_W2K3 ("6afab99c-6e26-464a-975f-f58f105218bc")
494 * on the 2nd connection
496 * see: becomeDC_drsuapi_connect_send(), becomeDC_drsuapi2_connect_recv(),
497 * becomeDC_drsuapi_bind_send(), becomeDC_drsuapi_bind_recv(), becomeDC_drsuapi2_bind_recv()
498 * and becomeDC_drsuapi3_connect_recv()
502 * replicate CN=Schema,CN=Configuration,...
503 * on the 3rd DRSUAPI connection and the bind_handle from the 2nd connection
505 * see: becomeDC_drsuapi_pull_partition_send(), becomeDC_drsuapi_pull_partition_recv(),
506 * becomeDC_drsuapi3_pull_schema_send() and becomeDC_drsuapi3_pull_schema_recv()
508 ***************************************************************
509 * Add this stage we call the schema_chunk() callback function
510 * for each replication message
511 ***************************************************************/
514 * replicate CN=Configuration,...
515 * on the 3rd DRSUAPI connection and the bind_handle from the 2nd connection
517 * see: becomeDC_drsuapi_pull_partition_send(), becomeDC_drsuapi_pull_partition_recv(),
518 * becomeDC_drsuapi3_pull_config_send() and becomeDC_drsuapi3_pull_config_recv()
520 ***************************************************************
521 * Add this stage we call the config_chunk() callback function
522 * for each replication message
523 ***************************************************************/
526 * LDAP unbind on the 1st LDAP connection
528 * not implemented, because it's not needed...
532 * Open 2nd LDAP connection to the DC using admin credentials
534 * see: becomeDC_connect_ldap2() and becomeDC_ldap_connect()
538 * LDAP search 2nd LDAP connection:
540 * not implemented because it gives no new information
541 * same as becomeDC_ldap1_computer_object()
544 * basedn: <domain_partition>
546 * filter: (&(|(objectClass=user)(objectClass=computer))(sAMAccountName=<new_dc_account_name>))
547 * attrs: distinguishedName
550 * CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
551 * distinguishedName: CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
552 * userAccoountControl: 4096 <0x00001000>
556 * LDAP search 2nd LDAP connection:
558 * not implemented because it gives no new information
559 * same as becomeDC_ldap1_computer_object()
562 * basedn: CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
564 * filter: (objectClass=*)
565 * attrs: userAccountControl
567 * CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
568 * userAccoountControl: 4096 <0x00001000>
572 * LDAP modify 2nd LDAP connection:
574 * see: becomeDC_ldap2_modify_computer()
577 * CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
578 * userAccoountControl: 532480 <0x82000>
584 * LDAP search 2nd LDAP connection:
586 * see: becomeDC_ldap2_move_computer()
589 * basedn: <WKGUID=2fbac1870ade11d297c400c04fd8d5cd,<domain_partition>>
591 * filter: (objectClass=*)
594 * CN=Domain Controllers,<domain_partition>
598 * LDAP search 2nd LDAP connection:
600 * not implemented because it gives no new information
603 * basedn: CN=Domain Controllers,<domain_partition>
605 * filter: (objectClass=*)
606 * attrs: distinguishedName
608 * CN=Domain Controller,<domain_partition>
609 * distinguishedName: CN=Domain Controllers,<domain_partition>
613 * LDAP modifyRDN 2nd LDAP connection:
615 * see: becomeDC_ldap2_move_computer()
618 * entry: CN=<new_dc_netbios_name>,CN=Computers,<domain_partition>
619 * newrdn: CN=<new_dc_netbios_name>
621 * newparent: CN=Domain Controllers,<domain_partition>
627 * LDAP unbind on the 2nd LDAP connection
629 * not implemented, because it's not needed...
633 * replicate Domain Partition
634 * on the 3rd DRSUAPI connection and the bind_handle from the 2nd connection
636 * see: becomeDC_drsuapi_pull_partition_send(), becomeDC_drsuapi_pull_partition_recv(),
637 * becomeDC_drsuapi3_pull_domain_send() and becomeDC_drsuapi3_pull_domain_recv()
639 ***************************************************************
640 * Add this stage we call the domain_chunk() callback function
641 * for each replication message
642 ***************************************************************/
644 /* call DsReplicaUpdateRefs() for all partitions like this:
645 * req1: struct drsuapi_DsReplicaUpdateRefsRequest1
647 * naming_context: struct drsuapi_DsReplicaObjectIdentifier
648 * __ndr_size : 0x000000ae (174)
649 * __ndr_size_sid : 0x00000000 (0)
650 * guid : 00000000-0000-0000-0000-000000000000
652 * dn : 'CN=Schema,CN=Configuration,DC=w2k3,DC=vmnet1,DC=vm,DC=base'
654 * dest_dsa_dns_name : '4a0df188-a0b8-47ea-bbe5-e614723f16dd._msdcs.w2k3.vmnet1.vm.base'
655 * dest_dsa_guid : 4a0df188-a0b8-47ea-bbe5-e614723f16dd
656 * options : 0x0000001c (28)
657 * 0: DRSUAPI_DS_REPLICA_UPDATE_ASYNCHRONOUS_OPERATION
658 * 0: DRSUAPI_DS_REPLICA_UPDATE_WRITEABLE
659 * 1: DRSUAPI_DS_REPLICA_UPDATE_ADD_REFERENCE
660 * 1: DRSUAPI_DS_REPLICA_UPDATE_DELETE_REFERENCE
661 * 1: DRSUAPI_DS_REPLICA_UPDATE_0x00000010
663 * 4a0df188-a0b8-47ea-bbe5-e614723f16dd is the objectGUID the DsAddEntry() returned for the
664 * CN=NTDS Settings,CN=<machine_name>,CN=Servers,CN=Default-First-Site-Name, ...
665 * on the 2nd!!! DRSUAPI connection
667 * see: becomeDC_drsuapi_update_refs_send(), becomeDC_drsuapi2_update_refs_schema_recv(),
668 * becomeDC_drsuapi2_update_refs_config_recv() and becomeDC_drsuapi2_update_refs_domain_recv()
672 * Windows does opens the 4th and 5th DRSUAPI connection...
673 * and does a DsBind() with the objectGUID from DsAddEntry() as bind_guid
674 * on the 4th connection
676 * and then 2 full replications of the domain partition on the 5th connection
677 * with the bind_handle from the 4th connection
679 * not implemented because it gives no new information
682 struct libnet_BecomeDC_state
{
683 struct composite_context
*creq
;
685 struct libnet_context
*libnet
;
687 struct dom_sid zero_sid
;
690 struct cldap_socket
*sock
;
691 struct cldap_netlogon io
;
692 struct NETLOGON_SAM_LOGON_RESPONSE_EX netlogon
;
695 struct becomeDC_ldap
{
696 struct ldb_context
*ldb
;
697 const struct ldb_message
*rootdse
;
700 struct becomeDC_drsuapi
{
701 struct libnet_BecomeDC_state
*s
;
702 struct dcerpc_binding
*binding
;
703 struct dcerpc_pipe
*pipe
;
704 DATA_BLOB gensec_skey
;
705 struct drsuapi_DsBind bind_r
;
706 struct GUID bind_guid
;
707 struct drsuapi_DsBindInfoCtr bind_info_ctr
;
708 struct drsuapi_DsBindInfo28 local_info28
;
709 struct drsuapi_DsBindInfo28 remote_info28
;
710 struct policy_handle bind_handle
;
711 } drsuapi1
, drsuapi2
, drsuapi3
;
713 void *ndr_struct_ptr
;
715 struct libnet_BecomeDC_Domain domain
;
716 struct libnet_BecomeDC_Forest forest
;
717 struct libnet_BecomeDC_SourceDSA source_dsa
;
718 struct libnet_BecomeDC_DestDSA dest_dsa
;
720 struct libnet_BecomeDC_Partition schema_part
, config_part
, domain_part
;
722 struct becomeDC_fsmo
{
723 const char *dns_name
;
724 const char *server_dn_str
;
725 const char *ntds_dn_str
;
726 struct GUID ntds_guid
;
727 } infrastructure_fsmo
;
729 struct becomeDC_fsmo rid_manager_fsmo
;
731 struct libnet_BecomeDC_CheckOptions _co
;
732 struct libnet_BecomeDC_PrepareDB _pp
;
733 struct libnet_BecomeDC_StoreChunk _sc
;
734 struct libnet_BecomeDC_Callbacks callbacks
;
739 static int32_t get_dc_function_level(struct loadparm_context
*lp_ctx
)
741 /* per default we are (Windows) 2008 compatible */
742 return lp_parm_int(lp_ctx
, NULL
, "ads", "dc function level",
743 DS_DC_FUNCTION_2008
);
746 static int32_t get_min_function_level(struct loadparm_context
*lp_ctx
)
748 /* per default it is (Windows) 2003 Native compatible */
749 return lp_parm_int(lp_ctx
, NULL
, "ads", "min function level",
750 DS_DOMAIN_FUNCTION_2003
);
753 static void becomeDC_recv_cldap(struct tevent_req
*req
);
755 static void becomeDC_send_cldap(struct libnet_BecomeDC_state
*s
)
757 struct composite_context
*c
= s
->creq
;
758 struct tevent_req
*req
;
759 struct tsocket_address
*dest_address
;
762 s
->cldap
.io
.in
.dest_address
= NULL
;
763 s
->cldap
.io
.in
.dest_port
= 0;
764 s
->cldap
.io
.in
.realm
= s
->domain
.dns_name
;
765 s
->cldap
.io
.in
.host
= s
->dest_dsa
.netbios_name
;
766 s
->cldap
.io
.in
.user
= NULL
;
767 s
->cldap
.io
.in
.domain_guid
= NULL
;
768 s
->cldap
.io
.in
.domain_sid
= NULL
;
769 s
->cldap
.io
.in
.acct_control
= -1;
770 s
->cldap
.io
.in
.version
= NETLOGON_NT_VERSION_5
| NETLOGON_NT_VERSION_5EX
;
771 s
->cldap
.io
.in
.map_response
= true;
773 ret
= tsocket_address_inet_from_strings(s
, "ip",
774 s
->source_dsa
.address
,
775 lp_cldap_port(s
->libnet
->lp_ctx
),
778 c
->status
= map_nt_error_from_unix(errno
);
779 if (!composite_is_ok(c
)) return;
782 c
->status
= cldap_socket_init(s
, s
->libnet
->event_ctx
,
783 NULL
, dest_address
, &s
->cldap
.sock
);
784 if (!composite_is_ok(c
)) return;
786 req
= cldap_netlogon_send(s
, s
->cldap
.sock
, &s
->cldap
.io
);
787 if (composite_nomem(req
, c
)) return;
788 tevent_req_set_callback(req
, becomeDC_recv_cldap
, s
);
791 static void becomeDC_connect_ldap1(struct libnet_BecomeDC_state
*s
);
793 static void becomeDC_recv_cldap(struct tevent_req
*req
)
795 struct libnet_BecomeDC_state
*s
= tevent_req_callback_data(req
,
796 struct libnet_BecomeDC_state
);
797 struct composite_context
*c
= s
->creq
;
799 c
->status
= cldap_netlogon_recv(req
,
800 lp_iconv_convenience(s
->libnet
->lp_ctx
),
803 if (!composite_is_ok(c
)) {
804 DEBUG(0,("Failed to send, receive or parse CLDAP reply from server %s for our host %s: %s\n",
805 s
->cldap
.io
.in
.dest_address
,
807 nt_errstr(c
->status
)));
810 s
->cldap
.netlogon
= s
->cldap
.io
.out
.netlogon
.data
.nt5_ex
;
812 s
->domain
.dns_name
= s
->cldap
.netlogon
.dns_domain
;
813 s
->domain
.netbios_name
= s
->cldap
.netlogon
.domain
;
814 s
->domain
.guid
= s
->cldap
.netlogon
.domain_uuid
;
816 s
->forest
.dns_name
= s
->cldap
.netlogon
.forest
;
818 s
->source_dsa
.dns_name
= s
->cldap
.netlogon
.pdc_dns_name
;
819 s
->source_dsa
.netbios_name
= s
->cldap
.netlogon
.pdc_name
;
820 s
->source_dsa
.site_name
= s
->cldap
.netlogon
.server_site
;
822 s
->dest_dsa
.site_name
= s
->cldap
.netlogon
.client_site
;
824 becomeDC_connect_ldap1(s
);
827 static NTSTATUS
becomeDC_ldap_connect(struct libnet_BecomeDC_state
*s
,
828 struct becomeDC_ldap
*ldap
)
832 url
= talloc_asprintf(s
, "ldap://%s/", s
->source_dsa
.dns_name
);
833 NT_STATUS_HAVE_NO_MEMORY(url
);
835 ldap
->ldb
= ldb_wrap_connect(s
, s
->libnet
->event_ctx
, s
->libnet
->lp_ctx
, url
,
840 if (ldap
->ldb
== NULL
) {
841 return NT_STATUS_UNEXPECTED_NETWORK_ERROR
;
847 static NTSTATUS
becomeDC_ldap1_rootdse(struct libnet_BecomeDC_state
*s
)
850 struct ldb_result
*r
;
851 struct ldb_dn
*basedn
;
852 static const char *attrs
[] = {
857 basedn
= ldb_dn_new(s
, s
->ldap1
.ldb
, NULL
);
858 NT_STATUS_HAVE_NO_MEMORY(basedn
);
860 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
, attrs
,
863 if (ret
!= LDB_SUCCESS
) {
864 return NT_STATUS_LDAP(ret
);
865 } else if (r
->count
!= 1) {
867 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
870 s
->ldap1
.rootdse
= r
->msgs
[0];
872 s
->domain
.dn_str
= ldb_msg_find_attr_as_string(s
->ldap1
.rootdse
, "defaultNamingContext", NULL
);
873 if (!s
->domain
.dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
875 s
->forest
.root_dn_str
= ldb_msg_find_attr_as_string(s
->ldap1
.rootdse
, "rootDomainNamingContext", NULL
);
876 if (!s
->forest
.root_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
877 s
->forest
.config_dn_str
= ldb_msg_find_attr_as_string(s
->ldap1
.rootdse
, "configurationNamingContext", NULL
);
878 if (!s
->forest
.config_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
879 s
->forest
.schema_dn_str
= ldb_msg_find_attr_as_string(s
->ldap1
.rootdse
, "schemaNamingContext", NULL
);
880 if (!s
->forest
.schema_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
882 s
->source_dsa
.server_dn_str
= ldb_msg_find_attr_as_string(s
->ldap1
.rootdse
, "serverName", NULL
);
883 if (!s
->source_dsa
.server_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
884 s
->source_dsa
.ntds_dn_str
= ldb_msg_find_attr_as_string(s
->ldap1
.rootdse
, "dsServiceName", NULL
);
885 if (!s
->source_dsa
.ntds_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
890 static NTSTATUS
becomeDC_ldap1_crossref_behavior_version(struct libnet_BecomeDC_state
*s
)
893 struct ldb_result
*r
;
894 struct ldb_dn
*basedn
;
895 static const char *attrs
[] = {
896 "msDs-Behavior-Version",
900 basedn
= ldb_dn_new(s
, s
->ldap1
.ldb
, s
->forest
.config_dn_str
);
901 NT_STATUS_HAVE_NO_MEMORY(basedn
);
903 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, basedn
, LDB_SCOPE_ONELEVEL
, attrs
,
906 if (ret
!= LDB_SUCCESS
) {
907 return NT_STATUS_LDAP(ret
);
908 } else if (r
->count
!= 1) {
910 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
913 s
->forest
.crossref_behavior_version
= ldb_msg_find_attr_as_uint(r
->msgs
[0], "msDs-Behavior-Version", 0);
914 if (s
->forest
.crossref_behavior_version
<
915 get_min_function_level(s
->libnet
->lp_ctx
)) {
917 DEBUG(0,("The servers function level %u is below 'ads:min function level' of %u\n",
918 s
->forest
.crossref_behavior_version
,
919 get_min_function_level(s
->libnet
->lp_ctx
)));
920 return NT_STATUS_NOT_SUPPORTED
;
922 if (s
->forest
.crossref_behavior_version
>
923 get_dc_function_level(s
->libnet
->lp_ctx
)) {
925 DEBUG(0,("The servers function level %u is above 'ads:dc function level' of %u\n",
926 s
->forest
.crossref_behavior_version
,
927 get_dc_function_level(s
->libnet
->lp_ctx
)));
928 return NT_STATUS_NOT_SUPPORTED
;
935 static NTSTATUS
becomeDC_ldap1_domain_behavior_version(struct libnet_BecomeDC_state
*s
)
938 struct ldb_result
*r
;
939 struct ldb_dn
*basedn
;
940 static const char *attrs
[] = {
941 "msDs-Behavior-Version",
945 basedn
= ldb_dn_new(s
, s
->ldap1
.ldb
, s
->domain
.dn_str
);
946 NT_STATUS_HAVE_NO_MEMORY(basedn
);
948 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
, attrs
,
951 if (ret
!= LDB_SUCCESS
) {
952 return NT_STATUS_LDAP(ret
);
953 } else if (r
->count
!= 1) {
955 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
958 s
->domain
.behavior_version
= ldb_msg_find_attr_as_uint(r
->msgs
[0], "msDs-Behavior-Version", 0);
959 if (s
->domain
.behavior_version
<
960 get_min_function_level(s
->libnet
->lp_ctx
)) {
962 DEBUG(0,("The servers function level %u is below 'ads:min function level' of %u\n",
963 s
->forest
.crossref_behavior_version
,
964 get_min_function_level(s
->libnet
->lp_ctx
)));
965 return NT_STATUS_NOT_SUPPORTED
;
967 if (s
->domain
.behavior_version
>
968 get_dc_function_level(s
->libnet
->lp_ctx
)) {
970 DEBUG(0,("The servers function level %u is above 'ads:dc function level' of %u\n",
971 s
->forest
.crossref_behavior_version
,
972 get_dc_function_level(s
->libnet
->lp_ctx
)));
973 return NT_STATUS_NOT_SUPPORTED
;
980 static NTSTATUS
becomeDC_ldap1_schema_object_version(struct libnet_BecomeDC_state
*s
)
983 struct ldb_result
*r
;
984 struct ldb_dn
*basedn
;
985 static const char *attrs
[] = {
990 basedn
= ldb_dn_new(s
, s
->ldap1
.ldb
, s
->forest
.schema_dn_str
);
991 NT_STATUS_HAVE_NO_MEMORY(basedn
);
993 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
, attrs
,
996 if (ret
!= LDB_SUCCESS
) {
997 return NT_STATUS_LDAP(ret
);
998 } else if (r
->count
!= 1) {
1000 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1003 s
->forest
.schema_object_version
= ldb_msg_find_attr_as_uint(r
->msgs
[0], "objectVersion", 0);
1006 return NT_STATUS_OK
;
1009 static NTSTATUS
becomeDC_ldap1_w2k3_update_revision(struct libnet_BecomeDC_state
*s
)
1012 struct ldb_result
*r
;
1013 struct ldb_dn
*basedn
;
1014 static const char *attrs
[] = {
1019 basedn
= ldb_dn_new_fmt(s
, s
->ldap1
.ldb
, "CN=Windows2003Update,CN=DomainUpdates,CN=System,%s",
1021 NT_STATUS_HAVE_NO_MEMORY(basedn
);
1023 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
, attrs
,
1025 talloc_free(basedn
);
1026 if (ret
== LDB_ERR_NO_SUCH_OBJECT
) {
1027 /* w2k doesn't have this object */
1028 s
->domain
.w2k3_update_revision
= 0;
1029 return NT_STATUS_OK
;
1030 } else if (ret
!= LDB_SUCCESS
) {
1031 return NT_STATUS_LDAP(ret
);
1032 } else if (r
->count
!= 1) {
1034 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1037 s
->domain
.w2k3_update_revision
= ldb_msg_find_attr_as_uint(r
->msgs
[0], "revision", 0);
1040 return NT_STATUS_OK
;
1043 static NTSTATUS
becomeDC_ldap1_infrastructure_fsmo(struct libnet_BecomeDC_state
*s
)
1046 struct ldb_result
*r
;
1047 struct ldb_dn
*basedn
;
1048 struct ldb_dn
*ntds_dn
;
1049 struct ldb_dn
*server_dn
;
1050 static const char *dns_attrs
[] = {
1054 static const char *guid_attrs
[] = {
1059 ret
= dsdb_wellknown_dn(s
->ldap1
.ldb
, s
, samdb_base_dn(s
->ldap1
.ldb
),
1060 DS_GUID_INFRASTRUCTURE_CONTAINER
,
1062 if (ret
!= LDB_SUCCESS
) {
1063 return NT_STATUS_LDAP(ret
);
1066 ret
= samdb_reference_dn(s
->ldap1
.ldb
, s
, basedn
, "fSMORoleOwner", &ntds_dn
);
1067 if (ret
!= LDB_SUCCESS
) {
1068 talloc_free(basedn
);
1069 return NT_STATUS_LDAP(ret
);
1072 s
->infrastructure_fsmo
.ntds_dn_str
= ldb_dn_get_linearized(ntds_dn
);
1073 NT_STATUS_HAVE_NO_MEMORY(s
->infrastructure_fsmo
.ntds_dn_str
);
1075 server_dn
= ldb_dn_get_parent(s
, ntds_dn
);
1076 NT_STATUS_HAVE_NO_MEMORY(server_dn
);
1078 s
->infrastructure_fsmo
.server_dn_str
= ldb_dn_alloc_linearized(s
, server_dn
);
1079 NT_STATUS_HAVE_NO_MEMORY(s
->infrastructure_fsmo
.server_dn_str
);
1081 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, server_dn
, LDB_SCOPE_BASE
,
1082 dns_attrs
, "(objectClass=*)");
1083 if (ret
!= LDB_SUCCESS
) {
1084 return NT_STATUS_LDAP(ret
);
1085 } else if (r
->count
!= 1) {
1087 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1090 s
->infrastructure_fsmo
.dns_name
= samdb_result_string(r
->msgs
[0], "dnsHostName", NULL
);
1091 if (!s
->infrastructure_fsmo
.dns_name
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1092 talloc_steal(s
, s
->infrastructure_fsmo
.dns_name
);
1096 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, ntds_dn
, LDB_SCOPE_BASE
,
1097 guid_attrs
, "(objectClass=*)");
1098 if (ret
!= LDB_SUCCESS
) {
1099 return NT_STATUS_LDAP(ret
);
1100 } else if (r
->count
!= 1) {
1102 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1105 s
->infrastructure_fsmo
.ntds_guid
= samdb_result_guid(r
->msgs
[0], "objectGUID");
1109 return NT_STATUS_OK
;
1112 static NTSTATUS
becomeDC_ldap1_rid_manager_fsmo(struct libnet_BecomeDC_state
*s
)
1115 struct ldb_result
*r
;
1116 struct ldb_dn
*basedn
;
1117 const char *reference_dn_str
;
1118 struct ldb_dn
*ntds_dn
;
1119 struct ldb_dn
*server_dn
;
1120 static const char *rid_attrs
[] = {
1121 "rIDManagerReference",
1124 static const char *fsmo_attrs
[] = {
1128 static const char *dns_attrs
[] = {
1132 static const char *guid_attrs
[] = {
1137 basedn
= ldb_dn_new(s
, s
->ldap1
.ldb
, s
->domain
.dn_str
);
1138 NT_STATUS_HAVE_NO_MEMORY(basedn
);
1140 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
,
1141 rid_attrs
, "(objectClass=*)");
1142 talloc_free(basedn
);
1143 if (ret
!= LDB_SUCCESS
) {
1144 return NT_STATUS_LDAP(ret
);
1145 } else if (r
->count
!= 1) {
1147 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1150 reference_dn_str
= samdb_result_string(r
->msgs
[0], "rIDManagerReference", NULL
);
1151 if (!reference_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1153 basedn
= ldb_dn_new(s
, s
->ldap1
.ldb
, reference_dn_str
);
1154 NT_STATUS_HAVE_NO_MEMORY(basedn
);
1158 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
,
1159 fsmo_attrs
, "(objectClass=*)");
1160 talloc_free(basedn
);
1161 if (ret
!= LDB_SUCCESS
) {
1162 return NT_STATUS_LDAP(ret
);
1163 } else if (r
->count
!= 1) {
1165 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1168 s
->rid_manager_fsmo
.ntds_dn_str
= samdb_result_string(r
->msgs
[0], "fSMORoleOwner", NULL
);
1169 if (!s
->rid_manager_fsmo
.ntds_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1170 talloc_steal(s
, s
->rid_manager_fsmo
.ntds_dn_str
);
1174 ntds_dn
= ldb_dn_new(s
, s
->ldap1
.ldb
, s
->rid_manager_fsmo
.ntds_dn_str
);
1175 NT_STATUS_HAVE_NO_MEMORY(ntds_dn
);
1177 server_dn
= ldb_dn_get_parent(s
, ntds_dn
);
1178 NT_STATUS_HAVE_NO_MEMORY(server_dn
);
1180 s
->rid_manager_fsmo
.server_dn_str
= ldb_dn_alloc_linearized(s
, server_dn
);
1181 NT_STATUS_HAVE_NO_MEMORY(s
->rid_manager_fsmo
.server_dn_str
);
1183 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, server_dn
, LDB_SCOPE_BASE
,
1184 dns_attrs
, "(objectClass=*)");
1185 if (ret
!= LDB_SUCCESS
) {
1186 return NT_STATUS_LDAP(ret
);
1187 } else if (r
->count
!= 1) {
1189 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1192 s
->rid_manager_fsmo
.dns_name
= samdb_result_string(r
->msgs
[0], "dnsHostName", NULL
);
1193 if (!s
->rid_manager_fsmo
.dns_name
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1194 talloc_steal(s
, s
->rid_manager_fsmo
.dns_name
);
1198 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, ntds_dn
, LDB_SCOPE_BASE
,
1199 guid_attrs
, "(objectClass=*)");
1200 if (ret
!= LDB_SUCCESS
) {
1201 return NT_STATUS_LDAP(ret
);
1202 } else if (r
->count
!= 1) {
1204 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1207 s
->rid_manager_fsmo
.ntds_guid
= samdb_result_guid(r
->msgs
[0], "objectGUID");
1211 return NT_STATUS_OK
;
1214 static NTSTATUS
becomeDC_ldap1_site_object(struct libnet_BecomeDC_state
*s
)
1217 struct ldb_result
*r
;
1218 struct ldb_dn
*basedn
;
1220 basedn
= ldb_dn_new_fmt(s
, s
->ldap1
.ldb
, "CN=%s,CN=Sites,%s",
1221 s
->dest_dsa
.site_name
,
1222 s
->forest
.config_dn_str
);
1223 NT_STATUS_HAVE_NO_MEMORY(basedn
);
1225 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
,
1226 NULL
, "(objectClass=*)");
1227 talloc_free(basedn
);
1228 if (ret
!= LDB_SUCCESS
) {
1229 return NT_STATUS_LDAP(ret
);
1230 } else if (r
->count
!= 1) {
1232 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1235 s
->dest_dsa
.site_guid
= samdb_result_guid(r
->msgs
[0], "objectGUID");
1238 return NT_STATUS_OK
;
1241 static NTSTATUS
becomeDC_check_options(struct libnet_BecomeDC_state
*s
)
1243 if (!s
->callbacks
.check_options
) return NT_STATUS_OK
;
1245 s
->_co
.domain
= &s
->domain
;
1246 s
->_co
.forest
= &s
->forest
;
1247 s
->_co
.source_dsa
= &s
->source_dsa
;
1249 return s
->callbacks
.check_options(s
->callbacks
.private_data
, &s
->_co
);
1252 static NTSTATUS
becomeDC_ldap1_computer_object(struct libnet_BecomeDC_state
*s
)
1255 struct ldb_result
*r
;
1256 struct ldb_dn
*basedn
;
1257 static const char *attrs
[] = {
1258 "distinguishedName",
1259 "userAccountControl",
1263 basedn
= ldb_dn_new(s
, s
->ldap1
.ldb
, s
->domain
.dn_str
);
1264 NT_STATUS_HAVE_NO_MEMORY(basedn
);
1266 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, basedn
, LDB_SCOPE_SUBTREE
, attrs
,
1267 "(&(|(objectClass=user)(objectClass=computer))(sAMAccountName=%s$))",
1268 s
->dest_dsa
.netbios_name
);
1269 talloc_free(basedn
);
1270 if (ret
!= LDB_SUCCESS
) {
1271 return NT_STATUS_LDAP(ret
);
1272 } else if (r
->count
!= 1) {
1274 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1277 s
->dest_dsa
.computer_dn_str
= samdb_result_string(r
->msgs
[0], "distinguishedName", NULL
);
1278 if (!s
->dest_dsa
.computer_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1279 talloc_steal(s
, s
->dest_dsa
.computer_dn_str
);
1281 s
->dest_dsa
.user_account_control
= samdb_result_uint(r
->msgs
[0], "userAccountControl", 0);
1284 return NT_STATUS_OK
;
1287 static NTSTATUS
becomeDC_ldap1_server_object_1(struct libnet_BecomeDC_state
*s
)
1290 struct ldb_result
*r
;
1291 struct ldb_dn
*basedn
;
1292 const char *server_reference_dn_str
;
1293 struct ldb_dn
*server_reference_dn
;
1294 struct ldb_dn
*computer_dn
;
1296 basedn
= ldb_dn_new_fmt(s
, s
->ldap1
.ldb
, "CN=%s,CN=Servers,CN=%s,CN=Sites,%s",
1297 s
->dest_dsa
.netbios_name
,
1298 s
->dest_dsa
.site_name
,
1299 s
->forest
.config_dn_str
);
1300 NT_STATUS_HAVE_NO_MEMORY(basedn
);
1302 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
,
1303 NULL
, "(objectClass=*)");
1304 talloc_free(basedn
);
1305 if (ret
== LDB_ERR_NO_SUCH_OBJECT
) {
1306 /* if the object doesn't exist, we'll create it later */
1307 return NT_STATUS_OK
;
1308 } else if (ret
!= LDB_SUCCESS
) {
1309 return NT_STATUS_LDAP(ret
);
1310 } else if (r
->count
!= 1) {
1312 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1315 server_reference_dn_str
= samdb_result_string(r
->msgs
[0], "serverReference", NULL
);
1316 if (server_reference_dn_str
) {
1317 server_reference_dn
= ldb_dn_new(r
, s
->ldap1
.ldb
, server_reference_dn_str
);
1318 NT_STATUS_HAVE_NO_MEMORY(server_reference_dn
);
1320 computer_dn
= ldb_dn_new(r
, s
->ldap1
.ldb
, s
->dest_dsa
.computer_dn_str
);
1321 NT_STATUS_HAVE_NO_MEMORY(computer_dn
);
1324 * if the server object belongs to another DC in another domain
1325 * in the forest, we should not touch this object!
1327 if (ldb_dn_compare(computer_dn
, server_reference_dn
) != 0) {
1329 return NT_STATUS_OBJECT_NAME_COLLISION
;
1333 /* if the server object is already for the dest_dsa, then we don't need to create it */
1334 s
->dest_dsa
.server_dn_str
= samdb_result_string(r
->msgs
[0], "distinguishedName", NULL
);
1335 if (!s
->dest_dsa
.server_dn_str
) return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1336 talloc_steal(s
, s
->dest_dsa
.server_dn_str
);
1339 return NT_STATUS_OK
;
1342 static NTSTATUS
becomeDC_ldap1_server_object_2(struct libnet_BecomeDC_state
*s
)
1345 struct ldb_result
*r
;
1346 struct ldb_dn
*basedn
;
1347 const char *server_reference_bl_dn_str
;
1348 static const char *attrs
[] = {
1349 "serverReferenceBL",
1353 /* if the server_dn_str has a valid value, we skip this lookup */
1354 if (s
->dest_dsa
.server_dn_str
) return NT_STATUS_OK
;
1356 basedn
= ldb_dn_new(s
, s
->ldap1
.ldb
, s
->dest_dsa
.computer_dn_str
);
1357 NT_STATUS_HAVE_NO_MEMORY(basedn
);
1359 ret
= ldb_search(s
->ldap1
.ldb
, s
, &r
, basedn
, LDB_SCOPE_BASE
,
1360 attrs
, "(objectClass=*)");
1361 talloc_free(basedn
);
1362 if (ret
!= LDB_SUCCESS
) {
1363 return NT_STATUS_LDAP(ret
);
1364 } else if (r
->count
!= 1) {
1366 return NT_STATUS_INVALID_NETWORK_RESPONSE
;
1369 server_reference_bl_dn_str
= samdb_result_string(r
->msgs
[0], "serverReferenceBL", NULL
);
1370 if (!server_reference_bl_dn_str
) {
1371 /* if no back link is present, we're done for this function */
1373 return NT_STATUS_OK
;
1376 /* if the server object is already for the dest_dsa, then we don't need to create it */
1377 s
->dest_dsa
.server_dn_str
= samdb_result_string(r
->msgs
[0], "serverReferenceBL", NULL
);
1378 if (s
->dest_dsa
.server_dn_str
) {
1379 /* if a back link is present, we know that the server object is present */
1380 talloc_steal(s
, s
->dest_dsa
.server_dn_str
);
1384 return NT_STATUS_OK
;
1387 static NTSTATUS
becomeDC_ldap1_server_object_add(struct libnet_BecomeDC_state
*s
)
1390 struct ldb_message
*msg
;
1391 char *server_dn_str
;
1393 /* if the server_dn_str has a valid value, we skip this lookup */
1394 if (s
->dest_dsa
.server_dn_str
) return NT_STATUS_OK
;
1396 msg
= ldb_msg_new(s
);
1397 NT_STATUS_HAVE_NO_MEMORY(msg
);
1399 msg
->dn
= ldb_dn_new_fmt(msg
, s
->ldap1
.ldb
, "CN=%s,CN=Servers,CN=%s,CN=Sites,%s",
1400 s
->dest_dsa
.netbios_name
,
1401 s
->dest_dsa
.site_name
,
1402 s
->forest
.config_dn_str
);
1403 NT_STATUS_HAVE_NO_MEMORY(msg
->dn
);
1405 ret
= ldb_msg_add_string(msg
, "objectClass", "server");
1408 return NT_STATUS_NO_MEMORY
;
1410 ret
= ldb_msg_add_string(msg
, "systemFlags", "50000000");
1413 return NT_STATUS_NO_MEMORY
;
1415 ret
= ldb_msg_add_string(msg
, "serverReference", s
->dest_dsa
.computer_dn_str
);
1418 return NT_STATUS_NO_MEMORY
;
1421 server_dn_str
= ldb_dn_alloc_linearized(s
, msg
->dn
);
1422 NT_STATUS_HAVE_NO_MEMORY(server_dn_str
);
1424 ret
= ldb_add(s
->ldap1
.ldb
, msg
);
1426 if (ret
!= LDB_SUCCESS
) {
1427 talloc_free(server_dn_str
);
1428 return NT_STATUS_LDAP(ret
);
1431 s
->dest_dsa
.server_dn_str
= server_dn_str
;
1433 return NT_STATUS_OK
;
1436 static NTSTATUS
becomeDC_ldap1_server_object_modify(struct libnet_BecomeDC_state
*s
)
1439 struct ldb_message
*msg
;
1442 /* make a 'modify' msg, and only for serverReference */
1443 msg
= ldb_msg_new(s
);
1444 NT_STATUS_HAVE_NO_MEMORY(msg
);
1445 msg
->dn
= ldb_dn_new(msg
, s
->ldap1
.ldb
, s
->dest_dsa
.server_dn_str
);
1446 NT_STATUS_HAVE_NO_MEMORY(msg
->dn
);
1448 ret
= ldb_msg_add_string(msg
, "serverReference", s
->dest_dsa
.computer_dn_str
);
1451 return NT_STATUS_NO_MEMORY
;
1454 /* mark all the message elements (should be just one)
1455 as LDB_FLAG_MOD_ADD */
1456 for (i
=0;i
<msg
->num_elements
;i
++) {
1457 msg
->elements
[i
].flags
= LDB_FLAG_MOD_ADD
;
1460 ret
= ldb_modify(s
->ldap1
.ldb
, msg
);
1461 if (ret
== LDB_SUCCESS
) {
1463 return NT_STATUS_OK
;
1464 } else if (ret
== LDB_ERR_ATTRIBUTE_OR_VALUE_EXISTS
) {
1465 /* retry with LDB_FLAG_MOD_REPLACE */
1468 return NT_STATUS_LDAP(ret
);
1471 /* mark all the message elements (should be just one)
1472 as LDB_FLAG_MOD_REPLACE */
1473 for (i
=0;i
<msg
->num_elements
;i
++) {
1474 msg
->elements
[i
].flags
= LDB_FLAG_MOD_REPLACE
;
1477 ret
= ldb_modify(s
->ldap1
.ldb
, msg
);
1479 if (ret
!= LDB_SUCCESS
) {
1480 return NT_STATUS_LDAP(ret
);
1483 return NT_STATUS_OK
;
1486 static void becomeDC_drsuapi_connect_send(struct libnet_BecomeDC_state
*s
,
1487 struct becomeDC_drsuapi
*drsuapi
,
1488 void (*recv_fn
)(struct composite_context
*req
));
1489 static void becomeDC_drsuapi1_connect_recv(struct composite_context
*req
);
1490 static void becomeDC_connect_ldap2(struct libnet_BecomeDC_state
*s
);
1492 static void becomeDC_connect_ldap1(struct libnet_BecomeDC_state
*s
)
1494 struct composite_context
*c
= s
->creq
;
1496 c
->status
= becomeDC_ldap_connect(s
, &s
->ldap1
);
1497 if (!composite_is_ok(c
)) return;
1499 c
->status
= becomeDC_ldap1_rootdse(s
);
1500 if (!composite_is_ok(c
)) return;
1502 c
->status
= becomeDC_ldap1_crossref_behavior_version(s
);
1503 if (!composite_is_ok(c
)) return;
1505 c
->status
= becomeDC_ldap1_domain_behavior_version(s
);
1506 if (!composite_is_ok(c
)) return;
1508 c
->status
= becomeDC_ldap1_schema_object_version(s
);
1509 if (!composite_is_ok(c
)) return;
1511 c
->status
= becomeDC_ldap1_w2k3_update_revision(s
);
1512 if (!composite_is_ok(c
)) return;
1514 c
->status
= becomeDC_ldap1_infrastructure_fsmo(s
);
1515 if (!composite_is_ok(c
)) return;
1517 c
->status
= becomeDC_ldap1_rid_manager_fsmo(s
);
1518 if (!composite_is_ok(c
)) return;
1520 c
->status
= becomeDC_ldap1_site_object(s
);
1521 if (!composite_is_ok(c
)) return;
1523 c
->status
= becomeDC_check_options(s
);
1524 if (!composite_is_ok(c
)) return;
1526 c
->status
= becomeDC_ldap1_computer_object(s
);
1527 if (!composite_is_ok(c
)) return;
1529 c
->status
= becomeDC_ldap1_server_object_1(s
);
1530 if (!composite_is_ok(c
)) return;
1532 c
->status
= becomeDC_ldap1_server_object_2(s
);
1533 if (!composite_is_ok(c
)) return;
1535 c
->status
= becomeDC_ldap1_server_object_add(s
);
1536 if (!composite_is_ok(c
)) return;
1538 c
->status
= becomeDC_ldap1_server_object_modify(s
);
1539 if (!composite_is_ok(c
)) return;
1541 becomeDC_drsuapi_connect_send(s
, &s
->drsuapi1
, becomeDC_drsuapi1_connect_recv
);
1544 static void becomeDC_drsuapi_connect_send(struct libnet_BecomeDC_state
*s
,
1545 struct becomeDC_drsuapi
*drsuapi
,
1546 void (*recv_fn
)(struct composite_context
*req
))
1548 struct composite_context
*c
= s
->creq
;
1549 struct composite_context
*creq
;
1554 if (!drsuapi
->binding
) {
1555 const char *krb5_str
= "";
1556 const char *print_str
= "";
1558 * Note: Replication only works with Windows 2000 when 'krb5' is
1559 * passed as auth_type here. If NTLMSSP is used, Windows
1560 * 2000 returns garbage in the DsGetNCChanges() response
1561 * if encrypted password attributes would be in the
1562 * response. That means the replication of the schema and
1563 * configuration partition works fine, but it fails for
1564 * the domain partition.
1566 if (lp_parm_bool(s
->libnet
->lp_ctx
, NULL
, "become_dc",
1567 "force krb5", true))
1571 if (lp_parm_bool(s
->libnet
->lp_ctx
, NULL
, "become_dc",
1574 print_str
= "print,";
1576 binding_str
= talloc_asprintf(s
, "ncacn_ip_tcp:%s[%s%sseal]",
1577 s
->source_dsa
.dns_name
,
1578 krb5_str
, print_str
);
1579 if (composite_nomem(binding_str
, c
)) return;
1580 c
->status
= dcerpc_parse_binding(s
, binding_str
, &drsuapi
->binding
);
1581 talloc_free(binding_str
);
1582 if (!composite_is_ok(c
)) return;
1585 creq
= dcerpc_pipe_connect_b_send(s
, drsuapi
->binding
, &ndr_table_drsuapi
,
1586 s
->libnet
->cred
, s
->libnet
->event_ctx
,
1588 composite_continue(c
, creq
, recv_fn
, s
);
1591 static void becomeDC_drsuapi_bind_send(struct libnet_BecomeDC_state
*s
,
1592 struct becomeDC_drsuapi
*drsuapi
,
1593 void (*recv_fn
)(struct rpc_request
*req
));
1594 static void becomeDC_drsuapi1_bind_recv(struct rpc_request
*req
);
1596 static void becomeDC_drsuapi1_connect_recv(struct composite_context
*req
)
1598 struct libnet_BecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
1599 struct libnet_BecomeDC_state
);
1600 struct composite_context
*c
= s
->creq
;
1602 c
->status
= dcerpc_pipe_connect_b_recv(req
, s
, &s
->drsuapi1
.pipe
);
1603 if (!composite_is_ok(c
)) return;
1605 c
->status
= gensec_session_key(s
->drsuapi1
.pipe
->conn
->security_state
.generic_state
,
1606 &s
->drsuapi1
.gensec_skey
);
1607 if (!composite_is_ok(c
)) return;
1609 becomeDC_drsuapi_bind_send(s
, &s
->drsuapi1
, becomeDC_drsuapi1_bind_recv
);
1612 static void becomeDC_drsuapi_bind_send(struct libnet_BecomeDC_state
*s
,
1613 struct becomeDC_drsuapi
*drsuapi
,
1614 void (*recv_fn
)(struct rpc_request
*req
))
1616 struct composite_context
*c
= s
->creq
;
1617 struct rpc_request
*req
;
1618 struct drsuapi_DsBindInfo28
*bind_info28
;
1620 GUID_from_string(DRSUAPI_DS_BIND_GUID_W2K3
, &drsuapi
->bind_guid
);
1622 bind_info28
= &drsuapi
->local_info28
;
1623 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_BASE
;
1624 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ASYNC_REPLICATION
;
1625 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_REMOVEAPI
;
1626 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_MOVEREQ_V2
;
1627 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHG_COMPRESS
;
1628 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V1
;
1629 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_RESTORE_USN_OPTIMIZATION
;
1630 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_KCC_EXECUTE
;
1631 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRY_V2
;
1632 if (s
->domain
.behavior_version
>= DS_DOMAIN_FUNCTION_2003
) {
1633 /* TODO: find out how this is really triggered! */
1634 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_LINKED_VALUE_REPLICATION
;
1636 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V2
;
1637 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_INSTANCE_TYPE_NOT_REQ_ON_MOD
;
1638 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_CRYPTO_BIND
;
1639 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GET_REPL_INFO
;
1640 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_STRONG_ENCRYPTION
;
1641 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_DCINFO_V01
;
1642 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_TRANSITIVE_MEMBERSHIP
;
1643 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADD_SID_HISTORY
;
1644 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_POST_BETA3
;
1645 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V5
;
1646 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GET_MEMBERSHIPS2
;
1647 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V6
;
1648 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_NONDOMAIN_NCS
;
1649 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8
;
1650 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V5
;
1651 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V6
;
1652 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_ADDENTRYREPLY_V3
;
1653 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_GETCHGREPLY_V7
;
1654 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_VERIFY_OBJECT
;
1655 #if 0 /* we don't support XPRESS compression yet */
1656 bind_info28
->supported_extensions
|= DRSUAPI_SUPPORTED_EXTENSION_XPRESS_COMPRESS
;
1658 bind_info28
->site_guid
= s
->dest_dsa
.site_guid
;
1659 bind_info28
->pid
= 0;
1660 bind_info28
->repl_epoch
= 0;
1662 drsuapi
->bind_info_ctr
.length
= 28;
1663 drsuapi
->bind_info_ctr
.info
.info28
= *bind_info28
;
1665 drsuapi
->bind_r
.in
.bind_guid
= &drsuapi
->bind_guid
;
1666 drsuapi
->bind_r
.in
.bind_info
= &drsuapi
->bind_info_ctr
;
1667 drsuapi
->bind_r
.out
.bind_handle
= &drsuapi
->bind_handle
;
1669 req
= dcerpc_drsuapi_DsBind_send(drsuapi
->pipe
, s
, &drsuapi
->bind_r
);
1670 composite_continue_rpc(c
, req
, recv_fn
, s
);
1673 static WERROR
becomeDC_drsuapi_bind_recv(struct libnet_BecomeDC_state
*s
,
1674 struct becomeDC_drsuapi
*drsuapi
)
1676 if (!W_ERROR_IS_OK(drsuapi
->bind_r
.out
.result
)) {
1677 return drsuapi
->bind_r
.out
.result
;
1680 ZERO_STRUCT(drsuapi
->remote_info28
);
1681 if (drsuapi
->bind_r
.out
.bind_info
) {
1682 switch (drsuapi
->bind_r
.out
.bind_info
->length
) {
1684 struct drsuapi_DsBindInfo24
*info24
;
1685 info24
= &drsuapi
->bind_r
.out
.bind_info
->info
.info24
;
1686 drsuapi
->remote_info28
.supported_extensions
= info24
->supported_extensions
;
1687 drsuapi
->remote_info28
.site_guid
= info24
->site_guid
;
1688 drsuapi
->remote_info28
.pid
= info24
->pid
;
1689 drsuapi
->remote_info28
.repl_epoch
= 0;
1693 struct drsuapi_DsBindInfo48
*info48
;
1694 info48
= &drsuapi
->bind_r
.out
.bind_info
->info
.info48
;
1695 drsuapi
->remote_info28
.supported_extensions
= info48
->supported_extensions
;
1696 drsuapi
->remote_info28
.site_guid
= info48
->site_guid
;
1697 drsuapi
->remote_info28
.pid
= info48
->pid
;
1698 drsuapi
->remote_info28
.repl_epoch
= info48
->repl_epoch
;
1702 drsuapi
->remote_info28
= drsuapi
->bind_r
.out
.bind_info
->info
.info28
;
1710 static void becomeDC_drsuapi1_add_entry_send(struct libnet_BecomeDC_state
*s
);
1712 static void becomeDC_drsuapi1_bind_recv(struct rpc_request
*req
)
1714 struct libnet_BecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
1715 struct libnet_BecomeDC_state
);
1716 struct composite_context
*c
= s
->creq
;
1719 c
->status
= dcerpc_drsuapi_DsBind_recv(req
);
1720 if (!composite_is_ok(c
)) return;
1722 status
= becomeDC_drsuapi_bind_recv(s
, &s
->drsuapi1
);
1723 if (!W_ERROR_IS_OK(status
)) {
1724 composite_error(c
, werror_to_ntstatus(status
));
1728 becomeDC_drsuapi1_add_entry_send(s
);
1731 static void becomeDC_drsuapi1_add_entry_recv(struct rpc_request
*req
);
1733 static void becomeDC_drsuapi1_add_entry_send(struct libnet_BecomeDC_state
*s
)
1735 struct composite_context
*c
= s
->creq
;
1736 struct rpc_request
*req
;
1737 struct drsuapi_DsAddEntry
*r
;
1738 struct drsuapi_DsReplicaObjectIdentifier
*identifier
;
1739 uint32_t num_attrs
, i
= 0;
1740 struct drsuapi_DsReplicaAttribute
*attrs
;
1741 struct smb_iconv_convenience
*iconv_convenience
= lp_iconv_convenience(s
->libnet
->lp_ctx
);
1742 enum ndr_err_code ndr_err
;
1745 /* choose a random invocationId */
1746 s
->dest_dsa
.invocation_id
= GUID_random();
1749 * if the schema version indicates w2k3, then also send some w2k3
1750 * specific attributes.
1752 if (s
->forest
.schema_object_version
>= 30) {
1758 r
= talloc_zero(s
, struct drsuapi_DsAddEntry
);
1759 if (composite_nomem(r
, c
)) return;
1761 /* setup identifier */
1762 identifier
= talloc(r
, struct drsuapi_DsReplicaObjectIdentifier
);
1763 if (composite_nomem(identifier
, c
)) return;
1764 identifier
->guid
= GUID_zero();
1765 identifier
->sid
= s
->zero_sid
;
1766 identifier
->dn
= talloc_asprintf(identifier
, "CN=NTDS Settings,%s",
1767 s
->dest_dsa
.server_dn_str
);
1768 if (composite_nomem(identifier
->dn
, c
)) return;
1770 /* allocate attribute array */
1772 attrs
= talloc_array(r
, struct drsuapi_DsReplicaAttribute
, num_attrs
);
1773 if (composite_nomem(attrs
, c
)) return;
1775 /* ntSecurityDescriptor */
1777 struct drsuapi_DsAttributeValue
*vs
;
1779 struct security_descriptor
*v
;
1780 struct dom_sid
*domain_admins_sid
;
1781 const char *domain_admins_sid_str
;
1783 vs
= talloc_array(attrs
, struct drsuapi_DsAttributeValue
, 1);
1784 if (composite_nomem(vs
, c
)) return;
1786 vd
= talloc_array(vs
, DATA_BLOB
, 1);
1787 if (composite_nomem(vd
, c
)) return;
1789 domain_admins_sid
= dom_sid_add_rid(vs
, s
->domain
.sid
, DOMAIN_RID_ADMINS
);
1790 if (composite_nomem(domain_admins_sid
, c
)) return;
1792 domain_admins_sid_str
= dom_sid_string(domain_admins_sid
, domain_admins_sid
);
1793 if (composite_nomem(domain_admins_sid_str
, c
)) return;
1795 v
= security_descriptor_dacl_create(vd
,
1797 /* owner: domain admins */
1798 domain_admins_sid_str
,
1799 /* owner group: domain admins */
1800 domain_admins_sid_str
,
1801 /* authenticated users */
1802 SID_NT_AUTHENTICATED_USERS
,
1803 SEC_ACE_TYPE_ACCESS_ALLOWED
,
1804 SEC_STD_READ_CONTROL
|
1807 SEC_ADS_LIST_OBJECT
,
1810 domain_admins_sid_str
,
1811 SEC_ACE_TYPE_ACCESS_ALLOWED
,
1813 SEC_ADS_CREATE_CHILD
|
1815 SEC_ADS_SELF_WRITE
|
1817 SEC_ADS_WRITE_PROP
|
1818 SEC_ADS_DELETE_TREE
|
1819 SEC_ADS_LIST_OBJECT
|
1820 SEC_ADS_CONTROL_ACCESS
,
1824 SEC_ACE_TYPE_ACCESS_ALLOWED
,
1826 SEC_ADS_CREATE_CHILD
|
1827 SEC_ADS_DELETE_CHILD
|
1829 SEC_ADS_SELF_WRITE
|
1831 SEC_ADS_WRITE_PROP
|
1832 SEC_ADS_DELETE_TREE
|
1833 SEC_ADS_LIST_OBJECT
|
1834 SEC_ADS_CONTROL_ACCESS
,
1838 if (composite_nomem(v
, c
)) return;
1840 ndr_err
= ndr_push_struct_blob(&vd
[0], vd
, iconv_convenience
, v
,(ndr_push_flags_fn_t
)ndr_push_security_descriptor
);
1841 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1842 c
->status
= ndr_map_error2ntstatus(ndr_err
);
1843 if (!composite_is_ok(c
)) return;
1846 vs
[0].blob
= &vd
[0];
1848 attrs
[i
].attid
= DRSUAPI_ATTRIBUTE_ntSecurityDescriptor
;
1849 attrs
[i
].value_ctr
.num_values
= 1;
1850 attrs
[i
].value_ctr
.values
= vs
;
1855 /* objectClass: nTDSDSA */
1857 struct drsuapi_DsAttributeValue
*vs
;
1860 vs
= talloc_array(attrs
, struct drsuapi_DsAttributeValue
, 1);
1861 if (composite_nomem(vs
, c
)) return;
1863 vd
= talloc_array(vs
, DATA_BLOB
, 1);
1864 if (composite_nomem(vd
, c
)) return;
1866 vd
[0] = data_blob_talloc(vd
, NULL
, 4);
1867 if (composite_nomem(vd
[0].data
, c
)) return;
1869 /* value for nTDSDSA */
1870 SIVAL(vd
[0].data
, 0, 0x0017002F);
1872 vs
[0].blob
= &vd
[0];
1874 attrs
[i
].attid
= DRSUAPI_ATTRIBUTE_objectClass
;
1875 attrs
[i
].value_ctr
.num_values
= 1;
1876 attrs
[i
].value_ctr
.values
= vs
;
1881 /* objectCategory: CN=NTDS-DSA,CN=Schema,... or CN=NTDS-DSA-RO,CN=Schema,... */
1883 struct drsuapi_DsAttributeValue
*vs
;
1885 struct drsuapi_DsReplicaObjectIdentifier3 v
[1];
1887 vs
= talloc_array(attrs
, struct drsuapi_DsAttributeValue
, 1);
1888 if (composite_nomem(vs
, c
)) return;
1890 vd
= talloc_array(vs
, DATA_BLOB
, 1);
1891 if (composite_nomem(vd
, c
)) return;
1893 v
[0].guid
= GUID_zero();
1894 v
[0].sid
= s
->zero_sid
;
1897 v
[0].dn
= talloc_asprintf(vd
, "CN=NTDS-DSA-RO,%s",
1898 s
->forest
.schema_dn_str
);
1900 v
[0].dn
= talloc_asprintf(vd
, "CN=NTDS-DSA,%s",
1901 s
->forest
.schema_dn_str
);
1903 if (composite_nomem(v
[0].dn
, c
)) return;
1905 ndr_err
= ndr_push_struct_blob(&vd
[0], vd
, iconv_convenience
, &v
[0],
1906 (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3
);
1907 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1908 c
->status
= ndr_map_error2ntstatus(ndr_err
);
1909 if (!composite_is_ok(c
)) return;
1912 vs
[0].blob
= &vd
[0];
1914 attrs
[i
].attid
= DRSUAPI_ATTRIBUTE_objectCategory
;
1915 attrs
[i
].value_ctr
.num_values
= 1;
1916 attrs
[i
].value_ctr
.values
= vs
;
1921 /* invocationId: random guid */
1923 struct drsuapi_DsAttributeValue
*vs
;
1925 const struct GUID
*v
;
1927 vs
= talloc_array(attrs
, struct drsuapi_DsAttributeValue
, 1);
1928 if (composite_nomem(vs
, c
)) return;
1930 vd
= talloc_array(vs
, DATA_BLOB
, 1);
1931 if (composite_nomem(vd
, c
)) return;
1933 v
= &s
->dest_dsa
.invocation_id
;
1935 c
->status
= GUID_to_ndr_blob(v
, vd
, &vd
[0]);
1936 if (!composite_is_ok(c
)) return;
1938 vs
[0].blob
= &vd
[0];
1940 attrs
[i
].attid
= DRSUAPI_ATTRIBUTE_invocationId
;
1941 attrs
[i
].value_ctr
.num_values
= 1;
1942 attrs
[i
].value_ctr
.values
= vs
;
1947 /* hasMasterNCs: ... */
1949 struct drsuapi_DsAttributeValue
*vs
;
1951 struct drsuapi_DsReplicaObjectIdentifier3 v
[3];
1953 vs
= talloc_array(attrs
, struct drsuapi_DsAttributeValue
, 3);
1954 if (composite_nomem(vs
, c
)) return;
1956 vd
= talloc_array(vs
, DATA_BLOB
, 3);
1957 if (composite_nomem(vd
, c
)) return;
1959 v
[0].guid
= GUID_zero();
1960 v
[0].sid
= s
->zero_sid
;
1961 v
[0].dn
= s
->forest
.config_dn_str
;
1963 v
[1].guid
= GUID_zero();
1964 v
[1].sid
= s
->zero_sid
;
1965 v
[1].dn
= s
->domain
.dn_str
;
1967 v
[2].guid
= GUID_zero();
1968 v
[2].sid
= s
->zero_sid
;
1969 v
[2].dn
= s
->forest
.schema_dn_str
;
1971 ndr_err
= ndr_push_struct_blob(&vd
[0], vd
, iconv_convenience
, &v
[0],
1972 (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3
);
1973 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1974 c
->status
= ndr_map_error2ntstatus(ndr_err
);
1975 if (!composite_is_ok(c
)) return;
1978 ndr_err
= ndr_push_struct_blob(&vd
[1], vd
, iconv_convenience
, &v
[1],
1979 (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3
);
1980 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1981 c
->status
= ndr_map_error2ntstatus(ndr_err
);
1982 if (!composite_is_ok(c
)) return;
1985 ndr_err
= ndr_push_struct_blob(&vd
[2], vd
, iconv_convenience
, &v
[2],
1986 (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3
);
1987 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
1988 c
->status
= ndr_map_error2ntstatus(ndr_err
);
1989 if (!composite_is_ok(c
)) return;
1992 vs
[0].blob
= &vd
[0];
1993 vs
[1].blob
= &vd
[1];
1994 vs
[2].blob
= &vd
[2];
1996 attrs
[i
].attid
= DRSUAPI_ATTRIBUTE_hasMasterNCs
;
1997 attrs
[i
].value_ctr
.num_values
= 3;
1998 attrs
[i
].value_ctr
.values
= vs
;
2003 /* msDS-hasMasterNCs: ... */
2005 struct drsuapi_DsAttributeValue
*vs
;
2007 struct drsuapi_DsReplicaObjectIdentifier3 v
[3];
2009 vs
= talloc_array(attrs
, struct drsuapi_DsAttributeValue
, 3);
2010 if (composite_nomem(vs
, c
)) return;
2012 vd
= talloc_array(vs
, DATA_BLOB
, 3);
2013 if (composite_nomem(vd
, c
)) return;
2015 v
[0].guid
= GUID_zero();
2016 v
[0].sid
= s
->zero_sid
;
2017 v
[0].dn
= s
->forest
.config_dn_str
;
2019 v
[1].guid
= GUID_zero();
2020 v
[1].sid
= s
->zero_sid
;
2021 v
[1].dn
= s
->domain
.dn_str
;
2023 v
[2].guid
= GUID_zero();
2024 v
[2].sid
= s
->zero_sid
;
2025 v
[2].dn
= s
->forest
.schema_dn_str
;
2027 ndr_err
= ndr_push_struct_blob(&vd
[0], vd
, iconv_convenience
, &v
[0],
2028 (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3
);
2029 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2030 c
->status
= ndr_map_error2ntstatus(ndr_err
);
2031 if (!composite_is_ok(c
)) return;
2034 ndr_err
= ndr_push_struct_blob(&vd
[1], vd
, iconv_convenience
, &v
[1],
2035 (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3
);
2036 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2037 c
->status
= ndr_map_error2ntstatus(ndr_err
);
2038 if (!composite_is_ok(c
)) return;
2041 ndr_err
= ndr_push_struct_blob(&vd
[2], vd
, iconv_convenience
, &v
[2],
2042 (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3
);
2043 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2044 c
->status
= ndr_map_error2ntstatus(ndr_err
);
2045 if (!composite_is_ok(c
)) return;
2048 vs
[0].blob
= &vd
[0];
2049 vs
[1].blob
= &vd
[1];
2050 vs
[2].blob
= &vd
[2];
2052 attrs
[i
].attid
= DRSUAPI_ATTRIBUTE_msDS_hasMasterNCs
;
2053 attrs
[i
].value_ctr
.num_values
= 3;
2054 attrs
[i
].value_ctr
.values
= vs
;
2059 /* dMDLocation: CN=Schema,... */
2061 struct drsuapi_DsAttributeValue
*vs
;
2063 struct drsuapi_DsReplicaObjectIdentifier3 v
[1];
2065 vs
= talloc_array(attrs
, struct drsuapi_DsAttributeValue
, 1);
2066 if (composite_nomem(vs
, c
)) return;
2068 vd
= talloc_array(vs
, DATA_BLOB
, 1);
2069 if (composite_nomem(vd
, c
)) return;
2071 v
[0].guid
= GUID_zero();
2072 v
[0].sid
= s
->zero_sid
;
2073 v
[0].dn
= s
->forest
.schema_dn_str
;
2075 ndr_err
= ndr_push_struct_blob(&vd
[0], vd
, iconv_convenience
, &v
[0],
2076 (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3
);
2077 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2078 c
->status
= ndr_map_error2ntstatus(ndr_err
);
2079 if (!composite_is_ok(c
)) return;
2082 vs
[0].blob
= &vd
[0];
2084 attrs
[i
].attid
= DRSUAPI_ATTRIBUTE_dMDLocation
;
2085 attrs
[i
].value_ctr
.num_values
= 1;
2086 attrs
[i
].value_ctr
.values
= vs
;
2091 /* msDS-HasDomainNCs: <domain_partition> */
2093 struct drsuapi_DsAttributeValue
*vs
;
2095 struct drsuapi_DsReplicaObjectIdentifier3 v
[1];
2097 vs
= talloc_array(attrs
, struct drsuapi_DsAttributeValue
, 1);
2098 if (composite_nomem(vs
, c
)) return;
2100 vd
= talloc_array(vs
, DATA_BLOB
, 1);
2101 if (composite_nomem(vd
, c
)) return;
2103 v
[0].guid
= GUID_zero();
2104 v
[0].sid
= s
->zero_sid
;
2105 v
[0].dn
= s
->domain
.dn_str
;
2107 ndr_err
= ndr_push_struct_blob(&vd
[0], vd
, iconv_convenience
, &v
[0],
2108 (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3
);
2109 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2110 c
->status
= ndr_map_error2ntstatus(ndr_err
);
2111 if (!composite_is_ok(c
)) return;
2114 vs
[0].blob
= &vd
[0];
2116 attrs
[i
].attid
= DRSUAPI_ATTRIBUTE_msDS_HasDomainNCs
;
2117 attrs
[i
].value_ctr
.num_values
= 1;
2118 attrs
[i
].value_ctr
.values
= vs
;
2123 /* msDS-Behavior-Version */
2125 struct drsuapi_DsAttributeValue
*vs
;
2128 vs
= talloc_array(attrs
, struct drsuapi_DsAttributeValue
, 1);
2129 if (composite_nomem(vs
, c
)) return;
2131 vd
= talloc_array(vs
, DATA_BLOB
, 1);
2132 if (composite_nomem(vd
, c
)) return;
2134 vd
[0] = data_blob_talloc(vd
, NULL
, 4);
2135 if (composite_nomem(vd
[0].data
, c
)) return;
2137 SIVAL(vd
[0].data
, 0, get_dc_function_level(s
->libnet
->lp_ctx
));
2139 vs
[0].blob
= &vd
[0];
2141 attrs
[i
].attid
= DRSUAPI_ATTRIBUTE_msDS_Behavior_Version
;
2142 attrs
[i
].value_ctr
.num_values
= 1;
2143 attrs
[i
].value_ctr
.values
= vs
;
2150 struct drsuapi_DsAttributeValue
*vs
;
2153 vs
= talloc_array(attrs
, struct drsuapi_DsAttributeValue
, 1);
2154 if (composite_nomem(vs
, c
)) return;
2156 vd
= talloc_array(vs
, DATA_BLOB
, 1);
2157 if (composite_nomem(vd
, c
)) return;
2159 vd
[0] = data_blob_talloc(vd
, NULL
, 4);
2160 if (composite_nomem(vd
[0].data
, c
)) return;
2163 SIVAL(vd
[0].data
, 0, SYSTEM_FLAG_CONFIG_ALLOW_RENAME
);
2165 SIVAL(vd
[0].data
, 0, SYSTEM_FLAG_DISALLOW_MOVE_ON_DELETE
);
2168 vs
[0].blob
= &vd
[0];
2170 attrs
[i
].attid
= DRSUAPI_ATTRIBUTE_systemFlags
;
2171 attrs
[i
].value_ctr
.num_values
= 1;
2172 attrs
[i
].value_ctr
.values
= vs
;
2177 /* serverReference: ... */
2179 struct drsuapi_DsAttributeValue
*vs
;
2181 struct drsuapi_DsReplicaObjectIdentifier3 v
[1];
2183 vs
= talloc_array(attrs
, struct drsuapi_DsAttributeValue
, 1);
2184 if (composite_nomem(vs
, c
)) return;
2186 vd
= talloc_array(vs
, DATA_BLOB
, 1);
2187 if (composite_nomem(vd
, c
)) return;
2189 v
[0].guid
= GUID_zero();
2190 v
[0].sid
= s
->zero_sid
;
2191 v
[0].dn
= s
->dest_dsa
.computer_dn_str
;
2193 ndr_err
= ndr_push_struct_blob(&vd
[0], vd
, iconv_convenience
, &v
[0],
2194 (ndr_push_flags_fn_t
)ndr_push_drsuapi_DsReplicaObjectIdentifier3
);
2195 if (!NDR_ERR_CODE_IS_SUCCESS(ndr_err
)) {
2196 c
->status
= ndr_map_error2ntstatus(ndr_err
);
2197 if (!composite_is_ok(c
)) return;
2200 vs
[0].blob
= &vd
[0];
2202 attrs
[i
].attid
= DRSUAPI_ATTRIBUTE_serverReference
;
2203 attrs
[i
].value_ctr
.num_values
= 1;
2204 attrs
[i
].value_ctr
.values
= vs
;
2211 struct drsuapi_DsAttributeValue
*vs
;
2214 vs
= talloc_array(attrs
, struct drsuapi_DsAttributeValue
, 1);
2215 if (composite_nomem(vs
, c
)) return;
2217 vd
= talloc_array(vs
, DATA_BLOB
, 1);
2218 if (composite_nomem(vd
, c
)) return;
2220 vd
[0] = data_blob_talloc(vd
, NULL
, 4);
2221 if (composite_nomem(vd
[0].data
, c
)) return;
2223 SIVAL(vd
[0].data
, 0, DS_NTDSDSA_OPT_DISABLE_OUTBOUND_REPL
);
2225 vs
[0].blob
= &vd
[0];
2227 attrs
[i
].attid
= DRSUAPI_ATTRIBUTE_options
;
2228 attrs
[i
].value_ctr
.num_values
= 1;
2229 attrs
[i
].value_ctr
.values
= vs
;
2234 /* truncate the attribute list to the attribute count we have filled in */
2237 /* setup request structure */
2238 r
->in
.bind_handle
= &s
->drsuapi1
.bind_handle
;
2240 r
->in
.req
= talloc(s
, union drsuapi_DsAddEntryRequest
);
2241 r
->in
.req
->req2
.first_object
.next_object
= NULL
;
2242 r
->in
.req
->req2
.first_object
.object
.identifier
= identifier
;
2243 r
->in
.req
->req2
.first_object
.object
.flags
= 0x00000000;
2244 r
->in
.req
->req2
.first_object
.object
.attribute_ctr
.num_attributes
= num_attrs
;
2245 r
->in
.req
->req2
.first_object
.object
.attribute_ctr
.attributes
= attrs
;
2247 r
->out
.level_out
= talloc(s
, int32_t);
2248 r
->out
.ctr
= talloc(s
, union drsuapi_DsAddEntryCtr
);
2250 s
->ndr_struct_ptr
= r
;
2251 req
= dcerpc_drsuapi_DsAddEntry_send(s
->drsuapi1
.pipe
, r
, r
);
2252 composite_continue_rpc(c
, req
, becomeDC_drsuapi1_add_entry_recv
, s
);
2255 static void becomeDC_drsuapi2_connect_recv(struct composite_context
*req
);
2256 static NTSTATUS
becomeDC_prepare_db(struct libnet_BecomeDC_state
*s
);
2258 static void becomeDC_drsuapi1_add_entry_recv(struct rpc_request
*req
)
2260 struct libnet_BecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
2261 struct libnet_BecomeDC_state
);
2262 struct composite_context
*c
= s
->creq
;
2263 struct drsuapi_DsAddEntry
*r
= talloc_get_type_abort(s
->ndr_struct_ptr
,
2264 struct drsuapi_DsAddEntry
);
2267 s
->ndr_struct_ptr
= NULL
;
2269 c
->status
= dcerpc_drsuapi_DsAddEntry_recv(req
);
2270 if (!composite_is_ok(c
)) return;
2272 if (!W_ERROR_IS_OK(r
->out
.result
)) {
2273 composite_error(c
, werror_to_ntstatus(r
->out
.result
));
2277 if (*r
->out
.level_out
== 3) {
2278 if (r
->out
.ctr
->ctr3
.count
!= 1) {
2281 if (r
->out
.ctr
->ctr3
.level
!= 1) {
2282 composite_error(c
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
2286 if (!r
->out
.ctr
->ctr3
.error
) {
2287 composite_error(c
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
2291 status
= r
->out
.ctr
->ctr3
.error
->info1
.status
;
2293 if (!r
->out
.ctr
->ctr3
.error
->info1
.info
) {
2294 composite_error(c
, werror_to_ntstatus(status
));
2298 /* see if we can get a more detailed error */
2299 switch (r
->out
.ctr
->ctr3
.error
->info1
.level
) {
2301 status
= r
->out
.ctr
->ctr3
.error
->info1
.info
->error1
.status
;
2307 status
= r
->out
.ctr
->ctr3
.error
->info1
.info
->errorX
.status
;
2311 composite_error(c
, werror_to_ntstatus(status
));
2315 s
->dest_dsa
.ntds_guid
= r
->out
.ctr
->ctr3
.objects
[0].guid
;
2316 } else if (*r
->out
.level_out
== 2) {
2317 if (r
->out
.ctr
->ctr2
.count
!= 1) {
2318 composite_error(c
, werror_to_ntstatus(r
->out
.ctr
->ctr2
.error
.status
));
2322 s
->dest_dsa
.ntds_guid
= r
->out
.ctr
->ctr2
.objects
[0].guid
;
2324 composite_error(c
, NT_STATUS_INVALID_NETWORK_RESPONSE
);
2330 s
->dest_dsa
.ntds_dn_str
= talloc_asprintf(s
, "CN=NTDS Settings,%s",
2331 s
->dest_dsa
.server_dn_str
);
2332 if (composite_nomem(s
->dest_dsa
.ntds_dn_str
, c
)) return;
2334 c
->status
= becomeDC_prepare_db(s
);
2335 if (!composite_is_ok(c
)) return;
2337 /* this avoids the epmapper lookup on the 2nd connection */
2338 binding_str
= dcerpc_binding_string(s
, s
->drsuapi1
.binding
);
2339 if (composite_nomem(binding_str
, c
)) return;
2341 c
->status
= dcerpc_parse_binding(s
, binding_str
, &s
->drsuapi2
.binding
);
2342 talloc_free(binding_str
);
2343 if (!composite_is_ok(c
)) return;
2345 /* w2k3 uses the same assoc_group_id as on the first connection, so we do */
2346 s
->drsuapi2
.binding
->assoc_group_id
= s
->drsuapi1
.pipe
->assoc_group_id
;
2348 becomeDC_drsuapi_connect_send(s
, &s
->drsuapi2
, becomeDC_drsuapi2_connect_recv
);
2351 static NTSTATUS
becomeDC_prepare_db(struct libnet_BecomeDC_state
*s
)
2353 if (!s
->callbacks
.prepare_db
) return NT_STATUS_OK
;
2355 s
->_pp
.domain
= &s
->domain
;
2356 s
->_pp
.forest
= &s
->forest
;
2357 s
->_pp
.source_dsa
= &s
->source_dsa
;
2358 s
->_pp
.dest_dsa
= &s
->dest_dsa
;
2360 return s
->callbacks
.prepare_db(s
->callbacks
.private_data
, &s
->_pp
);
2363 static void becomeDC_drsuapi2_bind_recv(struct rpc_request
*req
);
2365 static void becomeDC_drsuapi2_connect_recv(struct composite_context
*req
)
2367 struct libnet_BecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
2368 struct libnet_BecomeDC_state
);
2369 struct composite_context
*c
= s
->creq
;
2371 c
->status
= dcerpc_pipe_connect_b_recv(req
, s
, &s
->drsuapi2
.pipe
);
2372 if (!composite_is_ok(c
)) return;
2374 c
->status
= gensec_session_key(s
->drsuapi2
.pipe
->conn
->security_state
.generic_state
,
2375 &s
->drsuapi2
.gensec_skey
);
2376 if (!composite_is_ok(c
)) return;
2378 becomeDC_drsuapi_bind_send(s
, &s
->drsuapi2
, becomeDC_drsuapi2_bind_recv
);
2381 static void becomeDC_drsuapi3_connect_recv(struct composite_context
*req
);
2383 static void becomeDC_drsuapi2_bind_recv(struct rpc_request
*req
)
2385 struct libnet_BecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
2386 struct libnet_BecomeDC_state
);
2387 struct composite_context
*c
= s
->creq
;
2391 c
->status
= dcerpc_drsuapi_DsBind_recv(req
);
2392 if (!composite_is_ok(c
)) return;
2394 status
= becomeDC_drsuapi_bind_recv(s
, &s
->drsuapi2
);
2395 if (!W_ERROR_IS_OK(status
)) {
2396 composite_error(c
, werror_to_ntstatus(status
));
2400 /* this avoids the epmapper lookup on the 3rd connection */
2401 binding_str
= dcerpc_binding_string(s
, s
->drsuapi1
.binding
);
2402 if (composite_nomem(binding_str
, c
)) return;
2404 c
->status
= dcerpc_parse_binding(s
, binding_str
, &s
->drsuapi3
.binding
);
2405 talloc_free(binding_str
);
2406 if (!composite_is_ok(c
)) return;
2408 /* w2k3 uses the same assoc_group_id as on the first connection, so we do */
2409 s
->drsuapi3
.binding
->assoc_group_id
= s
->drsuapi1
.pipe
->assoc_group_id
;
2410 /* w2k3 uses the concurrent multiplex feature on the 3rd connection, so we do */
2411 s
->drsuapi3
.binding
->flags
|= DCERPC_CONCURRENT_MULTIPLEX
;
2413 becomeDC_drsuapi_connect_send(s
, &s
->drsuapi3
, becomeDC_drsuapi3_connect_recv
);
2416 static void becomeDC_drsuapi3_pull_schema_send(struct libnet_BecomeDC_state
*s
);
2418 static void becomeDC_drsuapi3_connect_recv(struct composite_context
*req
)
2420 struct libnet_BecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
2421 struct libnet_BecomeDC_state
);
2422 struct composite_context
*c
= s
->creq
;
2424 c
->status
= dcerpc_pipe_connect_b_recv(req
, s
, &s
->drsuapi3
.pipe
);
2425 if (!composite_is_ok(c
)) return;
2427 c
->status
= gensec_session_key(s
->drsuapi3
.pipe
->conn
->security_state
.generic_state
,
2428 &s
->drsuapi3
.gensec_skey
);
2429 if (!composite_is_ok(c
)) return;
2431 becomeDC_drsuapi3_pull_schema_send(s
);
2434 static void becomeDC_drsuapi_pull_partition_send(struct libnet_BecomeDC_state
*s
,
2435 struct becomeDC_drsuapi
*drsuapi_h
,
2436 struct becomeDC_drsuapi
*drsuapi_p
,
2437 struct libnet_BecomeDC_Partition
*partition
,
2438 void (*recv_fn
)(struct rpc_request
*req
))
2440 struct composite_context
*c
= s
->creq
;
2441 struct rpc_request
*req
;
2442 struct drsuapi_DsGetNCChanges
*r
;
2444 r
= talloc(s
, struct drsuapi_DsGetNCChanges
);
2445 if (composite_nomem(r
, c
)) return;
2447 r
->out
.level_out
= talloc(r
, uint32_t);
2448 if (composite_nomem(r
->out
.level_out
, c
)) return;
2449 r
->in
.req
= talloc(r
, union drsuapi_DsGetNCChangesRequest
);
2450 if (composite_nomem(r
->in
.req
, c
)) return;
2451 r
->out
.ctr
= talloc(r
, union drsuapi_DsGetNCChangesCtr
);
2452 if (composite_nomem(r
->out
.ctr
, c
)) return;
2454 r
->in
.bind_handle
= &drsuapi_h
->bind_handle
;
2455 if (drsuapi_h
->remote_info28
.supported_extensions
& DRSUAPI_SUPPORTED_EXTENSION_GETCHGREQ_V8
) {
2457 r
->in
.req
->req8
.destination_dsa_guid
= partition
->destination_dsa_guid
;
2458 r
->in
.req
->req8
.source_dsa_invocation_id
= partition
->source_dsa_invocation_id
;
2459 r
->in
.req
->req8
.naming_context
= &partition
->nc
;
2460 r
->in
.req
->req8
.highwatermark
= partition
->highwatermark
;
2461 r
->in
.req
->req8
.uptodateness_vector
= NULL
;
2462 r
->in
.req
->req8
.replica_flags
= partition
->replica_flags
;
2463 r
->in
.req
->req8
.max_object_count
= 133;
2464 r
->in
.req
->req8
.max_ndr_size
= 1336811;
2465 r
->in
.req
->req8
.extended_op
= DRSUAPI_EXOP_NONE
;
2466 r
->in
.req
->req8
.fsmo_info
= 0;
2467 r
->in
.req
->req8
.partial_attribute_set
= NULL
;
2468 r
->in
.req
->req8
.partial_attribute_set_ex
= NULL
;
2469 r
->in
.req
->req8
.mapping_ctr
.num_mappings
= 0;
2470 r
->in
.req
->req8
.mapping_ctr
.mappings
= NULL
;
2473 r
->in
.req
->req5
.destination_dsa_guid
= partition
->destination_dsa_guid
;
2474 r
->in
.req
->req5
.source_dsa_invocation_id
= partition
->source_dsa_invocation_id
;
2475 r
->in
.req
->req5
.naming_context
= &partition
->nc
;
2476 r
->in
.req
->req5
.highwatermark
= partition
->highwatermark
;
2477 r
->in
.req
->req5
.uptodateness_vector
= NULL
;
2478 r
->in
.req
->req5
.replica_flags
= partition
->replica_flags
;
2479 r
->in
.req
->req5
.max_object_count
= 133;
2480 r
->in
.req
->req5
.max_ndr_size
= 1336770;
2481 r
->in
.req
->req5
.extended_op
= DRSUAPI_EXOP_NONE
;
2482 r
->in
.req
->req5
.fsmo_info
= 0;
2486 * we should try to use the drsuapi_p->pipe here, as w2k3 does
2487 * but it seems that some extra flags in the DCERPC Bind call
2488 * are needed for it. Or the same KRB5 TGS is needed on both
2491 s
->ndr_struct_ptr
= r
;
2492 req
= dcerpc_drsuapi_DsGetNCChanges_send(drsuapi_p
->pipe
, r
, r
);
2493 composite_continue_rpc(c
, req
, recv_fn
, s
);
2496 static WERROR
becomeDC_drsuapi_pull_partition_recv(struct libnet_BecomeDC_state
*s
,
2497 struct becomeDC_drsuapi
*drsuapi_h
,
2498 struct becomeDC_drsuapi
*drsuapi_p
,
2499 struct libnet_BecomeDC_Partition
*partition
,
2500 struct drsuapi_DsGetNCChanges
*r
)
2502 uint32_t ctr_level
= 0;
2503 struct drsuapi_DsGetNCChangesCtr1
*ctr1
= NULL
;
2504 struct drsuapi_DsGetNCChangesCtr6
*ctr6
= NULL
;
2505 struct GUID
*source_dsa_guid
= NULL
;
2506 struct GUID
*source_dsa_invocation_id
= NULL
;
2507 struct drsuapi_DsReplicaHighWaterMark
*new_highwatermark
= NULL
;
2508 bool more_data
= false;
2511 if (!W_ERROR_IS_OK(r
->out
.result
)) {
2512 return r
->out
.result
;
2515 if (*r
->out
.level_out
== 1) {
2517 ctr1
= &r
->out
.ctr
->ctr1
;
2518 } else if (*r
->out
.level_out
== 2 &&
2519 r
->out
.ctr
->ctr2
.mszip1
.ts
) {
2521 ctr1
= &r
->out
.ctr
->ctr2
.mszip1
.ts
->ctr1
;
2522 } else if (*r
->out
.level_out
== 6) {
2524 ctr6
= &r
->out
.ctr
->ctr6
;
2525 } else if (*r
->out
.level_out
== 7 &&
2526 r
->out
.ctr
->ctr7
.level
== 6 &&
2527 r
->out
.ctr
->ctr7
.type
== DRSUAPI_COMPRESSION_TYPE_MSZIP
&&
2528 r
->out
.ctr
->ctr7
.ctr
.mszip6
.ts
) {
2530 ctr6
= &r
->out
.ctr
->ctr7
.ctr
.mszip6
.ts
->ctr6
;
2531 } else if (*r
->out
.level_out
== 7 &&
2532 r
->out
.ctr
->ctr7
.level
== 6 &&
2533 r
->out
.ctr
->ctr7
.type
== DRSUAPI_COMPRESSION_TYPE_XPRESS
&&
2534 r
->out
.ctr
->ctr7
.ctr
.xpress6
.ts
) {
2536 ctr6
= &r
->out
.ctr
->ctr7
.ctr
.xpress6
.ts
->ctr6
;
2538 return WERR_BAD_NET_RESP
;
2541 if (!ctr1
&& ! ctr6
) {
2542 return WERR_BAD_NET_RESP
;
2545 if (ctr_level
== 6) {
2546 if (!W_ERROR_IS_OK(ctr6
->drs_error
)) {
2547 return ctr6
->drs_error
;
2551 switch (ctr_level
) {
2553 source_dsa_guid
= &ctr1
->source_dsa_guid
;
2554 source_dsa_invocation_id
= &ctr1
->source_dsa_invocation_id
;
2555 new_highwatermark
= &ctr1
->new_highwatermark
;
2556 more_data
= ctr1
->more_data
;
2559 source_dsa_guid
= &ctr6
->source_dsa_guid
;
2560 source_dsa_invocation_id
= &ctr6
->source_dsa_invocation_id
;
2561 new_highwatermark
= &ctr6
->new_highwatermark
;
2562 more_data
= ctr6
->more_data
;
2566 partition
->highwatermark
= *new_highwatermark
;
2567 partition
->source_dsa_guid
= *source_dsa_guid
;
2568 partition
->source_dsa_invocation_id
= *source_dsa_invocation_id
;
2569 partition
->more_data
= more_data
;
2571 if (!partition
->store_chunk
) return WERR_OK
;
2573 s
->_sc
.domain
= &s
->domain
;
2574 s
->_sc
.forest
= &s
->forest
;
2575 s
->_sc
.source_dsa
= &s
->source_dsa
;
2576 s
->_sc
.dest_dsa
= &s
->dest_dsa
;
2577 s
->_sc
.partition
= partition
;
2578 s
->_sc
.ctr_level
= ctr_level
;
2582 * we need to use the drsuapi_p->gensec_skey here,
2583 * when we use drsuapi_p->pipe in the for this request
2585 s
->_sc
.gensec_skey
= &drsuapi_p
->gensec_skey
;
2587 nt_status
= partition
->store_chunk(s
->callbacks
.private_data
, &s
->_sc
);
2588 if (!NT_STATUS_IS_OK(nt_status
)) {
2589 return ntstatus_to_werror(nt_status
);
2595 static void becomeDC_drsuapi3_pull_schema_recv(struct rpc_request
*req
);
2597 static void becomeDC_drsuapi3_pull_schema_send(struct libnet_BecomeDC_state
*s
)
2599 s
->schema_part
.nc
.guid
= GUID_zero();
2600 s
->schema_part
.nc
.sid
= s
->zero_sid
;
2601 s
->schema_part
.nc
.dn
= s
->forest
.schema_dn_str
;
2603 s
->schema_part
.destination_dsa_guid
= s
->drsuapi2
.bind_guid
;
2605 s
->schema_part
.replica_flags
= DRSUAPI_DRS_WRIT_REP
2606 | DRSUAPI_DRS_INIT_SYNC
2607 | DRSUAPI_DRS_PER_SYNC
2608 | DRSUAPI_DRS_FULL_SYNC_IN_PROGRESS
2609 | DRSUAPI_DRS_NEVER_SYNCED
2610 | DRSUAPI_DRS_USE_COMPRESSION
;
2612 s
->schema_part
.replica_flags
&= ~DRSUAPI_DRS_WRIT_REP
;
2615 s
->schema_part
.store_chunk
= s
->callbacks
.schema_chunk
;
2617 becomeDC_drsuapi_pull_partition_send(s
, &s
->drsuapi2
, &s
->drsuapi3
, &s
->schema_part
,
2618 becomeDC_drsuapi3_pull_schema_recv
);
2621 static void becomeDC_drsuapi3_pull_config_send(struct libnet_BecomeDC_state
*s
);
2623 static void becomeDC_drsuapi3_pull_schema_recv(struct rpc_request
*req
)
2625 struct libnet_BecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
2626 struct libnet_BecomeDC_state
);
2627 struct composite_context
*c
= s
->creq
;
2628 struct drsuapi_DsGetNCChanges
*r
= talloc_get_type_abort(s
->ndr_struct_ptr
,
2629 struct drsuapi_DsGetNCChanges
);
2632 s
->ndr_struct_ptr
= NULL
;
2634 c
->status
= dcerpc_drsuapi_DsGetNCChanges_recv(req
);
2635 if (!composite_is_ok(c
)) return;
2637 status
= becomeDC_drsuapi_pull_partition_recv(s
, &s
->drsuapi2
, &s
->drsuapi3
, &s
->schema_part
, r
);
2638 if (!W_ERROR_IS_OK(status
)) {
2639 composite_error(c
, werror_to_ntstatus(status
));
2645 if (s
->schema_part
.more_data
) {
2646 becomeDC_drsuapi_pull_partition_send(s
, &s
->drsuapi2
, &s
->drsuapi3
, &s
->schema_part
,
2647 becomeDC_drsuapi3_pull_schema_recv
);
2651 becomeDC_drsuapi3_pull_config_send(s
);
2654 static void becomeDC_drsuapi3_pull_config_recv(struct rpc_request
*req
);
2656 static void becomeDC_drsuapi3_pull_config_send(struct libnet_BecomeDC_state
*s
)
2658 s
->config_part
.nc
.guid
= GUID_zero();
2659 s
->config_part
.nc
.sid
= s
->zero_sid
;
2660 s
->config_part
.nc
.dn
= s
->forest
.config_dn_str
;
2662 s
->config_part
.destination_dsa_guid
= s
->drsuapi2
.bind_guid
;
2664 s
->config_part
.replica_flags
= DRSUAPI_DRS_WRIT_REP
2665 | DRSUAPI_DRS_INIT_SYNC
2666 | DRSUAPI_DRS_PER_SYNC
2667 | DRSUAPI_DRS_FULL_SYNC_IN_PROGRESS
2668 | DRSUAPI_DRS_NEVER_SYNCED
2669 | DRSUAPI_DRS_USE_COMPRESSION
;
2671 s
->schema_part
.replica_flags
&= ~DRSUAPI_DRS_WRIT_REP
;
2674 s
->config_part
.store_chunk
= s
->callbacks
.config_chunk
;
2676 becomeDC_drsuapi_pull_partition_send(s
, &s
->drsuapi2
, &s
->drsuapi3
, &s
->config_part
,
2677 becomeDC_drsuapi3_pull_config_recv
);
2680 static void becomeDC_drsuapi3_pull_config_recv(struct rpc_request
*req
)
2682 struct libnet_BecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
2683 struct libnet_BecomeDC_state
);
2684 struct composite_context
*c
= s
->creq
;
2685 struct drsuapi_DsGetNCChanges
*r
= talloc_get_type_abort(s
->ndr_struct_ptr
,
2686 struct drsuapi_DsGetNCChanges
);
2689 s
->ndr_struct_ptr
= NULL
;
2691 c
->status
= dcerpc_drsuapi_DsGetNCChanges_recv(req
);
2692 if (!composite_is_ok(c
)) return;
2694 status
= becomeDC_drsuapi_pull_partition_recv(s
, &s
->drsuapi2
, &s
->drsuapi3
, &s
->config_part
, r
);
2695 if (!W_ERROR_IS_OK(status
)) {
2696 composite_error(c
, werror_to_ntstatus(status
));
2702 if (s
->config_part
.more_data
) {
2703 becomeDC_drsuapi_pull_partition_send(s
, &s
->drsuapi2
, &s
->drsuapi3
, &s
->config_part
,
2704 becomeDC_drsuapi3_pull_config_recv
);
2708 becomeDC_connect_ldap2(s
);
2711 static void becomeDC_drsuapi3_pull_domain_recv(struct rpc_request
*req
);
2713 static void becomeDC_drsuapi3_pull_domain_send(struct libnet_BecomeDC_state
*s
)
2715 s
->domain_part
.nc
.guid
= GUID_zero();
2716 s
->domain_part
.nc
.sid
= s
->zero_sid
;
2717 s
->domain_part
.nc
.dn
= s
->domain
.dn_str
;
2719 s
->domain_part
.destination_dsa_guid
= s
->drsuapi2
.bind_guid
;
2721 s
->domain_part
.replica_flags
= DRSUAPI_DRS_WRIT_REP
2722 | DRSUAPI_DRS_INIT_SYNC
2723 | DRSUAPI_DRS_PER_SYNC
2724 | DRSUAPI_DRS_FULL_SYNC_IN_PROGRESS
2725 | DRSUAPI_DRS_NEVER_SYNCED
2726 | DRSUAPI_DRS_USE_COMPRESSION
;
2728 s
->schema_part
.replica_flags
&= ~DRSUAPI_DRS_WRIT_REP
;
2731 s
->domain_part
.store_chunk
= s
->callbacks
.domain_chunk
;
2733 becomeDC_drsuapi_pull_partition_send(s
, &s
->drsuapi2
, &s
->drsuapi3
, &s
->domain_part
,
2734 becomeDC_drsuapi3_pull_domain_recv
);
2737 static void becomeDC_drsuapi_update_refs_send(struct libnet_BecomeDC_state
*s
,
2738 struct becomeDC_drsuapi
*drsuapi
,
2739 struct libnet_BecomeDC_Partition
*partition
,
2740 void (*recv_fn
)(struct rpc_request
*req
));
2741 static void becomeDC_drsuapi2_update_refs_schema_recv(struct rpc_request
*req
);
2743 static void becomeDC_drsuapi3_pull_domain_recv(struct rpc_request
*req
)
2745 struct libnet_BecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
2746 struct libnet_BecomeDC_state
);
2747 struct composite_context
*c
= s
->creq
;
2748 struct drsuapi_DsGetNCChanges
*r
= talloc_get_type_abort(s
->ndr_struct_ptr
,
2749 struct drsuapi_DsGetNCChanges
);
2752 s
->ndr_struct_ptr
= NULL
;
2754 c
->status
= dcerpc_drsuapi_DsGetNCChanges_recv(req
);
2755 if (!composite_is_ok(c
)) return;
2757 status
= becomeDC_drsuapi_pull_partition_recv(s
, &s
->drsuapi2
, &s
->drsuapi3
, &s
->domain_part
, r
);
2758 if (!W_ERROR_IS_OK(status
)) {
2759 composite_error(c
, werror_to_ntstatus(status
));
2765 if (s
->domain_part
.more_data
) {
2766 becomeDC_drsuapi_pull_partition_send(s
, &s
->drsuapi2
, &s
->drsuapi3
, &s
->domain_part
,
2767 becomeDC_drsuapi3_pull_domain_recv
);
2771 becomeDC_drsuapi_update_refs_send(s
, &s
->drsuapi2
, &s
->schema_part
,
2772 becomeDC_drsuapi2_update_refs_schema_recv
);
2775 static void becomeDC_drsuapi_update_refs_send(struct libnet_BecomeDC_state
*s
,
2776 struct becomeDC_drsuapi
*drsuapi
,
2777 struct libnet_BecomeDC_Partition
*partition
,
2778 void (*recv_fn
)(struct rpc_request
*req
))
2780 struct composite_context
*c
= s
->creq
;
2781 struct rpc_request
*req
;
2782 struct drsuapi_DsReplicaUpdateRefs
*r
;
2783 const char *ntds_guid_str
;
2784 const char *ntds_dns_name
;
2786 r
= talloc(s
, struct drsuapi_DsReplicaUpdateRefs
);
2787 if (composite_nomem(r
, c
)) return;
2789 ntds_guid_str
= GUID_string(r
, &s
->dest_dsa
.ntds_guid
);
2790 if (composite_nomem(ntds_guid_str
, c
)) return;
2792 ntds_dns_name
= talloc_asprintf(r
, "%s._msdcs.%s",
2794 s
->domain
.dns_name
);
2795 if (composite_nomem(ntds_dns_name
, c
)) return;
2797 r
->in
.bind_handle
= &drsuapi
->bind_handle
;
2799 r
->in
.req
.req1
.naming_context
= &partition
->nc
;
2800 r
->in
.req
.req1
.dest_dsa_dns_name
= ntds_dns_name
;
2801 r
->in
.req
.req1
.dest_dsa_guid
= s
->dest_dsa
.ntds_guid
;
2802 r
->in
.req
.req1
.options
= DRSUAPI_DRS_ADD_REF
| DRSUAPI_DRS_DEL_REF
;
2804 /* I think this is how we mark ourselves as a RODC */
2805 if (!lp_parm_bool(s
->libnet
->lp_ctx
, NULL
, "repl", "RODC", false)) {
2806 r
->in
.req
.req1
.options
|= DRSUAPI_DRS_WRIT_REP
;
2809 s
->ndr_struct_ptr
= r
;
2810 req
= dcerpc_drsuapi_DsReplicaUpdateRefs_send(drsuapi
->pipe
, r
, r
);
2811 composite_continue_rpc(c
, req
, recv_fn
, s
);
2814 static void becomeDC_drsuapi2_update_refs_config_recv(struct rpc_request
*req
);
2816 static void becomeDC_drsuapi2_update_refs_schema_recv(struct rpc_request
*req
)
2818 struct libnet_BecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
2819 struct libnet_BecomeDC_state
);
2820 struct composite_context
*c
= s
->creq
;
2821 struct drsuapi_DsReplicaUpdateRefs
*r
= talloc_get_type_abort(s
->ndr_struct_ptr
,
2822 struct drsuapi_DsReplicaUpdateRefs
);
2824 s
->ndr_struct_ptr
= NULL
;
2826 c
->status
= dcerpc_drsuapi_DsReplicaUpdateRefs_recv(req
);
2827 if (!composite_is_ok(c
)) return;
2829 if (!W_ERROR_IS_OK(r
->out
.result
)) {
2830 composite_error(c
, werror_to_ntstatus(r
->out
.result
));
2836 becomeDC_drsuapi_update_refs_send(s
, &s
->drsuapi2
, &s
->config_part
,
2837 becomeDC_drsuapi2_update_refs_config_recv
);
2840 static void becomeDC_drsuapi2_update_refs_domain_recv(struct rpc_request
*req
);
2842 static void becomeDC_drsuapi2_update_refs_config_recv(struct rpc_request
*req
)
2844 struct libnet_BecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
2845 struct libnet_BecomeDC_state
);
2846 struct composite_context
*c
= s
->creq
;
2847 struct drsuapi_DsReplicaUpdateRefs
*r
= talloc_get_type(s
->ndr_struct_ptr
,
2848 struct drsuapi_DsReplicaUpdateRefs
);
2850 s
->ndr_struct_ptr
= NULL
;
2852 c
->status
= dcerpc_drsuapi_DsReplicaUpdateRefs_recv(req
);
2853 if (!composite_is_ok(c
)) return;
2855 if (!W_ERROR_IS_OK(r
->out
.result
)) {
2856 composite_error(c
, werror_to_ntstatus(r
->out
.result
));
2862 becomeDC_drsuapi_update_refs_send(s
, &s
->drsuapi2
, &s
->domain_part
,
2863 becomeDC_drsuapi2_update_refs_domain_recv
);
2866 static void becomeDC_drsuapi2_update_refs_domain_recv(struct rpc_request
*req
)
2868 struct libnet_BecomeDC_state
*s
= talloc_get_type(req
->async
.private_data
,
2869 struct libnet_BecomeDC_state
);
2870 struct composite_context
*c
= s
->creq
;
2871 struct drsuapi_DsReplicaUpdateRefs
*r
= talloc_get_type(s
->ndr_struct_ptr
,
2872 struct drsuapi_DsReplicaUpdateRefs
);
2874 s
->ndr_struct_ptr
= NULL
;
2876 c
->status
= dcerpc_drsuapi_DsReplicaUpdateRefs_recv(req
);
2877 if (!composite_is_ok(c
)) return;
2879 if (!W_ERROR_IS_OK(r
->out
.result
)) {
2880 composite_error(c
, werror_to_ntstatus(r
->out
.result
));
2886 /* TODO: use DDNS updates and register dns names */
2890 static NTSTATUS
becomeDC_ldap2_modify_computer(struct libnet_BecomeDC_state
*s
)
2893 struct ldb_message
*msg
;
2895 uint32_t user_account_control
= UF_SERVER_TRUST_ACCOUNT
|
2896 UF_TRUSTED_FOR_DELEGATION
;
2898 /* as the value is already as we want it to be, we're done */
2899 if (s
->dest_dsa
.user_account_control
== user_account_control
) {
2900 return NT_STATUS_OK
;
2903 /* make a 'modify' msg, and only for serverReference */
2904 msg
= ldb_msg_new(s
);
2905 NT_STATUS_HAVE_NO_MEMORY(msg
);
2906 msg
->dn
= ldb_dn_new(msg
, s
->ldap2
.ldb
, s
->dest_dsa
.computer_dn_str
);
2907 NT_STATUS_HAVE_NO_MEMORY(msg
->dn
);
2909 ret
= ldb_msg_add_fmt(msg
, "userAccountControl", "%u", user_account_control
);
2912 return NT_STATUS_NO_MEMORY
;
2915 /* mark all the message elements (should be just one)
2916 as LDB_FLAG_MOD_REPLACE */
2917 for (i
=0;i
<msg
->num_elements
;i
++) {
2918 msg
->elements
[i
].flags
= LDB_FLAG_MOD_REPLACE
;
2921 ret
= ldb_modify(s
->ldap2
.ldb
, msg
);
2923 if (ret
!= LDB_SUCCESS
) {
2924 return NT_STATUS_LDAP(ret
);
2927 s
->dest_dsa
.user_account_control
= user_account_control
;
2929 return NT_STATUS_OK
;
2932 static NTSTATUS
becomeDC_ldap2_move_computer(struct libnet_BecomeDC_state
*s
)
2935 struct ldb_dn
*old_dn
;
2936 struct ldb_dn
*new_dn
;
2938 ret
= dsdb_wellknown_dn(s
->ldap2
.ldb
, s
, samdb_base_dn(s
->ldap2
.ldb
),
2939 DS_GUID_DOMAIN_CONTROLLERS_CONTAINER
,
2941 if (ret
!= LDB_SUCCESS
) {
2942 return NT_STATUS_LDAP(ret
);
2945 if (!ldb_dn_add_child_fmt(new_dn
, "CN=%s", s
->dest_dsa
.netbios_name
)) {
2946 talloc_free(new_dn
);
2947 return NT_STATUS_NO_MEMORY
;
2950 old_dn
= ldb_dn_new(new_dn
, s
->ldap2
.ldb
, s
->dest_dsa
.computer_dn_str
);
2951 NT_STATUS_HAVE_NO_MEMORY(old_dn
);
2953 if (ldb_dn_compare(old_dn
, new_dn
) == 0) {
2954 /* we don't need to rename if the old and new dn match */
2955 talloc_free(new_dn
);
2956 return NT_STATUS_OK
;
2959 ret
= ldb_rename(s
->ldap2
.ldb
, old_dn
, new_dn
);
2960 if (ret
!= LDB_SUCCESS
) {
2961 talloc_free(new_dn
);
2962 return NT_STATUS_LDAP(ret
);
2965 s
->dest_dsa
.computer_dn_str
= ldb_dn_alloc_linearized(s
, new_dn
);
2966 NT_STATUS_HAVE_NO_MEMORY(s
->dest_dsa
.computer_dn_str
);
2968 talloc_free(new_dn
);
2970 return NT_STATUS_OK
;
2973 static void becomeDC_connect_ldap2(struct libnet_BecomeDC_state
*s
)
2975 struct composite_context
*c
= s
->creq
;
2977 c
->status
= becomeDC_ldap_connect(s
, &s
->ldap2
);
2978 if (!composite_is_ok(c
)) return;
2980 c
->status
= becomeDC_ldap2_modify_computer(s
);
2981 if (!composite_is_ok(c
)) return;
2983 c
->status
= becomeDC_ldap2_move_computer(s
);
2984 if (!composite_is_ok(c
)) return;
2986 becomeDC_drsuapi3_pull_domain_send(s
);
2989 struct composite_context
*libnet_BecomeDC_send(struct libnet_context
*ctx
, TALLOC_CTX
*mem_ctx
, struct libnet_BecomeDC
*r
)
2991 struct composite_context
*c
;
2992 struct libnet_BecomeDC_state
*s
;
2995 c
= composite_create(mem_ctx
, ctx
->event_ctx
);
2996 if (c
== NULL
) return NULL
;
2998 s
= talloc_zero(c
, struct libnet_BecomeDC_state
);
2999 if (composite_nomem(s
, c
)) return c
;
3000 c
->private_data
= s
;
3005 s
->domain
.dns_name
= talloc_strdup(s
, r
->in
.domain_dns_name
);
3006 if (composite_nomem(s
->domain
.dns_name
, c
)) return c
;
3007 s
->domain
.netbios_name
= talloc_strdup(s
, r
->in
.domain_netbios_name
);
3008 if (composite_nomem(s
->domain
.netbios_name
, c
)) return c
;
3009 s
->domain
.sid
= dom_sid_dup(s
, r
->in
.domain_sid
);
3010 if (composite_nomem(s
->domain
.sid
, c
)) return c
;
3012 /* Source DSA input */
3013 s
->source_dsa
.address
= talloc_strdup(s
, r
->in
.source_dsa_address
);
3014 if (composite_nomem(s
->source_dsa
.address
, c
)) return c
;
3016 /* Destination DSA input */
3017 s
->dest_dsa
.netbios_name
= talloc_strdup(s
, r
->in
.dest_dsa_netbios_name
);
3018 if (composite_nomem(s
->dest_dsa
.netbios_name
, c
)) return c
;
3020 /* Destination DSA dns_name construction */
3021 tmp_name
= strlower_talloc(s
, s
->dest_dsa
.netbios_name
);
3022 if (composite_nomem(tmp_name
, c
)) return c
;
3023 tmp_name
= talloc_asprintf_append_buffer(tmp_name
, ".%s",s
->domain
.dns_name
);
3024 if (composite_nomem(tmp_name
, c
)) return c
;
3025 s
->dest_dsa
.dns_name
= tmp_name
;
3027 /* Callback function pointers */
3028 s
->callbacks
= r
->in
.callbacks
;
3031 s
->rodc_join
= r
->in
.rodc_join
;
3033 becomeDC_send_cldap(s
);
3037 NTSTATUS
libnet_BecomeDC_recv(struct composite_context
*c
, TALLOC_CTX
*mem_ctx
, struct libnet_BecomeDC
*r
)
3041 status
= composite_wait(c
);
3043 ZERO_STRUCT(r
->out
);
3049 NTSTATUS
libnet_BecomeDC(struct libnet_context
*ctx
, TALLOC_CTX
*mem_ctx
, struct libnet_BecomeDC
*r
)
3052 struct composite_context
*c
;
3053 c
= libnet_BecomeDC_send(ctx
, mem_ctx
, r
);
3054 status
= libnet_BecomeDC_recv(c
, mem_ctx
, r
);