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(),
228 if (!NT_STATUS_IS_OK(status
)) {
230 _("Unable to write the machine account password in the secrets database"));
235 _("Pending machine account password change found - aborting."));
236 status
= secrets_failed_password_change("localhost",
237 NT_STATUS_REQUEST_NOT_ACCEPTED
,
238 NT_STATUS_NOT_COMMITTED
,
240 if (!NT_STATUS_IS_OK(status
)) {
242 _("Failed to abort machine account password change"));
246 status
= secrets_finish_password_change("localhost", now
, info
);
247 if (!NT_STATUS_IS_OK(status
)) {
249 _("Unable to write the machine account password in the secrets database"));
253 d_printf(_("Modified trust account password in secrets database\n"));
256 d_printf(_("Machine account password change requires the -f flag.\n"
257 "Do NOT use this function unless you know what it does!\n"
258 "This function will change the ADS Domain member "
259 "machine account password in the secrets.tdb file!\n"));
266 * @brief Set the authorised user for winbindd access in secrets.tdb
268 static int net_setauthuser(struct net_context
*c
, int argc
, const char **argv
)
270 const char *password
= NULL
;
273 if (!secrets_init()) {
274 d_fprintf(stderr
, _("Failed to open secrets.tdb.\n"));
278 /* Delete the settings. */
280 if (strncmp(argv
[0], "delete", 6) != 0) {
281 d_fprintf(stderr
,_("Usage:\n"));
283 _(" net setauthuser -U user[%%password] \n"
284 " Set the auth user account to user"
285 "password. Prompt for password if not "
288 _(" net setauthuser delete\n"
289 " Delete the auth user setting.\n"));
292 secrets_delete_entry(SECRETS_AUTH_USER
);
293 secrets_delete_entry(SECRETS_AUTH_DOMAIN
);
294 secrets_delete_entry(SECRETS_AUTH_PASSWORD
);
298 if (!c
->opt_user_specified
) {
299 d_fprintf(stderr
, _("Usage:\n"));
301 _(" net setauthuser -U user[%%password]\n"
302 " Set the auth user account to user"
303 "password. Prompt for password if not "
306 _(" net setauthuser delete\n"
307 " Delete the auth user setting.\n"));
311 password
= net_prompt_pass(c
, _("the auth user"));
312 if (password
== NULL
) {
313 d_fprintf(stderr
,_("Failed to get the auth users password.\n"));
317 ok
= secrets_store_creds(c
->creds
);
319 d_fprintf(stderr
, _("Failed storing auth user credentials\n"));
327 * @brief Get the auth user settings
329 static int net_getauthuser(struct net_context
*c
, int argc
, const char **argv
)
331 char *user
, *domain
, *password
;
333 /* Lift data from secrets file */
335 secrets_fetch_ipc_userpass(&user
, &domain
, &password
);
337 if ((!user
|| !*user
) && (!domain
|| !*domain
) &&
338 (!password
|| !*password
)){
342 BURN_FREE_STR(password
);
343 d_printf(_("No authorised user configured\n"));
347 /* Pretty print authorised user info */
349 d_printf("%s%s%s%s%s\n", domain
? domain
: "",
350 domain
? lp_winbind_separator(): "", user
,
351 password
? "%" : "", password
? password
: "");
355 BURN_FREE_STR(password
);
360 Retrieve our local SID or the SID for the specified name
362 static int net_getlocalsid(struct net_context
*c
, int argc
, const char **argv
)
366 struct dom_sid_buf sid_str
;
372 name
= lp_netbios_name();
375 if(!initialize_password_db(false, NULL
)) {
376 d_fprintf(stderr
, _("WARNING: Could not open passdb\n"));
380 /* first check to see if we can even access secrets, so we don't
381 panic when we can't. */
383 if (!secrets_init()) {
385 _("Unable to open secrets.tdb. Can't fetch domain "
386 "SID for name: %s\n"), name
);
390 /* Generate one, if it doesn't exist */
391 get_global_sam_sid();
393 if (!secrets_fetch_domain_sid(name
, &sid
)) {
394 DEBUG(0, ("Can't fetch domain SID for name: %s\n", name
));
397 d_printf(_("SID for domain %s is: %s\n"),
399 dom_sid_str_buf(&sid
, &sid_str
));
403 static int net_setlocalsid(struct net_context
*c
, int argc
, const char **argv
)
408 || (strncmp(argv
[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
409 || (!string_to_sid(&sid
, argv
[0]))
410 || (sid
.num_auths
!= 4)) {
411 d_printf(_("Usage:"));
412 d_printf(" net setlocalsid S-1-5-21-x-y-z\n");
416 if (!secrets_store_domain_sid(lp_netbios_name(), &sid
)) {
417 DEBUG(0,("Can't store domain SID as a pdc/bdc.\n"));
424 static int net_setdomainsid(struct net_context
*c
, int argc
, const char **argv
)
429 || (strncmp(argv
[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
430 || (!string_to_sid(&sid
, argv
[0]))
431 || (sid
.num_auths
!= 4)) {
432 d_printf(_("Usage:"));
433 d_printf(" net setdomainsid S-1-5-21-x-y-z\n");
437 if (!secrets_store_domain_sid(lp_workgroup(), &sid
)) {
438 DEBUG(0,("Can't store domain SID.\n"));
445 static int net_getdomainsid(struct net_context
*c
, int argc
, const char **argv
)
447 struct dom_sid domain_sid
;
448 struct dom_sid_buf sid_str
;
451 d_printf(_("Usage:"));
452 d_printf(" net getdomainsid\n");
456 if(!initialize_password_db(false, NULL
)) {
457 d_fprintf(stderr
, _("WARNING: Could not open passdb\n"));
461 /* first check to see if we can even access secrets, so we don't
462 panic when we can't. */
464 if (!secrets_init()) {
465 d_fprintf(stderr
, _("Unable to open secrets.tdb. Can't fetch "
466 "domain SID for name: %s\n"),
467 get_global_sam_name());
471 /* Generate one, if it doesn't exist */
472 get_global_sam_sid();
475 if (!secrets_fetch_domain_sid(lp_netbios_name(), &domain_sid
)) {
476 d_fprintf(stderr
, _("Could not fetch local SID\n"));
479 d_printf(_("SID for local machine %s is: %s\n"),
481 dom_sid_str_buf(&domain_sid
, &sid_str
));
483 if (!secrets_fetch_domain_sid(c
->opt_workgroup
, &domain_sid
)) {
484 d_fprintf(stderr
, _("Could not fetch domain SID\n"));
488 d_printf(_("SID for domain %s is: %s\n"),
490 dom_sid_str_buf(&domain_sid
, &sid_str
));
495 static bool search_maxrid(struct pdb_search
*search
, const char *type
,
498 struct samr_displayentry
*entries
;
499 uint32_t i
, num_entries
;
501 if (search
== NULL
) {
502 d_fprintf(stderr
, _("get_maxrid: Could not search %s\n"), type
);
506 num_entries
= pdb_search_entries(search
, 0, 0xffffffff, &entries
);
507 for (i
=0; i
<num_entries
; i
++)
508 *max_rid
= MAX(*max_rid
, entries
[i
].rid
);
513 static uint32_t get_maxrid(void)
515 uint32_t max_rid
= 0;
517 if (!search_maxrid(pdb_search_users(talloc_tos(), 0), "users", &max_rid
))
520 if (!search_maxrid(pdb_search_groups(talloc_tos()), "groups", &max_rid
))
523 if (!search_maxrid(pdb_search_aliases(talloc_tos(),
524 get_global_sam_sid()),
525 "aliases", &max_rid
))
531 static int net_maxrid(struct net_context
*c
, int argc
, const char **argv
)
536 d_fprintf(stderr
, "%s net maxrid\n", _("Usage:"));
540 if ((rid
= get_maxrid()) == 0) {
541 d_fprintf(stderr
, _("can't get current maximum rid\n"));
545 d_printf(_("Currently used maximum rid: %d\n"), rid
);
550 /* main function table */
551 static struct functable net_func
[] = {
556 N_("Run functions using RPC transport"),
557 N_(" Use 'net help rpc' to get more extensive information "
558 "about 'net rpc' commands.")
564 N_("Run functions using RAP transport"),
565 N_(" Use 'net help rap' to get more extensive information "
566 "about 'net rap' commands.")
572 N_("Run functions using ADS transport"),
573 N_(" Use 'net help ads' to get more extensive information "
574 "about 'net ads' commands.")
577 /* eventually these should auto-choose the transport ... */
581 NET_TRANSPORT_RPC
| NET_TRANSPORT_RAP
,
582 N_("Functions on remote opened files"),
583 N_(" Use 'net help file' to get more information about 'net "
589 NET_TRANSPORT_RPC
| NET_TRANSPORT_RAP
,
590 N_("Functions on shares"),
591 N_(" Use 'net help share' to get more information about 'net "
598 N_("Manage sessions"),
599 N_(" Use 'net help session' to get more information about "
600 "'net session' commands.")
606 N_("List servers in workgroup"),
607 N_(" Use 'net help server' to get more information about 'net "
614 N_("List domains/workgroups on network"),
615 N_(" Use 'net help domain' to get more information about 'net "
622 N_("Modify printer queue"),
623 N_(" Use 'net help printq' to get more information about 'net "
629 NET_TRANSPORT_ADS
| NET_TRANSPORT_RPC
| NET_TRANSPORT_RAP
,
631 N_(" Use 'net help user' to get more information about 'net "
637 NET_TRANSPORT_ADS
| NET_TRANSPORT_RPC
| NET_TRANSPORT_RAP
,
639 N_(" Use 'net help group' to get more information about 'net "
646 N_("Manage group mappings"),
647 N_(" Use 'net help groupmap' to get more information about "
648 "'net groupmap' commands.")
654 N_("Functions on the SAM database"),
655 N_(" Use 'net help sam' to get more information about 'net "
662 N_("Validate username and password"),
663 N_(" Use 'net help validate' to get more information about "
664 "'net validate' commands.")
670 N_("Modify group memberships"),
671 N_(" Use 'net help groupmember' to get more information about "
672 "'net groupmember' commands.")
677 N_("Execute remote command on a remote OS/2 server"),
678 N_(" Use 'net help admin' to get more information about 'net "
684 N_("List/modify running services"),
685 N_(" Use 'net help service' to get more information about "
686 "'net service' commands.")
692 N_("Change user password on target server"),
693 N_(" Use 'net help password' to get more information about "
694 "'net password' commands.")
700 N_("Run functions related to the primary workstation trust."),
701 N_(" Use 'net help primarytrust' to get more extensive information "
702 "about 'net primarytrust' commands.")
706 NET_TRANSPORT_ADS
| NET_TRANSPORT_RPC
,
707 N_("Change the trust password"),
708 N_(" Use 'net help changetrustpw' to get more information "
709 "about 'net changetrustpw'.")
714 N_("Change the secret password"),
715 N_(" net [options] changesecretpw\n"
716 " Change the ADS domain member machine account password "
718 " Do NOT use this function unless you know what it does.\n"
719 " Requires the -f flag to work.")
725 N_("Set the winbind auth user"),
726 N_(" net -U user[%%password] [-W domain] setauthuser\n"
727 " Set the auth user, password (and optionally domain\n"
728 " Will prompt for password if not given.\n"
729 " net setauthuser delete\n"
730 " Delete the existing auth user settings.")
736 N_("Get the winbind auth user settings"),
737 N_(" net getauthuser\n"
738 " Get the current winbind auth user settings.")
744 N_(" Use 'net help time' to get more information about 'net "
750 N_("Look up host names/IP addresses"),
751 N_(" Use 'net help lookup' to get more information about 'net "
757 N_("Manipulate the global lock table"),
758 N_(" Use 'net help g_lock' to get more information about "
759 "'net g_lock' commands.")
763 NET_TRANSPORT_ADS
| NET_TRANSPORT_RPC
,
764 N_("Join a domain/AD"),
765 N_(" Use 'net help join' to get more information about 'net "
770 NET_TRANSPORT_ADS
| NET_TRANSPORT_RPC
,
771 N_("Perform offline domain join"),
772 N_(" Use 'net help offlinejoin' to get more information about 'net "
778 N_("Join/unjoin (remote) machines to/from a domain/AD"),
779 N_(" Use 'net help dom' to get more information about 'net "
785 N_("Operate on the cache tdb file"),
786 N_(" Use 'net help cache' to get more information about 'net "
792 N_("Get the SID for the local domain"),
793 N_(" net getlocalsid")
798 N_("Set the SID for the local domain"),
799 N_(" net setlocalsid S-1-5-21-x-y-z")
804 N_("Set domain SID on member servers"),
805 N_(" net setdomainsid S-1-5-21-x-y-z")
810 N_("Get domain SID on member servers"),
811 N_(" net getdomainsid")
816 N_("Display the maximum RID currently used"),
822 N_("IDmap functions"),
823 N_(" Use 'net help idmap to get more information about 'net "
829 N_("Display server status"),
830 N_(" Use 'net help status' to get more information about 'net "
836 N_("Manage user-modifiable shares"),
837 N_(" Use 'net help usershare to get more information about "
838 "'net usershare' commands.")
843 N_("Display list of all users with SID"),
844 N_(" Use 'net help usersidlist' to get more information about "
845 "'net usersidlist'.")
850 N_("Manage Samba registry based configuration"),
851 N_(" Use 'net help conf' to get more information about 'net "
857 N_("Manage the Samba registry"),
858 N_(" Use 'net help registry' to get more information about "
859 "'net registry' commands.")
864 N_("Process Win32 *.evt eventlog files"),
865 N_(" Use 'net help eventlog' to get more information about "
866 "'net eventlog' commands.")
871 N_("Process tdb printer files"),
872 N_(" Use 'net help printing' to get more information about "
873 "'net printing' commands.")
879 N_("Manage the serverid tdb"),
880 N_(" Use 'net help serverid' to get more information about "
881 "'net serverid' commands.")
887 N_("notifyd client code"),
888 N_(" Use 'net help notify' to get more information about "
889 "'net notify' commands.")
895 N_("Show information from tdb records"),
896 N_(" Use 'net help tdb' to get more information about "
897 "'net tdb' commands.")
903 N_("Filesystem operation through the VFS stack"),
904 N_(" Use 'net help vfs' to get more information about "
905 "'net vfs' commands.")
911 N_("Manage witness registrations"),
912 N_(" Use 'net help witness' to get more information about "
913 "'net witness' commands.")
916 #ifdef WITH_FAKE_KASERVER
920 N_("Manage AFS tokens"),
921 N_(" Use 'net help afs' to get more information about 'net "
929 N_("Print usage information"),
930 N_(" Use 'net help help' to list usage information for 'net' "
933 {NULL
, NULL
, 0, NULL
, NULL
}
937 /****************************************************************************
939 ****************************************************************************/
940 int main(int argc
, char **argv
)
945 const char ** argv_new
;
946 const char **argv_const
= discard_const_p(const char *, argv
);
948 TALLOC_CTX
*frame
= talloc_stackframe();
949 struct net_context
*c
= talloc_zero(frame
, struct net_context
);
952 struct poptOption long_options
[] = {
956 .argInfo
= POPT_ARG_NONE
,
960 .longName
= "target-workgroup",
962 .argInfo
= POPT_ARG_STRING
,
963 .arg
= &c
->opt_target_workgroup
,
966 .longName
= "ipaddress",
968 .argInfo
= POPT_ARG_STRING
,
975 .argInfo
= POPT_ARG_INT
,
979 .longName
= "myname",
981 .argInfo
= POPT_ARG_STRING
,
982 .arg
= &c
->opt_requester_name
,
985 .longName
= "server",
987 .argInfo
= POPT_ARG_STRING
,
991 .longName
= "container",
993 .argInfo
= POPT_ARG_STRING
,
994 .arg
= &c
->opt_container
,
997 .longName
= "comment",
999 .argInfo
= POPT_ARG_STRING
,
1000 .arg
= &c
->opt_comment
,
1003 .longName
= "maxusers",
1005 .argInfo
= POPT_ARG_INT
,
1006 .arg
= &c
->opt_maxusers
,
1009 .longName
= "flags",
1011 .argInfo
= POPT_ARG_INT
,
1012 .arg
= &c
->opt_flags
,
1016 .argInfo
= POPT_ARG_NONE
,
1017 .arg
= &c
->opt_long_list_entries
,
1020 .longName
= "reboot",
1022 .argInfo
= POPT_ARG_NONE
,
1023 .arg
= &c
->opt_reboot
,
1026 .longName
= "force",
1028 .argInfo
= POPT_ARG_NONE
,
1029 .arg
= &c
->opt_force
,
1032 .longName
= "stdin",
1034 .argInfo
= POPT_ARG_NONE
,
1035 .arg
= &c
->opt_stdin
,
1038 .longName
= "timeout",
1040 .argInfo
= POPT_ARG_INT
,
1041 .arg
= &c
->opt_timeout
,
1044 .longName
= "request-timeout",
1046 .argInfo
= POPT_ARG_INT
,
1047 .arg
= &c
->opt_request_timeout
,
1050 .longName
= "use-ccache",
1052 .argInfo
= POPT_ARG_NONE
,
1053 .arg
= &c
->opt_ccache
,
1056 .longName
= "verbose",
1058 .argInfo
= POPT_ARG_NONE
,
1059 .arg
= &c
->opt_verbose
,
1064 .argInfo
= POPT_ARG_NONE
,
1065 .arg
= &c
->opt_testmode
,
1067 /* Options for 'net groupmap set' */
1069 .longName
= "local",
1071 .argInfo
= POPT_ARG_NONE
,
1072 .arg
= &c
->opt_localgroup
,
1075 .longName
= "domain",
1077 .argInfo
= POPT_ARG_NONE
,
1078 .arg
= &c
->opt_domaingroup
,
1081 .longName
= "ntname",
1083 .argInfo
= POPT_ARG_STRING
,
1084 .arg
= &c
->opt_newntname
,
1089 .argInfo
= POPT_ARG_INT
,
1092 /* Options for 'net rpc share migrate' */
1096 .argInfo
= POPT_ARG_NONE
,
1097 .arg
= &c
->opt_acls
,
1100 .longName
= "attrs",
1102 .argInfo
= POPT_ARG_NONE
,
1103 .arg
= &c
->opt_attrs
,
1106 .longName
= "timestamps",
1108 .argInfo
= POPT_ARG_NONE
,
1109 .arg
= &c
->opt_timestamps
,
1112 .longName
= "exclude",
1114 .argInfo
= POPT_ARG_STRING
,
1115 .arg
= &c
->opt_exclude
,
1118 .longName
= "destination",
1120 .argInfo
= POPT_ARG_STRING
,
1121 .arg
= &c
->opt_destination
,
1124 .longName
= "tallocreport",
1126 .argInfo
= POPT_ARG_NONE
,
1127 .arg
= &c
->do_talloc_report
,
1129 /* Options for 'net rpc vampire (keytab)' */
1131 .longName
= "force-full-repl",
1133 .argInfo
= POPT_ARG_NONE
,
1134 .arg
= &c
->opt_force_full_repl
,
1137 .longName
= "single-obj-repl",
1139 .argInfo
= POPT_ARG_NONE
,
1140 .arg
= &c
->opt_single_obj_repl
,
1143 .longName
= "clean-old-entries",
1145 .argInfo
= POPT_ARG_NONE
,
1146 .arg
= &c
->opt_clean_old_entries
,
1148 /* Options for 'net idmap'*/
1152 .argInfo
= POPT_ARG_STRING
,
1158 .argInfo
= POPT_ARG_NONE
,
1159 .arg
= &c
->opt_lock
,
1164 .argInfo
= POPT_ARG_NONE
,
1165 .arg
= &c
->opt_auto
,
1168 .longName
= "repair",
1170 .argInfo
= POPT_ARG_NONE
,
1171 .arg
= &c
->opt_repair
,
1173 /* Options for 'net registry check'*/
1175 .longName
= "reg-version",
1177 .argInfo
= POPT_ARG_INT
,
1178 .arg
= &c
->opt_reg_version
,
1181 .longName
= "output",
1183 .argInfo
= POPT_ARG_STRING
,
1184 .arg
= &c
->opt_output
,
1189 .argInfo
= POPT_ARG_NONE
,
1190 .arg
= &c
->opt_wipe
,
1192 /* Options for 'net registry import' */
1194 .longName
= "precheck",
1196 .argInfo
= POPT_ARG_STRING
,
1197 .arg
= &c
->opt_precheck
,
1199 /* Options for 'net ads join or leave' */
1201 .longName
= "no-dns-updates",
1203 .argInfo
= POPT_ARG_NONE
,
1204 .arg
= &c
->opt_no_dns_updates
,
1207 .longName
= "keep-account",
1209 .argInfo
= POPT_ARG_NONE
,
1210 .arg
= &c
->opt_keep_account
,
1215 .argInfo
= POPT_ARG_NONE
,
1216 .arg
= &c
->opt_json
,
1218 /* Options for 'net vfs' */
1220 .longName
= "continue",
1221 .argInfo
= POPT_ARG_NONE
,
1222 .arg
= &c
->opt_continue_on_error
,
1223 .descrip
= "Continue on errors",
1226 .longName
= "recursive",
1227 .argInfo
= POPT_ARG_NONE
,
1228 .arg
= &c
->opt_recursive
,
1229 .descrip
= "Traverse directory hierarchy",
1232 .longName
= "follow-symlinks",
1233 .argInfo
= POPT_ARG_NONE
,
1234 .arg
= &c
->opt_follow_symlink
,
1235 .descrip
= "follow symlinks",
1237 /* Options for 'net ads dns register' */
1239 .longName
= "dns-ttl",
1240 .argInfo
= POPT_ARG_INT
,
1241 .arg
= &c
->opt_dns_ttl
,
1242 .descrip
= "TTL in seconds of DNS records",
1244 /* Options for 'net witness {list,...}' */
1246 .longName
= "witness-registration",
1248 .argInfo
= POPT_ARG_STRING
,
1249 .arg
= &c
->opt_witness_registration
,
1252 .longName
= "witness-net-name",
1254 .argInfo
= POPT_ARG_STRING
,
1255 .arg
= &c
->opt_witness_net_name
,
1258 .longName
= "witness-share-name",
1260 .argInfo
= POPT_ARG_STRING
,
1261 .arg
= &c
->opt_witness_share_name
,
1264 .longName
= "witness-ip-address",
1266 .argInfo
= POPT_ARG_STRING
,
1267 .arg
= &c
->opt_witness_ip_address
,
1270 .longName
= "witness-client-computer-name",
1272 .argInfo
= POPT_ARG_STRING
,
1273 .arg
= &c
->opt_witness_client_computer_name
,
1276 .longName
= "witness-apply-to-all",
1278 .argInfo
= POPT_ARG_NONE
,
1279 .arg
= &c
->opt_witness_apply_to_all
,
1282 .longName
= "witness-new-ip",
1284 .argInfo
= POPT_ARG_STRING
,
1285 .arg
= &c
->opt_witness_new_ip
,
1288 .longName
= "witness-new-node",
1290 .argInfo
= POPT_ARG_INT
,
1291 .arg
= &c
->opt_witness_new_node
,
1294 POPT_COMMON_CONNECTION
1295 POPT_COMMON_CREDENTIALS
1301 /* Ignore possible SIGPIPE upon ldap_unbind when over TLS */
1302 BlockSignals(True
, SIGPIPE
);
1304 zero_sockaddr(&c
->opt_dest_ip
);
1305 c
->opt_witness_new_node
= -2;
1309 setlocale(LC_ALL
, "");
1310 #if defined(HAVE_BINDTEXTDOMAIN)
1311 bindtextdomain(MODULE_NAME
, get_dyn_LOCALEDIR());
1313 #if defined(HAVE_TEXTDOMAIN)
1314 textdomain(MODULE_NAME
);
1317 ok
= samba_cmdline_init(frame
,
1318 SAMBA_CMDLINE_CONFIG_CLIENT
,
1319 false /* require_smbconf */);
1321 DBG_ERR("Failed to init cmdline parser!\n");
1325 c
->lp_ctx
= samba_cmdline_get_lp_ctx();
1326 /* set default debug level to 0 regardless of what smb.conf sets */
1327 lpcfg_set_cmdline(c
->lp_ctx
, "log level", "0");
1328 c
->private_data
= net_func
;
1330 pc
= samba_popt_get_context(getprogname(),
1334 POPT_CONTEXT_KEEP_FIRST
);
1336 DBG_ERR("Failed to setup popt context!\n");
1341 while((opt
= poptGetNextOpt(pc
)) != -1) {
1344 c
->display_usage
= true;
1347 if (!interpret_string_addr(&c
->opt_dest_ip
,
1348 poptGetOptArg(pc
), 0)) {
1349 d_fprintf(stderr
, _("\nInvalid ip address specified\n"));
1351 c
->opt_have_ip
= true;
1355 d_fprintf(stderr
, _("\nInvalid option %s: %s\n"),
1356 poptBadOption(pc
, 0), poptStrerror(opt
));
1357 net_help(c
, argc
, argv_const
);
1362 c
->creds
= samba_cmdline_get_creds();
1365 enum credentials_obtained username_obtained
=
1367 enum smb_encryption_setting encrypt_state
=
1368 cli_credentials_get_smb_encryption(c
->creds
);
1369 enum credentials_use_kerberos krb5_state
=
1370 cli_credentials_get_kerberos_state(c
->creds
);
1371 uint32_t gensec_features
;
1373 c
->opt_user_name
= cli_credentials_get_username_and_obtained(
1375 &username_obtained
);
1376 c
->opt_user_specified
= (username_obtained
== CRED_SPECIFIED
);
1378 c
->opt_workgroup
= cli_credentials_get_domain(c
->creds
);
1380 c
->smb_encrypt
= (encrypt_state
== SMB_ENCRYPTION_REQUIRED
);
1382 c
->opt_kerberos
= (krb5_state
> CRED_USE_KERBEROS_DESIRED
);
1384 gensec_features
= cli_credentials_get_gensec_features(c
->creds
);
1385 c
->opt_ccache
= (gensec_features
& GENSEC_FEATURE_NTLM_CCACHE
);
1388 c
->msg_ctx
= cmdline_messaging_context(get_dyn_CONFIGFILE());
1390 #if defined(HAVE_BIND_TEXTDOMAIN_CODESET)
1391 /* Bind our gettext results to 'unix charset'
1393 This ensures that the translations and any embedded strings are in the
1394 same charset. It won't be the one from the user's locale (we no
1395 longer auto-detect that), but it will be self-consistent.
1397 bind_textdomain_codeset(MODULE_NAME
, lp_unix_charset());
1400 argv_new
= (const char **)poptGetArgs(pc
);
1403 for (i
=0; i
<argc
; i
++) {
1404 if (argv_new
[i
] == NULL
) {
1410 if (c
->do_talloc_report
) {
1411 talloc_enable_leak_report();
1414 if (c
->opt_requester_name
) {
1415 lpcfg_set_cmdline(c
->lp_ctx
, "netbios name", c
->opt_requester_name
);
1418 if (!c
->opt_target_workgroup
) {
1419 c
->opt_target_workgroup
= talloc_strdup(c
, lp_workgroup());
1424 /* this makes sure that when we do things like call scripts,
1425 that it won't assert because we are not root */
1428 samba_cmdline_burn(argc
, argv
);
1430 rc
= net_run_function(c
, argc_new
-1, argv_new
+1, "net", net_func
);
1432 DEBUG(2,("return code = %d\n", rc
));
1434 libnetapi_free(c
->netapi_ctx
);
1436 poptFreeContext(pc
);
1438 cmdline_messaging_context_free();