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 "popt_common_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"
55 #ifdef WITH_FAKE_KASERVER
56 #include "utils/net_afs.h"
59 /***********************************************************************/
60 /* end of internationalization section */
61 /***********************************************************************/
63 enum netr_SchannelType get_sec_channel_type(const char *param)
65 if (!(param && *param)) {
66 return get_default_sec_channel();
68 if (strequal(param, "PDC")) {
70 } else if (strequal(param, "BDC")) {
72 } else if (strequal(param, "MEMBER")) {
73 return SEC_CHAN_WKSTA;
75 } else if (strequal(param, "DOMAIN")) {
76 return SEC_CHAN_DOMAIN;
79 return get_default_sec_channel();
84 static int net_changetrustpw(struct net_context *c, int argc, const char **argv)
86 if (net_ads_check_our_domain(c) == 0)
87 return net_ads_changetrustpw(c, argc, argv);
89 return net_rpc_changetrustpw(c, argc, argv);
92 static void set_line_buffering(FILE *f)
94 setvbuf(f, NULL, _IOLBF, 0);
97 static int net_primarytrust_dumpinfo(struct net_context *c, int argc,
100 int role = lp_server_role();
101 const char *domain = lp_workgroup();
102 struct secrets_domain_info1 *info = NULL;
103 bool include_secrets = c->opt_force;
107 if (role >= ROLE_ACTIVE_DIRECTORY_DC) {
108 d_printf(_("net primarytrust dumpinfo is only supported "
109 "on a DOMAIN_MEMBER for now.\n"));
114 set_line_buffering(stdin);
115 set_line_buffering(stdout);
116 set_line_buffering(stderr);
119 status = secrets_fetch_or_upgrade_domain_info(domain,
122 if (!NT_STATUS_IS_OK(status)) {
124 _("Unable to fetch the information for domain[%s] "
125 "in the secrets database.\n"),
130 str = secrets_domain_info_string(info, info, domain, include_secrets);
132 d_fprintf(stderr, "secrets_domain_info_string() failed.\n");
138 d_printf(_("The password values are only included using "
147 * Entrypoint for 'net primarytrust' code.
149 * @param argc Standard argc.
150 * @param argv Standard argv without initial components.
152 * @return Integer status (0 means success).
155 static int net_primarytrust(struct net_context *c, int argc, const char **argv)
157 struct functable func[] = {
160 net_primarytrust_dumpinfo,
162 N_("Dump the details of the workstation trust"),
163 N_(" net [options] primarytrust dumpinfo'\n"
164 " Dump the details of the workstation trust "
166 " Requires the -f flag to include the password values.")
168 {NULL, NULL, 0, NULL, NULL}
171 return net_run_function(c, argc, argv, "net primarytrust", func);
174 static int net_changesecretpw(struct net_context *c, int argc,
178 int role = lp_server_role();
180 if (role != ROLE_DOMAIN_MEMBER) {
181 d_printf(_("Machine account password change only supported on a DOMAIN_MEMBER.\n"
182 "Do NOT use this function unless you know what it does!\n"
183 "This function will change the ADS Domain member "
184 "machine account password in the secrets.tdb file!\n"));
189 struct secrets_domain_info1 *info = NULL;
190 struct secrets_domain_info1_change *prev = NULL;
192 struct timeval tv = timeval_current();
193 NTTIME now = timeval_to_nttime(&tv);
196 set_line_buffering(stdin);
197 set_line_buffering(stdout);
198 set_line_buffering(stderr);
201 trust_pw = get_pass(_("Enter machine password: "), c->opt_stdin);
202 if (trust_pw == NULL) {
204 _("Error in reading machine password\n"));
208 status = secrets_prepare_password_change(lp_workgroup(),
213 if (!NT_STATUS_IS_OK(status)) {
215 _("Unable to write the machine account password in the secrets database"));
220 _("Pending machine account password change found - aborting."));
221 status = secrets_failed_password_change("localhost",
222 NT_STATUS_REQUEST_NOT_ACCEPTED,
223 NT_STATUS_NOT_COMMITTED,
225 if (!NT_STATUS_IS_OK(status)) {
227 _("Failed to abort machine account password change"));
231 status = secrets_finish_password_change("localhost", now, info);
232 if (!NT_STATUS_IS_OK(status)) {
234 _("Unable to write the machine account password in the secrets database"));
238 d_printf(_("Modified trust account password in secrets database\n"));
241 d_printf(_("Machine account password change requires the -f flag.\n"
242 "Do NOT use this function unless you know what it does!\n"
243 "This function will change the ADS Domain member "
244 "machine account password in the secrets.tdb file!\n"));
251 * @brief Set the authorised user for winbindd access in secrets.tdb
253 static int net_setauthuser(struct net_context *c, int argc, const char **argv)
255 const char *password = NULL;
257 if (!secrets_init()) {
258 d_fprintf(stderr, _("Failed to open secrets.tdb.\n"));
262 /* Delete the settings. */
264 if (strncmp(argv[0], "delete", 6) != 0) {
265 d_fprintf(stderr,_("Usage:\n"));
267 _(" net setauthuser -U user[%%password] \n"
268 " Set the auth user account to user"
269 "password. Prompt for password if not "
272 _(" net setauthuser delete\n"
273 " Delete the auth user setting.\n"));
276 secrets_delete_entry(SECRETS_AUTH_USER);
277 secrets_delete_entry(SECRETS_AUTH_DOMAIN);
278 secrets_delete_entry(SECRETS_AUTH_PASSWORD);
282 if (!c->opt_user_specified) {
283 d_fprintf(stderr, _("Usage:\n"));
285 _(" net setauthuser -U user[%%password]\n"
286 " Set the auth user account to user"
287 "password. Prompt for password if not "
290 _(" net setauthuser delete\n"
291 " Delete the auth user setting.\n"));
295 password = net_prompt_pass(c, _("the auth user"));
296 if (password == NULL) {
297 d_fprintf(stderr,_("Failed to get the auth users password.\n"));
301 if (!secrets_store(SECRETS_AUTH_USER, c->opt_user_name,
302 strlen(c->opt_user_name) + 1)) {
303 d_fprintf(stderr, _("error storing auth user name\n"));
307 if (!secrets_store(SECRETS_AUTH_DOMAIN, c->opt_workgroup,
308 strlen(c->opt_workgroup) + 1)) {
309 d_fprintf(stderr, _("error storing auth user domain\n"));
313 if (!secrets_store(SECRETS_AUTH_PASSWORD, password,
314 strlen(password) + 1)) {
315 d_fprintf(stderr, _("error storing auth user password\n"));
323 * @brief Get the auth user settings
325 static int net_getauthuser(struct net_context *c, int argc, const char **argv)
327 char *user, *domain, *password;
329 /* Lift data from secrets file */
331 secrets_fetch_ipc_userpass(&user, &domain, &password);
333 if ((!user || !*user) && (!domain || !*domain ) &&
334 (!password || !*password)){
339 d_printf(_("No authorised user configured\n"));
343 /* Pretty print authorised user info */
345 d_printf("%s%s%s%s%s\n", domain ? domain : "",
346 domain ? lp_winbind_separator(): "", user,
347 password ? "%" : "", password ? password : "");
356 Retrieve our local SID or the SID for the specified name
358 static int net_getlocalsid(struct net_context *c, int argc, const char **argv)
368 name = lp_netbios_name();
371 if(!initialize_password_db(false, NULL)) {
372 d_fprintf(stderr, _("WARNING: Could not open passdb\n"));
376 /* first check to see if we can even access secrets, so we don't
377 panic when we can't. */
379 if (!secrets_init()) {
381 _("Unable to open secrets.tdb. Can't fetch domain "
382 "SID for name: %s\n"), name);
386 /* Generate one, if it doesn't exist */
387 get_global_sam_sid();
389 if (!secrets_fetch_domain_sid(name, &sid)) {
390 DEBUG(0, ("Can't fetch domain SID for name: %s\n", name));
393 sid_to_fstring(sid_str, &sid);
394 d_printf(_("SID for domain %s is: %s\n"), name, sid_str);
398 static int net_setlocalsid(struct net_context *c, int argc, const char **argv)
403 || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
404 || (!string_to_sid(&sid, argv[0]))
405 || (sid.num_auths != 4)) {
406 d_printf(_("Usage:"));
407 d_printf(" net setlocalsid S-1-5-21-x-y-z\n");
411 if (!secrets_store_domain_sid(lp_netbios_name(), &sid)) {
412 DEBUG(0,("Can't store domain SID as a pdc/bdc.\n"));
419 static int net_setdomainsid(struct net_context *c, int argc, const char **argv)
424 || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
425 || (!string_to_sid(&sid, argv[0]))
426 || (sid.num_auths != 4)) {
427 d_printf(_("Usage:"));
428 d_printf(" net setdomainsid S-1-5-21-x-y-z\n");
432 if (!secrets_store_domain_sid(lp_workgroup(), &sid)) {
433 DEBUG(0,("Can't store domain SID.\n"));
440 static int net_getdomainsid(struct net_context *c, int argc, const char **argv)
442 struct dom_sid domain_sid;
446 d_printf(_("Usage:"));
447 d_printf(" net getdomainsid\n");
451 if(!initialize_password_db(false, NULL)) {
452 d_fprintf(stderr, _("WARNING: Could not open passdb\n"));
456 /* first check to see if we can even access secrets, so we don't
457 panic when we can't. */
459 if (!secrets_init()) {
460 d_fprintf(stderr, _("Unable to open secrets.tdb. Can't fetch "
461 "domain SID for name: %s\n"),
462 get_global_sam_name());
466 /* Generate one, if it doesn't exist */
467 get_global_sam_sid();
470 if (!secrets_fetch_domain_sid(lp_netbios_name(), &domain_sid)) {
471 d_fprintf(stderr, _("Could not fetch local SID\n"));
474 sid_to_fstring(sid_str, &domain_sid);
475 d_printf(_("SID for local machine %s is: %s\n"),
476 lp_netbios_name(), sid_str);
478 if (!secrets_fetch_domain_sid(c->opt_workgroup, &domain_sid)) {
479 d_fprintf(stderr, _("Could not fetch domain SID\n"));
483 sid_to_fstring(sid_str, &domain_sid);
484 d_printf(_("SID for domain %s is: %s\n"), c->opt_workgroup, sid_str);
489 static bool search_maxrid(struct pdb_search *search, const char *type,
492 struct samr_displayentry *entries;
493 uint32_t i, num_entries;
495 if (search == NULL) {
496 d_fprintf(stderr, _("get_maxrid: Could not search %s\n"), type);
500 num_entries = pdb_search_entries(search, 0, 0xffffffff, &entries);
501 for (i=0; i<num_entries; i++)
502 *max_rid = MAX(*max_rid, entries[i].rid);
507 static uint32_t get_maxrid(void)
509 uint32_t max_rid = 0;
511 if (!search_maxrid(pdb_search_users(talloc_tos(), 0), "users", &max_rid))
514 if (!search_maxrid(pdb_search_groups(talloc_tos()), "groups", &max_rid))
517 if (!search_maxrid(pdb_search_aliases(talloc_tos(),
518 get_global_sam_sid()),
519 "aliases", &max_rid))
525 static int net_maxrid(struct net_context *c, int argc, const char **argv)
530 d_fprintf(stderr, "%s net maxrid\n", _("Usage:"));
534 if ((rid = get_maxrid()) == 0) {
535 d_fprintf(stderr, _("can't get current maximum rid\n"));
539 d_printf(_("Currently used maximum rid: %d\n"), rid);
544 /* main function table */
545 static struct functable net_func[] = {
550 N_("Run functions using RPC transport"),
551 N_(" Use 'net help rpc' to get more extensive information "
552 "about 'net rpc' commands.")
558 N_("Run functions using RAP transport"),
559 N_(" Use 'net help rap' to get more extensive information "
560 "about 'net rap' commands.")
566 N_("Run functions using ADS transport"),
567 N_(" Use 'net help ads' to get more extensive information "
568 "about 'net ads' commands.")
571 /* eventually these should auto-choose the transport ... */
575 NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
576 N_("Functions on remote opened files"),
577 N_(" Use 'net help file' to get more information about 'net "
583 NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
584 N_("Functions on shares"),
585 N_(" Use 'net help share' to get more information about 'net "
592 N_("Manage sessions"),
593 N_(" Use 'net help session' to get more information about "
594 "'net session' commands.")
600 N_("List servers in workgroup"),
601 N_(" Use 'net help server' to get more information about 'net "
608 N_("List domains/workgroups on network"),
609 N_(" Use 'net help domain' to get more information about 'net "
616 N_("Modify printer queue"),
617 N_(" Use 'net help printq' to get more information about 'net "
623 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
625 N_(" Use 'net help user' to get more information about 'net "
631 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
633 N_(" Use 'net help group' to get more information about 'net "
640 N_("Manage group mappings"),
641 N_(" Use 'net help groupmap' to get more information about "
642 "'net groupmap' commands.")
648 N_("Functions on the SAM database"),
649 N_(" Use 'net help sam' to get more information about 'net "
656 N_("Validate username and password"),
657 N_(" Use 'net help validate' to get more information about "
658 "'net validate' commands.")
664 N_("Modify group memberships"),
665 N_(" Use 'net help groupmember' to get more information about "
666 "'net groupmember' commands.")
671 N_("Execute remote command on a remote OS/2 server"),
672 N_(" Use 'net help admin' to get more information about 'net "
678 N_("List/modify running services"),
679 N_(" Use 'net help service' to get more information about "
680 "'net service' commands.")
686 N_("Change user password on target server"),
687 N_(" Use 'net help password' to get more information about "
688 "'net password' commands.")
694 N_("Run functions related to the primary workstation trust."),
695 N_(" Use 'net help primarytrust' to get more extensive information "
696 "about 'net primarytrust' commands.")
700 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC,
701 N_("Change the trust password"),
702 N_(" Use 'net help changetrustpw' to get more information "
703 "about 'net changetrustpw'.")
708 N_("Change the secret password"),
709 N_(" net [options] changesecretpw\n"
710 " Change the ADS domain member machine account password "
712 " Do NOT use this function unless you know what it does.\n"
713 " Requires the -f flag to work.")
719 N_("Set the winbind auth user"),
720 N_(" net -U user[%%password] [-W domain] setauthuser\n"
721 " Set the auth user, password (and optionally domain\n"
722 " Will prompt for password if not given.\n"
723 " net setauthuser delete\n"
724 " Delete the existing auth user settings.")
730 N_("Get the winbind auth user settings"),
731 N_(" net getauthuser\n"
732 " Get the current winbind auth user settings.")
738 N_(" Use 'net help time' to get more information about 'net "
744 N_("Look up host names/IP addresses"),
745 N_(" Use 'net help lookup' to get more information about 'net "
751 N_("Manipulate the global lock table"),
752 N_(" Use 'net help g_lock' to get more information about "
753 "'net g_lock' commands.")
757 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC,
758 N_("Join a domain/AD"),
759 N_(" Use 'net help join' to get more information about 'net "
765 N_("Join/unjoin (remote) machines to/from a domain/AD"),
766 N_(" Use 'net help dom' to get more information about 'net "
772 N_("Operate on the cache tdb file"),
773 N_(" Use 'net help cache' to get more information about 'net "
779 N_("Get the SID for the local domain"),
780 N_(" net getlocalsid")
785 N_("Set the SID for the local domain"),
786 N_(" net setlocalsid S-1-5-21-x-y-z")
791 N_("Set domain SID on member servers"),
792 N_(" net setdomainsid S-1-5-21-x-y-z")
797 N_("Get domain SID on member servers"),
798 N_(" net getdomainsid")
803 N_("Display the maximum RID currently used"),
809 N_("IDmap functions"),
810 N_(" Use 'net help idmap to get more information about 'net "
816 N_("Display server status"),
817 N_(" Use 'net help status' to get more information about 'net "
823 N_("Manage user-modifiable shares"),
824 N_(" Use 'net help usershare to get more information about "
825 "'net usershare' commands.")
830 N_("Display list of all users with SID"),
831 N_(" Use 'net help usersidlist' to get more information about "
832 "'net usersidlist'.")
837 N_("Manage Samba registry based configuration"),
838 N_(" Use 'net help conf' to get more information about 'net "
844 N_("Manage the Samba registry"),
845 N_(" Use 'net help registry' to get more information about "
846 "'net registry' commands.")
851 N_("Process Win32 *.evt eventlog files"),
852 N_(" Use 'net help eventlog' to get more information about "
853 "'net eventlog' commands.")
858 N_("Process tdb printer files"),
859 N_(" Use 'net help printing' to get more information about "
860 "'net printing' commands.")
866 N_("Manage the serverid tdb"),
867 N_(" Use 'net help serverid' to get more information about "
868 "'net serverid' commands.")
874 N_("notifyd client code"),
875 N_(" Use 'net help notify' to get more information about "
876 "'net notify' commands.")
882 N_("Show information from tdb records"),
883 N_(" Use 'net help tdb' to get more information about "
884 "'net tdb' commands.")
887 #ifdef WITH_FAKE_KASERVER
891 N_("Manage AFS tokens"),
892 N_(" Use 'net help afs' to get more information about 'net "
900 N_("Print usage information"),
901 N_(" Use 'net help help' to list usage information for 'net' "
904 {NULL, NULL, 0, NULL, NULL}
908 static void get_credentials_file(struct net_context *c,
911 struct cli_credentials *cred = cli_credentials_init(c);
914 d_printf("ERROR: Unable to allocate memory!\n");
918 if (!cli_credentials_parse_file(cred, file, CRED_GUESS_FILE)) {
922 c->opt_user_name = cli_credentials_get_username(cred);
923 c->opt_user_specified = (c->opt_user_name != NULL);
924 c->opt_password = cli_credentials_get_password(cred);
925 c->opt_target_workgroup = cli_credentials_get_domain(cred);
928 /****************************************************************************
930 ****************************************************************************/
931 int main(int argc, char **argv)
937 const char ** argv_new;
938 const char **argv_const = discard_const_p(const char *, argv);
940 TALLOC_CTX *frame = talloc_stackframe();
941 struct net_context *c = talloc_zero(frame, struct net_context);
943 struct poptOption long_options[] = {
944 {"help", 'h', POPT_ARG_NONE, 0, 'h'},
945 {"workgroup", 'w', POPT_ARG_STRING, &c->opt_target_workgroup},
946 {"user", 'U', POPT_ARG_STRING, &c->opt_user_name, 'U'},
947 {"authentication-file", 'A', POPT_ARG_STRING, &c->opt_user_name, 'A', "Get the credentials from a file", "FILE"},
948 {"ipaddress", 'I', POPT_ARG_STRING, 0,'I'},
949 {"port", 'p', POPT_ARG_INT, &c->opt_port},
950 {"myname", 'n', POPT_ARG_STRING, &c->opt_requester_name},
951 {"server", 'S', POPT_ARG_STRING, &c->opt_host},
952 {"encrypt", 'e', POPT_ARG_NONE, NULL, 'e', N_("Encrypt SMB transport") },
953 {"container", 'c', POPT_ARG_STRING, &c->opt_container},
954 {"comment", 'C', POPT_ARG_STRING, &c->opt_comment},
955 {"maxusers", 'M', POPT_ARG_INT, &c->opt_maxusers},
956 {"flags", 'F', POPT_ARG_INT, &c->opt_flags},
957 {"long", 'l', POPT_ARG_NONE, &c->opt_long_list_entries},
958 {"reboot", 'r', POPT_ARG_NONE, &c->opt_reboot},
959 {"force", 'f', POPT_ARG_NONE, &c->opt_force},
960 {"stdin", 'i', POPT_ARG_NONE, &c->opt_stdin},
961 {"timeout", 't', POPT_ARG_INT, &c->opt_timeout},
962 {"request-timeout",0,POPT_ARG_INT, &c->opt_request_timeout},
963 {"machine-pass",'P', POPT_ARG_NONE, &c->opt_machine_pass},
964 {"kerberos", 'k', POPT_ARG_NONE, &c->opt_kerberos},
965 {"myworkgroup", 'W', POPT_ARG_STRING, &c->opt_workgroup},
966 {"use-ccache", 0, POPT_ARG_NONE, &c->opt_ccache},
967 {"verbose", 'v', POPT_ARG_NONE, &c->opt_verbose},
968 {"test", 'T', POPT_ARG_NONE, &c->opt_testmode},
969 /* Options for 'net groupmap set' */
970 {"local", 'L', POPT_ARG_NONE, &c->opt_localgroup},
971 {"domain", 'D', POPT_ARG_NONE, &c->opt_domaingroup},
972 {"ntname", 'N', POPT_ARG_STRING, &c->opt_newntname},
973 {"rid", 'R', POPT_ARG_INT, &c->opt_rid},
974 /* Options for 'net rpc share migrate' */
975 {"acls", 0, POPT_ARG_NONE, &c->opt_acls},
976 {"attrs", 0, POPT_ARG_NONE, &c->opt_attrs},
977 {"timestamps", 0, POPT_ARG_NONE, &c->opt_timestamps},
978 {"exclude", 'X', POPT_ARG_STRING, &c->opt_exclude},
979 {"destination", 0, POPT_ARG_STRING, &c->opt_destination},
980 {"tallocreport", 0, POPT_ARG_NONE, &c->do_talloc_report},
981 /* Options for 'net rpc vampire (keytab)' */
982 {"force-full-repl", 0, POPT_ARG_NONE, &c->opt_force_full_repl},
983 {"single-obj-repl", 0, POPT_ARG_NONE, &c->opt_single_obj_repl},
984 {"clean-old-entries", 0, POPT_ARG_NONE, &c->opt_clean_old_entries},
985 /* Options for 'net idmap'*/
986 {"db", 0, POPT_ARG_STRING, &c->opt_db},
987 {"lock", 0, POPT_ARG_NONE, &c->opt_lock},
988 {"auto", 'a', POPT_ARG_NONE, &c->opt_auto},
989 {"repair", 0, POPT_ARG_NONE, &c->opt_repair},
990 /* Options for 'net registry check'*/
991 {"reg-version", 0, POPT_ARG_INT, &c->opt_reg_version},
992 {"output", 'o', POPT_ARG_STRING, &c->opt_output},
993 {"wipe", 0, POPT_ARG_NONE, &c->opt_wipe},
994 /* Options for 'net registry import' */
995 {"precheck", 0, POPT_ARG_STRING, &c->opt_precheck},
996 /* Options for 'net ads join or leave' */
997 {"no-dns-updates", 0, POPT_ARG_NONE, &c->opt_no_dns_updates},
998 {"keep-account", 0, POPT_ARG_NONE, &c->opt_keep_account},
999 {"json", 0, POPT_ARG_NONE, &c->opt_json},
1004 zero_sockaddr(&c->opt_dest_ip);
1006 setup_logging(argv[0], DEBUG_STDERR);
1010 setlocale(LC_ALL, "");
1011 #if defined(HAVE_BINDTEXTDOMAIN)
1012 bindtextdomain(MODULE_NAME, get_dyn_LOCALEDIR());
1014 #if defined(HAVE_TEXTDOMAIN)
1015 textdomain(MODULE_NAME);
1018 /* set default debug level to 0 regardless of what smb.conf sets */
1019 lp_set_cmdline("log level", "0");
1020 c->private_data = net_func;
1022 pc = poptGetContext(NULL, argc, argv_const, long_options,
1023 POPT_CONTEXT_KEEP_FIRST);
1025 while((opt = poptGetNextOpt(pc)) != -1) {
1028 c->display_usage = true;
1031 c->smb_encrypt = true;
1034 if (!interpret_string_addr(&c->opt_dest_ip,
1035 poptGetOptArg(pc), 0)) {
1036 d_fprintf(stderr, _("\nInvalid ip address specified\n"));
1038 c->opt_have_ip = true;
1042 c->opt_user_specified = true;
1043 c->opt_user_name = talloc_strdup(c, c->opt_user_name);
1044 p = strchr(c->opt_user_name,'%');
1047 c->opt_password = p+1;
1051 get_credentials_file(c, c->opt_user_name);
1054 d_fprintf(stderr, _("\nInvalid option %s: %s\n"),
1055 poptBadOption(pc, 0), poptStrerror(opt));
1056 net_help(c, argc, argv_const);
1061 c->msg_ctx = cmdline_messaging_context(get_dyn_CONFIGFILE());
1063 if (!lp_load_global(get_dyn_CONFIGFILE())) {
1064 d_fprintf(stderr, "Can't load %s - run testparm to debug it\n",
1065 get_dyn_CONFIGFILE());
1069 #if defined(HAVE_BIND_TEXTDOMAIN_CODESET)
1070 /* Bind our gettext results to 'unix charset'
1072 This ensures that the translations and any embedded strings are in the
1073 same charset. It won't be the one from the user's locale (we no
1074 longer auto-detect that), but it will be self-consistent.
1076 bind_textdomain_codeset(MODULE_NAME, lp_unix_charset());
1079 argv_new = (const char **)poptGetArgs(pc);
1082 for (i=0; i<argc; i++) {
1083 if (argv_new[i] == NULL) {
1089 if (c->do_talloc_report) {
1090 talloc_enable_leak_report();
1093 if (c->opt_requester_name) {
1094 lp_set_cmdline("netbios name", c->opt_requester_name);
1097 if (!c->opt_user_name && getenv("LOGNAME")) {
1098 c->opt_user_name = getenv("LOGNAME");
1101 if (!c->opt_workgroup) {
1102 c->opt_workgroup = talloc_strdup(c, lp_workgroup());
1105 if (!c->opt_target_workgroup) {
1106 c->opt_target_workgroup = talloc_strdup(c, lp_workgroup());
1114 /* this makes sure that when we do things like call scripts,
1115 that it won't assert because we are not root */
1118 if (c->opt_machine_pass) {
1119 /* it is very useful to be able to make ads queries as the
1120 machine account for testing purposes and for domain leave */
1122 net_use_krb_machine_account(c);
1125 if (!c->opt_password) {
1126 c->opt_password = getenv("PASSWD");
1129 popt_burn_cmdline_password(argc, argv);
1131 rc = net_run_function(c, argc_new-1, argv_new+1, "net", net_func);
1133 DEBUG(2,("return code = %d\n", rc));
1135 libnetapi_free(c->netapi_ctx);
1137 poptFreeContext(pc);