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[] = {
159 .funcname = "dumpinfo",
160 .fn = net_primarytrust_dumpinfo,
161 .valid_transports = NET_TRANSPORT_LOCAL,
162 .description = N_("Dump the details of the "
163 "workstation trust"),
164 .usage = N_(" net [options] primarytrust "
166 " Dump the details of the "
167 "workstation trust in "
169 " Requires the -f flag to "
170 "include the password values."),
177 return net_run_function(c, argc, argv, "net primarytrust", func);
180 static int net_changesecretpw(struct net_context *c, int argc,
184 int role = lp_server_role();
186 if (role != ROLE_DOMAIN_MEMBER) {
187 d_printf(_("Machine account password change only supported on a DOMAIN_MEMBER.\n"
188 "Do NOT use this function unless you know what it does!\n"
189 "This function will change the ADS Domain member "
190 "machine account password in the secrets.tdb file!\n"));
195 struct secrets_domain_info1 *info = NULL;
196 struct secrets_domain_info1_change *prev = NULL;
198 struct timeval tv = timeval_current();
199 NTTIME now = timeval_to_nttime(&tv);
202 set_line_buffering(stdin);
203 set_line_buffering(stdout);
204 set_line_buffering(stderr);
207 trust_pw = get_pass(_("Enter machine password: "), c->opt_stdin);
208 if (trust_pw == NULL) {
210 _("Error in reading machine password\n"));
214 status = secrets_prepare_password_change(lp_workgroup(),
219 if (!NT_STATUS_IS_OK(status)) {
221 _("Unable to write the machine account password in the secrets database"));
226 _("Pending machine account password change found - aborting."));
227 status = secrets_failed_password_change("localhost",
228 NT_STATUS_REQUEST_NOT_ACCEPTED,
229 NT_STATUS_NOT_COMMITTED,
231 if (!NT_STATUS_IS_OK(status)) {
233 _("Failed to abort machine account password change"));
237 status = secrets_finish_password_change("localhost", now, info);
238 if (!NT_STATUS_IS_OK(status)) {
240 _("Unable to write the machine account password in the secrets database"));
244 d_printf(_("Modified trust account password in secrets database\n"));
247 d_printf(_("Machine account password change requires the -f flag.\n"
248 "Do NOT use this function unless you know what it does!\n"
249 "This function will change the ADS Domain member "
250 "machine account password in the secrets.tdb file!\n"));
257 * @brief Set the authorised user for winbindd access in secrets.tdb
259 static int net_setauthuser(struct net_context *c, int argc, const char **argv)
261 const char *password = NULL;
263 if (!secrets_init()) {
264 d_fprintf(stderr, _("Failed to open secrets.tdb.\n"));
268 /* Delete the settings. */
270 if (strncmp(argv[0], "delete", 6) != 0) {
271 d_fprintf(stderr,_("Usage:\n"));
273 _(" net setauthuser -U user[%%password] \n"
274 " Set the auth user account to user"
275 "password. Prompt for password if not "
278 _(" net setauthuser delete\n"
279 " Delete the auth user setting.\n"));
282 secrets_delete_entry(SECRETS_AUTH_USER);
283 secrets_delete_entry(SECRETS_AUTH_DOMAIN);
284 secrets_delete_entry(SECRETS_AUTH_PASSWORD);
288 if (!c->opt_user_specified) {
289 d_fprintf(stderr, _("Usage:\n"));
291 _(" net setauthuser -U user[%%password]\n"
292 " Set the auth user account to user"
293 "password. Prompt for password if not "
296 _(" net setauthuser delete\n"
297 " Delete the auth user setting.\n"));
301 password = net_prompt_pass(c, _("the auth user"));
302 if (password == NULL) {
303 d_fprintf(stderr,_("Failed to get the auth users password.\n"));
307 if (!secrets_store(SECRETS_AUTH_USER, c->opt_user_name,
308 strlen(c->opt_user_name) + 1)) {
309 d_fprintf(stderr, _("error storing auth user name\n"));
313 if (!secrets_store(SECRETS_AUTH_DOMAIN, c->opt_workgroup,
314 strlen(c->opt_workgroup) + 1)) {
315 d_fprintf(stderr, _("error storing auth user domain\n"));
319 if (!secrets_store(SECRETS_AUTH_PASSWORD, password,
320 strlen(password) + 1)) {
321 d_fprintf(stderr, _("error storing auth user password\n"));
329 * @brief Get the auth user settings
331 static int net_getauthuser(struct net_context *c, int argc, const char **argv)
333 char *user, *domain, *password;
335 /* Lift data from secrets file */
337 secrets_fetch_ipc_userpass(&user, &domain, &password);
339 if ((!user || !*user) && (!domain || !*domain ) &&
340 (!password || !*password)){
345 d_printf(_("No authorised user configured\n"));
349 /* Pretty print authorised user info */
351 d_printf("%s%s%s%s%s\n", domain ? domain : "",
352 domain ? lp_winbind_separator(): "", user,
353 password ? "%" : "", password ? password : "");
362 Retrieve our local SID or the SID for the specified name
364 static int net_getlocalsid(struct net_context *c, int argc, const char **argv)
368 struct dom_sid_buf sid_str;
374 name = lp_netbios_name();
377 if(!initialize_password_db(false, NULL)) {
378 d_fprintf(stderr, _("WARNING: Could not open passdb\n"));
382 /* first check to see if we can even access secrets, so we don't
383 panic when we can't. */
385 if (!secrets_init()) {
387 _("Unable to open secrets.tdb. Can't fetch domain "
388 "SID for name: %s\n"), name);
392 /* Generate one, if it doesn't exist */
393 get_global_sam_sid();
395 if (!secrets_fetch_domain_sid(name, &sid)) {
396 DEBUG(0, ("Can't fetch domain SID for name: %s\n", name));
399 d_printf(_("SID for domain %s is: %s\n"),
401 dom_sid_str_buf(&sid, &sid_str));
405 static int net_setlocalsid(struct net_context *c, int argc, const char **argv)
410 || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
411 || (!string_to_sid(&sid, argv[0]))
412 || (sid.num_auths != 4)) {
413 d_printf(_("Usage:"));
414 d_printf(" net setlocalsid S-1-5-21-x-y-z\n");
418 if (!secrets_store_domain_sid(lp_netbios_name(), &sid)) {
419 DEBUG(0,("Can't store domain SID as a pdc/bdc.\n"));
426 static int net_setdomainsid(struct net_context *c, int argc, const char **argv)
431 || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
432 || (!string_to_sid(&sid, argv[0]))
433 || (sid.num_auths != 4)) {
434 d_printf(_("Usage:"));
435 d_printf(" net setdomainsid S-1-5-21-x-y-z\n");
439 if (!secrets_store_domain_sid(lp_workgroup(), &sid)) {
440 DEBUG(0,("Can't store domain SID.\n"));
447 static int net_getdomainsid(struct net_context *c, int argc, const char **argv)
449 struct dom_sid domain_sid;
450 struct dom_sid_buf sid_str;
453 d_printf(_("Usage:"));
454 d_printf(" net getdomainsid\n");
458 if(!initialize_password_db(false, NULL)) {
459 d_fprintf(stderr, _("WARNING: Could not open passdb\n"));
463 /* first check to see if we can even access secrets, so we don't
464 panic when we can't. */
466 if (!secrets_init()) {
467 d_fprintf(stderr, _("Unable to open secrets.tdb. Can't fetch "
468 "domain SID for name: %s\n"),
469 get_global_sam_name());
473 /* Generate one, if it doesn't exist */
474 get_global_sam_sid();
477 if (!secrets_fetch_domain_sid(lp_netbios_name(), &domain_sid)) {
478 d_fprintf(stderr, _("Could not fetch local SID\n"));
481 d_printf(_("SID for local machine %s is: %s\n"),
483 dom_sid_str_buf(&domain_sid, &sid_str));
485 if (!secrets_fetch_domain_sid(c->opt_workgroup, &domain_sid)) {
486 d_fprintf(stderr, _("Could not fetch domain SID\n"));
490 d_printf(_("SID for domain %s is: %s\n"),
492 dom_sid_str_buf(&domain_sid, &sid_str));
497 static bool search_maxrid(struct pdb_search *search, const char *type,
500 struct samr_displayentry *entries;
501 uint32_t i, num_entries;
503 if (search == NULL) {
504 d_fprintf(stderr, _("get_maxrid: Could not search %s\n"), type);
508 num_entries = pdb_search_entries(search, 0, 0xffffffff, &entries);
509 for (i=0; i<num_entries; i++)
510 *max_rid = MAX(*max_rid, entries[i].rid);
515 static uint32_t get_maxrid(void)
517 uint32_t max_rid = 0;
519 if (!search_maxrid(pdb_search_users(talloc_tos(), 0), "users", &max_rid))
522 if (!search_maxrid(pdb_search_groups(talloc_tos()), "groups", &max_rid))
525 if (!search_maxrid(pdb_search_aliases(talloc_tos(),
526 get_global_sam_sid()),
527 "aliases", &max_rid))
533 static int net_maxrid(struct net_context *c, int argc, const char **argv)
538 d_fprintf(stderr, "%s net maxrid\n", _("Usage:"));
542 if ((rid = get_maxrid()) == 0) {
543 d_fprintf(stderr, _("can't get current maximum rid\n"));
547 d_printf(_("Currently used maximum rid: %d\n"), rid);
552 /* main function table */
553 static struct functable net_func[] = {
558 N_("Run functions using RPC transport"),
559 N_(" Use 'net help rpc' to get more extensive information "
560 "about 'net rpc' commands.")
566 N_("Run functions using RAP transport"),
567 N_(" Use 'net help rap' to get more extensive information "
568 "about 'net rap' commands.")
574 N_("Run functions using ADS transport"),
575 N_(" Use 'net help ads' to get more extensive information "
576 "about 'net ads' commands.")
579 /* eventually these should auto-choose the transport ... */
583 NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
584 N_("Functions on remote opened files"),
585 N_(" Use 'net help file' to get more information about 'net "
591 NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
592 N_("Functions on shares"),
593 N_(" Use 'net help share' to get more information about 'net "
600 N_("Manage sessions"),
601 N_(" Use 'net help session' to get more information about "
602 "'net session' commands.")
608 N_("List servers in workgroup"),
609 N_(" Use 'net help server' to get more information about 'net "
616 N_("List domains/workgroups on network"),
617 N_(" Use 'net help domain' to get more information about 'net "
624 N_("Modify printer queue"),
625 N_(" Use 'net help printq' to get more information about 'net "
631 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
633 N_(" Use 'net help user' to get more information about 'net "
639 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
641 N_(" Use 'net help group' to get more information about 'net "
648 N_("Manage group mappings"),
649 N_(" Use 'net help groupmap' to get more information about "
650 "'net groupmap' commands.")
656 N_("Functions on the SAM database"),
657 N_(" Use 'net help sam' to get more information about 'net "
664 N_("Validate username and password"),
665 N_(" Use 'net help validate' to get more information about "
666 "'net validate' commands.")
672 N_("Modify group memberships"),
673 N_(" Use 'net help groupmember' to get more information about "
674 "'net groupmember' commands.")
679 N_("Execute remote command on a remote OS/2 server"),
680 N_(" Use 'net help admin' to get more information about 'net "
686 N_("List/modify running services"),
687 N_(" Use 'net help service' to get more information about "
688 "'net service' commands.")
694 N_("Change user password on target server"),
695 N_(" Use 'net help password' to get more information about "
696 "'net password' commands.")
702 N_("Run functions related to the primary workstation trust."),
703 N_(" Use 'net help primarytrust' to get more extensive information "
704 "about 'net primarytrust' commands.")
708 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC,
709 N_("Change the trust password"),
710 N_(" Use 'net help changetrustpw' to get more information "
711 "about 'net changetrustpw'.")
716 N_("Change the secret password"),
717 N_(" net [options] changesecretpw\n"
718 " Change the ADS domain member machine account password "
720 " Do NOT use this function unless you know what it does.\n"
721 " Requires the -f flag to work.")
727 N_("Set the winbind auth user"),
728 N_(" net -U user[%%password] [-W domain] setauthuser\n"
729 " Set the auth user, password (and optionally domain\n"
730 " Will prompt for password if not given.\n"
731 " net setauthuser delete\n"
732 " Delete the existing auth user settings.")
738 N_("Get the winbind auth user settings"),
739 N_(" net getauthuser\n"
740 " Get the current winbind auth user settings.")
746 N_(" Use 'net help time' to get more information about 'net "
752 N_("Look up host names/IP addresses"),
753 N_(" Use 'net help lookup' to get more information about 'net "
759 N_("Manipulate the global lock table"),
760 N_(" Use 'net help g_lock' to get more information about "
761 "'net g_lock' commands.")
765 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC,
766 N_("Join a domain/AD"),
767 N_(" Use 'net help join' to get more information about 'net "
773 N_("Join/unjoin (remote) machines to/from a domain/AD"),
774 N_(" Use 'net help dom' to get more information about 'net "
780 N_("Operate on the cache tdb file"),
781 N_(" Use 'net help cache' to get more information about 'net "
787 N_("Get the SID for the local domain"),
788 N_(" net getlocalsid")
793 N_("Set the SID for the local domain"),
794 N_(" net setlocalsid S-1-5-21-x-y-z")
799 N_("Set domain SID on member servers"),
800 N_(" net setdomainsid S-1-5-21-x-y-z")
805 N_("Get domain SID on member servers"),
806 N_(" net getdomainsid")
811 N_("Display the maximum RID currently used"),
817 N_("IDmap functions"),
818 N_(" Use 'net help idmap to get more information about 'net "
824 N_("Display server status"),
825 N_(" Use 'net help status' to get more information about 'net "
831 N_("Manage user-modifiable shares"),
832 N_(" Use 'net help usershare to get more information about "
833 "'net usershare' commands.")
838 N_("Display list of all users with SID"),
839 N_(" Use 'net help usersidlist' to get more information about "
840 "'net usersidlist'.")
845 N_("Manage Samba registry based configuration"),
846 N_(" Use 'net help conf' to get more information about 'net "
852 N_("Manage the Samba registry"),
853 N_(" Use 'net help registry' to get more information about "
854 "'net registry' commands.")
859 N_("Process Win32 *.evt eventlog files"),
860 N_(" Use 'net help eventlog' to get more information about "
861 "'net eventlog' commands.")
866 N_("Process tdb printer files"),
867 N_(" Use 'net help printing' to get more information about "
868 "'net printing' commands.")
874 N_("Manage the serverid tdb"),
875 N_(" Use 'net help serverid' to get more information about "
876 "'net serverid' commands.")
882 N_("notifyd client code"),
883 N_(" Use 'net help notify' to get more information about "
884 "'net notify' commands.")
890 N_("Show information from tdb records"),
891 N_(" Use 'net help tdb' to get more information about "
892 "'net tdb' commands.")
895 #ifdef WITH_FAKE_KASERVER
899 N_("Manage AFS tokens"),
900 N_(" Use 'net help afs' to get more information about 'net "
908 N_("Print usage information"),
909 N_(" Use 'net help help' to list usage information for 'net' "
912 {NULL, NULL, 0, NULL, NULL}
916 static void get_credentials_file(struct net_context *c,
919 struct cli_credentials *cred = cli_credentials_init(c);
922 d_printf("ERROR: Unable to allocate memory!\n");
926 if (!cli_credentials_parse_file(cred, file, CRED_GUESS_FILE)) {
930 c->opt_user_name = cli_credentials_get_username(cred);
931 c->opt_user_specified = (c->opt_user_name != NULL);
932 c->opt_password = cli_credentials_get_password(cred);
933 c->opt_target_workgroup = cli_credentials_get_domain(cred);
936 /****************************************************************************
938 ****************************************************************************/
939 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);
951 struct poptOption long_options[] = {
955 .argInfo = POPT_ARG_NONE,
959 .longName = "workgroup",
961 .argInfo = POPT_ARG_STRING,
962 .arg = &c->opt_target_workgroup,
967 .argInfo = POPT_ARG_STRING,
968 .arg = &c->opt_user_name,
972 .longName = "authentication-file",
974 .argInfo = POPT_ARG_STRING,
975 .arg = &c->opt_user_name,
977 .descrip = "Get the credentials from a file",
978 .argDescrip = "FILE",
981 .longName = "ipaddress",
983 .argInfo = POPT_ARG_STRING,
990 .argInfo = POPT_ARG_INT,
994 .longName = "myname",
996 .argInfo = POPT_ARG_STRING,
997 .arg = &c->opt_requester_name,
1000 .longName = "server",
1002 .argInfo = POPT_ARG_STRING,
1003 .arg = &c->opt_host,
1006 .longName = "encrypt",
1008 .argInfo = POPT_ARG_NONE,
1011 .descrip = N_("Encrypt SMB transport"),
1014 .longName = "container",
1016 .argInfo = POPT_ARG_STRING,
1017 .arg = &c->opt_container,
1020 .longName = "comment",
1022 .argInfo = POPT_ARG_STRING,
1023 .arg = &c->opt_comment,
1026 .longName = "maxusers",
1028 .argInfo = POPT_ARG_INT,
1029 .arg = &c->opt_maxusers,
1032 .longName = "flags",
1034 .argInfo = POPT_ARG_INT,
1035 .arg = &c->opt_flags,
1040 .argInfo = POPT_ARG_NONE,
1041 .arg = &c->opt_long_list_entries,
1044 .longName = "reboot",
1046 .argInfo = POPT_ARG_NONE,
1047 .arg = &c->opt_reboot,
1050 .longName = "force",
1052 .argInfo = POPT_ARG_NONE,
1053 .arg = &c->opt_force,
1056 .longName = "stdin",
1058 .argInfo = POPT_ARG_NONE,
1059 .arg = &c->opt_stdin,
1062 .longName = "timeout",
1064 .argInfo = POPT_ARG_INT,
1065 .arg = &c->opt_timeout,
1068 .longName = "request-timeout",
1070 .argInfo = POPT_ARG_INT,
1071 .arg = &c->opt_request_timeout,
1074 .longName = "machine-pass",
1076 .argInfo = POPT_ARG_NONE,
1077 .arg = &c->opt_machine_pass,
1080 .longName = "kerberos",
1082 .argInfo = POPT_ARG_NONE,
1083 .arg = &c->opt_kerberos,
1086 .longName = "myworkgroup",
1088 .argInfo = POPT_ARG_STRING,
1089 .arg = &c->opt_workgroup,
1092 .longName = "use-ccache",
1094 .argInfo = POPT_ARG_NONE,
1095 .arg = &c->opt_ccache,
1098 .longName = "verbose",
1100 .argInfo = POPT_ARG_NONE,
1101 .arg = &c->opt_verbose,
1106 .argInfo = POPT_ARG_NONE,
1107 .arg = &c->opt_testmode,
1109 /* Options for 'net groupmap set' */
1111 .longName = "local",
1113 .argInfo = POPT_ARG_NONE,
1114 .arg = &c->opt_localgroup,
1117 .longName = "domain",
1119 .argInfo = POPT_ARG_NONE,
1120 .arg = &c->opt_domaingroup,
1123 .longName = "ntname",
1125 .argInfo = POPT_ARG_STRING,
1126 .arg = &c->opt_newntname,
1131 .argInfo = POPT_ARG_INT,
1134 /* Options for 'net rpc share migrate' */
1138 .argInfo = POPT_ARG_NONE,
1139 .arg = &c->opt_acls,
1142 .longName = "attrs",
1144 .argInfo = POPT_ARG_NONE,
1145 .arg = &c->opt_attrs,
1148 .longName = "timestamps",
1150 .argInfo = POPT_ARG_NONE,
1151 .arg = &c->opt_timestamps,
1154 .longName = "exclude",
1156 .argInfo = POPT_ARG_STRING,
1157 .arg = &c->opt_exclude,
1160 .longName = "destination",
1162 .argInfo = POPT_ARG_STRING,
1163 .arg = &c->opt_destination,
1166 .longName = "tallocreport",
1168 .argInfo = POPT_ARG_NONE,
1169 .arg = &c->do_talloc_report,
1171 /* Options for 'net rpc vampire (keytab)' */
1173 .longName = "force-full-repl",
1175 .argInfo = POPT_ARG_NONE,
1176 .arg = &c->opt_force_full_repl,
1179 .longName = "single-obj-repl",
1181 .argInfo = POPT_ARG_NONE,
1182 .arg = &c->opt_single_obj_repl,
1185 .longName = "clean-old-entries",
1187 .argInfo = POPT_ARG_NONE,
1188 .arg = &c->opt_clean_old_entries,
1190 /* Options for 'net idmap'*/
1194 .argInfo = POPT_ARG_STRING,
1200 .argInfo = POPT_ARG_NONE,
1201 .arg = &c->opt_lock,
1206 .argInfo = POPT_ARG_NONE,
1207 .arg = &c->opt_auto,
1210 .longName = "repair",
1212 .argInfo = POPT_ARG_NONE,
1213 .arg = &c->opt_repair,
1215 /* Options for 'net registry check'*/
1217 .longName = "reg-version",
1219 .argInfo = POPT_ARG_INT,
1220 .arg = &c->opt_reg_version,
1223 .longName = "output",
1225 .argInfo = POPT_ARG_STRING,
1226 .arg = &c->opt_output,
1231 .argInfo = POPT_ARG_NONE,
1232 .arg = &c->opt_wipe,
1234 /* Options for 'net registry import' */
1236 .longName = "precheck",
1238 .argInfo = POPT_ARG_STRING,
1239 .arg = &c->opt_precheck,
1241 /* Options for 'net ads join or leave' */
1243 .longName = "no-dns-updates",
1245 .argInfo = POPT_ARG_NONE,
1246 .arg = &c->opt_no_dns_updates,
1249 .longName = "keep-account",
1251 .argInfo = POPT_ARG_NONE,
1252 .arg = &c->opt_keep_account,
1257 .argInfo = POPT_ARG_NONE,
1258 .arg = &c->opt_json,
1264 zero_sockaddr(&c->opt_dest_ip);
1266 setup_logging(argv[0], DEBUG_STDERR);
1270 setlocale(LC_ALL, "");
1271 #if defined(HAVE_BINDTEXTDOMAIN)
1272 bindtextdomain(MODULE_NAME, get_dyn_LOCALEDIR());
1274 #if defined(HAVE_TEXTDOMAIN)
1275 textdomain(MODULE_NAME);
1278 /* set default debug level to 0 regardless of what smb.conf sets */
1279 lp_set_cmdline("log level", "0");
1280 c->private_data = net_func;
1282 pc = poptGetContext(NULL, argc, argv_const, long_options,
1283 POPT_CONTEXT_KEEP_FIRST);
1285 while((opt = poptGetNextOpt(pc)) != -1) {
1288 c->display_usage = true;
1291 c->smb_encrypt = true;
1294 if (!interpret_string_addr(&c->opt_dest_ip,
1295 poptGetOptArg(pc), 0)) {
1296 d_fprintf(stderr, _("\nInvalid ip address specified\n"));
1298 c->opt_have_ip = true;
1302 c->opt_user_specified = true;
1303 c->opt_user_name = talloc_strdup(c, c->opt_user_name);
1304 p = strchr(c->opt_user_name,'%');
1307 c->opt_password = p+1;
1311 get_credentials_file(c, c->opt_user_name);
1314 d_fprintf(stderr, _("\nInvalid option %s: %s\n"),
1315 poptBadOption(pc, 0), poptStrerror(opt));
1316 net_help(c, argc, argv_const);
1321 c->msg_ctx = cmdline_messaging_context(get_dyn_CONFIGFILE());
1323 if (!lp_load_global(get_dyn_CONFIGFILE())) {
1324 d_fprintf(stderr, "Can't load %s - run testparm to debug it\n",
1325 get_dyn_CONFIGFILE());
1329 #if defined(HAVE_BIND_TEXTDOMAIN_CODESET)
1330 /* Bind our gettext results to 'unix charset'
1332 This ensures that the translations and any embedded strings are in the
1333 same charset. It won't be the one from the user's locale (we no
1334 longer auto-detect that), but it will be self-consistent.
1336 bind_textdomain_codeset(MODULE_NAME, lp_unix_charset());
1339 argv_new = (const char **)poptGetArgs(pc);
1342 for (i=0; i<argc; i++) {
1343 if (argv_new[i] == NULL) {
1349 if (c->do_talloc_report) {
1350 talloc_enable_leak_report();
1353 if (c->opt_requester_name) {
1354 lp_set_cmdline("netbios name", c->opt_requester_name);
1357 if (!c->opt_user_name && getenv("LOGNAME")) {
1358 c->opt_user_name = getenv("LOGNAME");
1361 if (!c->opt_workgroup) {
1362 c->opt_workgroup = talloc_strdup(c, lp_workgroup());
1365 if (!c->opt_target_workgroup) {
1366 c->opt_target_workgroup = talloc_strdup(c, lp_workgroup());
1374 /* this makes sure that when we do things like call scripts,
1375 that it won't assert because we are not root */
1378 if (c->opt_machine_pass) {
1379 /* it is very useful to be able to make ads queries as the
1380 machine account for testing purposes and for domain leave */
1382 net_use_krb_machine_account(c);
1385 if (!c->opt_password) {
1386 c->opt_password = getenv("PASSWD");
1389 popt_burn_cmdline_password(argc, argv);
1391 rc = net_run_function(c, argc_new-1, argv_new+1, "net", net_func);
1393 DEBUG(2,("return code = %d\n", rc));
1395 libnetapi_free(c->netapi_ctx);
1397 poptFreeContext(pc);