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"
54 #ifdef WITH_FAKE_KASERVER
55 #include "utils/net_afs.h"
58 /***********************************************************************/
59 /* end of internationalization section */
60 /***********************************************************************/
62 enum netr_SchannelType get_sec_channel_type(const char *param)
64 if (!(param && *param)) {
65 return get_default_sec_channel();
67 if (strequal(param, "PDC")) {
69 } else if (strequal(param, "BDC")) {
71 } else if (strequal(param, "MEMBER")) {
72 return SEC_CHAN_WKSTA;
74 } else if (strequal(param, "DOMAIN")) {
75 return SEC_CHAN_DOMAIN;
78 return get_default_sec_channel();
83 static int net_changetrustpw(struct net_context *c, int argc, const char **argv)
85 if (net_ads_check_our_domain(c) == 0)
86 return net_ads_changetrustpw(c, argc, argv);
88 return net_rpc_changetrustpw(c, argc, argv);
91 static void set_line_buffering(FILE *f)
93 setvbuf(f, NULL, _IOLBF, 0);
96 static int net_primarytrust_dumpinfo(struct net_context *c, int argc,
99 int role = lp_server_role();
100 const char *domain = lp_workgroup();
101 struct secrets_domain_info1 *info = NULL;
102 bool include_secrets = c->opt_force;
106 if (role >= ROLE_ACTIVE_DIRECTORY_DC) {
107 d_printf(_("net primarytrust dumpinfo is only supported "
108 "on a DOMAIN_MEMBER for now.\n"));
113 set_line_buffering(stdin);
114 set_line_buffering(stdout);
115 set_line_buffering(stderr);
118 status = secrets_fetch_or_upgrade_domain_info(domain,
121 if (!NT_STATUS_IS_OK(status)) {
123 _("Unable to fetch the information for domain[%s] "
124 "in the secrets database.\n"),
129 str = secrets_domain_info_string(info, info, domain, include_secrets);
131 d_fprintf(stderr, "secrets_domain_info_string() failed.\n");
137 d_printf(_("The password values are only included using "
146 * Entrypoint for 'net primarytrust' code.
148 * @param argc Standard argc.
149 * @param argv Standard argv without initial components.
151 * @return Integer status (0 means success).
154 static int net_primarytrust(struct net_context *c, int argc, const char **argv)
156 struct functable func[] = {
159 net_primarytrust_dumpinfo,
161 N_("Dump the details of the workstation trust"),
162 N_(" net [options] primarytrust dumpinfo'\n"
163 " Dump the details of the workstation trust "
165 " Requires the -f flag to include the password values.")
167 {NULL, NULL, 0, NULL, NULL}
170 return net_run_function(c, argc, argv, "net primarytrust", func);
173 static int net_changesecretpw(struct net_context *c, int argc,
177 int role = lp_server_role();
179 if (role != ROLE_DOMAIN_MEMBER) {
180 d_printf(_("Machine account password change only supported on a DOMAIN_MEMBER.\n"
181 "Do NOT use this function unless you know what it does!\n"
182 "This function will change the ADS Domain member "
183 "machine account password in the secrets.tdb file!\n"));
188 struct secrets_domain_info1 *info = NULL;
189 struct secrets_domain_info1_change *prev = NULL;
191 struct timeval tv = timeval_current();
192 NTTIME now = timeval_to_nttime(&tv);
195 set_line_buffering(stdin);
196 set_line_buffering(stdout);
197 set_line_buffering(stderr);
200 trust_pw = get_pass(_("Enter machine password: "), c->opt_stdin);
201 if (trust_pw == NULL) {
203 _("Error in reading machine password\n"));
207 status = secrets_prepare_password_change(lp_workgroup(),
212 if (!NT_STATUS_IS_OK(status)) {
214 _("Unable to write the machine account password in the secrets database"));
219 _("Pending machine account password change found - aborting."));
220 status = secrets_failed_password_change("localhost",
221 NT_STATUS_REQUEST_NOT_ACCEPTED,
222 NT_STATUS_NOT_COMMITTED,
224 if (!NT_STATUS_IS_OK(status)) {
226 _("Failed to abort machine account password change"));
230 status = secrets_finish_password_change("localhost", now, info);
231 if (!NT_STATUS_IS_OK(status)) {
233 _("Unable to write the machine account password in the secrets database"));
237 d_printf(_("Modified trust account password in secrets database\n"));
240 d_printf(_("Machine account password change requires the -f flag.\n"
241 "Do NOT use this function unless you know what it does!\n"
242 "This function will change the ADS Domain member "
243 "machine account password in the secrets.tdb file!\n"));
250 * @brief Set the authorised user for winbindd access in secrets.tdb
252 static int net_setauthuser(struct net_context *c, int argc, const char **argv)
254 const char *password = NULL;
256 if (!secrets_init()) {
257 d_fprintf(stderr, _("Failed to open secrets.tdb.\n"));
261 /* Delete the settings. */
263 if (strncmp(argv[0], "delete", 6) != 0) {
264 d_fprintf(stderr,_("Usage:\n"));
266 _(" net setauthuser -U user[%%password] \n"
267 " Set the auth user account to user"
268 "password. Prompt for password if not "
271 _(" net setauthuser delete\n"
272 " Delete the auth user setting.\n"));
275 secrets_delete_entry(SECRETS_AUTH_USER);
276 secrets_delete_entry(SECRETS_AUTH_DOMAIN);
277 secrets_delete_entry(SECRETS_AUTH_PASSWORD);
281 if (!c->opt_user_specified) {
282 d_fprintf(stderr, _("Usage:\n"));
284 _(" net setauthuser -U user[%%password]\n"
285 " Set the auth user account to user"
286 "password. Prompt for password if not "
289 _(" net setauthuser delete\n"
290 " Delete the auth user setting.\n"));
294 password = net_prompt_pass(c, _("the auth user"));
295 if (password == NULL) {
296 d_fprintf(stderr,_("Failed to get the auth users password.\n"));
300 if (!secrets_store(SECRETS_AUTH_USER, c->opt_user_name,
301 strlen(c->opt_user_name) + 1)) {
302 d_fprintf(stderr, _("error storing auth user name\n"));
306 if (!secrets_store(SECRETS_AUTH_DOMAIN, c->opt_workgroup,
307 strlen(c->opt_workgroup) + 1)) {
308 d_fprintf(stderr, _("error storing auth user domain\n"));
312 if (!secrets_store(SECRETS_AUTH_PASSWORD, password,
313 strlen(password) + 1)) {
314 d_fprintf(stderr, _("error storing auth user password\n"));
322 * @brief Get the auth user settings
324 static int net_getauthuser(struct net_context *c, int argc, const char **argv)
326 char *user, *domain, *password;
328 /* Lift data from secrets file */
330 secrets_fetch_ipc_userpass(&user, &domain, &password);
332 if ((!user || !*user) && (!domain || !*domain ) &&
333 (!password || !*password)){
338 d_printf(_("No authorised user configured\n"));
342 /* Pretty print authorised user info */
344 d_printf("%s%s%s%s%s\n", domain ? domain : "",
345 domain ? lp_winbind_separator(): "", user,
346 password ? "%" : "", password ? password : "");
355 Retrieve our local SID or the SID for the specified name
357 static int net_getlocalsid(struct net_context *c, int argc, const char **argv)
367 name = lp_netbios_name();
370 if(!initialize_password_db(false, NULL)) {
371 d_fprintf(stderr, _("WARNING: Could not open passdb\n"));
375 /* first check to see if we can even access secrets, so we don't
376 panic when we can't. */
378 if (!secrets_init()) {
380 _("Unable to open secrets.tdb. Can't fetch domain "
381 "SID for name: %s\n"), name);
385 /* Generate one, if it doesn't exist */
386 get_global_sam_sid();
388 if (!secrets_fetch_domain_sid(name, &sid)) {
389 DEBUG(0, ("Can't fetch domain SID for name: %s\n", name));
392 sid_to_fstring(sid_str, &sid);
393 d_printf(_("SID for domain %s is: %s\n"), name, sid_str);
397 static int net_setlocalsid(struct net_context *c, int argc, const char **argv)
402 || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
403 || (!string_to_sid(&sid, argv[0]))
404 || (sid.num_auths != 4)) {
405 d_printf(_("Usage:"));
406 d_printf(" net setlocalsid S-1-5-21-x-y-z\n");
410 if (!secrets_store_domain_sid(lp_netbios_name(), &sid)) {
411 DEBUG(0,("Can't store domain SID as a pdc/bdc.\n"));
418 static int net_setdomainsid(struct net_context *c, int argc, const char **argv)
423 || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
424 || (!string_to_sid(&sid, argv[0]))
425 || (sid.num_auths != 4)) {
426 d_printf(_("Usage:"));
427 d_printf(" net setdomainsid S-1-5-21-x-y-z\n");
431 if (!secrets_store_domain_sid(lp_workgroup(), &sid)) {
432 DEBUG(0,("Can't store domain SID.\n"));
439 static int net_getdomainsid(struct net_context *c, int argc, const char **argv)
441 struct dom_sid domain_sid;
445 d_printf(_("Usage:"));
446 d_printf(" net getdomainsid\n");
450 if(!initialize_password_db(false, NULL)) {
451 d_fprintf(stderr, _("WARNING: Could not open passdb\n"));
455 /* first check to see if we can even access secrets, so we don't
456 panic when we can't. */
458 if (!secrets_init()) {
459 d_fprintf(stderr, _("Unable to open secrets.tdb. Can't fetch "
460 "domain SID for name: %s\n"),
461 get_global_sam_name());
465 /* Generate one, if it doesn't exist */
466 get_global_sam_sid();
469 if (!secrets_fetch_domain_sid(lp_netbios_name(), &domain_sid)) {
470 d_fprintf(stderr, _("Could not fetch local SID\n"));
473 sid_to_fstring(sid_str, &domain_sid);
474 d_printf(_("SID for local machine %s is: %s\n"),
475 lp_netbios_name(), sid_str);
477 if (!secrets_fetch_domain_sid(c->opt_workgroup, &domain_sid)) {
478 d_fprintf(stderr, _("Could not fetch domain SID\n"));
482 sid_to_fstring(sid_str, &domain_sid);
483 d_printf(_("SID for domain %s is: %s\n"), c->opt_workgroup, sid_str);
488 static bool search_maxrid(struct pdb_search *search, const char *type,
491 struct samr_displayentry *entries;
492 uint32_t i, num_entries;
494 if (search == NULL) {
495 d_fprintf(stderr, _("get_maxrid: Could not search %s\n"), type);
499 num_entries = pdb_search_entries(search, 0, 0xffffffff, &entries);
500 for (i=0; i<num_entries; i++)
501 *max_rid = MAX(*max_rid, entries[i].rid);
506 static uint32_t get_maxrid(void)
508 uint32_t max_rid = 0;
510 if (!search_maxrid(pdb_search_users(talloc_tos(), 0), "users", &max_rid))
513 if (!search_maxrid(pdb_search_groups(talloc_tos()), "groups", &max_rid))
516 if (!search_maxrid(pdb_search_aliases(talloc_tos(),
517 get_global_sam_sid()),
518 "aliases", &max_rid))
524 static int net_maxrid(struct net_context *c, int argc, const char **argv)
529 d_fprintf(stderr, "%s net maxrid\n", _("Usage:"));
533 if ((rid = get_maxrid()) == 0) {
534 d_fprintf(stderr, _("can't get current maximum rid\n"));
538 d_printf(_("Currently used maximum rid: %d\n"), rid);
543 /* main function table */
544 static struct functable net_func[] = {
549 N_("Run functions using RPC transport"),
550 N_(" Use 'net help rpc' to get more extensive information "
551 "about 'net rpc' commands.")
557 N_("Run functions using RAP transport"),
558 N_(" Use 'net help rap' to get more extensive information "
559 "about 'net rap' commands.")
565 N_("Run functions using ADS transport"),
566 N_(" Use 'net help ads' to get more extensive information "
567 "about 'net ads' commands.")
570 /* eventually these should auto-choose the transport ... */
574 NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
575 N_("Functions on remote opened files"),
576 N_(" Use 'net help file' to get more information about 'net "
582 NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
583 N_("Functions on shares"),
584 N_(" Use 'net help share' to get more information about 'net "
591 N_("Manage sessions"),
592 N_(" Use 'net help session' to get more information about "
593 "'net session' commands.")
599 N_("List servers in workgroup"),
600 N_(" Use 'net help server' to get more information about 'net "
607 N_("List domains/workgroups on network"),
608 N_(" Use 'net help domain' to get more information about 'net "
615 N_("Modify printer queue"),
616 N_(" Use 'net help printq' to get more information about 'net "
622 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
624 N_(" Use 'net help user' to get more information about 'net "
630 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
632 N_(" Use 'net help group' to get more information about 'net "
639 N_("Manage group mappings"),
640 N_(" Use 'net help groupmap' to get more information about "
641 "'net groupmap' commands.")
647 N_("Functions on the SAM database"),
648 N_(" Use 'net help sam' to get more information about 'net "
655 N_("Validate username and password"),
656 N_(" Use 'net help validate' to get more information about "
657 "'net validate' commands.")
663 N_("Modify group memberships"),
664 N_(" Use 'net help groupmember' to get more information about "
665 "'net groupmember' commands.")
670 N_("Execute remote command on a remote OS/2 server"),
671 N_(" Use 'net help admin' to get more information about 'net "
677 N_("List/modify running services"),
678 N_(" Use 'net help service' to get more information about "
679 "'net service' commands.")
685 N_("Change user password on target server"),
686 N_(" Use 'net help password' to get more information about "
687 "'net password' commands.")
693 N_("Run functions related to the primary workstation trust."),
694 N_(" Use 'net help primarytrust' to get more extensive information "
695 "about 'net primarytrust' commands.")
699 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC,
700 N_("Change the trust password"),
701 N_(" Use 'net help changetrustpw' to get more information "
702 "about 'net changetrustpw'.")
707 N_("Change the secret password"),
708 N_(" net [options] changesecretpw\n"
709 " Change the ADS domain member machine account password "
711 " Do NOT use this function unless you know what it does.\n"
712 " Requires the -f flag to work.")
718 N_("Set the winbind auth user"),
719 N_(" net -U user[%%password] [-W domain] setauthuser\n"
720 " Set the auth user, password (and optionally domain\n"
721 " Will prompt for password if not given.\n"
722 " net setauthuser delete\n"
723 " Delete the existing auth user settings.")
729 N_("Get the winbind auth user settings"),
730 N_(" net getauthuser\n"
731 " Get the current winbind auth user settings.")
737 N_(" Use 'net help time' to get more information about 'net "
743 N_("Look up host names/IP addresses"),
744 N_(" Use 'net help lookup' to get more information about 'net "
750 N_("Manipulate the global lock table"),
751 N_(" Use 'net help g_lock' to get more information about "
752 "'net g_lock' commands.")
756 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC,
757 N_("Join a domain/AD"),
758 N_(" Use 'net help join' to get more information about 'net "
764 N_("Join/unjoin (remote) machines to/from a domain/AD"),
765 N_(" Use 'net help dom' to get more information about 'net "
771 N_("Operate on the cache tdb file"),
772 N_(" Use 'net help cache' to get more information about 'net "
778 N_("Get the SID for the local domain"),
779 N_(" net getlocalsid")
784 N_("Set the SID for the local domain"),
785 N_(" net setlocalsid S-1-5-21-x-y-z")
790 N_("Set domain SID on member servers"),
791 N_(" net setdomainsid S-1-5-21-x-y-z")
796 N_("Get domain SID on member servers"),
797 N_(" net getdomainsid")
802 N_("Display the maximum RID currently used"),
808 N_("IDmap functions"),
809 N_(" Use 'net help idmap to get more information about 'net "
815 N_("Display server status"),
816 N_(" Use 'net help status' to get more information about 'net "
822 N_("Manage user-modifiable shares"),
823 N_(" Use 'net help usershare to get more information about "
824 "'net usershare' commands.")
829 N_("Display list of all users with SID"),
830 N_(" Use 'net help usersidlist' to get more information about "
831 "'net usersidlist'.")
836 N_("Manage Samba registry based configuration"),
837 N_(" Use 'net help conf' to get more information about 'net "
843 N_("Manage the Samba registry"),
844 N_(" Use 'net help registry' to get more information about "
845 "'net registry' commands.")
850 N_("Process Win32 *.evt eventlog files"),
851 N_(" Use 'net help eventlog' to get more information about "
852 "'net eventlog' commands.")
857 N_("Process tdb printer files"),
858 N_(" Use 'net help printing' to get more information about "
859 "'net printing' commands.")
865 N_("Manage the serverid tdb"),
866 N_(" Use 'net help serverid' to get more information about "
867 "'net serverid' commands.")
873 N_("notifyd client code"),
874 N_(" Use 'net help notify' to get more information about "
875 "'net notify' commands.")
881 N_("Show information from tdb records"),
882 N_(" Use 'net help tdb' to get more information about "
883 "'net tdb' commands.")
886 #ifdef WITH_FAKE_KASERVER
890 N_("Manage AFS tokens"),
891 N_(" Use 'net help afs' to get more information about 'net "
899 N_("Print usage information"),
900 N_(" Use 'net help help' to list usage information for 'net' "
903 {NULL, NULL, 0, NULL, NULL}
907 /****************************************************************************
909 ****************************************************************************/
910 int main(int argc, char **argv)
916 const char ** argv_new;
917 const char **argv_const = discard_const_p(const char *, argv);
919 TALLOC_CTX *frame = talloc_stackframe();
920 struct net_context *c = talloc_zero(frame, struct net_context);
922 struct poptOption long_options[] = {
923 {"help", 'h', POPT_ARG_NONE, 0, 'h'},
924 {"workgroup", 'w', POPT_ARG_STRING, &c->opt_target_workgroup},
925 {"user", 'U', POPT_ARG_STRING, &c->opt_user_name, 'U'},
926 {"ipaddress", 'I', POPT_ARG_STRING, 0,'I'},
927 {"port", 'p', POPT_ARG_INT, &c->opt_port},
928 {"myname", 'n', POPT_ARG_STRING, &c->opt_requester_name},
929 {"server", 'S', POPT_ARG_STRING, &c->opt_host},
930 {"encrypt", 'e', POPT_ARG_NONE, NULL, 'e', N_("Encrypt SMB transport") },
931 {"container", 'c', POPT_ARG_STRING, &c->opt_container},
932 {"comment", 'C', POPT_ARG_STRING, &c->opt_comment},
933 {"maxusers", 'M', POPT_ARG_INT, &c->opt_maxusers},
934 {"flags", 'F', POPT_ARG_INT, &c->opt_flags},
935 {"long", 'l', POPT_ARG_NONE, &c->opt_long_list_entries},
936 {"reboot", 'r', POPT_ARG_NONE, &c->opt_reboot},
937 {"force", 'f', POPT_ARG_NONE, &c->opt_force},
938 {"stdin", 'i', POPT_ARG_NONE, &c->opt_stdin},
939 {"timeout", 't', POPT_ARG_INT, &c->opt_timeout},
940 {"request-timeout",0,POPT_ARG_INT, &c->opt_request_timeout},
941 {"machine-pass",'P', POPT_ARG_NONE, &c->opt_machine_pass},
942 {"kerberos", 'k', POPT_ARG_NONE, &c->opt_kerberos},
943 {"myworkgroup", 'W', POPT_ARG_STRING, &c->opt_workgroup},
944 {"use-ccache", 0, POPT_ARG_NONE, &c->opt_ccache},
945 {"verbose", 'v', POPT_ARG_NONE, &c->opt_verbose},
946 {"test", 'T', POPT_ARG_NONE, &c->opt_testmode},
947 /* Options for 'net groupmap set' */
948 {"local", 'L', POPT_ARG_NONE, &c->opt_localgroup},
949 {"domain", 'D', POPT_ARG_NONE, &c->opt_domaingroup},
950 {"ntname", 'N', POPT_ARG_STRING, &c->opt_newntname},
951 {"rid", 'R', POPT_ARG_INT, &c->opt_rid},
952 /* Options for 'net rpc share migrate' */
953 {"acls", 0, POPT_ARG_NONE, &c->opt_acls},
954 {"attrs", 0, POPT_ARG_NONE, &c->opt_attrs},
955 {"timestamps", 0, POPT_ARG_NONE, &c->opt_timestamps},
956 {"exclude", 'X', POPT_ARG_STRING, &c->opt_exclude},
957 {"destination", 0, POPT_ARG_STRING, &c->opt_destination},
958 {"tallocreport", 0, POPT_ARG_NONE, &c->do_talloc_report},
959 /* Options for 'net rpc vampire (keytab)' */
960 {"force-full-repl", 0, POPT_ARG_NONE, &c->opt_force_full_repl},
961 {"single-obj-repl", 0, POPT_ARG_NONE, &c->opt_single_obj_repl},
962 {"clean-old-entries", 0, POPT_ARG_NONE, &c->opt_clean_old_entries},
963 /* Options for 'net idmap'*/
964 {"db", 0, POPT_ARG_STRING, &c->opt_db},
965 {"lock", 0, POPT_ARG_NONE, &c->opt_lock},
966 {"auto", 'a', POPT_ARG_NONE, &c->opt_auto},
967 {"repair", 0, POPT_ARG_NONE, &c->opt_repair},
968 /* Options for 'net registry check'*/
969 {"reg-version", 0, POPT_ARG_INT, &c->opt_reg_version},
970 {"output", 'o', POPT_ARG_STRING, &c->opt_output},
971 {"wipe", 0, POPT_ARG_NONE, &c->opt_wipe},
972 /* Options for 'net registry import' */
973 {"precheck", 0, POPT_ARG_STRING, &c->opt_precheck},
974 /* Options for 'net ads join or leave' */
975 {"no-dns-updates", 0, POPT_ARG_NONE, &c->opt_no_dns_updates},
976 {"keep-account", 0, POPT_ARG_NONE, &c->opt_keep_account},
977 {"json", 0, POPT_ARG_NONE, &c->opt_json},
982 zero_sockaddr(&c->opt_dest_ip);
984 setup_logging(argv[0], DEBUG_STDERR);
988 setlocale(LC_ALL, "");
989 #if defined(HAVE_BINDTEXTDOMAIN)
990 bindtextdomain(MODULE_NAME, get_dyn_LOCALEDIR());
992 #if defined(HAVE_TEXTDOMAIN)
993 textdomain(MODULE_NAME);
996 /* set default debug level to 0 regardless of what smb.conf sets */
997 lp_set_cmdline("log level", "0");
998 c->private_data = net_func;
1000 pc = poptGetContext(NULL, argc, argv_const, long_options,
1001 POPT_CONTEXT_KEEP_FIRST);
1003 while((opt = poptGetNextOpt(pc)) != -1) {
1006 c->display_usage = true;
1009 c->smb_encrypt = true;
1012 if (!interpret_string_addr(&c->opt_dest_ip,
1013 poptGetOptArg(pc), 0)) {
1014 d_fprintf(stderr, _("\nInvalid ip address specified\n"));
1016 c->opt_have_ip = true;
1020 c->opt_user_specified = true;
1021 c->opt_user_name = talloc_strdup(c, c->opt_user_name);
1022 p = strchr(c->opt_user_name,'%');
1025 c->opt_password = p+1;
1029 d_fprintf(stderr, _("\nInvalid option %s: %s\n"),
1030 poptBadOption(pc, 0), poptStrerror(opt));
1031 net_help(c, argc, argv_const);
1036 c->msg_ctx = cmdline_messaging_context(get_dyn_CONFIGFILE());
1038 if (!lp_load_global(get_dyn_CONFIGFILE())) {
1039 d_fprintf(stderr, "Can't load %s - run testparm to debug it\n",
1040 get_dyn_CONFIGFILE());
1044 #if defined(HAVE_BIND_TEXTDOMAIN_CODESET)
1045 /* Bind our gettext results to 'unix charset'
1047 This ensures that the translations and any embedded strings are in the
1048 same charset. It won't be the one from the user's locale (we no
1049 longer auto-detect that), but it will be self-consistent.
1051 bind_textdomain_codeset(MODULE_NAME, lp_unix_charset());
1054 argv_new = (const char **)poptGetArgs(pc);
1057 for (i=0; i<argc; i++) {
1058 if (argv_new[i] == NULL) {
1064 if (c->do_talloc_report) {
1065 talloc_enable_leak_report();
1068 if (c->opt_requester_name) {
1069 lp_set_cmdline("netbios name", c->opt_requester_name);
1072 if (!c->opt_user_name && getenv("LOGNAME")) {
1073 c->opt_user_name = getenv("LOGNAME");
1076 if (!c->opt_workgroup) {
1077 c->opt_workgroup = talloc_strdup(c, lp_workgroup());
1080 if (!c->opt_target_workgroup) {
1081 c->opt_target_workgroup = talloc_strdup(c, lp_workgroup());
1089 /* this makes sure that when we do things like call scripts,
1090 that it won't assert because we are not root */
1093 if (c->opt_machine_pass) {
1094 /* it is very useful to be able to make ads queries as the
1095 machine account for testing purposes and for domain leave */
1097 net_use_krb_machine_account(c);
1100 if (!c->opt_password) {
1101 c->opt_password = getenv("PASSWD");
1104 popt_burn_cmdline_password(argc, argv);
1106 rc = net_run_function(c, argc_new-1, argv_new+1, "net", net_func);
1108 DEBUG(2,("return code = %d\n", rc));
1110 gencache_stabilize();
1112 libnetapi_free(c->netapi_ctx);
1114 poptFreeContext(pc);