2 Samba Unix/Linux SMB client library
3 Distributed SMB/CIFS Server Management Utility
4 Copyright (C) 2001 Steve French (sfrench@us.ibm.com)
5 Copyright (C) 2001 Jim McDonough (jmcd@us.ibm.com)
6 Copyright (C) 2001 Andrew Tridgell (tridge@samba.org)
7 Copyright (C) 2001 Andrew Bartlett (abartlet@samba.org)
8 Copyright (C) 2008 Kai Blin (kai@samba.org)
10 Originally written by Steve and Jim. Largely rewritten by tridge in
13 Reworked again by abartlet in December 2001
15 Another overhaul, moving functionality into plug-ins loaded on demand by Kai
18 This program is free software; you can redistribute it and/or modify
19 it under the terms of the GNU General Public License as published by
20 the Free Software Foundation; either version 3 of the License, or
21 (at your option) any later version.
23 This program is distributed in the hope that it will be useful,
24 but WITHOUT ANY WARRANTY; without even the implied warranty of
25 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 GNU General Public License for more details.
28 You should have received a copy of the GNU General Public License
29 along with this program. If not, see <http://www.gnu.org/licenses/>. */
31 /*****************************************************/
33 /* Distributed SMB/CIFS Server Management Utility */
35 /* The intent was to make the syntax similar */
36 /* to the NET utility (first developed in DOS */
37 /* with additional interesting & useful functions */
38 /* added in later SMB server network operating */
41 /*****************************************************/
44 #include "lib/cmdline/cmdline.h"
45 #include "utils/net.h"
47 #include "lib/netapi/netapi.h"
48 #include "../libcli/security/security.h"
51 #include "cmdline_contexts.h"
52 #include "lib/gencache.h"
53 #include "auth/credentials/credentials.h"
54 #include "source3/utils/passwd_proto.h"
55 #include "auth/gensec/gensec.h"
56 #include "lib/param/param.h"
58 #ifdef WITH_FAKE_KASERVER
59 #include "utils/net_afs.h"
62 /***********************************************************************/
63 /* end of internationalization section */
64 /***********************************************************************/
66 enum netr_SchannelType
get_sec_channel_type(const char *param
)
68 if (!(param
&& *param
)) {
69 return get_default_sec_channel();
71 if (strequal(param
, "PDC")) {
73 } else if (strequal(param
, "BDC")) {
75 } else if (strequal(param
, "MEMBER")) {
76 return SEC_CHAN_WKSTA
;
78 } else if (strequal(param
, "DOMAIN")) {
79 return SEC_CHAN_DOMAIN
;
82 return get_default_sec_channel();
87 static int net_changetrustpw(struct net_context
*c
, int argc
, const char **argv
)
89 net_warn_member_options();
91 if (net_ads_check_our_domain(c
) == 0)
92 return net_ads_changetrustpw(c
, argc
, argv
);
94 return net_rpc_changetrustpw(c
, argc
, argv
);
97 static void set_line_buffering(FILE *f
)
99 setvbuf(f
, NULL
, _IOLBF
, 0);
102 static int net_primarytrust_dumpinfo(struct net_context
*c
, int argc
,
105 int role
= lp_server_role();
106 const char *domain
= lp_workgroup();
107 struct secrets_domain_info1
*info
= NULL
;
108 bool include_secrets
= c
->opt_force
;
112 if (role
>= ROLE_ACTIVE_DIRECTORY_DC
) {
113 d_printf(_("net primarytrust dumpinfo is only supported "
114 "on a DOMAIN_MEMBER for now.\n"));
118 net_warn_member_options();
121 set_line_buffering(stdin
);
122 set_line_buffering(stdout
);
123 set_line_buffering(stderr
);
126 status
= secrets_fetch_or_upgrade_domain_info(domain
,
129 if (!NT_STATUS_IS_OK(status
)) {
131 _("Unable to fetch the information for domain[%s] "
132 "in the secrets database.\n"),
137 str
= secrets_domain_info_string(info
, info
, domain
, include_secrets
);
139 d_fprintf(stderr
, "secrets_domain_info_string() failed.\n");
145 d_printf(_("The password values are only included using "
154 * Entrypoint for 'net primarytrust' code.
156 * @param argc Standard argc.
157 * @param argv Standard argv without initial components.
159 * @return Integer status (0 means success).
162 static int net_primarytrust(struct net_context
*c
, int argc
, const char **argv
)
164 struct functable func
[] = {
166 .funcname
= "dumpinfo",
167 .fn
= net_primarytrust_dumpinfo
,
168 .valid_transports
= NET_TRANSPORT_LOCAL
,
169 .description
= N_("Dump the details of the "
170 "workstation trust"),
171 .usage
= N_(" net [options] primarytrust "
173 " Dump the details of the "
174 "workstation trust in "
176 " Requires the -f flag to "
177 "include the password values."),
184 return net_run_function(c
, argc
, argv
, "net primarytrust", func
);
187 static int net_changesecretpw(struct net_context
*c
, int argc
,
191 int role
= lp_server_role();
193 if (role
!= ROLE_DOMAIN_MEMBER
) {
194 d_printf(_("Machine account password change only supported on a DOMAIN_MEMBER.\n"
195 "Do NOT use this function unless you know what it does!\n"
196 "This function will change the ADS Domain member "
197 "machine account password in the secrets.tdb file!\n"));
201 net_warn_member_options();
204 struct secrets_domain_info1
*info
= NULL
;
205 struct secrets_domain_info1_change
*prev
= NULL
;
207 struct timeval tv
= timeval_current();
208 NTTIME now
= timeval_to_nttime(&tv
);
211 set_line_buffering(stdin
);
212 set_line_buffering(stdout
);
213 set_line_buffering(stderr
);
216 trust_pw
= get_pass(_("Enter machine password: "), c
->opt_stdin
);
217 if (trust_pw
== NULL
) {
219 _("Error in reading machine password\n"));
223 status
= secrets_prepare_password_change(lp_workgroup(),
234 if (!NT_STATUS_IS_OK(status
)) {
236 _("Unable to write the machine account password in the secrets database"));
241 _("Pending machine account password change found - aborting."));
242 status
= secrets_failed_password_change("localhost",
243 NT_STATUS_REQUEST_NOT_ACCEPTED
,
244 NT_STATUS_NOT_COMMITTED
,
246 if (!NT_STATUS_IS_OK(status
)) {
248 _("Failed to abort machine account password change"));
252 status
= secrets_finish_password_change("localhost",
260 if (!NT_STATUS_IS_OK(status
)) {
262 _("Unable to write the machine account password in the secrets database"));
266 d_printf(_("Modified trust account password in secrets database\n"));
269 d_printf(_("Machine account password change requires the -f flag.\n"
270 "Do NOT use this function unless you know what it does!\n"
271 "This function will change the ADS Domain member "
272 "machine account password in the secrets.tdb file!\n"));
279 * @brief Set the authorised user for winbindd access in secrets.tdb
281 static int net_setauthuser(struct net_context
*c
, int argc
, const char **argv
)
283 const char *password
= NULL
;
286 if (!secrets_init()) {
287 d_fprintf(stderr
, _("Failed to open secrets.tdb.\n"));
291 /* Delete the settings. */
293 if (strncmp(argv
[0], "delete", 6) != 0) {
294 d_fprintf(stderr
,_("Usage:\n"));
296 _(" net setauthuser -U user[%%password] \n"
297 " Set the auth user account to user"
298 "password. Prompt for password if not "
301 _(" net setauthuser delete\n"
302 " Delete the auth user setting.\n"));
305 secrets_delete_entry(SECRETS_AUTH_USER
);
306 secrets_delete_entry(SECRETS_AUTH_DOMAIN
);
307 secrets_delete_entry(SECRETS_AUTH_PASSWORD
);
311 if (!c
->explicit_credentials
) {
312 d_fprintf(stderr
, _("Usage:\n"));
314 _(" net setauthuser -U user[%%password]\n"
315 " Set the auth user account to user"
316 "password. Prompt for password if not "
319 _(" net setauthuser delete\n"
320 " Delete the auth user setting.\n"));
324 password
= cli_credentials_get_password(c
->creds
);
325 if (password
== NULL
) {
326 d_fprintf(stderr
,_("Failed to get the auth users password.\n"));
330 ok
= secrets_store_creds(c
->creds
);
332 d_fprintf(stderr
, _("Failed storing auth user credentials\n"));
340 * @brief Get the auth user settings
342 static int net_getauthuser(struct net_context
*c
, int argc
, const char **argv
)
344 char *user
, *domain
, *password
;
346 /* Lift data from secrets file */
348 secrets_fetch_ipc_userpass(&user
, &domain
, &password
);
350 if ((!user
|| !*user
) && (!domain
|| !*domain
) &&
351 (!password
|| !*password
)){
355 BURN_FREE_STR(password
);
356 d_printf(_("No authorised user configured\n"));
360 /* Pretty print authorised user info */
362 d_printf("%s%s%s%s%s\n", domain
? domain
: "",
363 domain
? lp_winbind_separator(): "", user
,
364 password
? "%" : "", password
? password
: "");
368 BURN_FREE_STR(password
);
373 Retrieve our local SID or the SID for the specified name
375 static int net_getlocalsid(struct net_context
*c
, int argc
, const char **argv
)
379 struct dom_sid_buf sid_str
;
385 name
= lp_netbios_name();
388 if(!initialize_password_db(false, NULL
)) {
389 d_fprintf(stderr
, _("WARNING: Could not open passdb\n"));
393 /* first check to see if we can even access secrets, so we don't
394 panic when we can't. */
396 if (!secrets_init()) {
398 _("Unable to open secrets.tdb. Can't fetch domain "
399 "SID for name: %s\n"), name
);
403 /* Generate one, if it doesn't exist */
404 get_global_sam_sid();
406 if (!secrets_fetch_domain_sid(name
, &sid
)) {
407 DEBUG(0, ("Can't fetch domain SID for name: %s\n", name
));
410 d_printf(_("SID for domain %s is: %s\n"),
412 dom_sid_str_buf(&sid
, &sid_str
));
416 static int net_setlocalsid(struct net_context
*c
, int argc
, const char **argv
)
421 || (strncmp(argv
[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
422 || (!string_to_sid(&sid
, argv
[0]))
423 || (sid
.num_auths
!= 4)) {
424 d_printf(_("Usage:"));
425 d_printf(" net setlocalsid S-1-5-21-x-y-z\n");
429 if (!secrets_store_domain_sid(lp_netbios_name(), &sid
)) {
430 DEBUG(0,("Can't store domain SID as a pdc/bdc.\n"));
437 static int net_setdomainsid(struct net_context
*c
, int argc
, const char **argv
)
442 || (strncmp(argv
[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
443 || (!string_to_sid(&sid
, argv
[0]))
444 || (sid
.num_auths
!= 4)) {
445 d_printf(_("Usage:"));
446 d_printf(" net setdomainsid S-1-5-21-x-y-z\n");
450 if (!secrets_store_domain_sid(lp_workgroup(), &sid
)) {
451 DEBUG(0,("Can't store domain SID.\n"));
458 static int net_getdomainsid(struct net_context
*c
, int argc
, const char **argv
)
460 struct dom_sid domain_sid
;
461 struct dom_sid_buf sid_str
;
464 d_printf(_("Usage:"));
465 d_printf(" net getdomainsid\n");
469 if(!initialize_password_db(false, NULL
)) {
470 d_fprintf(stderr
, _("WARNING: Could not open passdb\n"));
474 /* first check to see if we can even access secrets, so we don't
475 panic when we can't. */
477 if (!secrets_init()) {
478 d_fprintf(stderr
, _("Unable to open secrets.tdb. Can't fetch "
479 "domain SID for name: %s\n"),
480 get_global_sam_name());
484 /* Generate one, if it doesn't exist */
485 get_global_sam_sid();
488 if (!secrets_fetch_domain_sid(lp_netbios_name(), &domain_sid
)) {
489 d_fprintf(stderr
, _("Could not fetch local SID\n"));
492 d_printf(_("SID for local machine %s is: %s\n"),
494 dom_sid_str_buf(&domain_sid
, &sid_str
));
496 if (!secrets_fetch_domain_sid(c
->opt_workgroup
, &domain_sid
)) {
497 d_fprintf(stderr
, _("Could not fetch domain SID\n"));
501 d_printf(_("SID for domain %s is: %s\n"),
503 dom_sid_str_buf(&domain_sid
, &sid_str
));
508 static bool search_maxrid(struct pdb_search
*search
, const char *type
,
511 struct samr_displayentry
*entries
;
512 uint32_t i
, num_entries
;
514 if (search
== NULL
) {
515 d_fprintf(stderr
, _("get_maxrid: Could not search %s\n"), type
);
519 num_entries
= pdb_search_entries(search
, 0, 0xffffffff, &entries
);
520 for (i
=0; i
<num_entries
; i
++)
521 *max_rid
= MAX(*max_rid
, entries
[i
].rid
);
526 static uint32_t get_maxrid(void)
528 uint32_t max_rid
= 0;
530 if (!search_maxrid(pdb_search_users(talloc_tos(), 0), "users", &max_rid
))
533 if (!search_maxrid(pdb_search_groups(talloc_tos()), "groups", &max_rid
))
536 if (!search_maxrid(pdb_search_aliases(talloc_tos(),
537 get_global_sam_sid()),
538 "aliases", &max_rid
))
544 static int net_maxrid(struct net_context
*c
, int argc
, const char **argv
)
549 d_fprintf(stderr
, "%s net maxrid\n", _("Usage:"));
553 if ((rid
= get_maxrid()) == 0) {
554 d_fprintf(stderr
, _("can't get current maximum rid\n"));
558 d_printf(_("Currently used maximum rid: %d\n"), rid
);
563 /* main function table */
564 static struct functable net_func
[] = {
569 N_("Run functions using RPC transport"),
570 N_(" Use 'net help rpc' to get more extensive information "
571 "about 'net rpc' commands.")
577 N_("Run functions using RAP transport"),
578 N_(" Use 'net help rap' to get more extensive information "
579 "about 'net rap' commands.")
585 N_("Run functions using ADS transport"),
586 N_(" Use 'net help ads' to get more extensive information "
587 "about 'net ads' commands.")
590 /* eventually these should auto-choose the transport ... */
594 NET_TRANSPORT_RPC
| NET_TRANSPORT_RAP
,
595 N_("Functions on remote opened files"),
596 N_(" Use 'net help file' to get more information about 'net "
602 NET_TRANSPORT_RPC
| NET_TRANSPORT_RAP
,
603 N_("Functions on shares"),
604 N_(" Use 'net help share' to get more information about 'net "
611 N_("Manage sessions"),
612 N_(" Use 'net help session' to get more information about "
613 "'net session' commands.")
619 N_("List servers in workgroup"),
620 N_(" Use 'net help server' to get more information about 'net "
627 N_("List domains/workgroups on network"),
628 N_(" Use 'net help domain' to get more information about 'net "
635 N_("Modify printer queue"),
636 N_(" Use 'net help printq' to get more information about 'net "
642 NET_TRANSPORT_ADS
| NET_TRANSPORT_RPC
| NET_TRANSPORT_RAP
,
644 N_(" Use 'net help user' to get more information about 'net "
650 NET_TRANSPORT_ADS
| NET_TRANSPORT_RPC
| NET_TRANSPORT_RAP
,
652 N_(" Use 'net help group' to get more information about 'net "
659 N_("Manage group mappings"),
660 N_(" Use 'net help groupmap' to get more information about "
661 "'net groupmap' commands.")
667 N_("Functions on the SAM database"),
668 N_(" Use 'net help sam' to get more information about 'net "
675 N_("Validate username and password"),
676 N_(" Use 'net help validate' to get more information about "
677 "'net validate' commands.")
683 N_("Modify group memberships"),
684 N_(" Use 'net help groupmember' to get more information about "
685 "'net groupmember' commands.")
690 N_("Execute remote command on a remote OS/2 server"),
691 N_(" Use 'net help admin' to get more information about 'net "
697 N_("List/modify running services"),
698 N_(" Use 'net help service' to get more information about "
699 "'net service' commands.")
705 N_("Change user password on target server"),
706 N_(" Use 'net help password' to get more information about "
707 "'net password' commands.")
713 N_("Run functions related to the primary workstation trust."),
714 N_(" Use 'net help primarytrust' to get more extensive information "
715 "about 'net primarytrust' commands.")
719 NET_TRANSPORT_ADS
| NET_TRANSPORT_RPC
,
720 N_("Change the trust password"),
721 N_(" Use 'net help changetrustpw' to get more information "
722 "about 'net changetrustpw'.")
727 N_("Change the secret password"),
728 N_(" net [options] changesecretpw\n"
729 " Change the ADS domain member machine account password "
731 " Do NOT use this function unless you know what it does.\n"
732 " Requires the -f flag to work.")
738 N_("Set the winbind auth user"),
739 N_(" net -U user[%%password] [-W domain] setauthuser\n"
740 " Set the auth user, password (and optionally domain\n"
741 " Will prompt for password if not given.\n"
742 " net setauthuser delete\n"
743 " Delete the existing auth user settings.")
749 N_("Get the winbind auth user settings"),
750 N_(" net getauthuser\n"
751 " Get the current winbind auth user settings.")
757 N_(" Use 'net help time' to get more information about 'net "
763 N_("Look up host names/IP addresses"),
764 N_(" Use 'net help lookup' to get more information about 'net "
770 N_("Manipulate the global lock table"),
771 N_(" Use 'net help g_lock' to get more information about "
772 "'net g_lock' commands.")
776 NET_TRANSPORT_ADS
| NET_TRANSPORT_RPC
,
777 N_("Join a domain/AD"),
778 N_(" Use 'net help join' to get more information about 'net "
783 NET_TRANSPORT_ADS
| NET_TRANSPORT_RPC
,
784 N_("Perform offline domain join"),
785 N_(" Use 'net help offlinejoin' to get more information about 'net "
791 N_("Join/unjoin (remote) machines to/from a domain/AD"),
792 N_(" Use 'net help dom' to get more information about 'net "
798 N_("Operate on the cache tdb file"),
799 N_(" Use 'net help cache' to get more information about 'net "
805 N_("Get the SID for the local domain"),
806 N_(" net getlocalsid")
811 N_("Set the SID for the local domain"),
812 N_(" net setlocalsid S-1-5-21-x-y-z")
817 N_("Set domain SID on member servers"),
818 N_(" net setdomainsid S-1-5-21-x-y-z")
823 N_("Get domain SID on member servers"),
824 N_(" net getdomainsid")
829 N_("Display the maximum RID currently used"),
835 N_("IDmap functions"),
836 N_(" Use 'net help idmap to get more information about 'net "
842 N_("Display server status"),
843 N_(" Use 'net help status' to get more information about 'net "
849 N_("Manage user-modifiable shares"),
850 N_(" Use 'net help usershare to get more information about "
851 "'net usershare' commands.")
856 N_("Display list of all users with SID"),
857 N_(" Use 'net help usersidlist' to get more information about "
858 "'net usersidlist'.")
863 N_("Manage Samba registry based configuration"),
864 N_(" Use 'net help conf' to get more information about 'net "
870 N_("Manage the Samba registry"),
871 N_(" Use 'net help registry' to get more information about "
872 "'net registry' commands.")
877 N_("Process Win32 *.evt eventlog files"),
878 N_(" Use 'net help eventlog' to get more information about "
879 "'net eventlog' commands.")
884 N_("Process tdb printer files"),
885 N_(" Use 'net help printing' to get more information about "
886 "'net printing' commands.")
892 N_("Manage the serverid tdb"),
893 N_(" Use 'net help serverid' to get more information about "
894 "'net serverid' commands.")
900 N_("notifyd client code"),
901 N_(" Use 'net help notify' to get more information about "
902 "'net notify' commands.")
908 N_("Show information from tdb records"),
909 N_(" Use 'net help tdb' to get more information about "
910 "'net tdb' commands.")
916 N_("Filesystem operation through the VFS stack"),
917 N_(" Use 'net help vfs' to get more information about "
918 "'net vfs' commands.")
924 N_("Manage witness registrations"),
925 N_(" Use 'net help witness' to get more information about "
926 "'net witness' commands.")
929 #ifdef WITH_FAKE_KASERVER
933 N_("Manage AFS tokens"),
934 N_(" Use 'net help afs' to get more information about 'net "
942 N_("Print usage information"),
943 N_(" Use 'net help help' to list usage information for 'net' "
946 {NULL
, NULL
, 0, NULL
, NULL
}
950 /****************************************************************************
952 ****************************************************************************/
953 int main(int argc
, char **argv
)
958 const char ** argv_new
;
959 const char **argv_const
= discard_const_p(const char *, argv
);
961 TALLOC_CTX
*frame
= talloc_stackframe();
962 struct net_context
*c
= talloc_zero(frame
, struct net_context
);
965 struct poptOption long_options
[] = {
969 .argInfo
= POPT_ARG_NONE
,
973 .longName
= "target-workgroup",
975 .argInfo
= POPT_ARG_STRING
,
976 .arg
= &c
->opt_target_workgroup
,
979 .longName
= "ipaddress",
981 .argInfo
= POPT_ARG_STRING
,
988 .argInfo
= POPT_ARG_INT
,
992 .longName
= "myname",
994 .argInfo
= POPT_ARG_STRING
,
995 .arg
= &c
->opt_requester_name
,
998 .longName
= "server",
1000 .argInfo
= POPT_ARG_STRING
,
1001 .arg
= &c
->opt_host
,
1004 .longName
= "container",
1006 .argInfo
= POPT_ARG_STRING
,
1007 .arg
= &c
->opt_container
,
1010 .longName
= "comment",
1012 .argInfo
= POPT_ARG_STRING
,
1013 .arg
= &c
->opt_comment
,
1016 .longName
= "maxusers",
1018 .argInfo
= POPT_ARG_INT
,
1019 .arg
= &c
->opt_maxusers
,
1022 .longName
= "flags",
1024 .argInfo
= POPT_ARG_INT
,
1025 .arg
= &c
->opt_flags
,
1029 .argInfo
= POPT_ARG_NONE
,
1030 .arg
= &c
->opt_long_list_entries
,
1033 .longName
= "reboot",
1035 .argInfo
= POPT_ARG_NONE
,
1036 .arg
= &c
->opt_reboot
,
1039 .longName
= "force",
1041 .argInfo
= POPT_ARG_NONE
,
1042 .arg
= &c
->opt_force
,
1045 .longName
= "stdin",
1047 .argInfo
= POPT_ARG_NONE
,
1048 .arg
= &c
->opt_stdin
,
1051 .longName
= "timeout",
1053 .argInfo
= POPT_ARG_INT
,
1054 .arg
= &c
->opt_timeout
,
1057 .longName
= "request-timeout",
1059 .argInfo
= POPT_ARG_INT
,
1060 .arg
= &c
->opt_request_timeout
,
1063 /* legacy for --use-winbind-ccache */
1064 .longName
= "use-ccache",
1066 .argInfo
= POPT_ARG_NONE
,
1067 .arg
= &c
->legacy_opt_ccache
,
1070 .longName
= "verbose",
1072 .argInfo
= POPT_ARG_NONE
,
1073 .arg
= &c
->opt_verbose
,
1078 .argInfo
= POPT_ARG_NONE
,
1079 .arg
= &c
->opt_testmode
,
1081 /* Options for 'net groupmap set' */
1083 .longName
= "local",
1085 .argInfo
= POPT_ARG_NONE
,
1086 .arg
= &c
->opt_localgroup
,
1089 .longName
= "domain",
1091 .argInfo
= POPT_ARG_NONE
,
1092 .arg
= &c
->opt_domaingroup
,
1095 .longName
= "ntname",
1097 .argInfo
= POPT_ARG_STRING
,
1098 .arg
= &c
->opt_newntname
,
1103 .argInfo
= POPT_ARG_INT
,
1106 /* Options for 'net rpc share migrate' */
1110 .argInfo
= POPT_ARG_NONE
,
1111 .arg
= &c
->opt_acls
,
1114 .longName
= "attrs",
1116 .argInfo
= POPT_ARG_NONE
,
1117 .arg
= &c
->opt_attrs
,
1120 .longName
= "timestamps",
1122 .argInfo
= POPT_ARG_NONE
,
1123 .arg
= &c
->opt_timestamps
,
1126 .longName
= "exclude",
1128 .argInfo
= POPT_ARG_STRING
,
1129 .arg
= &c
->opt_exclude
,
1132 .longName
= "destination",
1134 .argInfo
= POPT_ARG_STRING
,
1135 .arg
= &c
->opt_destination
,
1138 .longName
= "tallocreport",
1140 .argInfo
= POPT_ARG_NONE
,
1141 .arg
= &c
->do_talloc_report
,
1143 /* Options for 'net rpc vampire (keytab)' */
1145 .longName
= "force-full-repl",
1147 .argInfo
= POPT_ARG_NONE
,
1148 .arg
= &c
->opt_force_full_repl
,
1151 .longName
= "single-obj-repl",
1153 .argInfo
= POPT_ARG_NONE
,
1154 .arg
= &c
->opt_single_obj_repl
,
1157 .longName
= "clean-old-entries",
1159 .argInfo
= POPT_ARG_NONE
,
1160 .arg
= &c
->opt_clean_old_entries
,
1162 /* Options for 'net idmap'*/
1166 .argInfo
= POPT_ARG_STRING
,
1172 .argInfo
= POPT_ARG_NONE
,
1173 .arg
= &c
->opt_lock
,
1178 .argInfo
= POPT_ARG_NONE
,
1179 .arg
= &c
->opt_auto
,
1182 .longName
= "repair",
1184 .argInfo
= POPT_ARG_NONE
,
1185 .arg
= &c
->opt_repair
,
1187 /* Options for 'net registry check'*/
1189 .longName
= "reg-version",
1191 .argInfo
= POPT_ARG_INT
,
1192 .arg
= &c
->opt_reg_version
,
1195 .longName
= "output",
1197 .argInfo
= POPT_ARG_STRING
,
1198 .arg
= &c
->opt_output
,
1203 .argInfo
= POPT_ARG_NONE
,
1204 .arg
= &c
->opt_wipe
,
1206 /* Options for 'net registry import' */
1208 .longName
= "precheck",
1210 .argInfo
= POPT_ARG_STRING
,
1211 .arg
= &c
->opt_precheck
,
1213 /* Options for 'net ads join or leave' */
1215 .longName
= "no-dns-updates",
1217 .argInfo
= POPT_ARG_NONE
,
1218 .arg
= &c
->opt_no_dns_updates
,
1221 .longName
= "keep-account",
1223 .argInfo
= POPT_ARG_NONE
,
1224 .arg
= &c
->opt_keep_account
,
1229 .argInfo
= POPT_ARG_NONE
,
1230 .arg
= &c
->opt_json
,
1232 /* Options for 'net vfs' */
1234 .longName
= "continue",
1235 .argInfo
= POPT_ARG_NONE
,
1236 .arg
= &c
->opt_continue_on_error
,
1237 .descrip
= "Continue on errors",
1240 .longName
= "recursive",
1241 .argInfo
= POPT_ARG_NONE
,
1242 .arg
= &c
->opt_recursive
,
1243 .descrip
= "Traverse directory hierarchy",
1246 .longName
= "follow-symlinks",
1247 .argInfo
= POPT_ARG_NONE
,
1248 .arg
= &c
->opt_follow_symlink
,
1249 .descrip
= "follow symlinks",
1251 /* Options for 'net ads dns register' */
1253 .longName
= "dns-ttl",
1254 .argInfo
= POPT_ARG_INT
,
1255 .arg
= &c
->opt_dns_ttl
,
1256 .descrip
= "TTL in seconds of DNS records",
1258 /* Options for 'net witness {list,...}' */
1260 .longName
= "witness-registration",
1262 .argInfo
= POPT_ARG_STRING
,
1263 .arg
= &c
->opt_witness_registration
,
1266 .longName
= "witness-net-name",
1268 .argInfo
= POPT_ARG_STRING
,
1269 .arg
= &c
->opt_witness_net_name
,
1272 .longName
= "witness-share-name",
1274 .argInfo
= POPT_ARG_STRING
,
1275 .arg
= &c
->opt_witness_share_name
,
1278 .longName
= "witness-ip-address",
1280 .argInfo
= POPT_ARG_STRING
,
1281 .arg
= &c
->opt_witness_ip_address
,
1284 .longName
= "witness-client-computer-name",
1286 .argInfo
= POPT_ARG_STRING
,
1287 .arg
= &c
->opt_witness_client_computer_name
,
1290 .longName
= "witness-apply-to-all",
1292 .argInfo
= POPT_ARG_NONE
,
1293 .arg
= &c
->opt_witness_apply_to_all
,
1296 .longName
= "witness-new-ip",
1298 .argInfo
= POPT_ARG_STRING
,
1299 .arg
= &c
->opt_witness_new_ip
,
1302 .longName
= "witness-new-node",
1304 .argInfo
= POPT_ARG_INT
,
1305 .arg
= &c
->opt_witness_new_node
,
1308 .longName
= "witness-forced-response",
1310 .argInfo
= POPT_ARG_STRING
,
1311 .arg
= &c
->opt_witness_forced_response
,
1314 POPT_COMMON_CONNECTION
1315 POPT_COMMON_CREDENTIALS
1321 /* Ignore possible SIGPIPE upon ldap_unbind when over TLS */
1322 BlockSignals(True
, SIGPIPE
);
1324 zero_sockaddr(&c
->opt_dest_ip
);
1325 c
->opt_witness_new_node
= -2;
1329 setlocale(LC_ALL
, "");
1330 #if defined(HAVE_BINDTEXTDOMAIN)
1331 bindtextdomain(MODULE_NAME
, get_dyn_LOCALEDIR());
1333 #if defined(HAVE_TEXTDOMAIN)
1334 textdomain(MODULE_NAME
);
1337 ok
= samba_cmdline_init(frame
,
1338 SAMBA_CMDLINE_CONFIG_CLIENT
,
1339 false /* require_smbconf */);
1341 DBG_ERR("Failed to init cmdline parser!\n");
1345 c
->lp_ctx
= samba_cmdline_get_lp_ctx();
1346 /* set default debug level to 0 regardless of what smb.conf sets */
1347 lpcfg_set_cmdline(c
->lp_ctx
, "log level", "0");
1348 c
->private_data
= net_func
;
1350 pc
= samba_popt_get_context(getprogname(),
1354 POPT_CONTEXT_KEEP_FIRST
);
1356 DBG_ERR("Failed to setup popt context!\n");
1361 while((opt
= poptGetNextOpt(pc
)) != -1) {
1364 c
->display_usage
= true;
1367 if (!interpret_string_addr(&c
->opt_dest_ip
,
1368 poptGetOptArg(pc
), 0)) {
1369 d_fprintf(stderr
, _("\nInvalid ip address specified\n"));
1371 c
->opt_have_ip
= true;
1375 d_fprintf(stderr
, _("\nInvalid option %s: %s\n"),
1376 poptBadOption(pc
, 0), poptStrerror(opt
));
1377 net_help(c
, argc
, argv_const
);
1382 c
->creds
= samba_cmdline_get_creds();
1385 enum credentials_obtained principal_obtained
=
1386 cli_credentials_get_principal_obtained(c
->creds
);
1387 enum credentials_obtained password_obtained
=
1388 cli_credentials_get_password_obtained(c
->creds
);
1390 if (principal_obtained
== CRED_SPECIFIED
) {
1391 c
->explicit_credentials
= true;
1393 if (password_obtained
== CRED_SPECIFIED
) {
1394 c
->explicit_credentials
= true;
1397 c
->opt_workgroup
= cli_credentials_get_domain(c
->creds
);
1399 if (c
->legacy_opt_ccache
) {
1400 cli_credentials_add_gensec_features(
1402 GENSEC_FEATURE_NTLM_CCACHE
,
1407 c
->msg_ctx
= cmdline_messaging_context(get_dyn_CONFIGFILE());
1409 #if defined(HAVE_BIND_TEXTDOMAIN_CODESET)
1410 /* Bind our gettext results to 'unix charset'
1412 This ensures that the translations and any embedded strings are in the
1413 same charset. It won't be the one from the user's locale (we no
1414 longer auto-detect that), but it will be self-consistent.
1416 bind_textdomain_codeset(MODULE_NAME
, lp_unix_charset());
1419 argv_new
= (const char **)poptGetArgs(pc
);
1422 for (i
=0; i
<argc
; i
++) {
1423 if (argv_new
[i
] == NULL
) {
1429 if (c
->do_talloc_report
) {
1430 talloc_enable_leak_report();
1433 if (c
->opt_requester_name
) {
1434 lpcfg_set_cmdline(c
->lp_ctx
, "netbios name", c
->opt_requester_name
);
1437 if (!c
->opt_target_workgroup
) {
1438 c
->opt_target_workgroup
= talloc_strdup(c
, lp_workgroup());
1443 /* this makes sure that when we do things like call scripts,
1444 that it won't assert because we are not root */
1447 samba_cmdline_burn(argc
, argv
);
1449 rc
= net_run_function(c
, argc_new
-1, argv_new
+1, "net", net_func
);
1451 DEBUG(2,("return code = %d\n", rc
));
1453 libnetapi_free(c
->netapi_ctx
);
1455 poptFreeContext(pc
);
1457 cmdline_messaging_context_free();