2 * Unix SMB/CIFS implementation.
4 * Copyright (C) Gerald (Jerry) Carter 2006
5 * Copyright (C) Guenther Deschner 2007-2008
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 3 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, see <http://www.gnu.org/licenses/>.
23 #include "librpc/gen_ndr/ndr_libnet_join.h"
24 #include "libnet/libnet_join.h"
25 #include "libcli/auth/libcli_auth.h"
26 #include "../librpc/gen_ndr/ndr_samr_c.h"
27 #include "rpc_client/init_samr.h"
28 #include "../librpc/gen_ndr/ndr_lsa_c.h"
29 #include "rpc_client/cli_lsarpc.h"
30 #include "../librpc/gen_ndr/ndr_netlogon.h"
31 #include "rpc_client/cli_netlogon.h"
32 #include "lib/smbconf/smbconf.h"
33 #include "lib/smbconf/smbconf_reg.h"
34 #include "../libds/common/flags.h"
36 #include "rpc_client/init_lsa.h"
37 #include "rpc_client/cli_pipe.h"
38 #include "../libcli/security/security.h"
40 #include "libsmb/libsmb.h"
41 #include "../libcli/smb/smbXcli_base.h"
42 #include "lib/param/loadparm.h"
43 #include "libcli/auth/netlogon_creds_cli.h"
44 #include "auth/credentials/credentials.h"
46 /****************************************************************
47 ****************************************************************/
49 #define LIBNET_JOIN_DUMP_CTX(ctx, r, f) \
52 str = NDR_PRINT_FUNCTION_STRING(ctx, libnet_JoinCtx, f, r); \
53 DEBUG(1,("libnet_Join:\n%s", str)); \
57 #define LIBNET_JOIN_IN_DUMP_CTX(ctx, r) \
58 LIBNET_JOIN_DUMP_CTX(ctx, r, NDR_IN | NDR_SET_VALUES)
59 #define LIBNET_JOIN_OUT_DUMP_CTX(ctx, r) \
60 LIBNET_JOIN_DUMP_CTX(ctx, r, NDR_OUT)
62 #define LIBNET_UNJOIN_DUMP_CTX(ctx, r, f) \
65 str = NDR_PRINT_FUNCTION_STRING(ctx, libnet_UnjoinCtx, f, r); \
66 DEBUG(1,("libnet_Unjoin:\n%s", str)); \
70 #define LIBNET_UNJOIN_IN_DUMP_CTX(ctx, r) \
71 LIBNET_UNJOIN_DUMP_CTX(ctx, r, NDR_IN | NDR_SET_VALUES)
72 #define LIBNET_UNJOIN_OUT_DUMP_CTX(ctx, r) \
73 LIBNET_UNJOIN_DUMP_CTX(ctx, r, NDR_OUT)
75 /****************************************************************
76 ****************************************************************/
78 static void libnet_join_set_error_string(TALLOC_CTX
*mem_ctx
,
79 struct libnet_JoinCtx
*r
,
80 const char *format
, ...)
84 if (r
->out
.error_string
) {
88 va_start(args
, format
);
89 r
->out
.error_string
= talloc_vasprintf(mem_ctx
, format
, args
);
93 /****************************************************************
94 ****************************************************************/
96 static void libnet_unjoin_set_error_string(TALLOC_CTX
*mem_ctx
,
97 struct libnet_UnjoinCtx
*r
,
98 const char *format
, ...)
102 if (r
->out
.error_string
) {
106 va_start(args
, format
);
107 r
->out
.error_string
= talloc_vasprintf(mem_ctx
, format
, args
);
113 /****************************************************************
114 ****************************************************************/
116 static ADS_STATUS
libnet_connect_ads(const char *dns_domain_name
,
117 const char *netbios_domain_name
,
119 const char *user_name
,
120 const char *password
,
124 ADS_STRUCT
*my_ads
= NULL
;
127 my_ads
= ads_init(dns_domain_name
,
131 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
135 SAFE_FREE(my_ads
->auth
.user_name
);
136 my_ads
->auth
.user_name
= SMB_STRDUP(user_name
);
137 if ((cp
= strchr_m(my_ads
->auth
.user_name
, '@'))!=0) {
139 SAFE_FREE(my_ads
->auth
.realm
);
140 my_ads
->auth
.realm
= smb_xstrdup(cp
);
141 if (!strupper_m(my_ads
->auth
.realm
)) {
142 ads_destroy(&my_ads
);
143 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
149 SAFE_FREE(my_ads
->auth
.password
);
150 my_ads
->auth
.password
= SMB_STRDUP(password
);
153 status
= ads_connect_user_creds(my_ads
);
154 if (!ADS_ERR_OK(status
)) {
155 ads_destroy(&my_ads
);
163 /****************************************************************
164 ****************************************************************/
166 static ADS_STATUS
libnet_join_connect_ads(TALLOC_CTX
*mem_ctx
,
167 struct libnet_JoinCtx
*r
)
171 status
= libnet_connect_ads(r
->out
.dns_domain_name
,
172 r
->out
.netbios_domain_name
,
175 r
->in
.admin_password
,
177 if (!ADS_ERR_OK(status
)) {
178 libnet_join_set_error_string(mem_ctx
, r
,
179 "failed to connect to AD: %s",
184 if (!r
->out
.netbios_domain_name
) {
185 r
->out
.netbios_domain_name
= talloc_strdup(mem_ctx
,
186 r
->in
.ads
->server
.workgroup
);
187 ADS_ERROR_HAVE_NO_MEMORY(r
->out
.netbios_domain_name
);
190 if (!r
->out
.dns_domain_name
) {
191 r
->out
.dns_domain_name
= talloc_strdup(mem_ctx
,
192 r
->in
.ads
->config
.realm
);
193 ADS_ERROR_HAVE_NO_MEMORY(r
->out
.dns_domain_name
);
196 r
->out
.domain_is_ad
= true;
201 /****************************************************************
202 ****************************************************************/
204 static ADS_STATUS
libnet_unjoin_connect_ads(TALLOC_CTX
*mem_ctx
,
205 struct libnet_UnjoinCtx
*r
)
209 status
= libnet_connect_ads(r
->in
.domain_name
,
213 r
->in
.admin_password
,
215 if (!ADS_ERR_OK(status
)) {
216 libnet_unjoin_set_error_string(mem_ctx
, r
,
217 "failed to connect to AD: %s",
224 /****************************************************************
225 join a domain using ADS (LDAP mods)
226 ****************************************************************/
228 static ADS_STATUS
libnet_join_precreate_machine_acct(TALLOC_CTX
*mem_ctx
,
229 struct libnet_JoinCtx
*r
)
232 LDAPMessage
*res
= NULL
;
233 const char *attrs
[] = { "dn", NULL
};
236 status
= ads_check_ou_dn(mem_ctx
, r
->in
.ads
, &r
->in
.account_ou
);
237 if (!ADS_ERR_OK(status
)) {
241 status
= ads_search_dn(r
->in
.ads
, &res
, r
->in
.account_ou
, attrs
);
242 if (!ADS_ERR_OK(status
)) {
246 if (ads_count_replies(r
->in
.ads
, res
) != 1) {
247 ads_msgfree(r
->in
.ads
, res
);
248 return ADS_ERROR_LDAP(LDAP_NO_SUCH_OBJECT
);
251 ads_msgfree(r
->in
.ads
, res
);
253 /* Attempt to create the machine account and bail if this fails.
254 Assume that the admin wants exactly what they requested */
256 status
= ads_create_machine_acct(r
->in
.ads
,
260 if (ADS_ERR_OK(status
)) {
261 DEBUG(1,("machine account creation created\n"));
263 } else if ((status
.error_type
== ENUM_ADS_ERROR_LDAP
) &&
264 (status
.err
.rc
== LDAP_ALREADY_EXISTS
)) {
265 status
= ADS_SUCCESS
;
268 if (!ADS_ERR_OK(status
)) {
269 DEBUG(1,("machine account creation failed\n"));
273 status
= ads_move_machine_acct(r
->in
.ads
,
277 if (!ADS_ERR_OK(status
)) {
278 DEBUG(1,("failure to locate/move pre-existing "
279 "machine account\n"));
283 DEBUG(1,("The machine account %s the specified OU.\n",
284 moved
? "was moved into" : "already exists in"));
289 /****************************************************************
290 ****************************************************************/
292 static ADS_STATUS
libnet_unjoin_remove_machine_acct(TALLOC_CTX
*mem_ctx
,
293 struct libnet_UnjoinCtx
*r
)
298 status
= libnet_unjoin_connect_ads(mem_ctx
, r
);
299 if (!ADS_ERR_OK(status
)) {
300 libnet_unjoin_set_error_string(mem_ctx
, r
,
301 "failed to connect to AD: %s",
307 status
= ads_leave_realm(r
->in
.ads
, r
->in
.machine_name
);
308 if (!ADS_ERR_OK(status
)) {
309 libnet_unjoin_set_error_string(mem_ctx
, r
,
310 "failed to leave realm: %s",
318 /****************************************************************
319 ****************************************************************/
321 static ADS_STATUS
libnet_join_find_machine_acct(TALLOC_CTX
*mem_ctx
,
322 struct libnet_JoinCtx
*r
)
325 LDAPMessage
*res
= NULL
;
328 if (!r
->in
.machine_name
) {
329 return ADS_ERROR(LDAP_NO_MEMORY
);
332 status
= ads_find_machine_acct(r
->in
.ads
,
335 if (!ADS_ERR_OK(status
)) {
339 if (ads_count_replies(r
->in
.ads
, res
) != 1) {
340 status
= ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
344 dn
= ads_get_dn(r
->in
.ads
, mem_ctx
, res
);
346 status
= ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
350 r
->out
.dn
= talloc_strdup(mem_ctx
, dn
);
352 status
= ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
357 ads_msgfree(r
->in
.ads
, res
);
363 static ADS_STATUS
libnet_join_get_machine_spns(TALLOC_CTX
*mem_ctx
,
364 struct libnet_JoinCtx
*r
,
370 if (r
->in
.machine_name
== NULL
) {
371 return ADS_ERROR_SYSTEM(EINVAL
);
374 status
= ads_get_service_principal_names(mem_ctx
,
383 /****************************************************************
384 Set a machines dNSHostName and servicePrincipalName attributes
385 ****************************************************************/
387 static ADS_STATUS
libnet_join_set_machine_spn(TALLOC_CTX
*mem_ctx
,
388 struct libnet_JoinCtx
*r
)
393 const char **spn_array
= NULL
;
400 status
= libnet_join_find_machine_acct(mem_ctx
, r
);
401 if (!ADS_ERR_OK(status
)) {
405 status
= libnet_join_get_machine_spns(mem_ctx
,
407 discard_const_p(char **, &spn_array
),
409 if (!ADS_ERR_OK(status
)) {
410 DEBUG(5, ("Retrieving the servicePrincipalNames failed.\n"));
413 /* Windows only creates HOST/shortname & HOST/fqdn. */
415 spn
= talloc_asprintf(mem_ctx
, "HOST/%s", r
->in
.machine_name
);
417 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
419 if (!strupper_m(spn
)) {
420 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
423 ok
= ads_element_in_array(spn_array
, num_spns
, spn
);
425 ok
= add_string_to_array(spn_array
, spn
,
426 &spn_array
, &num_spns
);
428 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
432 if (!name_to_fqdn(my_fqdn
, r
->in
.machine_name
)
433 || (strchr(my_fqdn
, '.') == NULL
)) {
434 fstr_sprintf(my_fqdn
, "%s.%s", r
->in
.machine_name
,
435 r
->out
.dns_domain_name
);
438 if (!strlower_m(my_fqdn
)) {
439 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
442 if (!strequal(my_fqdn
, r
->in
.machine_name
)) {
443 spn
= talloc_asprintf(mem_ctx
, "HOST/%s", my_fqdn
);
445 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
448 ok
= ads_element_in_array(spn_array
, num_spns
, spn
);
450 ok
= add_string_to_array(spn_array
, spn
,
451 &spn_array
, &num_spns
);
453 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
458 /* make sure to NULL terminate the array */
459 spn_array
= talloc_realloc(mem_ctx
, spn_array
, const char *, num_spns
+ 1);
460 if (spn_array
== NULL
) {
461 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
463 spn_array
[num_spns
] = NULL
;
465 mods
= ads_init_mods(mem_ctx
);
467 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
470 /* fields of primary importance */
472 status
= ads_mod_str(mem_ctx
, &mods
, "dNSHostName", my_fqdn
);
473 if (!ADS_ERR_OK(status
)) {
474 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
477 status
= ads_mod_strlist(mem_ctx
, &mods
, "servicePrincipalName",
479 if (!ADS_ERR_OK(status
)) {
480 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
483 return ads_gen_mod(r
->in
.ads
, r
->out
.dn
, mods
);
486 /****************************************************************
487 ****************************************************************/
489 static ADS_STATUS
libnet_join_set_machine_upn(TALLOC_CTX
*mem_ctx
,
490 struct libnet_JoinCtx
*r
)
495 if (!r
->in
.create_upn
) {
501 status
= libnet_join_find_machine_acct(mem_ctx
, r
);
502 if (!ADS_ERR_OK(status
)) {
507 const char *realm
= r
->out
.dns_domain_name
;
509 /* in case we are about to generate a keytab during the join
510 * make sure the default upn we create is usable with kinit -k.
513 if (USE_KERBEROS_KEYTAB
) {
514 realm
= talloc_strdup_upper(mem_ctx
,
515 r
->out
.dns_domain_name
);
519 return ADS_ERROR(LDAP_NO_MEMORY
);
522 r
->in
.upn
= talloc_asprintf(mem_ctx
,
527 return ADS_ERROR(LDAP_NO_MEMORY
);
531 /* now do the mods */
533 mods
= ads_init_mods(mem_ctx
);
535 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
538 /* fields of primary importance */
540 status
= ads_mod_str(mem_ctx
, &mods
, "userPrincipalName", r
->in
.upn
);
541 if (!ADS_ERR_OK(status
)) {
542 return ADS_ERROR_LDAP(LDAP_NO_MEMORY
);
545 return ads_gen_mod(r
->in
.ads
, r
->out
.dn
, mods
);
549 /****************************************************************
550 ****************************************************************/
552 static ADS_STATUS
libnet_join_set_os_attributes(TALLOC_CTX
*mem_ctx
,
553 struct libnet_JoinCtx
*r
)
559 if (!r
->in
.os_name
|| !r
->in
.os_version
) {
565 status
= libnet_join_find_machine_acct(mem_ctx
, r
);
566 if (!ADS_ERR_OK(status
)) {
570 /* now do the mods */
572 mods
= ads_init_mods(mem_ctx
);
574 return ADS_ERROR(LDAP_NO_MEMORY
);
577 os_sp
= talloc_asprintf(mem_ctx
, "Samba %s", samba_version_string());
579 return ADS_ERROR(LDAP_NO_MEMORY
);
582 /* fields of primary importance */
584 status
= ads_mod_str(mem_ctx
, &mods
, "operatingSystem",
586 if (!ADS_ERR_OK(status
)) {
590 status
= ads_mod_str(mem_ctx
, &mods
, "operatingSystemVersion",
592 if (!ADS_ERR_OK(status
)) {
596 status
= ads_mod_str(mem_ctx
, &mods
, "operatingSystemServicePack",
598 if (!ADS_ERR_OK(status
)) {
602 return ads_gen_mod(r
->in
.ads
, r
->out
.dn
, mods
);
605 /****************************************************************
606 ****************************************************************/
608 static ADS_STATUS
libnet_join_set_etypes(TALLOC_CTX
*mem_ctx
,
609 struct libnet_JoinCtx
*r
)
613 uint32_t etype_list
= ENC_CRC32
| ENC_RSA_MD5
| ENC_RC4_HMAC_MD5
;
614 const char *etype_list_str
;
616 #ifdef HAVE_ENCTYPE_AES128_CTS_HMAC_SHA1_96
617 etype_list
|= ENC_HMAC_SHA1_96_AES128
;
619 #ifdef HAVE_ENCTYPE_AES256_CTS_HMAC_SHA1_96
620 etype_list
|= ENC_HMAC_SHA1_96_AES256
;
623 etype_list_str
= talloc_asprintf(mem_ctx
, "%d", etype_list
);
624 if (!etype_list_str
) {
625 return ADS_ERROR(LDAP_NO_MEMORY
);
630 status
= libnet_join_find_machine_acct(mem_ctx
, r
);
631 if (!ADS_ERR_OK(status
)) {
635 /* now do the mods */
637 mods
= ads_init_mods(mem_ctx
);
639 return ADS_ERROR(LDAP_NO_MEMORY
);
642 status
= ads_mod_str(mem_ctx
, &mods
, "msDS-SupportedEncryptionTypes",
644 if (!ADS_ERR_OK(status
)) {
648 return ads_gen_mod(r
->in
.ads
, r
->out
.dn
, mods
);
651 /****************************************************************
652 ****************************************************************/
654 static bool libnet_join_create_keytab(TALLOC_CTX
*mem_ctx
,
655 struct libnet_JoinCtx
*r
)
657 if (!USE_SYSTEM_KEYTAB
) {
661 if (ads_keytab_create_default(r
->in
.ads
) != 0) {
668 /****************************************************************
669 ****************************************************************/
671 static bool libnet_join_derive_salting_principal(TALLOC_CTX
*mem_ctx
,
672 struct libnet_JoinCtx
*r
)
674 uint32_t domain_func
;
676 const char *salt
= NULL
;
677 char *std_salt
= NULL
;
679 status
= ads_domain_func_level(r
->in
.ads
, &domain_func
);
680 if (!ADS_ERR_OK(status
)) {
681 libnet_join_set_error_string(mem_ctx
, r
,
682 "failed to determine domain functional level: %s",
687 /* go ahead and setup the default salt */
689 std_salt
= kerberos_standard_des_salt();
691 libnet_join_set_error_string(mem_ctx
, r
,
692 "failed to obtain standard DES salt");
696 salt
= talloc_strdup(mem_ctx
, std_salt
);
703 /* if it's a Windows functional domain, we have to look for the UPN */
705 if (domain_func
== DS_DOMAIN_FUNCTION_2000
) {
708 upn
= ads_get_upn(r
->in
.ads
, mem_ctx
,
711 salt
= talloc_strdup(mem_ctx
, upn
);
718 return kerberos_secrets_store_des_salt(salt
);
721 /****************************************************************
722 ****************************************************************/
724 static ADS_STATUS
libnet_join_post_processing_ads(TALLOC_CTX
*mem_ctx
,
725 struct libnet_JoinCtx
*r
)
728 uint32_t func_level
= 0;
731 status
= libnet_join_connect_ads(mem_ctx
, r
);
732 if (!ADS_ERR_OK(status
)) {
737 status
= libnet_join_set_machine_spn(mem_ctx
, r
);
738 if (!ADS_ERR_OK(status
)) {
739 libnet_join_set_error_string(mem_ctx
, r
,
740 "Failed to set machine spn: %s\n"
741 "Do you have sufficient permissions to create machine "
747 status
= libnet_join_set_os_attributes(mem_ctx
, r
);
748 if (!ADS_ERR_OK(status
)) {
749 libnet_join_set_error_string(mem_ctx
, r
,
750 "failed to set machine os attributes: %s",
755 status
= libnet_join_set_machine_upn(mem_ctx
, r
);
756 if (!ADS_ERR_OK(status
)) {
757 libnet_join_set_error_string(mem_ctx
, r
,
758 "failed to set machine upn: %s",
763 status
= ads_domain_func_level(r
->in
.ads
, &func_level
);
764 if (!ADS_ERR_OK(status
)) {
765 libnet_join_set_error_string(mem_ctx
, r
,
766 "failed to query domain controller functional level: %s",
771 if (func_level
>= DS_DOMAIN_FUNCTION_2008
) {
772 status
= libnet_join_set_etypes(mem_ctx
, r
);
773 if (!ADS_ERR_OK(status
)) {
774 libnet_join_set_error_string(mem_ctx
, r
,
775 "failed to set machine kerberos encryption types: %s",
781 if (!libnet_join_derive_salting_principal(mem_ctx
, r
)) {
782 return ADS_ERROR_NT(NT_STATUS_UNSUCCESSFUL
);
785 if (!libnet_join_create_keytab(mem_ctx
, r
)) {
786 libnet_join_set_error_string(mem_ctx
, r
,
787 "failed to create kerberos keytab");
788 return ADS_ERROR_NT(NT_STATUS_UNSUCCESSFUL
);
793 #endif /* HAVE_ADS */
795 /****************************************************************
796 Store the machine password and domain SID
797 ****************************************************************/
799 static bool libnet_join_joindomain_store_secrets(TALLOC_CTX
*mem_ctx
,
800 struct libnet_JoinCtx
*r
)
802 if (!secrets_store_domain_sid(r
->out
.netbios_domain_name
,
805 DEBUG(1,("Failed to save domain sid\n"));
809 if (!secrets_store_machine_password(r
->in
.machine_password
,
810 r
->out
.netbios_domain_name
,
811 r
->in
.secure_channel_type
))
813 DEBUG(1,("Failed to save machine password\n"));
820 /****************************************************************
821 Connect dc's IPC$ share
822 ****************************************************************/
824 static NTSTATUS
libnet_join_connect_dc_ipc(const char *dc
,
829 struct cli_state
**cli
)
834 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
;
837 if (use_kerberos
&& pass
) {
838 flags
|= CLI_FULL_CONNECTION_FALLBACK_AFTER_KERBEROS
;
841 return cli_full_connection(cli
, NULL
,
849 SMB_SIGNING_DEFAULT
);
852 /****************************************************************
853 Lookup domain dc's info
854 ****************************************************************/
856 static NTSTATUS
libnet_join_lookup_dc_rpc(TALLOC_CTX
*mem_ctx
,
857 struct libnet_JoinCtx
*r
,
858 struct cli_state
**cli
)
860 struct rpc_pipe_client
*pipe_hnd
= NULL
;
861 struct policy_handle lsa_pol
;
862 NTSTATUS status
, result
;
863 union lsa_PolicyInformation
*info
= NULL
;
864 struct dcerpc_binding_handle
*b
;
866 status
= libnet_join_connect_dc_ipc(r
->in
.dc_name
,
869 r
->in
.admin_password
,
872 if (!NT_STATUS_IS_OK(status
)) {
876 status
= cli_rpc_pipe_open_noauth(*cli
, &ndr_table_lsarpc
,
878 if (!NT_STATUS_IS_OK(status
)) {
879 DEBUG(0,("Error connecting to LSA pipe. Error was %s\n",
884 b
= pipe_hnd
->binding_handle
;
886 status
= rpccli_lsa_open_policy(pipe_hnd
, mem_ctx
, true,
887 SEC_FLAG_MAXIMUM_ALLOWED
, &lsa_pol
);
888 if (!NT_STATUS_IS_OK(status
)) {
892 status
= dcerpc_lsa_QueryInfoPolicy2(b
, mem_ctx
,
897 if (NT_STATUS_IS_OK(status
) && NT_STATUS_IS_OK(result
)) {
898 r
->out
.domain_is_ad
= true;
899 r
->out
.netbios_domain_name
= info
->dns
.name
.string
;
900 r
->out
.dns_domain_name
= info
->dns
.dns_domain
.string
;
901 r
->out
.forest_name
= info
->dns
.dns_forest
.string
;
902 r
->out
.domain_sid
= dom_sid_dup(mem_ctx
, info
->dns
.sid
);
903 NT_STATUS_HAVE_NO_MEMORY(r
->out
.domain_sid
);
906 if (!NT_STATUS_IS_OK(status
)) {
907 status
= dcerpc_lsa_QueryInfoPolicy(b
, mem_ctx
,
909 LSA_POLICY_INFO_ACCOUNT_DOMAIN
,
912 if (!NT_STATUS_IS_OK(status
)) {
915 if (!NT_STATUS_IS_OK(result
)) {
920 r
->out
.netbios_domain_name
= info
->account_domain
.name
.string
;
921 r
->out
.domain_sid
= dom_sid_dup(mem_ctx
, info
->account_domain
.sid
);
922 NT_STATUS_HAVE_NO_MEMORY(r
->out
.domain_sid
);
925 dcerpc_lsa_Close(b
, mem_ctx
, &lsa_pol
, &result
);
926 TALLOC_FREE(pipe_hnd
);
932 /****************************************************************
933 Do the domain join unsecure
934 ****************************************************************/
936 static NTSTATUS
libnet_join_joindomain_rpc_unsecure(TALLOC_CTX
*mem_ctx
,
937 struct libnet_JoinCtx
*r
,
938 struct cli_state
*cli
)
940 TALLOC_CTX
*frame
= talloc_stackframe();
941 struct rpc_pipe_client
*netlogon_pipe
= NULL
;
942 struct netlogon_creds_cli_context
*netlogon_creds
= NULL
;
943 struct samr_Password current_nt_hash
;
944 const char *account_name
= NULL
;
947 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_netlogon
,
949 if (!NT_STATUS_IS_OK(status
)) {
954 if (!r
->in
.machine_password
) {
955 r
->in
.machine_password
= generate_random_password(mem_ctx
,
956 DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH
,
957 DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH
);
958 if (r
->in
.machine_password
== NULL
) {
960 return NT_STATUS_NO_MEMORY
;
964 /* according to WKSSVC_JOIN_FLAGS_MACHINE_PWD_PASSED */
965 E_md4hash(r
->in
.admin_password
, current_nt_hash
.hash
);
967 account_name
= talloc_asprintf(frame
, "%s$",
969 if (account_name
== NULL
) {
971 return NT_STATUS_NO_MEMORY
;
974 status
= rpccli_create_netlogon_creds(netlogon_pipe
->desthost
,
977 r
->in
.secure_channel_type
,
981 if (!NT_STATUS_IS_OK(status
)) {
986 status
= rpccli_setup_netlogon_creds(cli
, NCACN_NP
,
988 true, /* force_reauth */
990 NULL
); /* previous_nt_hash */
991 if (!NT_STATUS_IS_OK(status
)) {
996 status
= netlogon_creds_cli_ServerPasswordSet(netlogon_creds
,
997 netlogon_pipe
->binding_handle
,
998 r
->in
.machine_password
,
999 NULL
); /* new_version */
1000 if (!NT_STATUS_IS_OK(status
)) {
1006 return NT_STATUS_OK
;
1009 /****************************************************************
1011 ****************************************************************/
1013 static NTSTATUS
libnet_join_joindomain_rpc(TALLOC_CTX
*mem_ctx
,
1014 struct libnet_JoinCtx
*r
,
1015 struct cli_state
*cli
)
1017 struct rpc_pipe_client
*pipe_hnd
= NULL
;
1018 struct policy_handle sam_pol
, domain_pol
, user_pol
;
1019 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
, result
;
1021 struct lsa_String lsa_acct_name
;
1023 uint32_t acct_flags
= ACB_WSTRUST
;
1024 struct samr_Ids user_rids
;
1025 struct samr_Ids name_types
;
1026 union samr_UserInfo user_info
;
1027 struct dcerpc_binding_handle
*b
= NULL
;
1028 unsigned int old_timeout
= 0;
1030 DATA_BLOB session_key
= data_blob_null
;
1031 struct samr_CryptPassword crypt_pwd
;
1032 struct samr_CryptPasswordEx crypt_pwd_ex
;
1034 ZERO_STRUCT(sam_pol
);
1035 ZERO_STRUCT(domain_pol
);
1036 ZERO_STRUCT(user_pol
);
1038 switch (r
->in
.secure_channel_type
) {
1039 case SEC_CHAN_WKSTA
:
1040 acct_flags
= ACB_WSTRUST
;
1043 acct_flags
= ACB_SVRTRUST
;
1046 return NT_STATUS_INVALID_PARAMETER
;
1049 if (!r
->in
.machine_password
) {
1050 r
->in
.machine_password
= generate_random_password(mem_ctx
,
1051 DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH
,
1052 DEFAULT_TRUST_ACCOUNT_PASSWORD_LENGTH
);
1053 NT_STATUS_HAVE_NO_MEMORY(r
->in
.machine_password
);
1056 /* Open the domain */
1058 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
,
1060 if (!NT_STATUS_IS_OK(status
)) {
1061 DEBUG(0,("Error connecting to SAM pipe. Error was %s\n",
1062 nt_errstr(status
)));
1066 b
= pipe_hnd
->binding_handle
;
1068 status
= cli_get_session_key(mem_ctx
, pipe_hnd
, &session_key
);
1069 if (!NT_STATUS_IS_OK(status
)) {
1070 DEBUG(0,("Error getting session_key of SAM pipe. Error was %s\n",
1071 nt_errstr(status
)));
1075 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
1077 SAMR_ACCESS_ENUM_DOMAINS
1078 | SAMR_ACCESS_LOOKUP_DOMAIN
,
1081 if (!NT_STATUS_IS_OK(status
)) {
1084 if (!NT_STATUS_IS_OK(result
)) {
1089 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
1091 SAMR_DOMAIN_ACCESS_LOOKUP_INFO_1
1092 | SAMR_DOMAIN_ACCESS_CREATE_USER
1093 | SAMR_DOMAIN_ACCESS_OPEN_ACCOUNT
,
1097 if (!NT_STATUS_IS_OK(status
)) {
1100 if (!NT_STATUS_IS_OK(result
)) {
1105 /* Create domain user */
1107 acct_name
= talloc_asprintf(mem_ctx
, "%s$", r
->in
.machine_name
);
1108 if (!strlower_m(acct_name
)) {
1109 status
= NT_STATUS_INVALID_PARAMETER
;
1113 init_lsa_String(&lsa_acct_name
, acct_name
);
1115 if (r
->in
.join_flags
& WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE
) {
1116 uint32_t access_desired
=
1117 SEC_GENERIC_READ
| SEC_GENERIC_WRITE
| SEC_GENERIC_EXECUTE
|
1118 SEC_STD_WRITE_DAC
| SEC_STD_DELETE
|
1119 SAMR_USER_ACCESS_SET_PASSWORD
|
1120 SAMR_USER_ACCESS_GET_ATTRIBUTES
|
1121 SAMR_USER_ACCESS_SET_ATTRIBUTES
;
1122 uint32_t access_granted
= 0;
1124 DEBUG(10,("Creating account with desired access mask: %d\n",
1127 status
= dcerpc_samr_CreateUser2(b
, mem_ctx
,
1136 if (!NT_STATUS_IS_OK(status
)) {
1141 if (!NT_STATUS_IS_OK(status
) &&
1142 !NT_STATUS_EQUAL(status
, NT_STATUS_USER_EXISTS
)) {
1144 DEBUG(10,("Creation of workstation account failed: %s\n",
1145 nt_errstr(status
)));
1147 /* If NT_STATUS_ACCESS_DENIED then we have a valid
1148 username/password combo but the user does not have
1149 administrator access. */
1151 if (NT_STATUS_EQUAL(status
, NT_STATUS_ACCESS_DENIED
)) {
1152 libnet_join_set_error_string(mem_ctx
, r
,
1153 "User specified does not have "
1154 "administrator privileges");
1160 if (NT_STATUS_EQUAL(status
, NT_STATUS_USER_EXISTS
)) {
1161 if (!(r
->in
.join_flags
&
1162 WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED
)) {
1167 /* We *must* do this.... don't ask... */
1169 if (NT_STATUS_IS_OK(status
)) {
1170 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1174 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
1181 if (!NT_STATUS_IS_OK(status
)) {
1184 if (!NT_STATUS_IS_OK(result
)) {
1188 if (user_rids
.count
!= 1) {
1189 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
1192 if (name_types
.count
!= 1) {
1193 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
1197 if (name_types
.ids
[0] != SID_NAME_USER
) {
1198 DEBUG(0,("%s is not a user account (type=%d)\n",
1199 acct_name
, name_types
.ids
[0]));
1200 status
= NT_STATUS_INVALID_WORKSTATION
;
1204 user_rid
= user_rids
.ids
[0];
1206 /* Open handle on user */
1208 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
1210 SEC_FLAG_MAXIMUM_ALLOWED
,
1214 if (!NT_STATUS_IS_OK(status
)) {
1217 if (!NT_STATUS_IS_OK(result
)) {
1222 /* Fill in the additional account flags now */
1224 acct_flags
|= ACB_PWNOEXP
;
1226 /* Set account flags on machine account */
1227 ZERO_STRUCT(user_info
.info16
);
1228 user_info
.info16
.acct_flags
= acct_flags
;
1230 status
= dcerpc_samr_SetUserInfo(b
, mem_ctx
,
1235 if (!NT_STATUS_IS_OK(status
)) {
1236 dcerpc_samr_DeleteUser(b
, mem_ctx
,
1240 libnet_join_set_error_string(mem_ctx
, r
,
1241 "Failed to set account flags for machine account (%s)\n",
1246 if (!NT_STATUS_IS_OK(result
)) {
1249 dcerpc_samr_DeleteUser(b
, mem_ctx
,
1253 libnet_join_set_error_string(mem_ctx
, r
,
1254 "Failed to set account flags for machine account (%s)\n",
1259 /* Set password on machine account - first try level 26 */
1262 * increase the timeout as password filter modules on the DC
1263 * might delay the operation for a significant amount of time
1265 old_timeout
= rpccli_set_timeout(pipe_hnd
, 600000);
1267 init_samr_CryptPasswordEx(r
->in
.machine_password
,
1271 user_info
.info26
.password
= crypt_pwd_ex
;
1272 user_info
.info26
.password_expired
= PASS_DONT_CHANGE_AT_NEXT_LOGON
;
1274 status
= dcerpc_samr_SetUserInfo2(b
, mem_ctx
,
1280 if (NT_STATUS_EQUAL(status
, NT_STATUS_RPC_ENUM_VALUE_OUT_OF_RANGE
)) {
1282 /* retry with level 24 */
1284 init_samr_CryptPassword(r
->in
.machine_password
,
1288 user_info
.info24
.password
= crypt_pwd
;
1289 user_info
.info24
.password_expired
= PASS_DONT_CHANGE_AT_NEXT_LOGON
;
1291 status
= dcerpc_samr_SetUserInfo2(b
, mem_ctx
,
1298 old_timeout
= rpccli_set_timeout(pipe_hnd
, old_timeout
);
1300 if (!NT_STATUS_IS_OK(status
)) {
1302 dcerpc_samr_DeleteUser(b
, mem_ctx
,
1306 libnet_join_set_error_string(mem_ctx
, r
,
1307 "Failed to set password for machine account (%s)\n",
1311 if (!NT_STATUS_IS_OK(result
)) {
1314 dcerpc_samr_DeleteUser(b
, mem_ctx
,
1318 libnet_join_set_error_string(mem_ctx
, r
,
1319 "Failed to set password for machine account (%s)\n",
1324 status
= NT_STATUS_OK
;
1331 data_blob_clear_free(&session_key
);
1333 if (is_valid_policy_hnd(&sam_pol
)) {
1334 dcerpc_samr_Close(b
, mem_ctx
, &sam_pol
, &result
);
1336 if (is_valid_policy_hnd(&domain_pol
)) {
1337 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1339 if (is_valid_policy_hnd(&user_pol
)) {
1340 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1342 TALLOC_FREE(pipe_hnd
);
1347 /****************************************************************
1348 ****************************************************************/
1350 NTSTATUS
libnet_join_ok(struct messaging_context
*msg_ctx
,
1351 const char *netbios_domain_name
,
1352 const char *dc_name
,
1353 const bool use_kerberos
)
1355 TALLOC_CTX
*frame
= talloc_stackframe();
1356 struct cli_state
*cli
= NULL
;
1357 struct rpc_pipe_client
*netlogon_pipe
= NULL
;
1358 struct netlogon_creds_cli_context
*netlogon_creds
= NULL
;
1359 struct netlogon_creds_CredentialState
*creds
= NULL
;
1360 uint32_t netlogon_flags
= 0;
1361 enum netr_SchannelType sec_chan_type
= 0;
1363 char *machine_password
= NULL
;
1364 const char *machine_name
= NULL
;
1365 const char *machine_account
= NULL
;
1367 struct samr_Password current_nt_hash
;
1368 struct samr_Password
*previous_nt_hash
= NULL
;
1373 return NT_STATUS_INVALID_PARAMETER
;
1376 if (!secrets_init()) {
1378 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO
;
1381 ok
= get_trust_pw_clear(netbios_domain_name
,
1387 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO
;
1390 machine_account
= talloc_asprintf(frame
, "%s$", machine_name
);
1391 if (machine_account
== NULL
) {
1392 SAFE_FREE(machine_password
);
1393 SAFE_FREE(previous_nt_hash
);
1395 return NT_STATUS_CANT_ACCESS_DOMAIN_INFO
;
1399 flags
|= CLI_FULL_CONNECTION_USE_KERBEROS
;
1402 status
= cli_full_connection(&cli
, NULL
,
1407 netbios_domain_name
,
1410 SMB_SIGNING_DEFAULT
);
1412 E_md4hash(machine_password
, current_nt_hash
.hash
);
1413 SAFE_FREE(machine_password
);
1415 if (!NT_STATUS_IS_OK(status
)) {
1416 status
= cli_full_connection(&cli
, NULL
,
1424 SMB_SIGNING_DEFAULT
);
1427 if (!NT_STATUS_IS_OK(status
)) {
1428 SAFE_FREE(previous_nt_hash
);
1433 status
= rpccli_create_netlogon_creds(dc_name
,
1434 netbios_domain_name
,
1440 if (!NT_STATUS_IS_OK(status
)) {
1441 SAFE_FREE(previous_nt_hash
);
1447 status
= rpccli_setup_netlogon_creds(cli
, NCACN_NP
,
1449 true, /* force_reauth */
1452 SAFE_FREE(previous_nt_hash
);
1453 if (!NT_STATUS_IS_OK(status
)) {
1454 DEBUG(0,("connect_to_domain_password_server: "
1455 "unable to open the domain client session to "
1456 "machine %s. Flags[0x%08X] Error was : %s.\n",
1457 dc_name
, (unsigned)netlogon_flags
,
1458 nt_errstr(status
)));
1464 status
= netlogon_creds_cli_get(netlogon_creds
,
1467 if (!NT_STATUS_IS_OK(status
)) {
1472 netlogon_flags
= creds
->negotiate_flags
;
1475 if (!(netlogon_flags
& NETLOGON_NEG_AUTHENTICATED_RPC
)) {
1478 return NT_STATUS_OK
;
1481 status
= cli_rpc_pipe_open_schannel_with_key(
1482 cli
, &ndr_table_netlogon
, NCACN_NP
,
1483 netbios_domain_name
,
1484 netlogon_creds
, &netlogon_pipe
);
1486 TALLOC_FREE(netlogon_pipe
);
1488 if (!NT_STATUS_IS_OK(status
)) {
1489 DEBUG(0,("libnet_join_ok: failed to open schannel session "
1490 "on netlogon pipe to server %s for domain %s. "
1492 smbXcli_conn_remote_name(cli
->conn
),
1493 netbios_domain_name
, nt_errstr(status
)));
1501 return NT_STATUS_OK
;
1504 /****************************************************************
1505 ****************************************************************/
1507 static WERROR
libnet_join_post_verify(TALLOC_CTX
*mem_ctx
,
1508 struct libnet_JoinCtx
*r
)
1512 status
= libnet_join_ok(r
->in
.msg_ctx
,
1513 r
->out
.netbios_domain_name
,
1515 r
->in
.use_kerberos
);
1516 if (!NT_STATUS_IS_OK(status
)) {
1517 libnet_join_set_error_string(mem_ctx
, r
,
1518 "failed to verify domain membership after joining: %s",
1519 get_friendly_nt_error_msg(status
));
1520 return WERR_SETUP_NOT_JOINED
;
1526 /****************************************************************
1527 ****************************************************************/
1529 static bool libnet_join_unjoindomain_remove_secrets(TALLOC_CTX
*mem_ctx
,
1530 struct libnet_UnjoinCtx
*r
)
1532 if (!secrets_delete_machine_password_ex(lp_workgroup())) {
1536 if (!secrets_delete_domain_sid(lp_workgroup())) {
1543 /****************************************************************
1544 ****************************************************************/
1546 static NTSTATUS
libnet_join_unjoindomain_rpc(TALLOC_CTX
*mem_ctx
,
1547 struct libnet_UnjoinCtx
*r
)
1549 struct cli_state
*cli
= NULL
;
1550 struct rpc_pipe_client
*pipe_hnd
= NULL
;
1551 struct policy_handle sam_pol
, domain_pol
, user_pol
;
1552 NTSTATUS status
= NT_STATUS_UNSUCCESSFUL
, result
;
1555 struct lsa_String lsa_acct_name
;
1556 struct samr_Ids user_rids
;
1557 struct samr_Ids name_types
;
1558 union samr_UserInfo
*info
= NULL
;
1559 struct dcerpc_binding_handle
*b
= NULL
;
1561 ZERO_STRUCT(sam_pol
);
1562 ZERO_STRUCT(domain_pol
);
1563 ZERO_STRUCT(user_pol
);
1565 status
= libnet_join_connect_dc_ipc(r
->in
.dc_name
,
1566 r
->in
.admin_account
,
1568 r
->in
.admin_password
,
1571 if (!NT_STATUS_IS_OK(status
)) {
1575 /* Open the domain */
1577 status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_samr
,
1579 if (!NT_STATUS_IS_OK(status
)) {
1580 DEBUG(0,("Error connecting to SAM pipe. Error was %s\n",
1581 nt_errstr(status
)));
1585 b
= pipe_hnd
->binding_handle
;
1587 status
= dcerpc_samr_Connect2(b
, mem_ctx
,
1589 SEC_FLAG_MAXIMUM_ALLOWED
,
1592 if (!NT_STATUS_IS_OK(status
)) {
1595 if (!NT_STATUS_IS_OK(result
)) {
1600 status
= dcerpc_samr_OpenDomain(b
, mem_ctx
,
1602 SEC_FLAG_MAXIMUM_ALLOWED
,
1606 if (!NT_STATUS_IS_OK(status
)) {
1609 if (!NT_STATUS_IS_OK(result
)) {
1614 /* Create domain user */
1616 acct_name
= talloc_asprintf(mem_ctx
, "%s$", r
->in
.machine_name
);
1617 if (!strlower_m(acct_name
)) {
1618 status
= NT_STATUS_INVALID_PARAMETER
;
1622 init_lsa_String(&lsa_acct_name
, acct_name
);
1624 status
= dcerpc_samr_LookupNames(b
, mem_ctx
,
1632 if (!NT_STATUS_IS_OK(status
)) {
1635 if (!NT_STATUS_IS_OK(result
)) {
1639 if (user_rids
.count
!= 1) {
1640 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
1643 if (name_types
.count
!= 1) {
1644 status
= NT_STATUS_INVALID_NETWORK_RESPONSE
;
1648 if (name_types
.ids
[0] != SID_NAME_USER
) {
1649 DEBUG(0, ("%s is not a user account (type=%d)\n", acct_name
,
1650 name_types
.ids
[0]));
1651 status
= NT_STATUS_INVALID_WORKSTATION
;
1655 user_rid
= user_rids
.ids
[0];
1657 /* Open handle on user */
1659 status
= dcerpc_samr_OpenUser(b
, mem_ctx
,
1661 SEC_FLAG_MAXIMUM_ALLOWED
,
1665 if (!NT_STATUS_IS_OK(status
)) {
1668 if (!NT_STATUS_IS_OK(result
)) {
1675 status
= dcerpc_samr_QueryUserInfo(b
, mem_ctx
,
1680 if (!NT_STATUS_IS_OK(status
)) {
1681 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1684 if (!NT_STATUS_IS_OK(result
)) {
1686 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1690 /* now disable and setuser info */
1692 info
->info16
.acct_flags
|= ACB_DISABLED
;
1694 status
= dcerpc_samr_SetUserInfo(b
, mem_ctx
,
1699 if (!NT_STATUS_IS_OK(status
)) {
1700 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1703 if (!NT_STATUS_IS_OK(result
)) {
1705 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1709 dcerpc_samr_Close(b
, mem_ctx
, &user_pol
, &result
);
1712 if (pipe_hnd
&& b
) {
1713 if (is_valid_policy_hnd(&domain_pol
)) {
1714 dcerpc_samr_Close(b
, mem_ctx
, &domain_pol
, &result
);
1716 if (is_valid_policy_hnd(&sam_pol
)) {
1717 dcerpc_samr_Close(b
, mem_ctx
, &sam_pol
, &result
);
1719 TALLOC_FREE(pipe_hnd
);
1729 /****************************************************************
1730 ****************************************************************/
1732 static WERROR
do_join_modify_vals_config(struct libnet_JoinCtx
*r
)
1734 WERROR werr
= WERR_OK
;
1736 struct smbconf_ctx
*ctx
;
1738 err
= smbconf_init_reg(r
, &ctx
, NULL
);
1739 if (!SBC_ERROR_IS_OK(err
)) {
1740 werr
= WERR_NO_SUCH_SERVICE
;
1744 if (!(r
->in
.join_flags
& WKSSVC_JOIN_FLAGS_JOIN_TYPE
)) {
1746 err
= smbconf_set_global_parameter(ctx
, "security", "user");
1747 if (!SBC_ERROR_IS_OK(err
)) {
1748 werr
= WERR_NO_SUCH_SERVICE
;
1752 err
= smbconf_set_global_parameter(ctx
, "workgroup",
1754 if (!SBC_ERROR_IS_OK(err
)) {
1755 werr
= WERR_NO_SUCH_SERVICE
;
1759 smbconf_delete_global_parameter(ctx
, "realm");
1763 err
= smbconf_set_global_parameter(ctx
, "security", "domain");
1764 if (!SBC_ERROR_IS_OK(err
)) {
1765 werr
= WERR_NO_SUCH_SERVICE
;
1769 err
= smbconf_set_global_parameter(ctx
, "workgroup",
1770 r
->out
.netbios_domain_name
);
1771 if (!SBC_ERROR_IS_OK(err
)) {
1772 werr
= WERR_NO_SUCH_SERVICE
;
1776 if (r
->out
.domain_is_ad
) {
1777 err
= smbconf_set_global_parameter(ctx
, "security", "ads");
1778 if (!SBC_ERROR_IS_OK(err
)) {
1779 werr
= WERR_NO_SUCH_SERVICE
;
1783 err
= smbconf_set_global_parameter(ctx
, "realm",
1784 r
->out
.dns_domain_name
);
1785 if (!SBC_ERROR_IS_OK(err
)) {
1786 werr
= WERR_NO_SUCH_SERVICE
;
1792 smbconf_shutdown(ctx
);
1796 /****************************************************************
1797 ****************************************************************/
1799 static WERROR
do_unjoin_modify_vals_config(struct libnet_UnjoinCtx
*r
)
1801 WERROR werr
= WERR_OK
;
1803 struct smbconf_ctx
*ctx
;
1805 err
= smbconf_init_reg(r
, &ctx
, NULL
);
1806 if (!SBC_ERROR_IS_OK(err
)) {
1807 werr
= WERR_NO_SUCH_SERVICE
;
1811 if (r
->in
.unjoin_flags
& WKSSVC_JOIN_FLAGS_JOIN_TYPE
) {
1813 err
= smbconf_set_global_parameter(ctx
, "security", "user");
1814 if (!SBC_ERROR_IS_OK(err
)) {
1815 werr
= WERR_NO_SUCH_SERVICE
;
1819 err
= smbconf_delete_global_parameter(ctx
, "workgroup");
1820 if (!SBC_ERROR_IS_OK(err
)) {
1821 werr
= WERR_NO_SUCH_SERVICE
;
1825 smbconf_delete_global_parameter(ctx
, "realm");
1829 smbconf_shutdown(ctx
);
1833 /****************************************************************
1834 ****************************************************************/
1836 static WERROR
do_JoinConfig(struct libnet_JoinCtx
*r
)
1840 if (!W_ERROR_IS_OK(r
->out
.result
)) {
1841 return r
->out
.result
;
1844 if (!r
->in
.modify_config
) {
1848 werr
= do_join_modify_vals_config(r
);
1849 if (!W_ERROR_IS_OK(werr
)) {
1853 lp_load_global(get_dyn_CONFIGFILE());
1855 r
->out
.modified_config
= true;
1856 r
->out
.result
= werr
;
1861 /****************************************************************
1862 ****************************************************************/
1864 static WERROR
libnet_unjoin_config(struct libnet_UnjoinCtx
*r
)
1868 if (!W_ERROR_IS_OK(r
->out
.result
)) {
1869 return r
->out
.result
;
1872 if (!r
->in
.modify_config
) {
1876 werr
= do_unjoin_modify_vals_config(r
);
1877 if (!W_ERROR_IS_OK(werr
)) {
1881 lp_load_global(get_dyn_CONFIGFILE());
1883 r
->out
.modified_config
= true;
1884 r
->out
.result
= werr
;
1889 /****************************************************************
1890 ****************************************************************/
1892 static bool libnet_parse_domain_dc(TALLOC_CTX
*mem_ctx
,
1893 const char *domain_str
,
1894 const char **domain_p
,
1897 char *domain
= NULL
;
1899 const char *p
= NULL
;
1901 if (!domain_str
|| !domain_p
|| !dc_p
) {
1905 p
= strchr_m(domain_str
, '\\');
1908 domain
= talloc_strndup(mem_ctx
, domain_str
,
1909 PTR_DIFF(p
, domain_str
));
1910 dc
= talloc_strdup(mem_ctx
, p
+1);
1915 domain
= talloc_strdup(mem_ctx
, domain_str
);
1931 /****************************************************************
1932 ****************************************************************/
1934 static WERROR
libnet_join_pre_processing(TALLOC_CTX
*mem_ctx
,
1935 struct libnet_JoinCtx
*r
)
1937 if (!r
->in
.domain_name
) {
1938 libnet_join_set_error_string(mem_ctx
, r
,
1939 "No domain name defined");
1940 return WERR_INVALID_PARAM
;
1943 if (strlen(r
->in
.machine_name
) > 15) {
1944 libnet_join_set_error_string(mem_ctx
, r
,
1945 "Our netbios name can be at most 15 chars long, "
1946 "\"%s\" is %u chars long\n",
1948 (unsigned int)strlen(r
->in
.machine_name
));
1949 return WERR_INVALID_PARAM
;
1952 if (!libnet_parse_domain_dc(mem_ctx
, r
->in
.domain_name
,
1955 libnet_join_set_error_string(mem_ctx
, r
,
1956 "Failed to parse domain name");
1957 return WERR_INVALID_PARAM
;
1960 if (!r
->in
.admin_domain
) {
1961 char *admin_domain
= NULL
;
1962 char *admin_account
= NULL
;
1963 split_domain_user(mem_ctx
,
1964 r
->in
.admin_account
,
1967 r
->in
.admin_domain
= admin_domain
;
1968 r
->in
.admin_account
= admin_account
;
1971 if (!secrets_init()) {
1972 libnet_join_set_error_string(mem_ctx
, r
,
1973 "Unable to open secrets database");
1974 return WERR_CAN_NOT_COMPLETE
;
1980 /****************************************************************
1981 ****************************************************************/
1983 static void libnet_join_add_dom_rids_to_builtins(struct dom_sid
*domain_sid
)
1987 /* Try adding dom admins to builtin\admins. Only log failures. */
1988 status
= create_builtin_administrators(domain_sid
);
1989 if (NT_STATUS_EQUAL(status
, NT_STATUS_PROTOCOL_UNREACHABLE
)) {
1990 DEBUG(10,("Unable to auto-add domain administrators to "
1991 "BUILTIN\\Administrators during join because "
1992 "winbindd must be running.\n"));
1993 } else if (!NT_STATUS_IS_OK(status
)) {
1994 DEBUG(5, ("Failed to auto-add domain administrators to "
1995 "BUILTIN\\Administrators during join: %s\n",
1996 nt_errstr(status
)));
1999 /* Try adding dom users to builtin\users. Only log failures. */
2000 status
= create_builtin_users(domain_sid
);
2001 if (NT_STATUS_EQUAL(status
, NT_STATUS_PROTOCOL_UNREACHABLE
)) {
2002 DEBUG(10,("Unable to auto-add domain users to BUILTIN\\users "
2003 "during join because winbindd must be running.\n"));
2004 } else if (!NT_STATUS_IS_OK(status
)) {
2005 DEBUG(5, ("Failed to auto-add domain administrators to "
2006 "BUILTIN\\Administrators during join: %s\n",
2007 nt_errstr(status
)));
2011 /****************************************************************
2012 ****************************************************************/
2014 static WERROR
libnet_join_post_processing(TALLOC_CTX
*mem_ctx
,
2015 struct libnet_JoinCtx
*r
)
2019 if (!W_ERROR_IS_OK(r
->out
.result
)) {
2020 return r
->out
.result
;
2023 werr
= do_JoinConfig(r
);
2024 if (!W_ERROR_IS_OK(werr
)) {
2028 if (!(r
->in
.join_flags
& WKSSVC_JOIN_FLAGS_JOIN_TYPE
)) {
2032 saf_join_store(r
->out
.netbios_domain_name
, r
->in
.dc_name
);
2033 if (r
->out
.dns_domain_name
) {
2034 saf_join_store(r
->out
.dns_domain_name
, r
->in
.dc_name
);
2038 if (r
->out
.domain_is_ad
&&
2039 !(r
->in
.join_flags
& WKSSVC_JOIN_FLAGS_JOIN_UNSECURE
)) {
2040 ADS_STATUS ads_status
;
2042 ads_status
= libnet_join_post_processing_ads(mem_ctx
, r
);
2043 if (!ADS_ERR_OK(ads_status
)) {
2044 return WERR_GENERAL_FAILURE
;
2047 #endif /* HAVE_ADS */
2049 libnet_join_add_dom_rids_to_builtins(r
->out
.domain_sid
);
2054 /****************************************************************
2055 ****************************************************************/
2057 static int libnet_destroy_JoinCtx(struct libnet_JoinCtx
*r
)
2060 ads_destroy(&r
->in
.ads
);
2066 /****************************************************************
2067 ****************************************************************/
2069 static int libnet_destroy_UnjoinCtx(struct libnet_UnjoinCtx
*r
)
2072 ads_destroy(&r
->in
.ads
);
2078 /****************************************************************
2079 ****************************************************************/
2081 WERROR
libnet_init_JoinCtx(TALLOC_CTX
*mem_ctx
,
2082 struct libnet_JoinCtx
**r
)
2084 struct libnet_JoinCtx
*ctx
;
2086 ctx
= talloc_zero(mem_ctx
, struct libnet_JoinCtx
);
2091 talloc_set_destructor(ctx
, libnet_destroy_JoinCtx
);
2093 ctx
->in
.machine_name
= talloc_strdup(mem_ctx
, lp_netbios_name());
2094 W_ERROR_HAVE_NO_MEMORY(ctx
->in
.machine_name
);
2096 ctx
->in
.secure_channel_type
= SEC_CHAN_WKSTA
;
2103 /****************************************************************
2104 ****************************************************************/
2106 WERROR
libnet_init_UnjoinCtx(TALLOC_CTX
*mem_ctx
,
2107 struct libnet_UnjoinCtx
**r
)
2109 struct libnet_UnjoinCtx
*ctx
;
2111 ctx
= talloc_zero(mem_ctx
, struct libnet_UnjoinCtx
);
2116 talloc_set_destructor(ctx
, libnet_destroy_UnjoinCtx
);
2118 ctx
->in
.machine_name
= talloc_strdup(mem_ctx
, lp_netbios_name());
2119 W_ERROR_HAVE_NO_MEMORY(ctx
->in
.machine_name
);
2126 /****************************************************************
2127 ****************************************************************/
2129 static WERROR
libnet_join_check_config(TALLOC_CTX
*mem_ctx
,
2130 struct libnet_JoinCtx
*r
)
2132 bool valid_security
= false;
2133 bool valid_workgroup
= false;
2134 bool valid_realm
= false;
2136 /* check if configuration is already set correctly */
2138 valid_workgroup
= strequal(lp_workgroup(), r
->out
.netbios_domain_name
);
2140 switch (r
->out
.domain_is_ad
) {
2142 valid_security
= (lp_security() == SEC_DOMAIN
);
2143 if (valid_workgroup
&& valid_security
) {
2144 /* nothing to be done */
2149 valid_realm
= strequal(lp_realm(), r
->out
.dns_domain_name
);
2150 switch (lp_security()) {
2153 valid_security
= true;
2156 if (valid_workgroup
&& valid_realm
&& valid_security
) {
2157 /* nothing to be done */
2163 /* check if we are supposed to manipulate configuration */
2165 if (!r
->in
.modify_config
) {
2167 char *wrong_conf
= talloc_strdup(mem_ctx
, "");
2169 if (!valid_workgroup
) {
2170 wrong_conf
= talloc_asprintf_append(wrong_conf
,
2171 "\"workgroup\" set to '%s', should be '%s'",
2172 lp_workgroup(), r
->out
.netbios_domain_name
);
2173 W_ERROR_HAVE_NO_MEMORY(wrong_conf
);
2177 wrong_conf
= talloc_asprintf_append(wrong_conf
,
2178 "\"realm\" set to '%s', should be '%s'",
2179 lp_realm(), r
->out
.dns_domain_name
);
2180 W_ERROR_HAVE_NO_MEMORY(wrong_conf
);
2183 if (!valid_security
) {
2184 const char *sec
= NULL
;
2185 switch (lp_security()) {
2186 case SEC_USER
: sec
= "user"; break;
2187 case SEC_DOMAIN
: sec
= "domain"; break;
2188 case SEC_ADS
: sec
= "ads"; break;
2190 wrong_conf
= talloc_asprintf_append(wrong_conf
,
2191 "\"security\" set to '%s', should be %s",
2192 sec
, r
->out
.domain_is_ad
?
2193 "either 'domain' or 'ads'" : "'domain'");
2194 W_ERROR_HAVE_NO_MEMORY(wrong_conf
);
2197 libnet_join_set_error_string(mem_ctx
, r
,
2198 "Invalid configuration (%s) and configuration modification "
2199 "was not requested", wrong_conf
);
2200 return WERR_CAN_NOT_COMPLETE
;
2203 /* check if we are able to manipulate configuration */
2205 if (!lp_config_backend_is_registry()) {
2206 libnet_join_set_error_string(mem_ctx
, r
,
2207 "Configuration manipulation requested but not "
2208 "supported by backend");
2209 return WERR_NOT_SUPPORTED
;
2215 /****************************************************************
2216 ****************************************************************/
2218 static WERROR
libnet_DomainJoin(TALLOC_CTX
*mem_ctx
,
2219 struct libnet_JoinCtx
*r
)
2223 struct cli_state
*cli
= NULL
;
2225 ADS_STATUS ads_status
;
2226 #endif /* HAVE_ADS */
2228 if (!r
->in
.dc_name
) {
2229 struct netr_DsRGetDCNameInfo
*info
;
2231 status
= dsgetdcname(mem_ctx
,
2236 DS_FORCE_REDISCOVERY
|
2237 DS_DIRECTORY_SERVICE_REQUIRED
|
2238 DS_WRITABLE_REQUIRED
|
2241 if (!NT_STATUS_IS_OK(status
)) {
2242 libnet_join_set_error_string(mem_ctx
, r
,
2243 "failed to find DC for domain %s",
2245 get_friendly_nt_error_msg(status
));
2246 return WERR_DCNOTFOUND
;
2249 dc
= strip_hostname(info
->dc_unc
);
2250 r
->in
.dc_name
= talloc_strdup(mem_ctx
, dc
);
2251 W_ERROR_HAVE_NO_MEMORY(r
->in
.dc_name
);
2254 status
= libnet_join_lookup_dc_rpc(mem_ctx
, r
, &cli
);
2255 if (!NT_STATUS_IS_OK(status
)) {
2256 libnet_join_set_error_string(mem_ctx
, r
,
2257 "failed to lookup DC info for domain '%s' over rpc: %s",
2258 r
->in
.domain_name
, get_friendly_nt_error_msg(status
));
2259 return ntstatus_to_werror(status
);
2262 werr
= libnet_join_check_config(mem_ctx
, r
);
2263 if (!W_ERROR_IS_OK(werr
)) {
2269 create_local_private_krb5_conf_for_domain(
2270 r
->out
.dns_domain_name
, r
->out
.netbios_domain_name
,
2271 NULL
, smbXcli_conn_remote_sockaddr(cli
->conn
));
2273 if (r
->out
.domain_is_ad
&& r
->in
.account_ou
&&
2274 !(r
->in
.join_flags
& WKSSVC_JOIN_FLAGS_JOIN_UNSECURE
)) {
2276 ads_status
= libnet_join_connect_ads(mem_ctx
, r
);
2277 if (!ADS_ERR_OK(ads_status
)) {
2278 return WERR_DEFAULT_JOIN_REQUIRED
;
2281 ads_status
= libnet_join_precreate_machine_acct(mem_ctx
, r
);
2282 if (!ADS_ERR_OK(ads_status
)) {
2283 libnet_join_set_error_string(mem_ctx
, r
,
2284 "failed to precreate account in ou %s: %s",
2286 ads_errstr(ads_status
));
2287 return WERR_DEFAULT_JOIN_REQUIRED
;
2290 r
->in
.join_flags
&= ~WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE
;
2292 #endif /* HAVE_ADS */
2294 if ((r
->in
.join_flags
& WKSSVC_JOIN_FLAGS_JOIN_UNSECURE
) &&
2295 (r
->in
.join_flags
& WKSSVC_JOIN_FLAGS_MACHINE_PWD_PASSED
)) {
2296 status
= libnet_join_joindomain_rpc_unsecure(mem_ctx
, r
, cli
);
2298 status
= libnet_join_joindomain_rpc(mem_ctx
, r
, cli
);
2300 if (!NT_STATUS_IS_OK(status
)) {
2301 libnet_join_set_error_string(mem_ctx
, r
,
2302 "failed to join domain '%s' over rpc: %s",
2303 r
->in
.domain_name
, get_friendly_nt_error_msg(status
));
2304 if (NT_STATUS_EQUAL(status
, NT_STATUS_USER_EXISTS
)) {
2305 return WERR_SETUP_ALREADY_JOINED
;
2307 werr
= ntstatus_to_werror(status
);
2311 if (!libnet_join_joindomain_store_secrets(mem_ctx
, r
)) {
2312 werr
= WERR_SETUP_NOT_JOINED
;
2326 /****************************************************************
2327 ****************************************************************/
2329 static WERROR
libnet_join_rollback(TALLOC_CTX
*mem_ctx
,
2330 struct libnet_JoinCtx
*r
)
2333 struct libnet_UnjoinCtx
*u
= NULL
;
2335 werr
= libnet_init_UnjoinCtx(mem_ctx
, &u
);
2336 if (!W_ERROR_IS_OK(werr
)) {
2340 u
->in
.debug
= r
->in
.debug
;
2341 u
->in
.dc_name
= r
->in
.dc_name
;
2342 u
->in
.domain_name
= r
->in
.domain_name
;
2343 u
->in
.admin_account
= r
->in
.admin_account
;
2344 u
->in
.admin_password
= r
->in
.admin_password
;
2345 u
->in
.modify_config
= r
->in
.modify_config
;
2346 u
->in
.use_kerberos
= r
->in
.use_kerberos
;
2347 u
->in
.unjoin_flags
= WKSSVC_JOIN_FLAGS_JOIN_TYPE
|
2348 WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE
;
2350 werr
= libnet_Unjoin(mem_ctx
, u
);
2356 /****************************************************************
2357 ****************************************************************/
2359 WERROR
libnet_Join(TALLOC_CTX
*mem_ctx
,
2360 struct libnet_JoinCtx
*r
)
2365 LIBNET_JOIN_IN_DUMP_CTX(mem_ctx
, r
);
2368 ZERO_STRUCT(r
->out
);
2370 werr
= libnet_join_pre_processing(mem_ctx
, r
);
2371 if (!W_ERROR_IS_OK(werr
)) {
2375 if (r
->in
.join_flags
& WKSSVC_JOIN_FLAGS_JOIN_TYPE
) {
2376 werr
= libnet_DomainJoin(mem_ctx
, r
);
2377 if (!W_ERROR_IS_OK(werr
)) {
2382 werr
= libnet_join_post_processing(mem_ctx
, r
);
2383 if (!W_ERROR_IS_OK(werr
)) {
2387 if (r
->in
.join_flags
& WKSSVC_JOIN_FLAGS_JOIN_TYPE
) {
2388 werr
= libnet_join_post_verify(mem_ctx
, r
);
2389 if (!W_ERROR_IS_OK(werr
)) {
2390 libnet_join_rollback(mem_ctx
, r
);
2395 r
->out
.result
= werr
;
2398 LIBNET_JOIN_OUT_DUMP_CTX(mem_ctx
, r
);
2403 /****************************************************************
2404 ****************************************************************/
2406 static WERROR
libnet_DomainUnjoin(TALLOC_CTX
*mem_ctx
,
2407 struct libnet_UnjoinCtx
*r
)
2411 if (!r
->in
.domain_sid
) {
2413 if (!secrets_fetch_domain_sid(lp_workgroup(), &sid
)) {
2414 libnet_unjoin_set_error_string(mem_ctx
, r
,
2415 "Unable to fetch domain sid: are we joined?");
2416 return WERR_SETUP_NOT_JOINED
;
2418 r
->in
.domain_sid
= dom_sid_dup(mem_ctx
, &sid
);
2419 W_ERROR_HAVE_NO_MEMORY(r
->in
.domain_sid
);
2422 if (!(r
->in
.unjoin_flags
& WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE
) &&
2423 !r
->in
.delete_machine_account
) {
2424 libnet_join_unjoindomain_remove_secrets(mem_ctx
, r
);
2428 if (!r
->in
.dc_name
) {
2429 struct netr_DsRGetDCNameInfo
*info
;
2431 status
= dsgetdcname(mem_ctx
,
2436 DS_DIRECTORY_SERVICE_REQUIRED
|
2437 DS_WRITABLE_REQUIRED
|
2440 if (!NT_STATUS_IS_OK(status
)) {
2441 libnet_unjoin_set_error_string(mem_ctx
, r
,
2442 "failed to find DC for domain %s",
2444 get_friendly_nt_error_msg(status
));
2445 return WERR_DCNOTFOUND
;
2448 dc
= strip_hostname(info
->dc_unc
);
2449 r
->in
.dc_name
= talloc_strdup(mem_ctx
, dc
);
2450 W_ERROR_HAVE_NO_MEMORY(r
->in
.dc_name
);
2454 /* for net ads leave, try to delete the account. If it works,
2455 no sense in disabling. If it fails, we can still try to
2458 if (r
->in
.delete_machine_account
) {
2459 ADS_STATUS ads_status
;
2460 ads_status
= libnet_unjoin_connect_ads(mem_ctx
, r
);
2461 if (ADS_ERR_OK(ads_status
)) {
2463 r
->out
.dns_domain_name
=
2464 talloc_strdup(mem_ctx
,
2465 r
->in
.ads
->server
.realm
);
2467 libnet_unjoin_remove_machine_acct(mem_ctx
, r
);
2469 if (!ADS_ERR_OK(ads_status
)) {
2470 libnet_unjoin_set_error_string(mem_ctx
, r
,
2471 "failed to remove machine account from AD: %s",
2472 ads_errstr(ads_status
));
2474 r
->out
.deleted_machine_account
= true;
2475 W_ERROR_HAVE_NO_MEMORY(r
->out
.dns_domain_name
);
2476 libnet_join_unjoindomain_remove_secrets(mem_ctx
, r
);
2480 #endif /* HAVE_ADS */
2482 /* The WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE flag really means
2484 if (r
->in
.unjoin_flags
& WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE
) {
2485 status
= libnet_join_unjoindomain_rpc(mem_ctx
, r
);
2486 if (!NT_STATUS_IS_OK(status
)) {
2487 libnet_unjoin_set_error_string(mem_ctx
, r
,
2488 "failed to disable machine account via rpc: %s",
2489 get_friendly_nt_error_msg(status
));
2490 if (NT_STATUS_EQUAL(status
, NT_STATUS_NO_SUCH_USER
)) {
2491 return WERR_SETUP_NOT_JOINED
;
2493 return ntstatus_to_werror(status
);
2496 r
->out
.disabled_machine_account
= true;
2499 /* If disable succeeded or was not requested at all, we
2500 should be getting rid of our end of things */
2502 libnet_join_unjoindomain_remove_secrets(mem_ctx
, r
);
2507 /****************************************************************
2508 ****************************************************************/
2510 static WERROR
libnet_unjoin_pre_processing(TALLOC_CTX
*mem_ctx
,
2511 struct libnet_UnjoinCtx
*r
)
2513 if (!r
->in
.domain_name
) {
2514 libnet_unjoin_set_error_string(mem_ctx
, r
,
2515 "No domain name defined");
2516 return WERR_INVALID_PARAM
;
2519 if (!libnet_parse_domain_dc(mem_ctx
, r
->in
.domain_name
,
2522 libnet_unjoin_set_error_string(mem_ctx
, r
,
2523 "Failed to parse domain name");
2524 return WERR_INVALID_PARAM
;
2528 return WERR_SETUP_DOMAIN_CONTROLLER
;
2531 if (!r
->in
.admin_domain
) {
2532 char *admin_domain
= NULL
;
2533 char *admin_account
= NULL
;
2534 split_domain_user(mem_ctx
,
2535 r
->in
.admin_account
,
2538 r
->in
.admin_domain
= admin_domain
;
2539 r
->in
.admin_account
= admin_account
;
2542 if (!secrets_init()) {
2543 libnet_unjoin_set_error_string(mem_ctx
, r
,
2544 "Unable to open secrets database");
2545 return WERR_CAN_NOT_COMPLETE
;
2551 /****************************************************************
2552 ****************************************************************/
2554 static WERROR
libnet_unjoin_post_processing(TALLOC_CTX
*mem_ctx
,
2555 struct libnet_UnjoinCtx
*r
)
2557 saf_delete(r
->out
.netbios_domain_name
);
2558 saf_delete(r
->out
.dns_domain_name
);
2560 return libnet_unjoin_config(r
);
2563 /****************************************************************
2564 ****************************************************************/
2566 WERROR
libnet_Unjoin(TALLOC_CTX
*mem_ctx
,
2567 struct libnet_UnjoinCtx
*r
)
2572 LIBNET_UNJOIN_IN_DUMP_CTX(mem_ctx
, r
);
2575 werr
= libnet_unjoin_pre_processing(mem_ctx
, r
);
2576 if (!W_ERROR_IS_OK(werr
)) {
2580 if (r
->in
.unjoin_flags
& WKSSVC_JOIN_FLAGS_JOIN_TYPE
) {
2581 werr
= libnet_DomainUnjoin(mem_ctx
, r
);
2582 if (!W_ERROR_IS_OK(werr
)) {
2583 libnet_unjoin_config(r
);
2588 werr
= libnet_unjoin_post_processing(mem_ctx
, r
);
2589 if (!W_ERROR_IS_OK(werr
)) {
2594 r
->out
.result
= werr
;
2597 LIBNET_UNJOIN_OUT_DUMP_CTX(mem_ctx
, r
);