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)
362 struct dom_sid_buf sid_str;
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 d_printf(_("SID for domain %s is: %s\n"),
395 dom_sid_str_buf(&sid, &sid_str));
399 static int net_setlocalsid(struct net_context *c, int argc, const char **argv)
404 || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
405 || (!string_to_sid(&sid, argv[0]))
406 || (sid.num_auths != 4)) {
407 d_printf(_("Usage:"));
408 d_printf(" net setlocalsid S-1-5-21-x-y-z\n");
412 if (!secrets_store_domain_sid(lp_netbios_name(), &sid)) {
413 DEBUG(0,("Can't store domain SID as a pdc/bdc.\n"));
420 static int net_setdomainsid(struct net_context *c, int argc, const char **argv)
425 || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
426 || (!string_to_sid(&sid, argv[0]))
427 || (sid.num_auths != 4)) {
428 d_printf(_("Usage:"));
429 d_printf(" net setdomainsid S-1-5-21-x-y-z\n");
433 if (!secrets_store_domain_sid(lp_workgroup(), &sid)) {
434 DEBUG(0,("Can't store domain SID.\n"));
441 static int net_getdomainsid(struct net_context *c, int argc, const char **argv)
443 struct dom_sid domain_sid;
444 struct dom_sid_buf sid_str;
447 d_printf(_("Usage:"));
448 d_printf(" net getdomainsid\n");
452 if(!initialize_password_db(false, NULL)) {
453 d_fprintf(stderr, _("WARNING: Could not open passdb\n"));
457 /* first check to see if we can even access secrets, so we don't
458 panic when we can't. */
460 if (!secrets_init()) {
461 d_fprintf(stderr, _("Unable to open secrets.tdb. Can't fetch "
462 "domain SID for name: %s\n"),
463 get_global_sam_name());
467 /* Generate one, if it doesn't exist */
468 get_global_sam_sid();
471 if (!secrets_fetch_domain_sid(lp_netbios_name(), &domain_sid)) {
472 d_fprintf(stderr, _("Could not fetch local SID\n"));
475 d_printf(_("SID for local machine %s is: %s\n"),
477 dom_sid_str_buf(&domain_sid, &sid_str));
479 if (!secrets_fetch_domain_sid(c->opt_workgroup, &domain_sid)) {
480 d_fprintf(stderr, _("Could not fetch domain SID\n"));
484 d_printf(_("SID for domain %s is: %s\n"),
486 dom_sid_str_buf(&domain_sid, &sid_str));
491 static bool search_maxrid(struct pdb_search *search, const char *type,
494 struct samr_displayentry *entries;
495 uint32_t i, num_entries;
497 if (search == NULL) {
498 d_fprintf(stderr, _("get_maxrid: Could not search %s\n"), type);
502 num_entries = pdb_search_entries(search, 0, 0xffffffff, &entries);
503 for (i=0; i<num_entries; i++)
504 *max_rid = MAX(*max_rid, entries[i].rid);
509 static uint32_t get_maxrid(void)
511 uint32_t max_rid = 0;
513 if (!search_maxrid(pdb_search_users(talloc_tos(), 0), "users", &max_rid))
516 if (!search_maxrid(pdb_search_groups(talloc_tos()), "groups", &max_rid))
519 if (!search_maxrid(pdb_search_aliases(talloc_tos(),
520 get_global_sam_sid()),
521 "aliases", &max_rid))
527 static int net_maxrid(struct net_context *c, int argc, const char **argv)
532 d_fprintf(stderr, "%s net maxrid\n", _("Usage:"));
536 if ((rid = get_maxrid()) == 0) {
537 d_fprintf(stderr, _("can't get current maximum rid\n"));
541 d_printf(_("Currently used maximum rid: %d\n"), rid);
546 /* main function table */
547 static struct functable net_func[] = {
552 N_("Run functions using RPC transport"),
553 N_(" Use 'net help rpc' to get more extensive information "
554 "about 'net rpc' commands.")
560 N_("Run functions using RAP transport"),
561 N_(" Use 'net help rap' to get more extensive information "
562 "about 'net rap' commands.")
568 N_("Run functions using ADS transport"),
569 N_(" Use 'net help ads' to get more extensive information "
570 "about 'net ads' commands.")
573 /* eventually these should auto-choose the transport ... */
577 NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
578 N_("Functions on remote opened files"),
579 N_(" Use 'net help file' to get more information about 'net "
585 NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
586 N_("Functions on shares"),
587 N_(" Use 'net help share' to get more information about 'net "
594 N_("Manage sessions"),
595 N_(" Use 'net help session' to get more information about "
596 "'net session' commands.")
602 N_("List servers in workgroup"),
603 N_(" Use 'net help server' to get more information about 'net "
610 N_("List domains/workgroups on network"),
611 N_(" Use 'net help domain' to get more information about 'net "
618 N_("Modify printer queue"),
619 N_(" Use 'net help printq' to get more information about 'net "
625 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
627 N_(" Use 'net help user' to get more information about 'net "
633 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC | NET_TRANSPORT_RAP,
635 N_(" Use 'net help group' to get more information about 'net "
642 N_("Manage group mappings"),
643 N_(" Use 'net help groupmap' to get more information about "
644 "'net groupmap' commands.")
650 N_("Functions on the SAM database"),
651 N_(" Use 'net help sam' to get more information about 'net "
658 N_("Validate username and password"),
659 N_(" Use 'net help validate' to get more information about "
660 "'net validate' commands.")
666 N_("Modify group memberships"),
667 N_(" Use 'net help groupmember' to get more information about "
668 "'net groupmember' commands.")
673 N_("Execute remote command on a remote OS/2 server"),
674 N_(" Use 'net help admin' to get more information about 'net "
680 N_("List/modify running services"),
681 N_(" Use 'net help service' to get more information about "
682 "'net service' commands.")
688 N_("Change user password on target server"),
689 N_(" Use 'net help password' to get more information about "
690 "'net password' commands.")
696 N_("Run functions related to the primary workstation trust."),
697 N_(" Use 'net help primarytrust' to get more extensive information "
698 "about 'net primarytrust' commands.")
702 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC,
703 N_("Change the trust password"),
704 N_(" Use 'net help changetrustpw' to get more information "
705 "about 'net changetrustpw'.")
710 N_("Change the secret password"),
711 N_(" net [options] changesecretpw\n"
712 " Change the ADS domain member machine account password "
714 " Do NOT use this function unless you know what it does.\n"
715 " Requires the -f flag to work.")
721 N_("Set the winbind auth user"),
722 N_(" net -U user[%%password] [-W domain] setauthuser\n"
723 " Set the auth user, password (and optionally domain\n"
724 " Will prompt for password if not given.\n"
725 " net setauthuser delete\n"
726 " Delete the existing auth user settings.")
732 N_("Get the winbind auth user settings"),
733 N_(" net getauthuser\n"
734 " Get the current winbind auth user settings.")
740 N_(" Use 'net help time' to get more information about 'net "
746 N_("Look up host names/IP addresses"),
747 N_(" Use 'net help lookup' to get more information about 'net "
753 N_("Manipulate the global lock table"),
754 N_(" Use 'net help g_lock' to get more information about "
755 "'net g_lock' commands.")
759 NET_TRANSPORT_ADS | NET_TRANSPORT_RPC,
760 N_("Join a domain/AD"),
761 N_(" Use 'net help join' to get more information about 'net "
767 N_("Join/unjoin (remote) machines to/from a domain/AD"),
768 N_(" Use 'net help dom' to get more information about 'net "
774 N_("Operate on the cache tdb file"),
775 N_(" Use 'net help cache' to get more information about 'net "
781 N_("Get the SID for the local domain"),
782 N_(" net getlocalsid")
787 N_("Set the SID for the local domain"),
788 N_(" net setlocalsid S-1-5-21-x-y-z")
793 N_("Set domain SID on member servers"),
794 N_(" net setdomainsid S-1-5-21-x-y-z")
799 N_("Get domain SID on member servers"),
800 N_(" net getdomainsid")
805 N_("Display the maximum RID currently used"),
811 N_("IDmap functions"),
812 N_(" Use 'net help idmap to get more information about 'net "
818 N_("Display server status"),
819 N_(" Use 'net help status' to get more information about 'net "
825 N_("Manage user-modifiable shares"),
826 N_(" Use 'net help usershare to get more information about "
827 "'net usershare' commands.")
832 N_("Display list of all users with SID"),
833 N_(" Use 'net help usersidlist' to get more information about "
834 "'net usersidlist'.")
839 N_("Manage Samba registry based configuration"),
840 N_(" Use 'net help conf' to get more information about 'net "
846 N_("Manage the Samba registry"),
847 N_(" Use 'net help registry' to get more information about "
848 "'net registry' commands.")
853 N_("Process Win32 *.evt eventlog files"),
854 N_(" Use 'net help eventlog' to get more information about "
855 "'net eventlog' commands.")
860 N_("Process tdb printer files"),
861 N_(" Use 'net help printing' to get more information about "
862 "'net printing' commands.")
868 N_("Manage the serverid tdb"),
869 N_(" Use 'net help serverid' to get more information about "
870 "'net serverid' commands.")
876 N_("notifyd client code"),
877 N_(" Use 'net help notify' to get more information about "
878 "'net notify' commands.")
884 N_("Show information from tdb records"),
885 N_(" Use 'net help tdb' to get more information about "
886 "'net tdb' commands.")
889 #ifdef WITH_FAKE_KASERVER
893 N_("Manage AFS tokens"),
894 N_(" Use 'net help afs' to get more information about 'net "
902 N_("Print usage information"),
903 N_(" Use 'net help help' to list usage information for 'net' "
906 {NULL, NULL, 0, NULL, NULL}
910 static void get_credentials_file(struct net_context *c,
913 struct cli_credentials *cred = cli_credentials_init(c);
916 d_printf("ERROR: Unable to allocate memory!\n");
920 if (!cli_credentials_parse_file(cred, file, CRED_GUESS_FILE)) {
924 c->opt_user_name = cli_credentials_get_username(cred);
925 c->opt_user_specified = (c->opt_user_name != NULL);
926 c->opt_password = cli_credentials_get_password(cred);
927 c->opt_target_workgroup = cli_credentials_get_domain(cred);
930 /****************************************************************************
932 ****************************************************************************/
933 int main(int argc, char **argv)
939 const char ** argv_new;
940 const char **argv_const = discard_const_p(const char *, argv);
942 TALLOC_CTX *frame = talloc_stackframe();
943 struct net_context *c = talloc_zero(frame, struct net_context);
945 struct poptOption long_options[] = {
949 .argInfo = POPT_ARG_NONE,
953 .longName = "workgroup",
955 .argInfo = POPT_ARG_STRING,
956 .arg = &c->opt_target_workgroup,
961 .argInfo = POPT_ARG_STRING,
962 .arg = &c->opt_user_name,
966 .longName = "authentication-file",
968 .argInfo = POPT_ARG_STRING,
969 .arg = &c->opt_user_name,
971 .descrip = "Get the credentials from a file",
972 .argDescrip = "FILE",
975 .longName = "ipaddress",
977 .argInfo = POPT_ARG_STRING,
984 .argInfo = POPT_ARG_INT,
988 .longName = "myname",
990 .argInfo = POPT_ARG_STRING,
991 .arg = &c->opt_requester_name,
994 .longName = "server",
996 .argInfo = POPT_ARG_STRING,
1000 .longName = "encrypt",
1002 .argInfo = POPT_ARG_NONE,
1005 .descrip = N_("Encrypt SMB transport"),
1008 .longName = "container",
1010 .argInfo = POPT_ARG_STRING,
1011 .arg = &c->opt_container,
1014 .longName = "comment",
1016 .argInfo = POPT_ARG_STRING,
1017 .arg = &c->opt_comment,
1020 .longName = "maxusers",
1022 .argInfo = POPT_ARG_INT,
1023 .arg = &c->opt_maxusers,
1026 .longName = "flags",
1028 .argInfo = POPT_ARG_INT,
1029 .arg = &c->opt_flags,
1034 .argInfo = POPT_ARG_NONE,
1035 .arg = &c->opt_long_list_entries,
1038 .longName = "reboot",
1040 .argInfo = POPT_ARG_NONE,
1041 .arg = &c->opt_reboot,
1044 .longName = "force",
1046 .argInfo = POPT_ARG_NONE,
1047 .arg = &c->opt_force,
1050 .longName = "stdin",
1052 .argInfo = POPT_ARG_NONE,
1053 .arg = &c->opt_stdin,
1056 .longName = "timeout",
1058 .argInfo = POPT_ARG_INT,
1059 .arg = &c->opt_timeout,
1062 .longName = "request-timeout",
1064 .argInfo = POPT_ARG_INT,
1065 .arg = &c->opt_request_timeout,
1068 .longName = "machine-pass",
1070 .argInfo = POPT_ARG_NONE,
1071 .arg = &c->opt_machine_pass,
1074 .longName = "kerberos",
1076 .argInfo = POPT_ARG_NONE,
1077 .arg = &c->opt_kerberos,
1080 .longName = "myworkgroup",
1082 .argInfo = POPT_ARG_STRING,
1083 .arg = &c->opt_workgroup,
1086 .longName = "use-ccache",
1088 .argInfo = POPT_ARG_NONE,
1089 .arg = &c->opt_ccache,
1092 .longName = "verbose",
1094 .argInfo = POPT_ARG_NONE,
1095 .arg = &c->opt_verbose,
1100 .argInfo = POPT_ARG_NONE,
1101 .arg = &c->opt_testmode,
1103 /* Options for 'net groupmap set' */
1105 .longName = "local",
1107 .argInfo = POPT_ARG_NONE,
1108 .arg = &c->opt_localgroup,
1111 .longName = "domain",
1113 .argInfo = POPT_ARG_NONE,
1114 .arg = &c->opt_domaingroup,
1117 .longName = "ntname",
1119 .argInfo = POPT_ARG_STRING,
1120 .arg = &c->opt_newntname,
1125 .argInfo = POPT_ARG_INT,
1128 /* Options for 'net rpc share migrate' */
1132 .argInfo = POPT_ARG_NONE,
1133 .arg = &c->opt_acls,
1136 .longName = "attrs",
1138 .argInfo = POPT_ARG_NONE,
1139 .arg = &c->opt_attrs,
1142 .longName = "timestamps",
1144 .argInfo = POPT_ARG_NONE,
1145 .arg = &c->opt_timestamps,
1148 .longName = "exclude",
1150 .argInfo = POPT_ARG_STRING,
1151 .arg = &c->opt_exclude,
1154 .longName = "destination",
1156 .argInfo = POPT_ARG_STRING,
1157 .arg = &c->opt_destination,
1160 .longName = "tallocreport",
1162 .argInfo = POPT_ARG_NONE,
1163 .arg = &c->do_talloc_report,
1165 /* Options for 'net rpc vampire (keytab)' */
1167 .longName = "force-full-repl",
1169 .argInfo = POPT_ARG_NONE,
1170 .arg = &c->opt_force_full_repl,
1173 .longName = "single-obj-repl",
1175 .argInfo = POPT_ARG_NONE,
1176 .arg = &c->opt_single_obj_repl,
1179 .longName = "clean-old-entries",
1181 .argInfo = POPT_ARG_NONE,
1182 .arg = &c->opt_clean_old_entries,
1184 /* Options for 'net idmap'*/
1188 .argInfo = POPT_ARG_STRING,
1194 .argInfo = POPT_ARG_NONE,
1195 .arg = &c->opt_lock,
1200 .argInfo = POPT_ARG_NONE,
1201 .arg = &c->opt_auto,
1204 .longName = "repair",
1206 .argInfo = POPT_ARG_NONE,
1207 .arg = &c->opt_repair,
1209 /* Options for 'net registry check'*/
1211 .longName = "reg-version",
1213 .argInfo = POPT_ARG_INT,
1214 .arg = &c->opt_reg_version,
1217 .longName = "output",
1219 .argInfo = POPT_ARG_STRING,
1220 .arg = &c->opt_output,
1225 .argInfo = POPT_ARG_NONE,
1226 .arg = &c->opt_wipe,
1228 /* Options for 'net registry import' */
1230 .longName = "precheck",
1232 .argInfo = POPT_ARG_STRING,
1233 .arg = &c->opt_precheck,
1235 /* Options for 'net ads join or leave' */
1237 .longName = "no-dns-updates",
1239 .argInfo = POPT_ARG_NONE,
1240 .arg = &c->opt_no_dns_updates,
1243 .longName = "keep-account",
1245 .argInfo = POPT_ARG_NONE,
1246 .arg = &c->opt_keep_account,
1251 .argInfo = POPT_ARG_NONE,
1252 .arg = &c->opt_json,
1258 zero_sockaddr(&c->opt_dest_ip);
1260 setup_logging(argv[0], DEBUG_STDERR);
1264 setlocale(LC_ALL, "");
1265 #if defined(HAVE_BINDTEXTDOMAIN)
1266 bindtextdomain(MODULE_NAME, get_dyn_LOCALEDIR());
1268 #if defined(HAVE_TEXTDOMAIN)
1269 textdomain(MODULE_NAME);
1272 /* set default debug level to 0 regardless of what smb.conf sets */
1273 lp_set_cmdline("log level", "0");
1274 c->private_data = net_func;
1276 pc = poptGetContext(NULL, argc, argv_const, long_options,
1277 POPT_CONTEXT_KEEP_FIRST);
1279 while((opt = poptGetNextOpt(pc)) != -1) {
1282 c->display_usage = true;
1285 c->smb_encrypt = true;
1288 if (!interpret_string_addr(&c->opt_dest_ip,
1289 poptGetOptArg(pc), 0)) {
1290 d_fprintf(stderr, _("\nInvalid ip address specified\n"));
1292 c->opt_have_ip = true;
1296 c->opt_user_specified = true;
1297 c->opt_user_name = talloc_strdup(c, c->opt_user_name);
1298 p = strchr(c->opt_user_name,'%');
1301 c->opt_password = p+1;
1305 get_credentials_file(c, c->opt_user_name);
1308 d_fprintf(stderr, _("\nInvalid option %s: %s\n"),
1309 poptBadOption(pc, 0), poptStrerror(opt));
1310 net_help(c, argc, argv_const);
1315 c->msg_ctx = cmdline_messaging_context(get_dyn_CONFIGFILE());
1317 if (!lp_load_global(get_dyn_CONFIGFILE())) {
1318 d_fprintf(stderr, "Can't load %s - run testparm to debug it\n",
1319 get_dyn_CONFIGFILE());
1323 #if defined(HAVE_BIND_TEXTDOMAIN_CODESET)
1324 /* Bind our gettext results to 'unix charset'
1326 This ensures that the translations and any embedded strings are in the
1327 same charset. It won't be the one from the user's locale (we no
1328 longer auto-detect that), but it will be self-consistent.
1330 bind_textdomain_codeset(MODULE_NAME, lp_unix_charset());
1333 argv_new = (const char **)poptGetArgs(pc);
1336 for (i=0; i<argc; i++) {
1337 if (argv_new[i] == NULL) {
1343 if (c->do_talloc_report) {
1344 talloc_enable_leak_report();
1347 if (c->opt_requester_name) {
1348 lp_set_cmdline("netbios name", c->opt_requester_name);
1351 if (!c->opt_user_name && getenv("LOGNAME")) {
1352 c->opt_user_name = getenv("LOGNAME");
1355 if (!c->opt_workgroup) {
1356 c->opt_workgroup = talloc_strdup(c, lp_workgroup());
1359 if (!c->opt_target_workgroup) {
1360 c->opt_target_workgroup = talloc_strdup(c, lp_workgroup());
1368 /* this makes sure that when we do things like call scripts,
1369 that it won't assert because we are not root */
1372 if (c->opt_machine_pass) {
1373 /* it is very useful to be able to make ads queries as the
1374 machine account for testing purposes and for domain leave */
1376 net_use_krb_machine_account(c);
1379 if (!c->opt_password) {
1380 c->opt_password = getenv("PASSWD");
1383 popt_burn_cmdline_password(argc, argv);
1385 rc = net_run_function(c, argc_new-1, argv_new+1, "net", net_func);
1387 DEBUG(2,("return code = %d\n", rc));
1389 libnetapi_free(c->netapi_ctx);
1391 poptFreeContext(pc);