2 Samba Unix/Linux SMB client library
4 Copyright (C) 2001 Andrew Tridgell (tridge@samba.org)
5 Copyright (C) 2001 Remus Koos (remuskoos@yahoo.com)
6 Copyright (C) 2002 Jim McDonough (jmcd@us.ibm.com)
7 Copyright (C) 2006 Gerald (Jerry) Carter (jerry@samba.org)
9 This program is free software; you can redistribute it and/or modify
10 it under the terms of the GNU General Public License as published by
11 the Free Software Foundation; either version 3 of the License, or
12 (at your option) any later version.
14 This program is distributed in the hope that it will be useful,
15 but WITHOUT ANY WARRANTY; without even the implied warranty of
16 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 GNU General Public License for more details.
19 You should have received a copy of the GNU General Public License
20 along with this program. If not, see <http://www.gnu.org/licenses/>.
24 #include "utils/net.h"
25 #include "libsmb/namequery.h"
26 #include "rpc_client/cli_pipe.h"
27 #include "librpc/gen_ndr/ndr_krb5pac.h"
28 #include "../librpc/gen_ndr/ndr_spoolss.h"
29 #include "nsswitch/libwbclient/wbclient.h"
31 #include "libads/cldap.h"
32 #include "../lib/addns/dnsquery.h"
33 #include "../libds/common/flags.h"
34 #include "librpc/gen_ndr/libnet_join.h"
35 #include "libnet/libnet_join.h"
38 #include "../libcli/security/security.h"
39 #include "libsmb/libsmb.h"
40 #include "lib/param/loadparm.h"
41 #include "utils/net_dns.h"
42 #include "auth/kerberos/pac_utils.h"
43 #include "lib/util/string_wrappers.h"
44 #include "lib/util/util_file.h"
48 #include "audit_logging.h" /* various JSON helpers */
49 #include "auth/common_auth.h"
50 #endif /* [HAVE_JANSSON] */
54 /* when we do not have sufficient input parameters to contact a remote domain
55 * we always fall back to our own realm - Guenther*/
57 static const char *assume_own_realm(struct net_context
*c
)
59 if (!c
->opt_host
&& strequal(lp_workgroup(), c
->opt_target_workgroup
)) {
69 * note: JSON output deliberately bypasses gettext so as to provide the same
70 * output irrespective of the locale.
73 static int output_json(const struct json_object
*jsobj
)
75 TALLOC_CTX
*ctx
= NULL
;
78 if (json_is_invalid(jsobj
)) {
82 ctx
= talloc_new(NULL
);
84 d_fprintf(stderr
, _("Out of memory\n"));
88 json
= json_to_string(ctx
, jsobj
);
90 d_fprintf(stderr
, _("error encoding to JSON\n"));
94 d_printf("%s\n", json
);
100 static int net_ads_cldap_netlogon_json
103 const struct NETLOGON_SAM_LOGON_RESPONSE_EX
*reply
)
105 struct json_object jsobj
= json_new_object();
106 struct json_object flagsobj
= json_new_object();
107 char response_type
[32] = { '\0' };
110 if (json_is_invalid(&jsobj
) || json_is_invalid(&flagsobj
)) {
111 d_fprintf(stderr
, _("error setting up JSON value\n"));
116 switch (reply
->command
) {
117 case LOGON_SAM_LOGON_USER_UNKNOWN_EX
:
118 strncpy(response_type
,
119 "LOGON_SAM_LOGON_USER_UNKNOWN_EX",
120 sizeof(response_type
));
122 case LOGON_SAM_LOGON_RESPONSE_EX
:
123 strncpy(response_type
,
124 "LOGON_SAM_LOGON_RESPONSE_EX",
125 sizeof(response_type
));
128 snprintf(response_type
,
129 sizeof(response_type
),
135 ret
= json_add_string(&jsobj
, "Information for Domain Controller",
141 ret
= json_add_string(&jsobj
, "Response Type", response_type
);
146 ret
= json_add_guid(&jsobj
, "GUID", &reply
->domain_uuid
);
151 ret
= json_add_bool(&flagsobj
, "Is a PDC",
152 reply
->server_type
& NBT_SERVER_PDC
);
157 ret
= json_add_bool(&flagsobj
, "Is a GC of the forest",
158 reply
->server_type
& NBT_SERVER_GC
);
163 ret
= json_add_bool(&flagsobj
, "Is an LDAP server",
164 reply
->server_type
& NBT_SERVER_LDAP
);
169 ret
= json_add_bool(&flagsobj
, "Supports DS",
170 reply
->server_type
& NBT_SERVER_DS
);
175 ret
= json_add_bool(&flagsobj
, "Is running a KDC",
176 reply
->server_type
& NBT_SERVER_KDC
);
181 ret
= json_add_bool(&flagsobj
, "Is running time services",
182 reply
->server_type
& NBT_SERVER_TIMESERV
);
187 ret
= json_add_bool(&flagsobj
, "Is the closest DC",
188 reply
->server_type
& NBT_SERVER_CLOSEST
);
193 ret
= json_add_bool(&flagsobj
, "Is writable",
194 reply
->server_type
& NBT_SERVER_WRITABLE
);
199 ret
= json_add_bool(&flagsobj
, "Has a hardware clock",
200 reply
->server_type
& NBT_SERVER_GOOD_TIMESERV
);
205 ret
= json_add_bool(&flagsobj
,
206 "Is a non-domain NC serviced by LDAP server",
207 reply
->server_type
& NBT_SERVER_NDNC
);
213 (&flagsobj
, "Is NT6 DC that has some secrets",
214 reply
->server_type
& NBT_SERVER_SELECT_SECRET_DOMAIN_6
);
220 (&flagsobj
, "Is NT6 DC that has all secrets",
221 reply
->server_type
& NBT_SERVER_FULL_SECRET_DOMAIN_6
);
226 ret
= json_add_bool(&flagsobj
, "Runs Active Directory Web Services",
227 reply
->server_type
& NBT_SERVER_ADS_WEB_SERVICE
);
232 ret
= json_add_bool(&flagsobj
, "Runs on Windows 2012 or later",
233 reply
->server_type
& NBT_SERVER_DS_8
);
238 ret
= json_add_bool(&flagsobj
, "Runs on Windows 2012R2 or later",
239 reply
->server_type
& NBT_SERVER_DS_9
);
244 ret
= json_add_bool(&flagsobj
, "Runs on Windows 2016 or later",
245 reply
->server_type
& NBT_SERVER_DS_10
);
250 ret
= json_add_bool(&flagsobj
, "Has a DNS name",
251 reply
->server_type
& NBT_SERVER_HAS_DNS_NAME
);
256 ret
= json_add_bool(&flagsobj
, "Is a default NC",
257 reply
->server_type
& NBT_SERVER_IS_DEFAULT_NC
);
262 ret
= json_add_bool(&flagsobj
, "Is the forest root",
263 reply
->server_type
& NBT_SERVER_FOREST_ROOT
);
268 ret
= json_add_string(&jsobj
, "Forest", reply
->forest
);
273 ret
= json_add_string(&jsobj
, "Domain", reply
->dns_domain
);
278 ret
= json_add_string(&jsobj
, "Domain Controller", reply
->pdc_dns_name
);
284 ret
= json_add_string(&jsobj
, "Pre-Win2k Domain", reply
->domain_name
);
289 ret
= json_add_string(&jsobj
, "Pre-Win2k Hostname", reply
->pdc_name
);
294 if (*reply
->user_name
) {
295 ret
= json_add_string(&jsobj
, "User name", reply
->user_name
);
301 ret
= json_add_string(&jsobj
, "Server Site Name", reply
->server_site
);
306 ret
= json_add_string(&jsobj
, "Client Site Name", reply
->client_site
);
311 ret
= json_add_int(&jsobj
, "NT Version", reply
->nt_version
);
316 ret
= json_add_int(&jsobj
, "LMNT Token", reply
->lmnt_token
);
321 ret
= json_add_int(&jsobj
, "LM20 Token", reply
->lm20_token
);
326 ret
= json_add_object(&jsobj
, "Flags", &flagsobj
);
331 ret
= output_json(&jsobj
);
332 json_free(&jsobj
); /* frees flagsobj recursively */
337 json_free(&flagsobj
);
343 #else /* [HAVE_JANSSON] */
345 static int net_ads_cldap_netlogon_json
348 const struct NETLOGON_SAM_LOGON_RESPONSE_EX
* reply
)
350 d_fprintf(stderr
, _("JSON support not available\n"));
355 #endif /* [HAVE_JANSSON] */
358 do a cldap netlogon query
360 static int net_ads_cldap_netlogon(struct net_context
*c
, ADS_STRUCT
*ads
)
362 char addr
[INET6_ADDRSTRLEN
];
363 struct NETLOGON_SAM_LOGON_RESPONSE_EX reply
;
365 print_sockaddr(addr
, sizeof(addr
), &ads
->ldap
.ss
);
367 if ( !ads_cldap_netlogon_5(talloc_tos(), &ads
->ldap
.ss
, ads
->server
.realm
, &reply
) ) {
368 d_fprintf(stderr
, _("CLDAP query failed!\n"));
373 return net_ads_cldap_netlogon_json(ads
, addr
, &reply
);
376 d_printf(_("Information for Domain Controller: %s\n\n"),
379 d_printf(_("Response Type: "));
380 switch (reply
.command
) {
381 case LOGON_SAM_LOGON_USER_UNKNOWN_EX
:
382 d_printf("LOGON_SAM_LOGON_USER_UNKNOWN_EX\n");
384 case LOGON_SAM_LOGON_RESPONSE_EX
:
385 d_printf("LOGON_SAM_LOGON_RESPONSE_EX\n");
388 d_printf("0x%x\n", reply
.command
);
392 d_printf(_("GUID: %s\n"), GUID_string(talloc_tos(),&reply
.domain_uuid
));
394 d_printf(_("Flags:\n"
396 "\tIs a GC of the forest: %s\n"
397 "\tIs an LDAP server: %s\n"
398 "\tSupports DS: %s\n"
399 "\tIs running a KDC: %s\n"
400 "\tIs running time services: %s\n"
401 "\tIs the closest DC: %s\n"
402 "\tIs writable: %s\n"
403 "\tHas a hardware clock: %s\n"
404 "\tIs a non-domain NC serviced by LDAP server: %s\n"
405 "\tIs NT6 DC that has some secrets: %s\n"
406 "\tIs NT6 DC that has all secrets: %s\n"
407 "\tRuns Active Directory Web Services: %s\n"
408 "\tRuns on Windows 2012 or later: %s\n"
409 "\tRuns on Windows 2012R2 or later: %s\n"
410 "\tRuns on Windows 2016 or later: %s\n"
411 "\tHas a DNS name: %s\n"
412 "\tIs a default NC: %s\n"
413 "\tIs the forest root: %s\n"),
414 (reply
.server_type
& NBT_SERVER_PDC
) ? _("yes") : _("no"),
415 (reply
.server_type
& NBT_SERVER_GC
) ? _("yes") : _("no"),
416 (reply
.server_type
& NBT_SERVER_LDAP
) ? _("yes") : _("no"),
417 (reply
.server_type
& NBT_SERVER_DS
) ? _("yes") : _("no"),
418 (reply
.server_type
& NBT_SERVER_KDC
) ? _("yes") : _("no"),
419 (reply
.server_type
& NBT_SERVER_TIMESERV
) ? _("yes") : _("no"),
420 (reply
.server_type
& NBT_SERVER_CLOSEST
) ? _("yes") : _("no"),
421 (reply
.server_type
& NBT_SERVER_WRITABLE
) ? _("yes") : _("no"),
422 (reply
.server_type
& NBT_SERVER_GOOD_TIMESERV
) ? _("yes") : _("no"),
423 (reply
.server_type
& NBT_SERVER_NDNC
) ? _("yes") : _("no"),
424 (reply
.server_type
& NBT_SERVER_SELECT_SECRET_DOMAIN_6
) ? _("yes") : _("no"),
425 (reply
.server_type
& NBT_SERVER_FULL_SECRET_DOMAIN_6
) ? _("yes") : _("no"),
426 (reply
.server_type
& NBT_SERVER_ADS_WEB_SERVICE
) ? _("yes") : _("no"),
427 (reply
.server_type
& NBT_SERVER_DS_8
) ? _("yes") : _("no"),
428 (reply
.server_type
& NBT_SERVER_DS_9
) ? _("yes") : _("no"),
429 (reply
.server_type
& NBT_SERVER_DS_10
) ? _("yes") : _("no"),
430 (reply
.server_type
& NBT_SERVER_HAS_DNS_NAME
) ? _("yes") : _("no"),
431 (reply
.server_type
& NBT_SERVER_IS_DEFAULT_NC
) ? _("yes") : _("no"),
432 (reply
.server_type
& NBT_SERVER_FOREST_ROOT
) ? _("yes") : _("no"));
435 printf(_("Forest: %s\n"), reply
.forest
);
436 printf(_("Domain: %s\n"), reply
.dns_domain
);
437 printf(_("Domain Controller: %s\n"), reply
.pdc_dns_name
);
439 printf(_("Pre-Win2k Domain: %s\n"), reply
.domain_name
);
440 printf(_("Pre-Win2k Hostname: %s\n"), reply
.pdc_name
);
442 if (*reply
.user_name
) printf(_("User name: %s\n"), reply
.user_name
);
444 printf(_("Server Site Name: %s\n"), reply
.server_site
);
445 printf(_("Client Site Name: %s\n"), reply
.client_site
);
447 d_printf(_("NT Version: %d\n"), reply
.nt_version
);
448 d_printf(_("LMNT Token: %.2x\n"), reply
.lmnt_token
);
449 d_printf(_("LM20 Token: %.2x\n"), reply
.lm20_token
);
455 this implements the CLDAP based netlogon lookup requests
456 for finding the domain controller of a ADS domain
458 static int net_ads_lookup(struct net_context
*c
, int argc
, const char **argv
)
460 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
461 ADS_STRUCT
*ads
= NULL
;
465 if (c
->display_usage
) {
470 _("Find the ADS DC using CLDAP lookup.\n"));
471 TALLOC_FREE(tmp_ctx
);
475 status
= ads_startup_nobind(c
, false, tmp_ctx
, &ads
);
476 if (!ADS_ERR_OK(status
)) {
477 d_fprintf(stderr
, _("Didn't find the cldap server!\n"));
481 if (!ads
->config
.realm
) {
482 ads
->config
.realm
= talloc_strdup(ads
, c
->opt_target_workgroup
);
483 if (ads
->config
.realm
== NULL
) {
484 d_fprintf(stderr
, _("Out of memory\n"));
487 ads
->ldap
.port
= 389;
490 ret
= net_ads_cldap_netlogon(c
, ads
);
492 TALLOC_FREE(tmp_ctx
);
499 static int net_ads_info_json(ADS_STRUCT
*ads
)
502 char addr
[INET6_ADDRSTRLEN
];
504 struct json_object jsobj
= json_new_object();
506 if (json_is_invalid(&jsobj
)) {
507 d_fprintf(stderr
, _("error setting up JSON value\n"));
512 pass_time
= secrets_fetch_pass_last_set_time(ads
->server
.workgroup
);
514 print_sockaddr(addr
, sizeof(addr
), &ads
->ldap
.ss
);
516 ret
= json_add_string (&jsobj
, "LDAP server", addr
);
521 ret
= json_add_string (&jsobj
, "LDAP server name",
522 ads
->config
.ldap_server_name
);
527 ret
= json_add_string (&jsobj
, "Workgroup", ads
->config
.workgroup
);
532 ret
= json_add_string (&jsobj
, "Realm", ads
->config
.realm
);
537 ret
= json_add_string (&jsobj
, "Bind Path", ads
->config
.bind_path
);
542 ret
= json_add_int (&jsobj
, "LDAP port", ads
->ldap
.port
);
547 ret
= json_add_int (&jsobj
, "Server time", ads
->config
.current_time
);
552 ret
= json_add_string (&jsobj
, "KDC server", ads
->auth
.kdc_server
);
557 ret
= json_add_int (&jsobj
, "Server time offset",
558 ads
->config
.time_offset
);
563 ret
= json_add_int (&jsobj
, "Last machine account password change",
569 ret
= output_json(&jsobj
);
576 #else /* [HAVE_JANSSON] */
578 static int net_ads_info_json(ADS_STRUCT
*ads
)
580 d_fprintf(stderr
, _("JSON support not available\n"));
585 #endif /* [HAVE_JANSSON] */
589 static int net_ads_info(struct net_context
*c
, int argc
, const char **argv
)
591 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
592 ADS_STRUCT
*ads
= NULL
;
594 char addr
[INET6_ADDRSTRLEN
];
598 if (c
->display_usage
) {
603 _("Display information about an Active Directory "
605 TALLOC_FREE(tmp_ctx
);
609 status
= ads_startup_nobind(c
, false, tmp_ctx
, &ads
);
610 if (!ADS_ERR_OK(status
)) {
611 d_fprintf(stderr
, _("Didn't find the ldap server!\n"));
615 if (!ads
|| !ads
->config
.realm
) {
616 d_fprintf(stderr
, _("Didn't find the ldap server!\n"));
620 /* Try to set the server's current time since we didn't do a full
621 TCP LDAP session initially */
623 if ( !ADS_ERR_OK(ads_current_time( ads
)) ) {
624 d_fprintf( stderr
, _("Failed to get server's current time!\n"));
628 ret
= net_ads_info_json(ads
);
632 pass_time
= secrets_fetch_pass_last_set_time(ads
->server
.workgroup
);
634 print_sockaddr(addr
, sizeof(addr
), &ads
->ldap
.ss
);
636 d_printf(_("LDAP server: %s\n"), addr
);
637 d_printf(_("LDAP server name: %s\n"), ads
->config
.ldap_server_name
);
638 d_printf(_("Workgroup: %s\n"), ads
->config
.workgroup
);
639 d_printf(_("Realm: %s\n"), ads
->config
.realm
);
640 d_printf(_("Bind Path: %s\n"), ads
->config
.bind_path
);
641 d_printf(_("LDAP port: %d\n"), ads
->ldap
.port
);
642 d_printf(_("Server time: %s\n"),
643 http_timestring(tmp_ctx
, ads
->config
.current_time
));
645 d_printf(_("KDC server: %s\n"), ads
->auth
.kdc_server
);
646 d_printf(_("Server time offset: %d\n"), ads
->config
.time_offset
);
648 d_printf(_("Last machine account password change: %s\n"),
649 http_timestring(tmp_ctx
, pass_time
));
653 TALLOC_FREE(tmp_ctx
);
657 static ADS_STATUS
ads_startup_int(struct net_context
*c
,
658 bool only_own_domain
,
661 ADS_STRUCT
**ads_ret
)
663 ADS_STRUCT
*ads
= NULL
;
665 const char *realm
= NULL
;
666 const char *workgroup
= NULL
;
667 bool tried_closest_dc
= false;
669 /* lp_realm() should be handled by a command line param,
670 However, the join requires that realm be set in smb.conf
671 and compares our realm with the remote server's so this is
672 ok until someone needs more flexibility */
677 if (only_own_domain
) {
679 workgroup
= lp_workgroup();
681 realm
= assume_own_realm(c
);
682 workgroup
= c
->opt_target_workgroup
;
685 ads
= ads_init(mem_ctx
,
691 return ADS_ERROR_NT(NT_STATUS_NO_MEMORY
);
694 ads
->auth
.flags
|= auth_flags
;
696 if (auth_flags
& ADS_AUTH_NO_BIND
) {
697 status
= ads_connect_cldap_only(ads
);
698 if (!ADS_ERR_OK(status
)) {
699 DBG_ERR("ads_connect_cldap_only: %s\n",
705 status
= ads_connect_creds(ads
, c
->creds
);
706 if (!ADS_ERR_OK(status
)) {
707 DBG_ERR("ads_connect_creds: %s\n",
714 /* when contacting our own domain, make sure we use the closest DC.
715 * This is done by reconnecting to ADS because only the first call to
716 * ads_connect will give us our own sitename */
718 if ((only_own_domain
|| !c
->opt_host
) && !tried_closest_dc
) {
720 tried_closest_dc
= true; /* avoid loop */
722 if (!ads_closest_dc(ads
)) {
724 namecache_delete(ads
->server
.realm
, 0x1C);
725 namecache_delete(ads
->server
.workgroup
, 0x1C);
733 *ads_ret
= talloc_move(mem_ctx
, &ads
);
737 ADS_STATUS
ads_startup(struct net_context
*c
,
738 bool only_own_domain
,
742 return ads_startup_int(c
, only_own_domain
, 0, mem_ctx
, ads
);
745 ADS_STATUS
ads_startup_nobind(struct net_context
*c
,
746 bool only_own_domain
,
750 return ads_startup_int(c
,
758 Check to see if connection can be made via ads.
759 ads_startup() stores the password in opt_password if it needs to so
760 that rpc or rap can use it without re-prompting.
762 static int net_ads_check_int(struct net_context
*c
,
764 const char *workgroup
,
767 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
772 ads
= ads_init(tmp_ctx
, realm
, workgroup
, host
, ADS_SASL_PLAIN
);
777 status
= ads_connect_cldap_only(ads
);
778 if (!ADS_ERR_OK(status
)) {
784 TALLOC_FREE(tmp_ctx
);
788 int net_ads_check_our_domain(struct net_context
*c
)
790 return net_ads_check_int(c
, lp_realm(), lp_workgroup(), NULL
);
793 int net_ads_check(struct net_context
*c
)
795 return net_ads_check_int(c
, NULL
, c
->opt_workgroup
, c
->opt_host
);
799 determine the netbios workgroup name for a domain
801 static int net_ads_workgroup(struct net_context
*c
, int argc
, const char **argv
)
803 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
804 ADS_STRUCT
*ads
= NULL
;
806 struct NETLOGON_SAM_LOGON_RESPONSE_EX reply
;
810 if (c
->display_usage
) {
812 "net ads workgroup\n"
815 _("Print the workgroup name"));
816 TALLOC_FREE(tmp_ctx
);
820 status
= ads_startup_nobind(c
, false, tmp_ctx
, &ads
);
821 if (!ADS_ERR_OK(status
)) {
822 d_fprintf(stderr
, _("Didn't find the cldap server!\n"));
826 if (!ads
->config
.realm
) {
827 ads
->config
.realm
= talloc_strdup(ads
, c
->opt_target_workgroup
);
828 if (ads
->config
.realm
== NULL
) {
829 d_fprintf(stderr
, _("Out of memory\n"));
832 ads
->ldap
.port
= 389;
835 ok
= ads_cldap_netlogon_5(tmp_ctx
,
836 &ads
->ldap
.ss
, ads
->server
.realm
, &reply
);
838 d_fprintf(stderr
, _("CLDAP query failed!\n"));
842 d_printf(_("Workgroup: %s\n"), reply
.domain_name
);
846 TALLOC_FREE(tmp_ctx
);
853 static bool usergrp_display(ADS_STRUCT
*ads
, char *field
, void **values
, void *data_area
)
855 char **disp_fields
= (char **) data_area
;
857 if (!field
) { /* must be end of record */
858 if (disp_fields
[0]) {
859 if (!strchr_m(disp_fields
[0], '$')) {
861 d_printf("%-21.21s %s\n",
862 disp_fields
[0], disp_fields
[1]);
864 d_printf("%s\n", disp_fields
[0]);
867 SAFE_FREE(disp_fields
[0]);
868 SAFE_FREE(disp_fields
[1]);
871 if (!values
) /* must be new field, indicate string field */
873 if (strcasecmp_m(field
, "sAMAccountName") == 0) {
874 disp_fields
[0] = SMB_STRDUP((char *) values
[0]);
876 if (strcasecmp_m(field
, "description") == 0)
877 disp_fields
[1] = SMB_STRDUP((char *) values
[0]);
881 static int net_ads_user_usage(struct net_context
*c
, int argc
, const char **argv
)
883 return net_user_usage(c
, argc
, argv
);
886 static int ads_user_add(struct net_context
*c
, int argc
, const char **argv
)
888 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
889 ADS_STRUCT
*ads
= NULL
;
892 LDAPMessage
*res
=NULL
;
893 char *creds_ccname
= NULL
;
898 if (argc
< 1 || c
->display_usage
) {
899 TALLOC_FREE(tmp_ctx
);
900 return net_ads_user_usage(c
, argc
, argv
);
905 * We rely on ads_krb5_set_password() to
906 * set the password below.
908 * We could pass the password to
909 * ads_add_user_acct()
910 * and set the unicodePwd attribute there...
912 cli_credentials_set_kerberos_state(c
->creds
,
913 CRED_USE_KERBEROS_REQUIRED
,
917 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
918 if (!ADS_ERR_OK(status
)) {
922 status
= ads_find_user_acct(ads
, &res
, argv
[0]);
923 if (!ADS_ERR_OK(status
)) {
924 d_fprintf(stderr
, _("ads_user_add: %s\n"), ads_errstr(status
));
928 if (ads_count_replies(ads
, res
)) {
929 d_fprintf(stderr
, _("ads_user_add: User %s already exists\n"),
934 if (c
->opt_container
) {
935 ou_str
= SMB_STRDUP(c
->opt_container
);
937 ou_str
= ads_default_ou_string(ads
, DS_GUID_USERS_CONTAINER
);
940 status
= ads_add_user_acct(ads
, argv
[0], ou_str
, c
->opt_comment
);
941 if (!ADS_ERR_OK(status
)) {
942 d_fprintf(stderr
, _("Could not add user %s: %s\n"), argv
[0],
947 /* if no password is to be set, we're done */
949 d_printf(_("User %s added\n"), argv
[0]);
954 /* try setting the password */
955 upn
= talloc_asprintf(tmp_ctx
,
963 ok
= cli_credentials_get_ccache_name_obtained(c
->creds
,
968 d_printf(_("No valid krb5 ccache for: %s\n"),
969 cli_credentials_get_unparsed_name(c
->creds
, tmp_ctx
));
973 status
= ads_krb5_set_password(upn
, argv
[1], creds_ccname
);
974 if (ADS_ERR_OK(status
)) {
975 d_printf(_("User %s added\n"), argv
[0]);
981 /* password didn't set, delete account */
982 d_fprintf(stderr
, _("Could not add user %s. "
983 "Error setting password %s\n"),
984 argv
[0], ads_errstr(status
));
986 ads_msgfree(ads
, res
);
989 status
=ads_find_user_acct(ads
, &res
, argv
[0]);
990 if (ADS_ERR_OK(status
)) {
991 userdn
= ads_get_dn(ads
, tmp_ctx
, res
);
992 ads_del_dn(ads
, userdn
);
997 ads_msgfree(ads
, res
);
999 TALLOC_FREE(tmp_ctx
);
1003 static int ads_user_info(struct net_context
*c
, int argc
, const char **argv
)
1005 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1006 ADS_STRUCT
*ads
= NULL
;
1008 LDAPMessage
*res
= NULL
;
1011 const char *attrs
[] = {"memberOf", "primaryGroupID", NULL
};
1012 char *searchstring
= NULL
;
1013 char **grouplist
= NULL
;
1014 char *primary_group
= NULL
;
1015 char *escaped_user
= NULL
;
1016 struct dom_sid primary_group_sid
;
1018 enum wbcSidType type
;
1020 if (argc
< 1 || c
->display_usage
) {
1021 TALLOC_FREE(tmp_ctx
);
1022 return net_ads_user_usage(c
, argc
, argv
);
1025 escaped_user
= escape_ldap_string(tmp_ctx
, argv
[0]);
1026 if (!escaped_user
) {
1028 _("ads_user_info: failed to escape user %s\n"),
1033 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
1034 if (!ADS_ERR_OK(status
)) {
1038 searchstring
= talloc_asprintf(tmp_ctx
,
1039 "(sAMAccountName=%s)",
1041 if (searchstring
== NULL
) {
1045 status
= ads_search(ads
, &res
, searchstring
, attrs
);
1046 if (!ADS_ERR_OK(status
)) {
1047 d_fprintf(stderr
, _("ads_search: %s\n"), ads_errstr(status
));
1051 if (!ads_pull_uint32(ads
, res
, "primaryGroupID", &group_rid
)) {
1052 d_fprintf(stderr
, _("ads_pull_uint32 failed\n"));
1056 status
= ads_domain_sid(ads
, &primary_group_sid
);
1057 if (!ADS_ERR_OK(status
)) {
1058 d_fprintf(stderr
, _("ads_domain_sid: %s\n"), ads_errstr(status
));
1062 sid_append_rid(&primary_group_sid
, group_rid
);
1064 wbc_status
= wbcLookupSid((struct wbcDomainSid
*)&primary_group_sid
,
1065 NULL
, /* don't look up domain */
1068 if (!WBC_ERROR_IS_OK(wbc_status
)) {
1069 d_fprintf(stderr
, "wbcLookupSid: %s\n",
1070 wbcErrorString(wbc_status
));
1074 d_printf("%s\n", primary_group
);
1076 wbcFreeMemory(primary_group
);
1078 grouplist
= ldap_get_values((LDAP
*)ads
->ldap
.ld
,
1079 (LDAPMessage
*)res
, "memberOf");
1084 for (i
=0;grouplist
[i
];i
++) {
1085 groupname
= ldap_explode_dn(grouplist
[i
], 1);
1086 d_printf("%s\n", groupname
[0]);
1087 ldap_value_free(groupname
);
1089 ldap_value_free(grouplist
);
1094 TALLOC_FREE(escaped_user
);
1095 TALLOC_FREE(searchstring
);
1096 ads_msgfree(ads
, res
);
1097 TALLOC_FREE(tmp_ctx
);
1101 static int ads_user_delete(struct net_context
*c
, int argc
, const char **argv
)
1103 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1104 ADS_STRUCT
*ads
= NULL
;
1106 LDAPMessage
*res
= NULL
;
1107 char *userdn
= NULL
;
1111 TALLOC_FREE(tmp_ctx
);
1112 return net_ads_user_usage(c
, argc
, argv
);
1115 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
1116 if (!ADS_ERR_OK(status
)) {
1120 status
= ads_find_user_acct(ads
, &res
, argv
[0]);
1121 if (!ADS_ERR_OK(status
) || ads_count_replies(ads
, res
) != 1) {
1122 d_printf(_("User %s does not exist.\n"), argv
[0]);
1126 userdn
= ads_get_dn(ads
, tmp_ctx
, res
);
1127 if (userdn
== NULL
) {
1131 status
= ads_del_dn(ads
, userdn
);
1132 if (!ADS_ERR_OK(status
)) {
1133 d_fprintf(stderr
, _("Error deleting user %s: %s\n"), argv
[0],
1134 ads_errstr(status
));
1138 d_printf(_("User %s deleted\n"), argv
[0]);
1142 ads_msgfree(ads
, res
);
1143 TALLOC_FREE(tmp_ctx
);
1147 int net_ads_user(struct net_context
*c
, int argc
, const char **argv
)
1149 struct functable func
[] = {
1154 N_("Add an AD user"),
1155 N_("net ads user add\n"
1162 N_("Display information about an AD user"),
1163 N_("net ads user info\n"
1164 " Display information about an AD user")
1170 N_("Delete an AD user"),
1171 N_("net ads user delete\n"
1172 " Delete an AD user")
1174 {NULL
, NULL
, 0, NULL
, NULL
}
1176 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1177 ADS_STRUCT
*ads
= NULL
;
1179 const char *shortattrs
[] = {"sAMAccountName", NULL
};
1180 const char *longattrs
[] = {"sAMAccountName", "description", NULL
};
1181 char *disp_fields
[2] = {NULL
, NULL
};
1185 TALLOC_FREE(tmp_ctx
);
1186 return net_run_function(c
, argc
, argv
, "net ads user", func
);
1189 if (c
->display_usage
) {
1194 _("List AD users"));
1195 net_display_usage_from_functable(func
);
1196 TALLOC_FREE(tmp_ctx
);
1200 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
1201 if (!ADS_ERR_OK(status
)) {
1205 if (c
->opt_long_list_entries
)
1206 d_printf(_("\nUser name Comment"
1207 "\n-----------------------------\n"));
1209 status
= ads_do_search_all_fn(ads
,
1210 ads
->config
.bind_path
,
1212 "(objectCategory=user)",
1213 c
->opt_long_list_entries
?
1214 longattrs
: shortattrs
,
1217 if (!ADS_ERR_OK(status
)) {
1223 TALLOC_FREE(tmp_ctx
);
1227 static int net_ads_group_usage(struct net_context
*c
, int argc
, const char **argv
)
1229 return net_group_usage(c
, argc
, argv
);
1232 static int ads_group_add(struct net_context
*c
, int argc
, const char **argv
)
1234 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1235 ADS_STRUCT
*ads
= NULL
;
1237 LDAPMessage
*res
= NULL
;
1239 char *ou_str
= NULL
;
1241 if (argc
< 1 || c
->display_usage
) {
1242 TALLOC_FREE(tmp_ctx
);
1243 return net_ads_group_usage(c
, argc
, argv
);
1246 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
1247 if (!ADS_ERR_OK(status
)) {
1251 status
= ads_find_user_acct(ads
, &res
, argv
[0]);
1252 if (!ADS_ERR_OK(status
)) {
1253 d_fprintf(stderr
, _("ads_group_add: %s\n"), ads_errstr(status
));
1257 if (ads_count_replies(ads
, res
)) {
1258 d_fprintf(stderr
, _("ads_group_add: Group %s already exists\n"), argv
[0]);
1262 if (c
->opt_container
) {
1263 ou_str
= SMB_STRDUP(c
->opt_container
);
1265 ou_str
= ads_default_ou_string(ads
, DS_GUID_USERS_CONTAINER
);
1268 status
= ads_add_group_acct(ads
, argv
[0], ou_str
, c
->opt_comment
);
1269 if (!ADS_ERR_OK(status
)) {
1270 d_fprintf(stderr
, _("Could not add group %s: %s\n"), argv
[0],
1271 ads_errstr(status
));
1275 d_printf(_("Group %s added\n"), argv
[0]);
1279 ads_msgfree(ads
, res
);
1281 TALLOC_FREE(tmp_ctx
);
1285 static int ads_group_delete(struct net_context
*c
, int argc
, const char **argv
)
1287 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1288 ADS_STRUCT
*ads
= NULL
;
1290 LDAPMessage
*res
= NULL
;
1291 char *groupdn
= NULL
;
1294 if (argc
< 1 || c
->display_usage
) {
1295 TALLOC_FREE(tmp_ctx
);
1296 return net_ads_group_usage(c
, argc
, argv
);
1299 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
1300 if (!ADS_ERR_OK(status
)) {
1304 status
= ads_find_user_acct(ads
, &res
, argv
[0]);
1305 if (!ADS_ERR_OK(status
) || ads_count_replies(ads
, res
) != 1) {
1306 d_printf(_("Group %s does not exist.\n"), argv
[0]);
1310 groupdn
= ads_get_dn(ads
, tmp_ctx
, res
);
1311 if (groupdn
== NULL
) {
1315 status
= ads_del_dn(ads
, groupdn
);
1316 if (!ADS_ERR_OK(status
)) {
1317 d_fprintf(stderr
, _("Error deleting group %s: %s\n"), argv
[0],
1318 ads_errstr(status
));
1321 d_printf(_("Group %s deleted\n"), argv
[0]);
1325 ads_msgfree(ads
, res
);
1326 TALLOC_FREE(tmp_ctx
);
1330 int net_ads_group(struct net_context
*c
, int argc
, const char **argv
)
1332 struct functable func
[] = {
1337 N_("Add an AD group"),
1338 N_("net ads group add\n"
1345 N_("Delete an AD group"),
1346 N_("net ads group delete\n"
1347 " Delete an AD group")
1349 {NULL
, NULL
, 0, NULL
, NULL
}
1351 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1352 ADS_STRUCT
*ads
= NULL
;
1354 const char *shortattrs
[] = {"sAMAccountName", NULL
};
1355 const char *longattrs
[] = {"sAMAccountName", "description", NULL
};
1356 char *disp_fields
[2] = {NULL
, NULL
};
1360 TALLOC_FREE(tmp_ctx
);
1361 return net_run_function(c
, argc
, argv
, "net ads group", func
);
1364 if (c
->display_usage
) {
1369 _("List AD groups"));
1370 net_display_usage_from_functable(func
);
1371 TALLOC_FREE(tmp_ctx
);
1375 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
1376 if (!ADS_ERR_OK(status
)) {
1380 if (c
->opt_long_list_entries
)
1381 d_printf(_("\nGroup name Comment"
1382 "\n-----------------------------\n"));
1384 status
= ads_do_search_all_fn(ads
,
1385 ads
->config
.bind_path
,
1387 "(objectCategory=group)",
1388 c
->opt_long_list_entries
?
1389 longattrs
: shortattrs
,
1392 if (!ADS_ERR_OK(status
)) {
1398 TALLOC_FREE(tmp_ctx
);
1402 static int net_ads_status(struct net_context
*c
, int argc
, const char **argv
)
1404 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1405 ADS_STRUCT
*ads
= NULL
;
1407 LDAPMessage
*res
= NULL
;
1410 if (c
->display_usage
) {
1415 _("Display machine account details"));
1416 TALLOC_FREE(tmp_ctx
);
1420 net_warn_member_options();
1422 status
= ads_startup(c
, true, tmp_ctx
, &ads
);
1423 if (!ADS_ERR_OK(status
)) {
1427 status
= ads_find_machine_acct(ads
, &res
, lp_netbios_name());
1428 if (!ADS_ERR_OK(status
)) {
1429 d_fprintf(stderr
, _("ads_find_machine_acct: %s\n"),
1430 ads_errstr(status
));
1434 if (ads_count_replies(ads
, res
) == 0) {
1435 d_fprintf(stderr
, _("No machine account for '%s' found\n"),
1444 ads_msgfree(ads
, res
);
1445 TALLOC_FREE(tmp_ctx
);
1449 /*******************************************************************
1450 Leave an AD domain. Windows XP disables the machine account.
1451 We'll try the same. The old code would do an LDAP delete.
1452 That only worked using the machine creds because added the machine
1453 with full control to the computer object's ACL.
1454 *******************************************************************/
1456 static int net_ads_leave(struct net_context
*c
, int argc
, const char **argv
)
1458 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1459 struct libnet_UnjoinCtx
*r
= NULL
;
1463 if (c
->display_usage
) {
1465 "net ads leave [--keep-account]\n"
1468 _("Leave an AD domain"));
1469 TALLOC_FREE(tmp_ctx
);
1474 d_fprintf(stderr
, _("No realm set, are we joined ?\n"));
1475 TALLOC_FREE(tmp_ctx
);
1480 d_fprintf(stderr
, _("Could not initialise message context. "
1481 "Try running as root\n"));
1485 werr
= libnet_init_UnjoinCtx(tmp_ctx
, &r
);
1486 if (!W_ERROR_IS_OK(werr
)) {
1487 d_fprintf(stderr
, _("Could not initialise unjoin context.\n"));
1492 r
->in
.dc_name
= c
->opt_host
;
1493 r
->in
.domain_name
= lp_dnsdomain();
1494 r
->in
.admin_credentials
= c
->creds
;
1495 r
->in
.modify_config
= lp_config_backend_is_registry();
1497 /* Try to delete it, but if that fails, disable it. The
1498 WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE really means "disable */
1499 r
->in
.unjoin_flags
= WKSSVC_JOIN_FLAGS_JOIN_TYPE
|
1500 WKSSVC_JOIN_FLAGS_ACCOUNT_DELETE
;
1501 if (c
->opt_keep_account
) {
1502 r
->in
.delete_machine_account
= false;
1504 r
->in
.delete_machine_account
= true;
1507 r
->in
.msg_ctx
= c
->msg_ctx
;
1509 werr
= libnet_Unjoin(tmp_ctx
, r
);
1510 if (!W_ERROR_IS_OK(werr
)) {
1511 d_printf(_("Failed to leave domain: %s\n"),
1512 r
->out
.error_string
? r
->out
.error_string
:
1513 get_friendly_werror_msg(werr
));
1517 if (r
->out
.deleted_machine_account
) {
1518 d_printf(_("Deleted account for '%s' in realm '%s'\n"),
1519 r
->in
.machine_name
, r
->out
.dns_domain_name
);
1524 /* We couldn't delete it - see if the disable succeeded. */
1525 if (r
->out
.disabled_machine_account
) {
1526 d_printf(_("Disabled account for '%s' in realm '%s'\n"),
1527 r
->in
.machine_name
, r
->out
.dns_domain_name
);
1532 /* Based on what we requested, we shouldn't get here, but if
1533 we did, it means the secrets were removed, and therefore
1534 we have left the domain */
1535 d_fprintf(stderr
, _("Machine '%s' Left domain '%s'\n"),
1536 r
->in
.machine_name
, r
->out
.dns_domain_name
);
1540 TALLOC_FREE(tmp_ctx
);
1544 static ADS_STATUS
net_ads_join_ok(struct net_context
*c
)
1546 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1547 ADS_STRUCT
*ads
= NULL
;
1550 struct sockaddr_storage dcip
;
1552 if (!secrets_init()) {
1553 DEBUG(1,("Failed to initialise secrets database\n"));
1554 TALLOC_FREE(tmp_ctx
);
1555 return ADS_ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1558 net_warn_member_options();
1560 net_use_krb_machine_account(c
);
1562 if (!cli_credentials_authentication_requested(c
->creds
)) {
1563 DBG_ERR("Failed to get machine credentials\n");
1564 TALLOC_FREE(tmp_ctx
);
1565 return ADS_ERROR_NT(NT_STATUS_ACCESS_DENIED
);
1568 get_dc_name(lp_workgroup(), lp_realm(), dc_name
, &dcip
);
1570 status
= ads_startup(c
, true, tmp_ctx
, &ads
);
1571 if (!ADS_ERR_OK(status
)) {
1575 status
= ADS_ERROR_NT(NT_STATUS_OK
);
1577 TALLOC_FREE(tmp_ctx
);
1582 check that an existing join is OK
1584 int net_ads_testjoin(struct net_context
*c
, int argc
, const char **argv
)
1588 if (c
->display_usage
) {
1590 "net ads testjoin\n"
1593 _("Test if the existing join is ok"));
1597 net_warn_member_options();
1599 /* Display success or failure */
1600 status
= net_ads_join_ok(c
);
1601 if (!ADS_ERR_OK(status
)) {
1602 fprintf(stderr
, _("Join to domain is not valid: %s\n"),
1603 get_friendly_nt_error_msg(ads_ntstatus(status
)));
1607 printf(_("Join is OK\n"));
1611 /*******************************************************************
1612 Simple config checks before beginning the join
1613 ********************************************************************/
1615 static WERROR
check_ads_config( void )
1617 if (lp_server_role() != ROLE_DOMAIN_MEMBER
) {
1618 d_printf(_("Host is not configured as a member server.\n"));
1619 return WERR_INVALID_DOMAIN_ROLE
;
1622 if (strlen(lp_netbios_name()) > 15) {
1623 d_printf(_("Our netbios name can be at most 15 chars long, "
1624 "\"%s\" is %u chars long\n"), lp_netbios_name(),
1625 (unsigned int)strlen(lp_netbios_name()));
1626 return WERR_INVALID_COMPUTERNAME
;
1629 if ( lp_security() == SEC_ADS
&& !*lp_realm()) {
1630 d_fprintf(stderr
, _("realm must be set in %s for ADS "
1631 "join to succeed.\n"), get_dyn_CONFIGFILE());
1632 return WERR_INVALID_PARAMETER
;
1638 /*******************************************************************
1639 ********************************************************************/
1641 static int net_ads_join_usage(struct net_context
*c
, int argc
, const char **argv
)
1643 d_printf(_("net ads join [--no-dns-updates] [options]\n"
1644 "Valid options:\n"));
1645 d_printf(_(" dnshostname=FQDN Set the dnsHostName attribute during the join.\n"
1646 " The default is in the form netbiosname.dnsdomain\n"));
1647 d_printf(_(" createupn[=UPN] Set the userPrincipalName attribute during the join.\n"
1648 " The default UPN is in the form host/netbiosname@REALM.\n"));
1649 d_printf(_(" createcomputer=OU Precreate the computer account in a specific OU.\n"
1650 " The OU string read from top to bottom without RDNs\n"
1651 " and delimited by a '/'.\n"
1652 " E.g. \"createcomputer=Computers/Servers/Unix\"\n"
1653 " NB: A backslash '\\' is used as escape at multiple\n"
1654 " levels and may need to be doubled or even\n"
1655 " quadrupled. It is not used as a separator.\n"));
1656 d_printf(_(" machinepass=PASS Set the machine password to a specific value during\n"
1657 " the join. The default password is random.\n"));
1658 d_printf(_(" osName=string Set the operatingSystem attribute during the join.\n"));
1659 d_printf(_(" osVer=string Set the operatingSystemVersion attribute during join.\n"
1660 " NB: osName and osVer must be specified together for\n"
1661 " either to take effect. The operatingSystemService\n"
1662 " attribute is then also set along with the two\n"
1663 " other attributes.\n"));
1664 d_printf(_(" osServicePack=string Set the operatingSystemServicePack attribute\n"
1665 " during the join.\n"
1666 " NB: If not specified then by default the samba\n"
1667 " version string is used instead.\n"));
1672 int net_ads_join(struct net_context
*c
, int argc
, const char **argv
)
1674 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1675 struct libnet_JoinCtx
*r
= NULL
;
1676 const char *domain
= lp_realm();
1677 WERROR werr
= WERR_NERR_SETUPNOTJOINED
;
1678 bool createupn
= false;
1679 const char *dnshostname
= NULL
;
1680 const char *machineupn
= NULL
;
1681 const char *machine_password
= NULL
;
1682 const char *create_in_ou
= NULL
;
1684 const char *os_name
= NULL
;
1685 const char *os_version
= NULL
;
1686 const char *os_servicepack
= NULL
;
1687 bool modify_config
= lp_config_backend_is_registry();
1688 enum libnetjoin_JoinDomNameType domain_name_type
= JoinDomNameTypeDNS
;
1691 if (c
->display_usage
) {
1692 TALLOC_FREE(tmp_ctx
);
1693 return net_ads_join_usage(c
, argc
, argv
);
1696 net_warn_member_options();
1698 if (!modify_config
) {
1699 werr
= check_ads_config();
1700 if (!W_ERROR_IS_OK(werr
)) {
1701 d_fprintf(stderr
, _("Invalid configuration. Exiting....\n"));
1706 werr
= libnet_init_JoinCtx(tmp_ctx
, &r
);
1707 if (!W_ERROR_IS_OK(werr
)) {
1711 /* process additional command line args */
1713 for ( i
=0; i
<argc
; i
++ ) {
1714 if ( !strncasecmp_m(argv
[i
], "dnshostname", strlen("dnshostname")) ) {
1715 dnshostname
= get_string_param(argv
[i
]);
1717 else if ( !strncasecmp_m(argv
[i
], "createupn", strlen("createupn")) ) {
1719 machineupn
= get_string_param(argv
[i
]);
1721 else if ( !strncasecmp_m(argv
[i
], "createcomputer", strlen("createcomputer")) ) {
1722 if ( (create_in_ou
= get_string_param(argv
[i
])) == NULL
) {
1723 d_fprintf(stderr
, _("Please supply a valid OU path.\n"));
1724 werr
= WERR_INVALID_PARAMETER
;
1728 else if ( !strncasecmp_m(argv
[i
], "osName", strlen("osName")) ) {
1729 if ( (os_name
= get_string_param(argv
[i
])) == NULL
) {
1730 d_fprintf(stderr
, _("Please supply a operating system name.\n"));
1731 werr
= WERR_INVALID_PARAMETER
;
1735 else if ( !strncasecmp_m(argv
[i
], "osVer", strlen("osVer")) ) {
1736 if ( (os_version
= get_string_param(argv
[i
])) == NULL
) {
1737 d_fprintf(stderr
, _("Please supply a valid operating system version.\n"));
1738 werr
= WERR_INVALID_PARAMETER
;
1742 else if ( !strncasecmp_m(argv
[i
], "osServicePack", strlen("osServicePack")) ) {
1743 if ( (os_servicepack
= get_string_param(argv
[i
])) == NULL
) {
1744 d_fprintf(stderr
, _("Please supply a valid servicepack identifier.\n"));
1745 werr
= WERR_INVALID_PARAMETER
;
1749 else if ( !strncasecmp_m(argv
[i
], "machinepass", strlen("machinepass")) ) {
1750 if ( (machine_password
= get_string_param(argv
[i
])) == NULL
) {
1751 d_fprintf(stderr
, _("Please supply a valid password to set as trust account password.\n"));
1752 werr
= WERR_INVALID_PARAMETER
;
1757 if (strchr(domain
, '.') == NULL
) {
1758 domain_name_type
= JoinDomNameTypeUnknown
;
1760 domain_name_type
= JoinDomNameTypeDNS
;
1766 d_fprintf(stderr
, _("Please supply a valid domain name\n"));
1767 werr
= WERR_INVALID_PARAMETER
;
1772 d_fprintf(stderr
, _("Could not initialise message context. "
1773 "Try running as root\n"));
1774 werr
= WERR_ACCESS_DENIED
;
1778 /* Do the domain join here */
1780 r
->in
.domain_name
= domain
;
1781 r
->in
.domain_name_type
= domain_name_type
;
1782 r
->in
.create_upn
= createupn
;
1783 r
->in
.upn
= machineupn
;
1784 r
->in
.dnshostname
= dnshostname
;
1785 r
->in
.account_ou
= create_in_ou
;
1786 r
->in
.os_name
= os_name
;
1787 r
->in
.os_version
= os_version
;
1788 r
->in
.os_servicepack
= os_servicepack
;
1789 r
->in
.dc_name
= c
->opt_host
;
1790 r
->in
.admin_credentials
= c
->creds
;
1791 r
->in
.machine_password
= machine_password
;
1793 r
->in
.modify_config
= modify_config
;
1794 r
->in
.join_flags
= WKSSVC_JOIN_FLAGS_JOIN_TYPE
|
1795 WKSSVC_JOIN_FLAGS_ACCOUNT_CREATE
|
1796 WKSSVC_JOIN_FLAGS_DOMAIN_JOIN_IF_JOINED
;
1797 r
->in
.msg_ctx
= c
->msg_ctx
;
1799 werr
= libnet_Join(tmp_ctx
, r
);
1800 if (W_ERROR_EQUAL(werr
, WERR_NERR_DCNOTFOUND
) &&
1801 strequal(domain
, lp_realm())) {
1802 r
->in
.domain_name
= lp_workgroup();
1803 r
->in
.domain_name_type
= JoinDomNameTypeNBT
;
1804 werr
= libnet_Join(tmp_ctx
, r
);
1806 if (!W_ERROR_IS_OK(werr
)) {
1810 /* Check the short name of the domain */
1812 if (!modify_config
&& !strequal(lp_workgroup(), r
->out
.netbios_domain_name
)) {
1813 d_printf(_("The workgroup in %s does not match the short\n"
1814 "domain name obtained from the server.\n"
1815 "Using the name [%s] from the server.\n"
1816 "You should set \"workgroup = %s\" in %s.\n"),
1817 get_dyn_CONFIGFILE(), r
->out
.netbios_domain_name
,
1818 r
->out
.netbios_domain_name
, get_dyn_CONFIGFILE());
1821 d_printf(_("Using short domain name -- %s\n"), r
->out
.netbios_domain_name
);
1823 if (r
->out
.dns_domain_name
) {
1824 d_printf(_("Joined '%s' to dns domain '%s'\n"), r
->in
.machine_name
,
1825 r
->out
.dns_domain_name
);
1827 d_printf(_("Joined '%s' to domain '%s'\n"), r
->in
.machine_name
,
1828 r
->out
.netbios_domain_name
);
1831 /* print out informative error string in case there is one */
1832 if (r
->out
.error_string
!= NULL
) {
1833 d_printf("%s\n", r
->out
.error_string
);
1837 * We try doing the dns update (if it was compiled in
1838 * and if it was not disabled on the command line).
1839 * If the dns update fails, we still consider the join
1840 * operation as succeeded if we came this far.
1842 if (!c
->opt_no_dns_updates
) {
1843 net_ads_join_dns_updates(c
, tmp_ctx
, r
);
1850 /* issue an overall failure message at the end. */
1851 d_printf(_("Failed to join domain: %s\n"),
1852 r
&& r
->out
.error_string
? r
->out
.error_string
:
1853 get_friendly_werror_msg(werr
));
1856 TALLOC_FREE(tmp_ctx
);
1861 /*******************************************************************
1862 ********************************************************************/
1864 static int net_ads_dns_register(struct net_context
*c
, int argc
, const char **argv
)
1866 #if defined(HAVE_KRB5)
1867 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1868 ADS_STRUCT
*ads
= NULL
;
1871 const char *hostname
= NULL
;
1872 const char **addrs_list
= NULL
;
1873 struct sockaddr_storage
*addrs
= NULL
;
1879 talloc_enable_leak_report();
1882 if (argc
<= 1 && lp_clustering() && lp_cluster_addresses() == NULL
) {
1883 d_fprintf(stderr
, _("Refusing DNS updates with automatic "
1884 "detection of addresses in a clustered "
1886 c
->display_usage
= true;
1889 if (c
->display_usage
) {
1891 "net ads dns register [hostname [IP [IP...]]] "
1892 "[--force] [--dns-ttl TTL]\n"
1895 _("Register hostname with DNS\n"));
1896 TALLOC_FREE(tmp_ctx
);
1905 num_addrs
= argc
- 1;
1906 addrs_list
= &argv
[1];
1907 } else if (lp_clustering()) {
1908 addrs_list
= lp_cluster_addresses();
1909 num_addrs
= str_list_length(addrs_list
);
1912 if (num_addrs
> 0) {
1913 addrs
= talloc_zero_array(tmp_ctx
,
1914 struct sockaddr_storage
,
1916 if (addrs
== NULL
) {
1917 d_fprintf(stderr
, _("Error allocating memory!\n"));
1922 for (count
= 0; count
< num_addrs
; count
++) {
1923 if (!interpret_string_addr(&addrs
[count
], addrs_list
[count
], 0)) {
1924 d_fprintf(stderr
, "%s '%s'.\n",
1925 _("Cannot interpret address"),
1931 status
= ads_startup(c
, true, tmp_ctx
, &ads
);
1932 if ( !ADS_ERR_OK(status
) ) {
1933 DEBUG(1, ("error on ads_startup: %s\n", ads_errstr(status
)));
1937 ntstatus
= net_update_dns_ext(c
,
1945 if (!NT_STATUS_IS_OK(ntstatus
)) {
1946 d_fprintf( stderr
, _("DNS update failed!\n") );
1950 d_fprintf( stderr
, _("Successfully registered hostname with DNS\n") );
1954 TALLOC_FREE(tmp_ctx
);
1959 _("DNS update support not enabled at compile time!\n"));
1964 static int net_ads_dns_unregister(struct net_context
*c
,
1968 #if defined(HAVE_KRB5)
1969 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
1970 ADS_STRUCT
*ads
= NULL
;
1973 const char *hostname
= NULL
;
1977 talloc_enable_leak_report();
1981 c
->display_usage
= true;
1984 if (c
->display_usage
) {
1986 "net ads dns unregister [hostname]\n"
1989 _("Remove all IP Address entries for a given\n"
1990 " hostname from the Active Directory server.\n"));
1991 TALLOC_FREE(tmp_ctx
);
1995 /* Get the hostname for un-registering */
1998 status
= ads_startup(c
, true, tmp_ctx
, &ads
);
1999 if ( !ADS_ERR_OK(status
) ) {
2000 DEBUG(1, ("error on ads_startup: %s\n", ads_errstr(status
)));
2004 ntstatus
= net_update_dns_ext(c
,
2012 if (!NT_STATUS_IS_OK(ntstatus
)) {
2013 d_fprintf( stderr
, _("DNS update failed!\n") );
2017 d_fprintf( stderr
, _("Successfully un-registered hostname from DNS\n"));
2021 TALLOC_FREE(tmp_ctx
);
2026 _("DNS update support not enabled at compile time!\n"));
2032 static int net_ads_dns_async(struct net_context
*c
, int argc
, const char **argv
)
2034 size_t num_names
= 0;
2035 char **hostnames
= NULL
;
2037 struct samba_sockaddr
*addrs
= NULL
;
2040 if (argc
!= 1 || c
->display_usage
) {
2045 _("net ads dns async <name>\n"),
2046 _(" Async look up hostname from the DNS server\n"
2047 " hostname\tName to look up\n"));
2051 status
= ads_dns_lookup_a(talloc_tos(),
2056 if (!NT_STATUS_IS_OK(status
)) {
2057 d_printf("Looking up A record for %s got error %s\n",
2062 d_printf("Async A record lookup - got %u names for %s\n",
2063 (unsigned int)num_names
,
2065 for (i
= 0; i
< num_names
; i
++) {
2066 char addr_buf
[INET6_ADDRSTRLEN
];
2067 print_sockaddr(addr_buf
,
2070 d_printf("hostname[%u] = %s, IPv4addr = %s\n",
2076 #if defined(HAVE_IPV6)
2077 status
= ads_dns_lookup_aaaa(talloc_tos(),
2082 if (!NT_STATUS_IS_OK(status
)) {
2083 d_printf("Looking up AAAA record for %s got error %s\n",
2088 d_printf("Async AAAA record lookup - got %u names for %s\n",
2089 (unsigned int)num_names
,
2091 for (i
= 0; i
< num_names
; i
++) {
2092 char addr_buf
[INET6_ADDRSTRLEN
];
2093 print_sockaddr(addr_buf
,
2096 d_printf("hostname[%u] = %s, IPv6addr = %s\n",
2106 static int net_ads_dns(struct net_context
*c
, int argc
, const char *argv
[])
2108 struct functable func
[] = {
2111 net_ads_dns_register
,
2113 N_("Add host dns entry to AD"),
2114 N_("net ads dns register\n"
2115 " Add host dns entry to AD")
2119 net_ads_dns_unregister
,
2121 N_("Remove host dns entry from AD"),
2122 N_("net ads dns unregister\n"
2123 " Remove host dns entry from AD")
2130 N_("net ads dns async\n"
2131 " Look up host using async DNS")
2133 {NULL
, NULL
, 0, NULL
, NULL
}
2136 return net_run_function(c
, argc
, argv
, "net ads dns", func
);
2139 /*******************************************************************
2140 ********************************************************************/
2142 int net_ads_printer_usage(struct net_context
*c
, int argc
, const char **argv
)
2145 "\nnet ads printer search <printer>"
2146 "\n\tsearch for a printer in the directory\n"
2147 "\nnet ads printer info <printer> <server>"
2148 "\n\tlookup info in directory for printer on server"
2149 "\n\t(note: printer defaults to \"*\", server defaults to local)\n"
2150 "\nnet ads printer publish <printername>"
2151 "\n\tpublish printer in directory"
2152 "\n\t(note: printer name is required)\n"
2153 "\nnet ads printer remove <printername>"
2154 "\n\tremove printer from directory"
2155 "\n\t(note: printer name is required)\n"));
2159 /*******************************************************************
2160 ********************************************************************/
2162 static int net_ads_printer_search(struct net_context
*c
,
2166 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
2167 ADS_STRUCT
*ads
= NULL
;
2169 LDAPMessage
*res
= NULL
;
2172 if (c
->display_usage
) {
2174 "net ads printer search\n"
2177 _("List printers in the AD"));
2178 TALLOC_FREE(tmp_ctx
);
2182 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
2183 if (!ADS_ERR_OK(status
)) {
2187 status
= ads_find_printers(ads
, &res
);
2188 if (!ADS_ERR_OK(status
)) {
2189 d_fprintf(stderr
, _("ads_find_printer: %s\n"),
2190 ads_errstr(status
));
2194 if (ads_count_replies(ads
, res
) == 0) {
2195 d_fprintf(stderr
, _("No results found\n"));
2203 ads_msgfree(ads
, res
);
2204 TALLOC_FREE(tmp_ctx
);
2208 static int net_ads_printer_info(struct net_context
*c
,
2212 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
2213 ADS_STRUCT
*ads
= NULL
;
2215 const char *servername
= NULL
;
2216 const char *printername
= NULL
;
2217 LDAPMessage
*res
= NULL
;
2220 if (c
->display_usage
) {
2223 _("net ads printer info [printername [servername]]\n"
2224 " Display printer info from AD\n"
2225 " printername\tPrinter name or wildcard\n"
2226 " servername\tName of the print server\n"));
2227 TALLOC_FREE(tmp_ctx
);
2231 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
2232 if (!ADS_ERR_OK(status
)) {
2237 printername
= argv
[0];
2243 servername
= argv
[1];
2245 servername
= lp_netbios_name();
2248 status
= ads_find_printer_on_server(ads
, &res
, printername
, servername
);
2249 if (!ADS_ERR_OK(status
)) {
2250 d_fprintf(stderr
, _("Server '%s' not found: %s\n"),
2251 servername
, ads_errstr(status
));
2255 if (ads_count_replies(ads
, res
) == 0) {
2256 d_fprintf(stderr
, _("Printer '%s' not found\n"), printername
);
2264 ads_msgfree(ads
, res
);
2265 TALLOC_FREE(tmp_ctx
);
2269 static int net_ads_printer_publish(struct net_context
*c
,
2273 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
2274 ADS_STRUCT
*ads
= NULL
;
2276 const char *servername
= NULL
;
2277 const char *printername
= NULL
;
2278 struct cli_state
*cli
= NULL
;
2279 struct rpc_pipe_client
*pipe_hnd
= NULL
;
2280 struct sockaddr_storage server_ss
= { 0 };
2282 ADS_MODLIST mods
= NULL
;
2283 char *prt_dn
= NULL
;
2284 char *srv_dn
= NULL
;
2285 char **srv_cn
= NULL
;
2286 char *srv_cn_escaped
= NULL
;
2287 char *printername_escaped
= NULL
;
2288 LDAPMessage
*res
= NULL
;
2292 if (argc
< 1 || c
->display_usage
) {
2295 _("net ads printer publish <printername> [servername]\n"
2296 " Publish printer in AD\n"
2297 " printername\tName of the printer\n"
2298 " servername\tName of the print server\n"));
2299 TALLOC_FREE(tmp_ctx
);
2303 mods
= ads_init_mods(tmp_ctx
);
2305 d_fprintf(stderr
, _("Out of memory\n"));
2309 status
= ads_startup(c
, true, tmp_ctx
, &ads
);
2310 if (!ADS_ERR_OK(status
)) {
2314 printername
= argv
[0];
2317 servername
= argv
[1];
2319 servername
= lp_netbios_name();
2322 /* Get printer data from SPOOLSS */
2324 ok
= resolve_name(servername
, &server_ss
, 0x20, false);
2326 d_fprintf(stderr
, _("Could not find server %s\n"),
2331 cli_credentials_set_kerberos_state(c
->creds
,
2332 CRED_USE_KERBEROS_REQUIRED
,
2335 nt_status
= cli_full_connection_creds(c
,
2344 CLI_FULL_CONNECTION_IPC
);
2346 if (NT_STATUS_IS_ERR(nt_status
)) {
2347 d_fprintf(stderr
, _("Unable to open a connection to %s to "
2348 "obtain data for %s\n"),
2349 servername
, printername
);
2353 /* Publish on AD server */
2355 ads_find_machine_acct(ads
, &res
, servername
);
2357 if (ads_count_replies(ads
, res
) == 0) {
2358 d_fprintf(stderr
, _("Could not find machine account for server "
2364 srv_dn
= ldap_get_dn((LDAP
*)ads
->ldap
.ld
, (LDAPMessage
*)res
);
2365 srv_cn
= ldap_explode_dn(srv_dn
, 1);
2367 srv_cn_escaped
= escape_rdn_val_string_alloc(srv_cn
[0]);
2368 printername_escaped
= escape_rdn_val_string_alloc(printername
);
2369 if (!srv_cn_escaped
|| !printername_escaped
) {
2370 SAFE_FREE(srv_cn_escaped
);
2371 SAFE_FREE(printername_escaped
);
2372 d_fprintf(stderr
, _("Internal error, out of memory!"));
2376 prt_dn
= talloc_asprintf(tmp_ctx
,
2379 printername_escaped
,
2381 if (prt_dn
== NULL
) {
2382 SAFE_FREE(srv_cn_escaped
);
2383 SAFE_FREE(printername_escaped
);
2384 d_fprintf(stderr
, _("Internal error, out of memory!"));
2388 SAFE_FREE(srv_cn_escaped
);
2389 SAFE_FREE(printername_escaped
);
2391 nt_status
= cli_rpc_pipe_open_noauth(cli
, &ndr_table_spoolss
, &pipe_hnd
);
2392 if (!NT_STATUS_IS_OK(nt_status
)) {
2393 d_fprintf(stderr
, _("Unable to open a connection to the spoolss pipe on %s\n"),
2398 if (!W_ERROR_IS_OK(get_remote_printer_publishing_data(pipe_hnd
,
2405 status
= ads_add_printer_entry(ads
, prt_dn
, tmp_ctx
, &mods
);
2406 if (!ADS_ERR_OK(status
)) {
2407 d_fprintf(stderr
, "ads_publish_printer: %s\n",
2408 ads_errstr(status
));
2412 d_printf("published printer\n");
2416 talloc_destroy(tmp_ctx
);
2421 static int net_ads_printer_remove(struct net_context
*c
,
2425 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
2426 ADS_STRUCT
*ads
= NULL
;
2428 const char *servername
= NULL
;
2429 char *prt_dn
= NULL
;
2430 LDAPMessage
*res
= NULL
;
2433 if (argc
< 1 || c
->display_usage
) {
2436 _("net ads printer remove <printername> [servername]\n"
2437 " Remove a printer from the AD\n"
2438 " printername\tName of the printer\n"
2439 " servername\tName of the print server\n"));
2440 TALLOC_FREE(tmp_ctx
);
2444 status
= ads_startup(c
, true, tmp_ctx
, &ads
);
2445 if (!ADS_ERR_OK(status
)) {
2450 servername
= argv
[1];
2452 servername
= lp_netbios_name();
2455 status
= ads_find_printer_on_server(ads
, &res
, argv
[0], servername
);
2456 if (!ADS_ERR_OK(status
)) {
2457 d_fprintf(stderr
, _("ads_find_printer_on_server: %s\n"),
2458 ads_errstr(status
));
2462 if (ads_count_replies(ads
, res
) == 0) {
2463 d_fprintf(stderr
, _("Printer '%s' not found\n"), argv
[1]);
2467 prt_dn
= ads_get_dn(ads
, tmp_ctx
, res
);
2468 if (prt_dn
== NULL
) {
2469 d_fprintf(stderr
, _("Out of memory\n"));
2473 status
= ads_del_dn(ads
, prt_dn
);
2474 if (!ADS_ERR_OK(status
)) {
2475 d_fprintf(stderr
, _("ads_del_dn: %s\n"), ads_errstr(status
));
2481 ads_msgfree(ads
, res
);
2482 TALLOC_FREE(tmp_ctx
);
2486 static int net_ads_printer(struct net_context
*c
, int argc
, const char **argv
)
2488 struct functable func
[] = {
2491 net_ads_printer_search
,
2493 N_("Search for a printer"),
2494 N_("net ads printer search\n"
2495 " Search for a printer")
2499 net_ads_printer_info
,
2501 N_("Display printer information"),
2502 N_("net ads printer info\n"
2503 " Display printer information")
2507 net_ads_printer_publish
,
2509 N_("Publish a printer"),
2510 N_("net ads printer publish\n"
2511 " Publish a printer")
2515 net_ads_printer_remove
,
2517 N_("Delete a printer"),
2518 N_("net ads printer remove\n"
2519 " Delete a printer")
2521 {NULL
, NULL
, 0, NULL
, NULL
}
2524 return net_run_function(c
, argc
, argv
, "net ads printer", func
);
2528 static int net_ads_password(struct net_context
*c
, int argc
, const char **argv
)
2530 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
2531 ADS_STRUCT
*ads
= NULL
;
2532 const char *auth_principal
= cli_credentials_get_username(c
->creds
);
2533 const char *auth_password
= cli_credentials_get_password(c
->creds
);
2534 const char *realm
= NULL
;
2535 char *new_password
= NULL
;
2537 char *prompt
= NULL
;
2538 const char *user
= NULL
;
2539 char pwd
[256] = {0};
2543 if (c
->display_usage
) {
2546 _("net ads password <username>\n"
2547 " Change password for user\n"
2548 " username\tName of user to change password for\n"));
2549 TALLOC_FREE(tmp_ctx
);
2553 if (auth_principal
== NULL
|| auth_password
== NULL
) {
2554 d_fprintf(stderr
, _("You must supply an administrator "
2555 "username/password\n"));
2556 TALLOC_FREE(tmp_ctx
);
2561 d_fprintf(stderr
, _("ERROR: You must say which username to "
2562 "change password for\n"));
2563 TALLOC_FREE(tmp_ctx
);
2567 if (strchr_m(argv
[0], '@')) {
2568 user
= talloc_strdup(tmp_ctx
, argv
[0]);
2570 user
= talloc_asprintf(tmp_ctx
, "%s@%s", argv
[0], lp_realm());
2573 d_fprintf(stderr
, _("Out of memory\n"));
2577 chr
= strchr_m(auth_principal
, '@');
2584 /* use the realm so we can eventually change passwords for users
2585 in realms other than default */
2586 ads
= ads_init(tmp_ctx
,
2595 /* we don't actually need a full connect, but it's the easy way to
2596 fill in the KDC's address */
2597 ads
->auth
.flags
|= ADS_AUTH_GENERATE_KRB5_CONFIG
;
2598 ads_connect_cldap_only(ads
);
2600 if (!ads
->config
.realm
) {
2601 d_fprintf(stderr
, _("Didn't find the kerberos server!\n"));
2605 if (argv
[1] != NULL
) {
2606 new_password
= talloc_strdup(tmp_ctx
, argv
[1]);
2610 prompt
= talloc_asprintf(tmp_ctx
, _("Enter new password for %s:"), user
);
2611 if (prompt
== NULL
) {
2612 d_fprintf(stderr
, _("Out of memory\n"));
2616 rc
= samba_getpass(prompt
, pwd
, sizeof(pwd
), false, true);
2620 new_password
= talloc_strdup(tmp_ctx
, pwd
);
2621 memset(pwd
, '\0', sizeof(pwd
));
2624 if (new_password
== NULL
) {
2625 d_fprintf(stderr
, _("Out of memory\n"));
2629 status
= kerberos_set_password(auth_principal
,
2633 memset(new_password
, '\0', strlen(new_password
));
2634 if (!ADS_ERR_OK(status
)) {
2635 d_fprintf(stderr
, _("Password change failed: %s\n"),
2636 ads_errstr(status
));
2640 d_printf(_("Password change for %s completed.\n"), user
);
2644 TALLOC_FREE(tmp_ctx
);
2648 int net_ads_changetrustpw(struct net_context
*c
, int argc
, const char **argv
)
2650 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
2651 ADS_STRUCT
*ads
= NULL
;
2652 char *host_principal
= NULL
;
2653 char *my_name
= NULL
;
2657 if (c
->display_usage
) {
2659 "net ads changetrustpw\n"
2662 _("Change the machine account's trust password"));
2663 TALLOC_FREE(tmp_ctx
);
2667 if (!secrets_init()) {
2668 DEBUG(1,("Failed to initialise secrets database\n"));
2672 net_warn_member_options();
2674 net_use_krb_machine_account(c
);
2676 status
= ads_startup(c
, true, tmp_ctx
, &ads
);
2677 if (!ADS_ERR_OK(status
)) {
2681 my_name
= talloc_asprintf_strlower_m(tmp_ctx
, "%s", lp_netbios_name());
2682 if (my_name
== NULL
) {
2683 d_fprintf(stderr
, _("Out of memory\n"));
2687 host_principal
= talloc_asprintf(tmp_ctx
, "%s$@%s", my_name
, ads
->config
.realm
);
2688 if (host_principal
== NULL
) {
2689 d_fprintf(stderr
, _("Out of memory\n"));
2693 d_printf(_("Changing password for principal: %s\n"), host_principal
);
2695 status
= ads_change_trust_account_password(ads
, host_principal
);
2696 if (!ADS_ERR_OK(status
)) {
2697 d_fprintf(stderr
, _("Password change failed: %s\n"), ads_errstr(status
));
2701 d_printf(_("Password change for principal %s succeeded.\n"), host_principal
);
2705 TALLOC_FREE(tmp_ctx
);
2711 help for net ads search
2713 static int net_ads_search_usage(struct net_context
*c
, int argc
, const char **argv
)
2716 "\nnet ads search <expression> <attributes...>\n"
2717 "\nPerform a raw LDAP search on a ADS server and dump the results.\n"
2718 "The expression is a standard LDAP search expression, and the\n"
2719 "attributes are a list of LDAP fields to show in the results.\n\n"
2720 "Example: net ads search '(objectCategory=group)' sAMAccountName\n\n"
2722 net_common_flags_usage(c
, argc
, argv
);
2728 general ADS search function. Useful in diagnosing problems in ADS
2730 static int net_ads_search(struct net_context
*c
, int argc
, const char **argv
)
2732 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
2733 ADS_STRUCT
*ads
= NULL
;
2735 const char *ldap_exp
= NULL
;
2736 const char **attrs
= NULL
;
2737 LDAPMessage
*res
= NULL
;
2740 if (argc
< 1 || c
->display_usage
) {
2741 TALLOC_FREE(tmp_ctx
);
2742 return net_ads_search_usage(c
, argc
, argv
);
2745 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
2746 if (!ADS_ERR_OK(status
)) {
2753 status
= ads_do_search_retry(ads
,
2754 ads
->config
.bind_path
,
2759 if (!ADS_ERR_OK(status
)) {
2760 d_fprintf(stderr
, _("search failed: %s\n"), ads_errstr(status
));
2764 d_printf(_("Got %d replies\n\n"), ads_count_replies(ads
, res
));
2766 /* dump the results */
2771 ads_msgfree(ads
, res
);
2772 TALLOC_FREE(tmp_ctx
);
2778 help for net ads search
2780 static int net_ads_dn_usage(struct net_context
*c
, int argc
, const char **argv
)
2783 "\nnet ads dn <dn> <attributes...>\n"
2784 "\nperform a raw LDAP search on a ADS server and dump the results\n"
2785 "The DN standard LDAP DN, and the attributes are a list of LDAP fields \n"
2786 "to show in the results\n\n"
2787 "Example: net ads dn 'CN=administrator,CN=Users,DC=my,DC=domain' sAMAccountName\n\n"
2788 "Note: the DN must be provided properly escaped. See RFC 4514 for details\n\n"
2790 net_common_flags_usage(c
, argc
, argv
);
2796 general ADS search function. Useful in diagnosing problems in ADS
2798 static int net_ads_dn(struct net_context
*c
, int argc
, const char **argv
)
2800 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
2801 ADS_STRUCT
*ads
= NULL
;
2803 const char *dn
= NULL
;
2804 const char **attrs
= NULL
;
2805 LDAPMessage
*res
= NULL
;
2808 if (argc
< 1 || c
->display_usage
) {
2809 TALLOC_FREE(tmp_ctx
);
2810 return net_ads_dn_usage(c
, argc
, argv
);
2813 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
2814 if (!ADS_ERR_OK(status
)) {
2821 status
= ads_do_search_all(ads
,
2827 if (!ADS_ERR_OK(status
)) {
2828 d_fprintf(stderr
, _("search failed: %s\n"), ads_errstr(status
));
2832 d_printf("Got %d replies\n\n", ads_count_replies(ads
, res
));
2834 /* dump the results */
2839 ads_msgfree(ads
, res
);
2840 TALLOC_FREE(tmp_ctx
);
2845 help for net ads sid search
2847 static int net_ads_sid_usage(struct net_context
*c
, int argc
, const char **argv
)
2850 "\nnet ads sid <sid> <attributes...>\n"
2851 "\nperform a raw LDAP search on a ADS server and dump the results\n"
2852 "The SID is in string format, and the attributes are a list of LDAP fields \n"
2853 "to show in the results\n\n"
2854 "Example: net ads sid 'S-1-5-32' distinguishedName\n\n"
2856 net_common_flags_usage(c
, argc
, argv
);
2862 general ADS search function. Useful in diagnosing problems in ADS
2864 static int net_ads_sid(struct net_context
*c
, int argc
, const char **argv
)
2866 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
2867 ADS_STRUCT
*ads
= NULL
;
2869 const char *sid_string
= NULL
;
2870 const char **attrs
= NULL
;
2871 LDAPMessage
*res
= NULL
;
2872 struct dom_sid sid
= { 0 };
2875 if (argc
< 1 || c
->display_usage
) {
2876 TALLOC_FREE(tmp_ctx
);
2877 return net_ads_sid_usage(c
, argc
, argv
);
2880 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
2881 if (!ADS_ERR_OK(status
)) {
2885 sid_string
= argv
[0];
2888 if (!string_to_sid(&sid
, sid_string
)) {
2889 d_fprintf(stderr
, _("could not convert sid\n"));
2893 status
= ads_search_retry_sid(ads
, &res
, &sid
, attrs
);
2894 if (!ADS_ERR_OK(status
)) {
2895 d_fprintf(stderr
, _("search failed: %s\n"), ads_errstr(status
));
2899 d_printf(_("Got %d replies\n\n"), ads_count_replies(ads
, res
));
2901 /* dump the results */
2906 ads_msgfree(ads
, res
);
2907 TALLOC_FREE(tmp_ctx
);
2911 static int net_ads_keytab_flush(struct net_context
*c
,
2915 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
2916 ADS_STRUCT
*ads
= NULL
;
2920 if (c
->display_usage
) {
2922 "net ads keytab flush\n"
2925 _("Delete the whole keytab"));
2926 TALLOC_FREE(tmp_ctx
);
2930 if (!c
->explicit_credentials
) {
2931 net_use_krb_machine_account(c
);
2934 status
= ads_startup(c
, true, tmp_ctx
, &ads
);
2935 if (!ADS_ERR_OK(status
)) {
2939 ret
= ads_keytab_flush(ads
);
2941 TALLOC_FREE(tmp_ctx
);
2945 static int net_ads_keytab_create(struct net_context
*c
, int argc
, const char **argv
)
2947 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
2948 ADS_STRUCT
*ads
= NULL
;
2953 if (c
->display_usage
) {
2955 "net ads keytab create\n"
2958 _("Create (sync) new default keytab"));
2959 TALLOC_FREE(tmp_ctx
);
2963 net_warn_member_options();
2965 if (!c
->explicit_credentials
) {
2966 net_use_krb_machine_account(c
);
2969 status
= ads_startup(c
, true, tmp_ctx
, &ads
);
2970 if (!ADS_ERR_OK(status
)) {
2974 ntstatus
= sync_pw2keytabs();
2975 ret
= NT_STATUS_IS_OK(ntstatus
) ? 0 : 1;
2977 TALLOC_FREE(tmp_ctx
);
2981 static int net_ads_keytab_list(struct net_context
*c
, int argc
, const char **argv
)
2983 const char *keytab
= NULL
;
2985 if (c
->display_usage
) {
2988 _("net ads keytab list [keytab]\n"
2989 " List a local keytab\n"
2990 " keytab\tKeytab to list\n"));
2998 return ads_keytab_list(keytab
);
3001 int net_ads_keytab(struct net_context
*c
, int argc
, const char **argv
)
3003 struct functable func
[] = {
3006 net_ads_keytab_create
,
3008 N_("Create (sync) a fresh keytab"),
3009 N_("net ads keytab create\n"
3010 " Create (sync) a fresh keytab or update existing one (see also smb.conf 'sync machine password to keytab'.")
3014 net_ads_keytab_flush
,
3016 N_("Remove all keytab entries"),
3017 N_("net ads keytab flush\n"
3018 " Remove all keytab entries")
3022 net_ads_keytab_list
,
3024 N_("List a keytab"),
3025 N_("net ads keytab list\n"
3028 {NULL
, NULL
, 0, NULL
, NULL
}
3031 return net_run_function(c
, argc
, argv
, "net ads keytab", func
);
3034 static int net_ads_kerberos_renew(struct net_context
*c
, int argc
, const char **argv
)
3038 if (c
->display_usage
) {
3040 "net ads kerberos renew\n"
3043 _("Renew TGT from existing credential cache"));
3047 ret
= smb_krb5_renew_ticket(NULL
, NULL
, NULL
, NULL
);
3049 d_printf(_("failed to renew kerberos ticket: %s\n"),
3050 error_message(ret
));
3055 static int net_ads_kerberos_pac_common(struct net_context
*c
, int argc
, const char **argv
,
3056 struct PAC_DATA_CTR
**pac_data_ctr
)
3060 const char *impersonate_princ_s
= NULL
;
3061 const char *local_service
= NULL
;
3062 const char *principal
= NULL
;
3063 const char *password
= NULL
;
3066 for (i
=0; i
<argc
; i
++) {
3067 if (strnequal(argv
[i
], "impersonate", strlen("impersonate"))) {
3068 impersonate_princ_s
= get_string_param(argv
[i
]);
3069 if (impersonate_princ_s
== NULL
) {
3073 if (strnequal(argv
[i
], "local_service", strlen("local_service"))) {
3074 local_service
= get_string_param(argv
[i
]);
3075 if (local_service
== NULL
) {
3081 if (local_service
== NULL
) {
3082 local_service
= talloc_asprintf(c
, "%s$@%s",
3083 lp_netbios_name(), lp_realm());
3084 if (local_service
== NULL
) {
3089 principal
= cli_credentials_get_principal(c
->creds
, c
);
3090 if (principal
== NULL
) {
3091 d_printf("cli_credentials_get_principal() failed\n");
3094 password
= cli_credentials_get_password(c
->creds
);
3096 status
= kerberos_return_pac(c
,
3105 2592000, /* one month */
3106 impersonate_princ_s
,
3111 if (!NT_STATUS_IS_OK(status
)) {
3112 d_printf(_("failed to query kerberos PAC: %s\n"),
3122 static int net_ads_kerberos_pac_dump(struct net_context
*c
, int argc
, const char **argv
)
3124 struct PAC_DATA_CTR
*pac_data_ctr
= NULL
;
3127 enum PAC_TYPE type
= 0;
3129 if (c
->display_usage
) {
3131 "net ads kerberos pac dump [impersonate=string] [local_service=string] [pac_buffer_type=int]\n"
3134 _("Dump the Kerberos PAC"));
3138 for (i
=0; i
<argc
; i
++) {
3139 if (strnequal(argv
[i
], "pac_buffer_type", strlen("pac_buffer_type"))) {
3140 type
= get_int_param(argv
[i
]);
3144 ret
= net_ads_kerberos_pac_common(c
, argc
, argv
, &pac_data_ctr
);
3153 s
= NDR_PRINT_STRUCT_STRING(c
, PAC_DATA
,
3154 pac_data_ctr
->pac_data
);
3156 d_printf(_("The Pac: %s\n"), s
);
3163 num_buffers
= pac_data_ctr
->pac_data
->num_buffers
;
3165 for (i
=0; i
<num_buffers
; i
++) {
3169 if (pac_data_ctr
->pac_data
->buffers
[i
].type
!= type
) {
3173 s
= NDR_PRINT_UNION_STRING(c
, PAC_INFO
, type
,
3174 pac_data_ctr
->pac_data
->buffers
[i
].info
);
3176 d_printf(_("The Pac: %s\n"), s
);
3185 static int net_ads_kerberos_pac_save(struct net_context
*c
, int argc
, const char **argv
)
3187 struct PAC_DATA_CTR
*pac_data_ctr
= NULL
;
3188 char *filename
= NULL
;
3192 if (c
->display_usage
) {
3194 "net ads kerberos pac save [impersonate=string] [local_service=string] [filename=string]\n"
3197 _("Save the Kerberos PAC"));
3201 for (i
=0; i
<argc
; i
++) {
3202 if (strnequal(argv
[i
], "filename", strlen("filename"))) {
3203 filename
= get_string_param(argv
[i
]);
3204 if (filename
== NULL
) {
3210 ret
= net_ads_kerberos_pac_common(c
, argc
, argv
, &pac_data_ctr
);
3215 if (filename
== NULL
) {
3216 d_printf(_("please define \"filename=<filename>\" to save the PAC\n"));
3220 /* save the raw format */
3221 if (!file_save(filename
, pac_data_ctr
->pac_blob
.data
, pac_data_ctr
->pac_blob
.length
)) {
3222 d_printf(_("failed to save PAC in %s\n"), filename
);
3229 static int net_ads_kerberos_pac(struct net_context
*c
, int argc
, const char **argv
)
3231 struct functable func
[] = {
3234 net_ads_kerberos_pac_dump
,
3236 N_("Dump Kerberos PAC"),
3237 N_("net ads kerberos pac dump\n"
3238 " Dump a Kerberos PAC to stdout")
3242 net_ads_kerberos_pac_save
,
3244 N_("Save Kerberos PAC"),
3245 N_("net ads kerberos pac save\n"
3246 " Save a Kerberos PAC in a file")
3249 {NULL
, NULL
, 0, NULL
, NULL
}
3252 return net_run_function(c
, argc
, argv
, "net ads kerberos pac", func
);
3255 static int net_ads_kerberos_kinit(struct net_context
*c
, int argc
, const char **argv
)
3259 const char *principal
= NULL
;
3260 const char *password
= NULL
;
3262 if (c
->display_usage
) {
3264 "net ads kerberos kinit\n"
3267 _("Get Ticket Granting Ticket (TGT) for the user"));
3271 principal
= cli_credentials_get_principal(c
->creds
, c
);
3272 if (principal
== NULL
) {
3273 d_printf("cli_credentials_get_principal() failed\n");
3276 password
= cli_credentials_get_password(c
->creds
);
3278 ret
= kerberos_kinit_password_ext(principal
,
3286 2592000, /* one month */
3292 d_printf(_("failed to kinit password: %s\n"),
3298 int net_ads_kerberos(struct net_context
*c
, int argc
, const char **argv
)
3300 struct functable func
[] = {
3303 net_ads_kerberos_kinit
,
3305 N_("Retrieve Ticket Granting Ticket (TGT)"),
3306 N_("net ads kerberos kinit\n"
3307 " Receive Ticket Granting Ticket (TGT)")
3311 net_ads_kerberos_renew
,
3313 N_("Renew Ticket Granting Ticket from credential cache"),
3314 N_("net ads kerberos renew\n"
3315 " Renew Ticket Granting Ticket (TGT) from "
3320 net_ads_kerberos_pac
,
3322 N_("Dump Kerberos PAC"),
3323 N_("net ads kerberos pac\n"
3324 " Dump Kerberos PAC")
3326 {NULL
, NULL
, 0, NULL
, NULL
}
3329 return net_run_function(c
, argc
, argv
, "net ads kerberos", func
);
3332 static int net_ads_setspn_list(struct net_context
*c
,
3336 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
3337 ADS_STRUCT
*ads
= NULL
;
3342 if (c
->display_usage
) {
3345 _("net ads setspn list <machinename>\n"));
3346 TALLOC_FREE(tmp_ctx
);
3350 status
= ads_startup(c
, true, tmp_ctx
, &ads
);
3351 if (!ADS_ERR_OK(status
)) {
3356 ok
= ads_setspn_list(ads
, argv
[0]);
3358 ok
= ads_setspn_list(ads
, lp_netbios_name());
3363 TALLOC_FREE(tmp_ctx
);
3367 static int net_ads_setspn_add(struct net_context
*c
, int argc
, const char **argv
)
3369 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
3370 ADS_STRUCT
*ads
= NULL
;
3375 if (c
->display_usage
|| argc
< 1) {
3378 _("net ads setspn add <machinename> SPN\n"));
3379 TALLOC_FREE(tmp_ctx
);
3383 status
= ads_startup(c
, true, tmp_ctx
, &ads
);
3384 if (!ADS_ERR_OK(status
)) {
3389 ok
= ads_setspn_add(ads
, argv
[0], argv
[1]);
3391 ok
= ads_setspn_add(ads
, lp_netbios_name(), argv
[0]);
3396 TALLOC_FREE(tmp_ctx
);
3400 static int net_ads_setspn_delete(struct net_context
*c
, int argc
, const char **argv
)
3402 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
3403 ADS_STRUCT
*ads
= NULL
;
3408 if (c
->display_usage
|| argc
< 1) {
3411 _("net ads setspn delete <machinename> SPN\n"));
3412 TALLOC_FREE(tmp_ctx
);
3416 status
= ads_startup(c
, true, tmp_ctx
, &ads
);
3417 if (!ADS_ERR_OK(status
)) {
3422 ok
= ads_setspn_delete(ads
, argv
[0], argv
[1]);
3424 ok
= ads_setspn_delete(ads
, lp_netbios_name(), argv
[0]);
3429 TALLOC_FREE(tmp_ctx
);
3433 int net_ads_setspn(struct net_context
*c
, int argc
, const char **argv
)
3435 struct functable func
[] = {
3438 net_ads_setspn_list
,
3440 N_("List Service Principal Names (SPN)"),
3441 N_("net ads setspn list machine\n"
3442 " List Service Principal Names (SPN)")
3448 N_("Add Service Principal Names (SPN)"),
3449 N_("net ads setspn add machine spn\n"
3450 " Add Service Principal Names (SPN)")
3454 net_ads_setspn_delete
,
3456 N_("Delete Service Principal Names (SPN)"),
3457 N_("net ads setspn delete machine spn\n"
3458 " Delete Service Principal Names (SPN)")
3460 {NULL
, NULL
, 0, NULL
, NULL
}
3463 return net_run_function(c
, argc
, argv
, "net ads setspn", func
);
3466 static int net_ads_enctype_lookup_account(struct net_context
*c
,
3468 const char *account
,
3470 const char **enctype_str
)
3473 const char *attrs
[] = {
3474 "msDS-SupportedEncryptionTypes",
3481 filter
= talloc_asprintf(c
, "(&(objectclass=user)(sAMAccountName=%s))",
3483 if (filter
== NULL
) {
3487 status
= ads_search(ads
, res
, filter
, attrs
);
3488 if (!ADS_ERR_OK(status
)) {
3489 d_printf(_("no account found with filter: %s\n"), filter
);
3493 count
= ads_count_replies(ads
, *res
);
3498 d_printf(_("no account found with filter: %s\n"), filter
);
3501 d_printf(_("multiple accounts found with filter: %s\n"), filter
);
3506 *enctype_str
= ads_pull_string(ads
, c
, *res
,
3507 "msDS-SupportedEncryptionTypes");
3508 if (*enctype_str
== NULL
) {
3509 d_printf(_("no msDS-SupportedEncryptionTypes attribute found\n"));
3519 static void net_ads_enctype_dump_enctypes(const char *username
,
3520 const char *enctype_str
)
3522 int enctypes
= atoi(enctype_str
);
3524 d_printf(_("'%s' uses \"msDS-SupportedEncryptionTypes\": %d (0x%08x)\n"),
3525 username
, enctypes
, enctypes
);
3527 printf("[%s] 0x%08x DES-CBC-CRC\n",
3528 enctypes
& ENC_CRC32
? "X" : " ",
3530 printf("[%s] 0x%08x DES-CBC-MD5\n",
3531 enctypes
& ENC_RSA_MD5
? "X" : " ",
3533 printf("[%s] 0x%08x RC4-HMAC\n",
3534 enctypes
& ENC_RC4_HMAC_MD5
? "X" : " ",
3536 printf("[%s] 0x%08x AES128-CTS-HMAC-SHA1-96\n",
3537 enctypes
& ENC_HMAC_SHA1_96_AES128
? "X" : " ",
3538 ENC_HMAC_SHA1_96_AES128
);
3539 printf("[%s] 0x%08x AES256-CTS-HMAC-SHA1-96\n",
3540 enctypes
& ENC_HMAC_SHA1_96_AES256
? "X" : " ",
3541 ENC_HMAC_SHA1_96_AES256
);
3542 printf("[%s] 0x%08x AES256-CTS-HMAC-SHA1-96-SK\n",
3543 enctypes
& ENC_HMAC_SHA1_96_AES256_SK
? "X" : " ",
3544 ENC_HMAC_SHA1_96_AES256_SK
);
3545 printf("[%s] 0x%08x RESOURCE-SID-COMPRESSION-DISABLED\n",
3546 enctypes
& KERB_ENCTYPE_RESOURCE_SID_COMPRESSION_DISABLED
? "X" : " ",
3547 KERB_ENCTYPE_RESOURCE_SID_COMPRESSION_DISABLED
);
3550 static int net_ads_enctypes_list(struct net_context
*c
, int argc
, const char **argv
)
3552 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
3554 ADS_STRUCT
*ads
= NULL
;
3555 LDAPMessage
*res
= NULL
;
3556 const char *str
= NULL
;
3559 if (c
->display_usage
|| (argc
< 1)) {
3561 "net ads enctypes list\n"
3564 _("List supported enctypes"));
3565 TALLOC_FREE(tmp_ctx
);
3569 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
3570 if (!ADS_ERR_OK(status
)) {
3574 ret
= net_ads_enctype_lookup_account(c
, ads
, argv
[0], &res
, &str
);
3579 net_ads_enctype_dump_enctypes(argv
[0], str
);
3583 ads_msgfree(ads
, res
);
3584 TALLOC_FREE(tmp_ctx
);
3588 static int net_ads_enctypes_set(struct net_context
*c
, int argc
, const char **argv
)
3590 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
3593 ADS_STRUCT
*ads
= NULL
;
3594 LDAPMessage
*res
= NULL
;
3595 const char *etype_list_str
= NULL
;
3596 const char *dn
= NULL
;
3597 ADS_MODLIST mods
= NULL
;
3598 uint32_t etype_list
;
3599 const char *str
= NULL
;
3601 if (c
->display_usage
|| argc
< 1) {
3603 "net ads enctypes set <sAMAccountName> [enctypes]\n"
3606 _("Set supported enctypes"));
3607 TALLOC_FREE(tmp_ctx
);
3611 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
3612 if (!ADS_ERR_OK(status
)) {
3616 ret
= net_ads_enctype_lookup_account(c
, ads
, argv
[0], &res
, NULL
);
3621 dn
= ads_get_dn(ads
, tmp_ctx
, res
);
3627 etype_list
|= ENC_RC4_HMAC_MD5
;
3628 etype_list
|= ENC_HMAC_SHA1_96_AES128
;
3629 etype_list
|= ENC_HMAC_SHA1_96_AES256
;
3631 if (argv
[1] != NULL
) {
3632 sscanf(argv
[1], "%i", &etype_list
);
3635 etype_list_str
= talloc_asprintf(tmp_ctx
, "%d", etype_list
);
3636 if (!etype_list_str
) {
3640 mods
= ads_init_mods(tmp_ctx
);
3645 status
= ads_mod_str(tmp_ctx
, &mods
, "msDS-SupportedEncryptionTypes",
3647 if (!ADS_ERR_OK(status
)) {
3651 status
= ads_gen_mod(ads
, dn
, mods
);
3652 if (!ADS_ERR_OK(status
)) {
3653 d_printf(_("failed to add msDS-SupportedEncryptionTypes: %s\n"),
3654 ads_errstr(status
));
3658 ads_msgfree(ads
, res
);
3661 ret
= net_ads_enctype_lookup_account(c
, ads
, argv
[0], &res
, &str
);
3666 net_ads_enctype_dump_enctypes(argv
[0], str
);
3670 ads_msgfree(ads
, res
);
3671 TALLOC_FREE(tmp_ctx
);
3675 static int net_ads_enctypes_delete(struct net_context
*c
, int argc
, const char **argv
)
3677 TALLOC_CTX
*tmp_ctx
= talloc_stackframe();
3680 ADS_STRUCT
*ads
= NULL
;
3681 LDAPMessage
*res
= NULL
;
3682 const char *dn
= NULL
;
3683 ADS_MODLIST mods
= NULL
;
3685 if (c
->display_usage
|| argc
< 1) {
3687 "net ads enctypes delete <sAMAccountName>\n"
3690 _("Delete supported enctypes"));
3691 TALLOC_FREE(tmp_ctx
);
3695 status
= ads_startup(c
, false, tmp_ctx
, &ads
);
3696 if (!ADS_ERR_OK(status
)) {
3700 ret
= net_ads_enctype_lookup_account(c
, ads
, argv
[0], &res
, NULL
);
3705 dn
= ads_get_dn(ads
, tmp_ctx
, res
);
3710 mods
= ads_init_mods(tmp_ctx
);
3715 status
= ads_mod_str(tmp_ctx
, &mods
, "msDS-SupportedEncryptionTypes", NULL
);
3716 if (!ADS_ERR_OK(status
)) {
3720 status
= ads_gen_mod(ads
, dn
, mods
);
3721 if (!ADS_ERR_OK(status
)) {
3722 d_printf(_("failed to remove msDS-SupportedEncryptionTypes: %s\n"),
3723 ads_errstr(status
));
3730 ads_msgfree(ads
, res
);
3731 TALLOC_FREE(tmp_ctx
);
3735 static int net_ads_enctypes(struct net_context
*c
, int argc
, const char **argv
)
3737 struct functable func
[] = {
3740 net_ads_enctypes_list
,
3742 N_("List the supported encryption types"),
3743 N_("net ads enctypes list\n"
3744 " List the supported encryption types")
3748 net_ads_enctypes_set
,
3750 N_("Set the supported encryption types"),
3751 N_("net ads enctypes set\n"
3752 " Set the supported encryption types")
3756 net_ads_enctypes_delete
,
3758 N_("Delete the supported encryption types"),
3759 N_("net ads enctypes delete\n"
3760 " Delete the supported encryption types")
3763 {NULL
, NULL
, 0, NULL
, NULL
}
3766 return net_run_function(c
, argc
, argv
, "net ads enctypes", func
);
3770 int net_ads(struct net_context
*c
, int argc
, const char **argv
)
3772 struct functable func
[] = {
3777 N_("Display details on remote ADS server"),
3779 " Display details on remote ADS server")
3785 N_("Join the local machine to ADS realm"),
3787 " Join the local machine to ADS realm")
3793 N_("Validate machine account"),
3794 N_("net ads testjoin\n"
3795 " Validate machine account")
3801 N_("Remove the local machine from ADS"),
3802 N_("net ads leave\n"
3803 " Remove the local machine from ADS")
3809 N_("Display machine account details"),
3810 N_("net ads status\n"
3811 " Display machine account details")
3817 N_("List/modify users"),
3819 " List/modify users")
3825 N_("List/modify groups"),
3826 N_("net ads group\n"
3827 " List/modify groups")
3833 N_("Issue dynamic DNS update"),
3835 " Issue dynamic DNS update")
3841 N_("Change user passwords"),
3842 N_("net ads password\n"
3843 " Change user passwords")
3847 net_ads_changetrustpw
,
3849 N_("Change trust account password"),
3850 N_("net ads changetrustpw\n"
3851 " Change trust account password")
3857 N_("List/modify printer entries"),
3858 N_("net ads printer\n"
3859 " List/modify printer entries")
3865 N_("Issue LDAP search using filter"),
3866 N_("net ads search\n"
3867 " Issue LDAP search using filter")
3873 N_("Issue LDAP search by DN"),
3875 " Issue LDAP search by DN")
3881 N_("Issue LDAP search by SID"),
3883 " Issue LDAP search by SID")
3889 N_("Display workgroup name"),
3890 N_("net ads workgroup\n"
3891 " Display the workgroup name")
3897 N_("Perform CLDAP query on DC"),
3898 N_("net ads lookup\n"
3899 " Find the ADS DC using CLDAP lookups")
3905 N_("Manage local keytab file"),
3906 N_("net ads keytab\n"
3907 " Manage local keytab file")
3913 N_("Manage Service Principal Names (SPN)s"),
3914 N_("net ads spnset\n"
3915 " Manage Service Principal Names (SPN)s")
3921 N_("Manage group policy objects"),
3923 " Manage group policy objects")
3929 N_("Manage kerberos keytab"),
3930 N_("net ads kerberos\n"
3931 " Manage kerberos keytab")
3937 N_("List/modify supported encryption types"),
3938 N_("net ads enctypes\n"
3939 " List/modify enctypes")
3941 {NULL
, NULL
, 0, NULL
, NULL
}
3944 return net_run_function(c
, argc
, argv
, "net ads", func
);
3949 static int net_ads_noads(void)
3951 d_fprintf(stderr
, _("ADS support not compiled in\n"));
3955 int net_ads_keytab(struct net_context
*c
, int argc
, const char **argv
)
3957 return net_ads_noads();
3960 int net_ads_kerberos(struct net_context
*c
, int argc
, const char **argv
)
3962 return net_ads_noads();
3965 int net_ads_setspn(struct net_context
*c
, int argc
, const char **argv
)
3967 return net_ads_noads();
3970 int net_ads_changetrustpw(struct net_context
*c
, int argc
, const char **argv
)
3972 return net_ads_noads();
3975 int net_ads_join(struct net_context
*c
, int argc
, const char **argv
)
3977 return net_ads_noads();
3980 int net_ads_user(struct net_context
*c
, int argc
, const char **argv
)
3982 return net_ads_noads();
3985 int net_ads_group(struct net_context
*c
, int argc
, const char **argv
)
3987 return net_ads_noads();
3990 int net_ads_gpo(struct net_context
*c
, int argc
, const char **argv
)
3992 return net_ads_noads();
3995 /* this one shouldn't display a message */
3996 int net_ads_check(struct net_context
*c
)
4001 int net_ads_check_our_domain(struct net_context
*c
)
4006 int net_ads(struct net_context
*c
, int argc
, const char **argv
)
4008 return net_ads_noads();
4011 #endif /* HAVE_ADS */