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)
9 Originally written by Steve and Jim. Largely rewritten by tridge in
12 Reworked again by abartlet in December 2001
14 This program is free software; you can redistribute it and/or modify
15 it under the terms of the GNU General Public License as published by
16 the Free Software Foundation; either version 3 of the License, or
17 (at your option) any later version.
19 This program is distributed in the hope that it will be useful,
20 but WITHOUT ANY WARRANTY; without even the implied warranty of
21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 GNU General Public License for more details.
24 You should have received a copy of the GNU General Public License
25 along with this program. If not, see <http://www.gnu.org/licenses/>. */
27 /*****************************************************/
29 /* Distributed SMB/CIFS Server Management Utility */
31 /* The intent was to make the syntax similar */
32 /* to the NET utility (first developed in DOS */
33 /* with additional interesting & useful functions */
34 /* added in later SMB server network operating */
37 /*****************************************************/
40 #include "utils/net.h"
42 /***********************************************************************/
43 /* Beginning of internationalization section. Translatable constants */
44 /* should be kept in this area and referenced in the rest of the code. */
46 /* No functions, outside of Samba or LSB (Linux Standards Base) should */
47 /* be used (if possible). */
48 /***********************************************************************/
50 #define YES_STRING "Yes"
51 #define NO_STRING "No"
53 /************************************************************************************/
54 /* end of internationalization section */
55 /************************************************************************************/
57 /* Yes, these buggers are globals.... */
58 const char *opt_requester_name = NULL;
59 const char *opt_host = NULL;
60 const char *opt_password = NULL;
61 const char *opt_user_name = NULL;
62 BOOL opt_user_specified = False;
63 const char *opt_workgroup = NULL;
64 int opt_long_list_entries = 0;
70 int opt_maxusers = -1;
71 const char *opt_comment = "";
72 const char *opt_container = NULL;
75 const char *opt_target_workgroup = NULL;
76 int opt_machine_pass = 0;
77 BOOL opt_localgroup = False;
78 BOOL opt_domaingroup = False;
79 static BOOL do_talloc_report=False;
80 const char *opt_newntname = "";
84 int opt_timestamps = 0;
85 const char *opt_exclude = NULL;
86 const char *opt_destination = NULL;
87 BOOL opt_testmode = False;
89 BOOL opt_have_ip = False;
90 struct in_addr opt_dest_ip;
92 extern BOOL AllowDebugChange;
94 uint32 get_sec_channel_type(const char *param)
96 if (!(param && *param)) {
97 return get_default_sec_channel();
99 if (strequal(param, "PDC")) {
101 } else if (strequal(param, "BDC")) {
103 } else if (strequal(param, "MEMBER")) {
104 return SEC_CHAN_WKSTA;
106 } else if (strequal(param, "DOMAIN")) {
107 return SEC_CHAN_DOMAIN;
110 return get_default_sec_channel();
116 run a function from a function table. If not found then
117 call the specified usage function
119 int net_run_function(int argc, const char **argv, struct functable *table,
120 int (*usage_fn)(int argc, const char **argv))
125 d_printf("\nUsage: \n");
126 return usage_fn(argc, argv);
128 for (i=0; table[i].funcname; i++) {
129 if (StrCaseCmp(argv[0], table[i].funcname) == 0)
130 return table[i].fn(argc-1, argv+1);
132 d_fprintf(stderr, "No command: %s\n", argv[0]);
133 return usage_fn(argc, argv);
137 * run a function from a function table.
139 int net_run_function2(int argc, const char **argv, const char *whoami,
140 struct functable2 *table)
145 for (i=0; table[i].funcname; i++) {
146 if (StrCaseCmp(argv[0], table[i].funcname) == 0)
147 return table[i].fn(argc-1, argv+1);
151 for (i=0; table[i].funcname != NULL; i++) {
152 d_printf("%s %-15s %s\n", whoami, table[i].funcname,
159 /****************************************************************************
160 connect to \\server\service
161 ****************************************************************************/
163 NTSTATUS connect_to_service(struct cli_state **c, struct in_addr *server_ip,
164 const char *server_name,
165 const char *service_name,
166 const char *service_type)
170 opt_password = net_prompt_pass(opt_user_name);
172 return NT_STATUS_NO_MEMORY;
175 nt_status = cli_full_connection(c, NULL, server_name,
177 service_name, service_type,
178 opt_user_name, opt_workgroup,
179 opt_password, 0, Undefined, NULL);
180 if (NT_STATUS_IS_OK(nt_status)) {
183 d_fprintf(stderr, "Could not connect to server %s\n", server_name);
185 /* Display a nicer message depending on the result */
187 if (NT_STATUS_V(nt_status) ==
188 NT_STATUS_V(NT_STATUS_LOGON_FAILURE))
189 d_fprintf(stderr, "The username or password was not correct.\n");
191 if (NT_STATUS_V(nt_status) ==
192 NT_STATUS_V(NT_STATUS_ACCOUNT_LOCKED_OUT))
193 d_fprintf(stderr, "The account was locked out.\n");
195 if (NT_STATUS_V(nt_status) ==
196 NT_STATUS_V(NT_STATUS_ACCOUNT_DISABLED))
197 d_fprintf(stderr, "The account was disabled.\n");
204 /****************************************************************************
205 connect to \\server\ipc$
206 ****************************************************************************/
207 NTSTATUS connect_to_ipc(struct cli_state **c, struct in_addr *server_ip,
208 const char *server_name)
210 return connect_to_service(c, server_ip, server_name, "IPC$", "IPC");
213 /****************************************************************************
214 connect to \\server\ipc$ anonymously
215 ****************************************************************************/
216 NTSTATUS connect_to_ipc_anonymous(struct cli_state **c,
217 struct in_addr *server_ip, const char *server_name)
221 nt_status = cli_full_connection(c, opt_requester_name, server_name,
225 "", 0, Undefined, NULL);
227 if (NT_STATUS_IS_OK(nt_status)) {
230 DEBUG(1,("Cannot connect to server (anonymously). Error was %s\n", nt_errstr(nt_status)));
235 /****************************************************************************
236 Return malloced user@realm for krb5 login.
237 ****************************************************************************/
239 static char *get_user_and_realm(const char *username)
241 char *user_and_realm = NULL;
246 if (strchr_m(username, '@')) {
247 user_and_realm = SMB_STRDUP(username);
249 if (asprintf(&user_and_realm, "%s@%s", username, lp_realm()) == -1) {
250 user_and_realm = NULL;
253 return user_and_realm;
256 /****************************************************************************
257 connect to \\server\ipc$ using KRB5
258 ****************************************************************************/
260 NTSTATUS connect_to_ipc_krb5(struct cli_state **c,
261 struct in_addr *server_ip, const char *server_name)
264 char *user_and_realm = NULL;
266 opt_password = net_prompt_pass(opt_user_name);
268 return NT_STATUS_NO_MEMORY;
271 user_and_realm = get_user_and_realm(opt_user_name);
272 if (!user_and_realm) {
273 return NT_STATUS_NO_MEMORY;
276 nt_status = cli_full_connection(c, NULL, server_name,
279 user_and_realm, opt_workgroup,
280 opt_password, CLI_FULL_CONNECTION_USE_KERBEROS,
283 SAFE_FREE(user_and_realm);
285 if (NT_STATUS_IS_OK(nt_status)) {
288 DEBUG(1,("Cannot connect to server using kerberos. Error was %s\n", nt_errstr(nt_status)));
294 * Connect a server and open a given pipe
296 * @param cli_dst A cli_state
297 * @param pipe The pipe to open
298 * @param got_pipe boolean that stores if we got a pipe
300 * @return Normal NTSTATUS return.
302 NTSTATUS connect_dst_pipe(struct cli_state **cli_dst, struct rpc_pipe_client **pp_pipe_hnd, int pipe_num)
305 char *server_name = SMB_STRDUP("127.0.0.1");
306 struct cli_state *cli_tmp = NULL;
307 struct rpc_pipe_client *pipe_hnd = NULL;
309 if (server_name == NULL) {
310 return NT_STATUS_NO_MEMORY;
313 if (opt_destination) {
314 SAFE_FREE(server_name);
315 if ((server_name = SMB_STRDUP(opt_destination)) == NULL) {
316 return NT_STATUS_NO_MEMORY;
320 /* make a connection to a named pipe */
321 nt_status = connect_to_ipc(&cli_tmp, NULL, server_name);
322 if (!NT_STATUS_IS_OK(nt_status)) {
323 SAFE_FREE(server_name);
327 pipe_hnd = cli_rpc_pipe_open_noauth(cli_tmp, pipe_num, &nt_status);
329 DEBUG(0, ("couldn't not initialize pipe\n"));
330 cli_shutdown(cli_tmp);
331 SAFE_FREE(server_name);
336 *pp_pipe_hnd = pipe_hnd;
337 SAFE_FREE(server_name);
342 /****************************************************************************
343 Use the local machine account (krb) and password for this session.
344 ****************************************************************************/
346 int net_use_krb_machine_account(void)
348 char *user_name = NULL;
350 if (!secrets_init()) {
351 d_fprintf(stderr, "ERROR: Unable to open secrets database\n");
355 opt_password = secrets_fetch_machine_password(opt_target_workgroup, NULL, NULL);
356 if (asprintf(&user_name, "%s$@%s", global_myname(), lp_realm()) == -1) {
359 opt_user_name = user_name;
363 /****************************************************************************
364 Use the machine account name and password for this session.
365 ****************************************************************************/
367 int net_use_machine_account(void)
369 char *user_name = NULL;
371 if (!secrets_init()) {
372 d_fprintf(stderr, "ERROR: Unable to open secrets database\n");
376 opt_password = secrets_fetch_machine_password(opt_target_workgroup, NULL, NULL);
377 if (asprintf(&user_name, "%s$", global_myname()) == -1) {
380 opt_user_name = user_name;
384 BOOL net_find_server(const char *domain, unsigned flags, struct in_addr *server_ip, char **server_name)
386 const char *d = domain ? domain : opt_target_workgroup;
389 *server_name = SMB_STRDUP(opt_host);
393 *server_ip = opt_dest_ip;
395 *server_name = SMB_STRDUP(inet_ntoa(opt_dest_ip));
397 } else if (*server_name) {
398 /* resolve the IP address */
399 if (!resolve_name(*server_name, server_ip, 0x20)) {
400 DEBUG(1,("Unable to resolve server name\n"));
403 } else if (flags & NET_FLAGS_PDC) {
404 struct in_addr pdc_ip;
406 if (get_pdc_ip(d, &pdc_ip)) {
409 if (is_zero_ip_v4(pdc_ip))
412 if ( !name_status_find(d, 0x1b, 0x20, pdc_ip, dc_name) )
415 *server_name = SMB_STRDUP(dc_name);
418 } else if (flags & NET_FLAGS_DMB) {
419 struct in_addr msbrow_ip;
420 /* if (!resolve_name(MSBROWSE, &msbrow_ip, 1)) */
421 if (!resolve_name(d, &msbrow_ip, 0x1B)) {
422 DEBUG(1,("Unable to resolve domain browser via name lookup\n"));
425 *server_ip = msbrow_ip;
427 *server_name = SMB_STRDUP(inet_ntoa(opt_dest_ip));
428 } else if (flags & NET_FLAGS_MASTER) {
429 struct in_addr brow_ips;
430 if (!resolve_name(d, &brow_ips, 0x1D)) {
431 /* go looking for workgroups */
432 DEBUG(1,("Unable to resolve master browser via name lookup\n"));
435 *server_ip = brow_ips;
437 *server_name = SMB_STRDUP(inet_ntoa(opt_dest_ip));
438 } else if (!(flags & NET_FLAGS_LOCALHOST_DEFAULT_INSANE)) {
439 (*server_ip).s_addr = htonl(INADDR_LOOPBACK);
440 *server_name = SMB_STRDUP("127.0.0.1");
443 if (!server_name || !*server_name) {
444 DEBUG(1,("no server to connect to\n"));
452 BOOL net_find_pdc(struct in_addr *server_ip, fstring server_name, const char *domain_name)
454 if (get_pdc_ip(domain_name, server_ip)) {
455 if (is_zero_ip_v4(*server_ip))
458 if (!name_status_find(domain_name, 0x1b, 0x20, *server_ip, server_name))
467 NTSTATUS net_make_ipc_connection(unsigned flags, struct cli_state **pcli)
469 return net_make_ipc_connection_ex(NULL, NULL, NULL, flags, pcli);
472 NTSTATUS net_make_ipc_connection_ex(const char *domain, const char *server,
473 struct in_addr *ip, unsigned flags,
474 struct cli_state **pcli)
476 char *server_name = NULL;
477 struct in_addr server_ip;
478 struct cli_state *cli = NULL;
481 if ( !server || !ip ) {
482 if (!net_find_server(domain, flags, &server_ip, &server_name)) {
483 d_fprintf(stderr, "Unable to find a suitable server\n");
484 nt_status = NT_STATUS_UNSUCCESSFUL;
488 server_name = SMB_STRDUP( server );
492 if (flags & NET_FLAGS_ANONYMOUS) {
493 nt_status = connect_to_ipc_anonymous(&cli, &server_ip, server_name);
495 nt_status = connect_to_ipc(&cli, &server_ip, server_name);
498 /* store the server in the affinity cache if it was a PDC */
500 if ( (flags & NET_FLAGS_PDC) && NT_STATUS_IS_OK(nt_status) )
501 saf_store( cli->server_domain, cli->desthost );
503 SAFE_FREE(server_name);
504 if (!NT_STATUS_IS_OK(nt_status)) {
505 d_fprintf(stderr, "Connection failed: %s\n",
506 nt_errstr(nt_status));
517 static int net_user(int argc, const char **argv)
519 if (net_ads_check() == 0)
520 return net_ads_user(argc, argv);
522 /* if server is not specified, default to PDC? */
523 if (net_rpc_check(NET_FLAGS_PDC))
524 return net_rpc_user(argc, argv);
526 return net_rap_user(argc, argv);
529 static int net_group(int argc, const char **argv)
531 if (net_ads_check() == 0)
532 return net_ads_group(argc, argv);
534 if (argc == 0 && net_rpc_check(NET_FLAGS_PDC))
535 return net_rpc_group(argc, argv);
537 return net_rap_group(argc, argv);
540 static int net_join(int argc, const char **argv)
542 if (net_ads_check_our_domain() == 0) {
543 if (net_ads_join(argc, argv) == 0)
546 d_fprintf(stderr, "ADS join did not work, falling back to RPC...\n");
548 return net_rpc_join(argc, argv);
551 static int net_changetrustpw(int argc, const char **argv)
553 if (net_ads_check_our_domain() == 0)
554 return net_ads_changetrustpw(argc, argv);
556 return net_rpc_changetrustpw(argc, argv);
559 static void set_line_buffering(FILE *f)
561 setvbuf(f, NULL, _IOLBF, 0);
564 static int net_changesecretpw(int argc, const char **argv)
567 uint32 sec_channel_type = SEC_CHAN_WKSTA;
571 set_line_buffering(stdin);
572 set_line_buffering(stdout);
573 set_line_buffering(stderr);
576 trust_pw = get_pass("Enter machine password: ", opt_stdin);
578 if (!secrets_store_machine_password(trust_pw, lp_workgroup(), sec_channel_type)) {
579 d_fprintf(stderr, "Unable to write the machine account password in the secrets database");
583 d_printf("Modified trust account password in secrets database\n");
587 d_printf("Machine account password change requires the -f flag.\n");
588 d_printf("Do NOT use this function unless you know what it does!\n");
589 d_printf("This function will change the ADS Domain member machine account password in the secrets.tdb file!\n");
595 static int net_share(int argc, const char **argv)
597 if (net_rpc_check(0))
598 return net_rpc_share(argc, argv);
599 return net_rap_share(argc, argv);
602 static int net_file(int argc, const char **argv)
604 if (net_rpc_check(0))
605 return net_rpc_file(argc, argv);
606 return net_rap_file(argc, argv);
610 Retrieve our local SID or the SID for the specified name
612 static int net_getlocalsid(int argc, const char **argv)
622 name = global_myname();
625 if(!initialize_password_db(False, NULL)) {
626 DEBUG(0, ("WARNING: Could not open passdb - local sid may not reflect passdb\n"
627 "backend knowledge (such as the sid stored in LDAP)\n"));
630 /* first check to see if we can even access secrets, so we don't
631 panic when we can't. */
633 if (!secrets_init()) {
634 d_fprintf(stderr, "Unable to open secrets.tdb. Can't fetch domain SID for name: %s\n", name);
638 /* Generate one, if it doesn't exist */
639 get_global_sam_sid();
641 if (!secrets_fetch_domain_sid(name, &sid)) {
642 DEBUG(0, ("Can't fetch domain SID for name: %s\n", name));
645 sid_to_string(sid_str, &sid);
646 d_printf("SID for domain %s is: %s\n", name, sid_str);
650 static int net_setlocalsid(int argc, const char **argv)
655 || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
656 || (!string_to_sid(&sid, argv[0]))
657 || (sid.num_auths != 4)) {
658 d_printf("usage: net setlocalsid S-1-5-21-x-y-z\n");
662 if (!secrets_store_domain_sid(global_myname(), &sid)) {
663 DEBUG(0,("Can't store domain SID as a pdc/bdc.\n"));
670 static int net_setdomainsid(int argc, const char **argv)
675 || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
676 || (!string_to_sid(&sid, argv[0]))
677 || (sid.num_auths != 4)) {
678 d_printf("usage: net setdomainsid S-1-5-21-x-y-z\n");
682 if (!secrets_store_domain_sid(lp_workgroup(), &sid)) {
683 DEBUG(0,("Can't store domain SID.\n"));
690 static int net_getdomainsid(int argc, const char **argv)
695 if(!initialize_password_db(False, NULL)) {
696 DEBUG(0, ("WARNING: Could not open passdb - domain sid may not reflect passdb\n"
697 "backend knowledge (such as the sid stored in LDAP)\n"));
700 /* first check to see if we can even access secrets, so we don't
701 panic when we can't. */
703 if (!secrets_init()) {
704 d_fprintf(stderr, "Unable to open secrets.tdb. Can't fetch domain"
705 "SID for name: %s\n", get_global_sam_name());
709 /* Generate one, if it doesn't exist */
710 get_global_sam_sid();
712 if (!secrets_fetch_domain_sid(global_myname(), &domain_sid)) {
713 d_fprintf(stderr, "Could not fetch local SID\n");
716 sid_to_string(sid_str, &domain_sid);
717 d_printf("SID for domain %s is: %s\n", global_myname(), sid_str);
719 if (!secrets_fetch_domain_sid(opt_workgroup, &domain_sid)) {
720 d_fprintf(stderr, "Could not fetch domain SID\n");
724 sid_to_string(sid_str, &domain_sid);
725 d_printf("SID for domain %s is: %s\n", opt_workgroup, sid_str);
730 #ifdef WITH_FAKE_KASERVER
732 int net_help_afs(int argc, const char **argv)
734 d_printf(" net afs key filename\n"
735 "\tImports a OpenAFS KeyFile into our secrets.tdb\n\n");
736 d_printf(" net afs impersonate <user> <cell>\n"
737 "\tCreates a token for user@cell\n\n");
741 static int net_afs_key(int argc, const char **argv)
744 struct afs_keyfile keyfile;
747 d_printf("usage: 'net afs key <keyfile> cell'\n");
751 if (!secrets_init()) {
752 d_fprintf(stderr, "Could not open secrets.tdb\n");
756 if ((fd = open(argv[0], O_RDONLY, 0)) < 0) {
757 d_fprintf(stderr, "Could not open %s\n", argv[0]);
761 if (read(fd, &keyfile, sizeof(keyfile)) != sizeof(keyfile)) {
762 d_fprintf(stderr, "Could not read keyfile\n");
766 if (!secrets_store_afs_keyfile(argv[1], &keyfile)) {
767 d_fprintf(stderr, "Could not write keyfile to secrets.tdb\n");
774 static int net_afs_impersonate(int argc, const char **argv)
779 fprintf(stderr, "Usage: net afs impersonate <user> <cell>\n");
783 token = afs_createtoken_str(argv[0], argv[1]);
786 fprintf(stderr, "Could not create token\n");
790 if (!afs_settoken_str(token)) {
791 fprintf(stderr, "Could not set token into kernel\n");
795 printf("Success: %s@%s\n", argv[0], argv[1]);
799 static int net_afs(int argc, const char **argv)
801 struct functable func[] = {
802 {"key", net_afs_key},
803 {"impersonate", net_afs_impersonate},
804 {"help", net_help_afs},
807 return net_run_function(argc, argv, func, net_help_afs);
810 #endif /* WITH_FAKE_KASERVER */
812 static BOOL search_maxrid(struct pdb_search *search, const char *type,
815 struct samr_displayentry *entries;
816 uint32 i, num_entries;
818 if (search == NULL) {
819 d_fprintf(stderr, "get_maxrid: Could not search %s\n", type);
823 num_entries = pdb_search_entries(search, 0, 0xffffffff, &entries);
824 for (i=0; i<num_entries; i++)
825 *max_rid = MAX(*max_rid, entries[i].rid);
826 pdb_search_destroy(search);
830 static uint32 get_maxrid(void)
834 if (!search_maxrid(pdb_search_users(0), "users", &max_rid))
837 if (!search_maxrid(pdb_search_groups(), "groups", &max_rid))
840 if (!search_maxrid(pdb_search_aliases(get_global_sam_sid()),
841 "aliases", &max_rid))
847 static int net_maxrid(int argc, const char **argv)
852 DEBUG(0, ("usage: net maxrid\n"));
856 if ((rid = get_maxrid()) == 0) {
857 DEBUG(0, ("can't get current maximum rid\n"));
861 d_printf("Currently used maximum rid: %d\n", rid);
866 /****************************************************************************
867 ****************************************************************************/
869 const char *net_prompt_pass(const char *user)
872 const char *pass = NULL;
878 if (opt_machine_pass) {
882 asprintf(&prompt, "Enter %s's password:", user);
887 pass = getpass(prompt);
893 /* main function table */
894 static struct functable net_func[] = {
899 /* eventually these should auto-choose the transport ... */
901 {"SHARE", net_share},
902 {"SESSION", net_rap_session},
903 {"SERVER", net_rap_server},
904 {"DOMAIN", net_rap_domain},
905 {"PRINTQ", net_rap_printq},
907 {"GROUP", net_group},
908 {"GROUPMAP", net_groupmap},
910 {"VALIDATE", net_rap_validate},
911 {"GROUPMEMBER", net_rap_groupmember},
912 {"ADMIN", net_rap_admin},
913 {"SERVICE", net_rap_service},
914 {"PASSWORD", net_rap_password},
915 {"CHANGETRUSTPW", net_changetrustpw},
916 {"CHANGESECRETPW", net_changesecretpw},
918 {"LOOKUP", net_lookup},
920 {"CACHE", net_cache},
921 {"GETLOCALSID", net_getlocalsid},
922 {"SETLOCALSID", net_setlocalsid},
923 {"SETDOMAINSID", net_setdomainsid},
924 {"GETDOMAINSID", net_getdomainsid},
925 {"MAXRID", net_maxrid},
926 {"IDMAP", net_idmap},
927 {"STATUS", net_status},
928 {"USERSHARE", net_usershare},
929 {"USERSIDLIST", net_usersidlist},
931 #ifdef WITH_FAKE_KASERVER
940 /****************************************************************************
942 ****************************************************************************/
943 int main(int argc, const char **argv)
949 const char ** argv_new;
952 struct poptOption long_options[] = {
953 {"help", 'h', POPT_ARG_NONE, 0, 'h'},
954 {"workgroup", 'w', POPT_ARG_STRING, &opt_target_workgroup},
955 {"user", 'U', POPT_ARG_STRING, &opt_user_name, 'U'},
956 {"ipaddress", 'I', POPT_ARG_STRING, 0,'I'},
957 {"port", 'p', POPT_ARG_INT, &opt_port},
958 {"myname", 'n', POPT_ARG_STRING, &opt_requester_name},
959 {"server", 'S', POPT_ARG_STRING, &opt_host},
960 {"container", 'c', POPT_ARG_STRING, &opt_container},
961 {"comment", 'C', POPT_ARG_STRING, &opt_comment},
962 {"maxusers", 'M', POPT_ARG_INT, &opt_maxusers},
963 {"flags", 'F', POPT_ARG_INT, &opt_flags},
964 {"long", 'l', POPT_ARG_NONE, &opt_long_list_entries},
965 {"reboot", 'r', POPT_ARG_NONE, &opt_reboot},
966 {"force", 'f', POPT_ARG_NONE, &opt_force},
967 {"stdin", 'i', POPT_ARG_NONE, &opt_stdin},
968 {"timeout", 't', POPT_ARG_INT, &opt_timeout},
969 {"machine-pass",'P', POPT_ARG_NONE, &opt_machine_pass},
970 {"myworkgroup", 'W', POPT_ARG_STRING, &opt_workgroup},
971 {"verbose", 'v', POPT_ARG_NONE, &opt_verbose},
972 {"test", 'T', POPT_ARG_NONE, &opt_testmode},
973 /* Options for 'net groupmap set' */
974 {"local", 'L', POPT_ARG_NONE, &opt_localgroup},
975 {"domain", 'D', POPT_ARG_NONE, &opt_domaingroup},
976 {"ntname", 'N', POPT_ARG_STRING, &opt_newntname},
977 {"rid", 'R', POPT_ARG_INT, &opt_rid},
978 /* Options for 'net rpc share migrate' */
979 {"acls", 0, POPT_ARG_NONE, &opt_acls},
980 {"attrs", 0, POPT_ARG_NONE, &opt_attrs},
981 {"timestamps", 0, POPT_ARG_NONE, &opt_timestamps},
982 {"exclude", 'e', POPT_ARG_STRING, &opt_exclude},
983 {"destination", 0, POPT_ARG_STRING, &opt_destination},
984 {"tallocreport", 0, POPT_ARG_NONE, &do_talloc_report},
990 TALLOC_CTX *frame = talloc_stackframe();
992 zero_ip_v4(&opt_dest_ip);
996 /* set default debug level to 0 regardless of what smb.conf sets */
997 DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
1000 pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
1001 POPT_CONTEXT_KEEP_FIRST);
1003 while((opt = poptGetNextOpt(pc)) != -1) {
1006 net_help(argc, argv);
1010 opt_dest_ip = *interpret_addr2(poptGetOptArg(pc));
1011 if (is_zero_ip_v4(opt_dest_ip))
1012 d_fprintf(stderr, "\nInvalid ip address specified\n");
1017 opt_user_specified = True;
1018 opt_user_name = SMB_STRDUP(opt_user_name);
1019 p = strchr(opt_user_name,'%');
1026 d_fprintf(stderr, "\nInvalid option %s: %s\n",
1027 poptBadOption(pc, 0), poptStrerror(opt));
1028 net_help(argc, argv);
1034 * Don't load debug level from smb.conf. It should be
1035 * set by cmdline arg or remain default (0)
1037 AllowDebugChange = False;
1038 lp_load(dyn_CONFIGFILE,True,False,False,True);
1040 argv_new = (const char **)poptGetArgs(pc);
1043 for (i=0; i<argc; i++) {
1044 if (argv_new[i] == NULL) {
1050 if (do_talloc_report) {
1051 talloc_enable_leak_report();
1054 if (opt_requester_name) {
1055 set_global_myname(opt_requester_name);
1058 if (!opt_user_name && getenv("LOGNAME")) {
1059 opt_user_name = getenv("LOGNAME");
1062 if (!opt_workgroup) {
1063 opt_workgroup = smb_xstrdup(lp_workgroup());
1066 if (!opt_target_workgroup) {
1067 opt_target_workgroup = smb_xstrdup(lp_workgroup());
1075 /* this makes sure that when we do things like call scripts,
1076 that it won't assert becouse we are not root */
1079 if (opt_machine_pass) {
1080 /* it is very useful to be able to make ads queries as the
1081 machine account for testing purposes and for domain leave */
1083 net_use_krb_machine_account();
1086 if (!opt_password) {
1087 opt_password = getenv("PASSWD");
1090 rc = net_run_function(argc_new-1, argv_new+1, net_func, net_help);
1092 DEBUG(2,("return code = %d\n", rc));