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 int opt_localgroup = False;
78 int opt_domaingroup = False;
79 static int 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 int opt_testmode = False;
89 int opt_have_ip = False;
90 struct sockaddr_storage 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,
164 struct sockaddr_storage *server_ss,
165 const char *server_name,
166 const char *service_name,
167 const char *service_type)
171 opt_password = net_prompt_pass(opt_user_name);
173 return NT_STATUS_NO_MEMORY;
176 nt_status = cli_full_connection(c, NULL, server_name,
178 service_name, service_type,
179 opt_user_name, opt_workgroup,
180 opt_password, 0, Undefined, NULL);
181 if (NT_STATUS_IS_OK(nt_status)) {
184 d_fprintf(stderr, "Could not connect to server %s\n", server_name);
186 /* Display a nicer message depending on the result */
188 if (NT_STATUS_V(nt_status) ==
189 NT_STATUS_V(NT_STATUS_LOGON_FAILURE))
190 d_fprintf(stderr, "The username or password was not correct.\n");
192 if (NT_STATUS_V(nt_status) ==
193 NT_STATUS_V(NT_STATUS_ACCOUNT_LOCKED_OUT))
194 d_fprintf(stderr, "The account was locked out.\n");
196 if (NT_STATUS_V(nt_status) ==
197 NT_STATUS_V(NT_STATUS_ACCOUNT_DISABLED))
198 d_fprintf(stderr, "The account was disabled.\n");
204 /****************************************************************************
205 Connect to \\server\ipc$.
206 ****************************************************************************/
208 NTSTATUS connect_to_ipc(struct cli_state **c,
209 struct sockaddr_storage *server_ss,
210 const char *server_name)
212 return connect_to_service(c, server_ss, server_name, "IPC$", "IPC");
215 /****************************************************************************
216 Connect to \\server\ipc$ anonymously.
217 ****************************************************************************/
219 NTSTATUS connect_to_ipc_anonymous(struct cli_state **c,
220 struct sockaddr_storage *server_ss,
221 const char *server_name)
225 nt_status = cli_full_connection(c, opt_requester_name, server_name,
229 "", 0, Undefined, NULL);
231 if (NT_STATUS_IS_OK(nt_status)) {
234 DEBUG(1,("Cannot connect to server (anonymously). Error was %s\n", nt_errstr(nt_status)));
239 /****************************************************************************
240 Return malloced user@realm for krb5 login.
241 ****************************************************************************/
243 static char *get_user_and_realm(const char *username)
245 char *user_and_realm = NULL;
250 if (strchr_m(username, '@')) {
251 user_and_realm = SMB_STRDUP(username);
253 if (asprintf(&user_and_realm, "%s@%s", username, lp_realm()) == -1) {
254 user_and_realm = NULL;
257 return user_and_realm;
260 /****************************************************************************
261 Connect to \\server\ipc$ using KRB5.
262 ****************************************************************************/
264 NTSTATUS connect_to_ipc_krb5(struct cli_state **c,
265 struct sockaddr_storage *server_ss,
266 const char *server_name)
269 char *user_and_realm = NULL;
271 opt_password = net_prompt_pass(opt_user_name);
273 return NT_STATUS_NO_MEMORY;
276 user_and_realm = get_user_and_realm(opt_user_name);
277 if (!user_and_realm) {
278 return NT_STATUS_NO_MEMORY;
281 nt_status = cli_full_connection(c, NULL, server_name,
284 user_and_realm, opt_workgroup,
285 opt_password, CLI_FULL_CONNECTION_USE_KERBEROS,
288 SAFE_FREE(user_and_realm);
290 if (NT_STATUS_IS_OK(nt_status)) {
293 DEBUG(1,("Cannot connect to server using kerberos. Error was %s\n", nt_errstr(nt_status)));
299 * Connect a server and open a given pipe
301 * @param cli_dst A cli_state
302 * @param pipe The pipe to open
303 * @param got_pipe boolean that stores if we got a pipe
305 * @return Normal NTSTATUS return.
307 NTSTATUS connect_dst_pipe(struct cli_state **cli_dst, struct rpc_pipe_client **pp_pipe_hnd, int pipe_num)
310 char *server_name = SMB_STRDUP("127.0.0.1");
311 struct cli_state *cli_tmp = NULL;
312 struct rpc_pipe_client *pipe_hnd = NULL;
314 if (server_name == NULL) {
315 return NT_STATUS_NO_MEMORY;
318 if (opt_destination) {
319 SAFE_FREE(server_name);
320 if ((server_name = SMB_STRDUP(opt_destination)) == NULL) {
321 return NT_STATUS_NO_MEMORY;
325 /* make a connection to a named pipe */
326 nt_status = connect_to_ipc(&cli_tmp, NULL, server_name);
327 if (!NT_STATUS_IS_OK(nt_status)) {
328 SAFE_FREE(server_name);
332 pipe_hnd = cli_rpc_pipe_open_noauth(cli_tmp, pipe_num, &nt_status);
334 DEBUG(0, ("couldn't not initialize pipe\n"));
335 cli_shutdown(cli_tmp);
336 SAFE_FREE(server_name);
341 *pp_pipe_hnd = pipe_hnd;
342 SAFE_FREE(server_name);
347 /****************************************************************************
348 Use the local machine account (krb) and password for this session.
349 ****************************************************************************/
351 int net_use_krb_machine_account(void)
353 char *user_name = NULL;
355 if (!secrets_init()) {
356 d_fprintf(stderr, "ERROR: Unable to open secrets database\n");
360 opt_password = secrets_fetch_machine_password(opt_target_workgroup, NULL, NULL);
361 if (asprintf(&user_name, "%s$@%s", global_myname(), lp_realm()) == -1) {
364 opt_user_name = user_name;
368 /****************************************************************************
369 Use the machine account name and password for this session.
370 ****************************************************************************/
372 int net_use_machine_account(void)
374 char *user_name = NULL;
376 if (!secrets_init()) {
377 d_fprintf(stderr, "ERROR: Unable to open secrets database\n");
381 opt_password = secrets_fetch_machine_password(opt_target_workgroup, NULL, NULL);
382 if (asprintf(&user_name, "%s$", global_myname()) == -1) {
385 opt_user_name = user_name;
389 bool net_find_server(const char *domain,
391 struct sockaddr_storage *server_ss,
394 const char *d = domain ? domain : opt_target_workgroup;
397 *server_name = SMB_STRDUP(opt_host);
401 *server_ss = opt_dest_ip;
403 char addr[INET6_ADDRSTRLEN];
404 print_sockaddr(addr, sizeof(addr), &opt_dest_ip);
405 *server_name = SMB_STRDUP(addr);
407 } else if (*server_name) {
408 /* resolve the IP address */
409 if (!resolve_name(*server_name, server_ss, 0x20)) {
410 DEBUG(1,("Unable to resolve server name\n"));
413 } else if (flags & NET_FLAGS_PDC) {
415 struct sockaddr_storage pdc_ss;
417 if (!get_pdc_ip(d, &pdc_ss)) {
418 DEBUG(1,("Unable to resolve PDC server address\n"));
422 if (is_zero_addr(&pdc_ss)) {
426 if (!name_status_find(d, 0x1b, 0x20, &pdc_ss, dc_name)) {
430 *server_name = SMB_STRDUP(dc_name);
432 } else if (flags & NET_FLAGS_DMB) {
433 struct sockaddr_storage msbrow_ss;
434 char addr[INET6_ADDRSTRLEN];
436 /* if (!resolve_name(MSBROWSE, &msbrow_ip, 1)) */
437 if (!resolve_name(d, &msbrow_ss, 0x1B)) {
438 DEBUG(1,("Unable to resolve domain browser via name lookup\n"));
441 *server_ss = msbrow_ss;
442 print_sockaddr(addr, sizeof(addr), server_ss);
443 *server_name = SMB_STRDUP(addr);
444 } else if (flags & NET_FLAGS_MASTER) {
445 struct sockaddr_storage brow_ss;
446 char addr[INET6_ADDRSTRLEN];
447 if (!resolve_name(d, &brow_ss, 0x1D)) {
448 /* go looking for workgroups */
449 DEBUG(1,("Unable to resolve master browser via name lookup\n"));
452 *server_ss = brow_ss;
453 print_sockaddr(addr, sizeof(addr), server_ss);
454 *server_name = SMB_STRDUP(addr);
455 } else if (!(flags & NET_FLAGS_LOCALHOST_DEFAULT_INSANE)) {
456 if (!interpret_string_addr(server_ss,
457 "127.0.0.1", AI_NUMERICHOST)) {
458 DEBUG(1,("Unable to resolve 127.0.0.1\n"));
461 *server_name = SMB_STRDUP("127.0.0.1");
464 if (!server_name || !*server_name) {
465 DEBUG(1,("no server to connect to\n"));
472 bool net_find_pdc(struct sockaddr_storage *server_ss,
474 const char *domain_name)
476 if (!get_pdc_ip(domain_name, server_ss)) {
479 if (is_zero_addr(server_ss)) {
483 if (!name_status_find(domain_name, 0x1b, 0x20, server_ss, server_name)) {
490 NTSTATUS net_make_ipc_connection(unsigned flags, struct cli_state **pcli)
492 return net_make_ipc_connection_ex(NULL, NULL, NULL, flags, pcli);
495 NTSTATUS net_make_ipc_connection_ex(const char *domain, const char *server,
496 struct sockaddr_storage *pss, unsigned flags,
497 struct cli_state **pcli)
499 char *server_name = NULL;
500 struct sockaddr_storage server_ss;
501 struct cli_state *cli = NULL;
504 if ( !server || !pss ) {
505 if (!net_find_server(domain, flags, &server_ss, &server_name)) {
506 d_fprintf(stderr, "Unable to find a suitable server\n");
507 nt_status = NT_STATUS_UNSUCCESSFUL;
511 server_name = SMB_STRDUP( server );
515 if (flags & NET_FLAGS_ANONYMOUS) {
516 nt_status = connect_to_ipc_anonymous(&cli, &server_ss, server_name);
518 nt_status = connect_to_ipc(&cli, &server_ss, server_name);
521 /* store the server in the affinity cache if it was a PDC */
523 if ( (flags & NET_FLAGS_PDC) && NT_STATUS_IS_OK(nt_status) )
524 saf_store( cli->server_domain, cli->desthost );
526 SAFE_FREE(server_name);
527 if (!NT_STATUS_IS_OK(nt_status)) {
528 d_fprintf(stderr, "Connection failed: %s\n",
529 nt_errstr(nt_status));
540 static int net_user(int argc, const char **argv)
542 if (net_ads_check() == 0)
543 return net_ads_user(argc, argv);
545 /* if server is not specified, default to PDC? */
546 if (net_rpc_check(NET_FLAGS_PDC))
547 return net_rpc_user(argc, argv);
549 return net_rap_user(argc, argv);
552 static int net_group(int argc, const char **argv)
554 if (net_ads_check() == 0)
555 return net_ads_group(argc, argv);
557 if (argc == 0 && net_rpc_check(NET_FLAGS_PDC))
558 return net_rpc_group(argc, argv);
560 return net_rap_group(argc, argv);
563 static int net_join(int argc, const char **argv)
565 if (net_ads_check_our_domain() == 0) {
566 if (net_ads_join(argc, argv) == 0)
569 d_fprintf(stderr, "ADS join did not work, falling back to RPC...\n");
571 return net_rpc_join(argc, argv);
574 static int net_changetrustpw(int argc, const char **argv)
576 if (net_ads_check_our_domain() == 0)
577 return net_ads_changetrustpw(argc, argv);
579 return net_rpc_changetrustpw(argc, argv);
582 static void set_line_buffering(FILE *f)
584 setvbuf(f, NULL, _IOLBF, 0);
587 static int net_changesecretpw(int argc, const char **argv)
590 uint32 sec_channel_type = SEC_CHAN_WKSTA;
594 set_line_buffering(stdin);
595 set_line_buffering(stdout);
596 set_line_buffering(stderr);
599 trust_pw = get_pass("Enter machine password: ", opt_stdin);
601 if (!secrets_store_machine_password(trust_pw, lp_workgroup(), sec_channel_type)) {
602 d_fprintf(stderr, "Unable to write the machine account password in the secrets database");
606 d_printf("Modified trust account password in secrets database\n");
610 d_printf("Machine account password change requires the -f flag.\n");
611 d_printf("Do NOT use this function unless you know what it does!\n");
612 d_printf("This function will change the ADS Domain member machine account password in the secrets.tdb file!\n");
618 static int net_share(int argc, const char **argv)
620 if (net_rpc_check(0))
621 return net_rpc_share(argc, argv);
622 return net_rap_share(argc, argv);
625 static int net_file(int argc, const char **argv)
627 if (net_rpc_check(0))
628 return net_rpc_file(argc, argv);
629 return net_rap_file(argc, argv);
633 Retrieve our local SID or the SID for the specified name
635 static int net_getlocalsid(int argc, const char **argv)
645 name = global_myname();
648 if(!initialize_password_db(False, NULL)) {
649 DEBUG(0, ("WARNING: Could not open passdb - local sid may not reflect passdb\n"
650 "backend knowledge (such as the sid stored in LDAP)\n"));
653 /* first check to see if we can even access secrets, so we don't
654 panic when we can't. */
656 if (!secrets_init()) {
657 d_fprintf(stderr, "Unable to open secrets.tdb. Can't fetch domain SID for name: %s\n", name);
661 /* Generate one, if it doesn't exist */
662 get_global_sam_sid();
664 if (!secrets_fetch_domain_sid(name, &sid)) {
665 DEBUG(0, ("Can't fetch domain SID for name: %s\n", name));
668 sid_to_string(sid_str, &sid);
669 d_printf("SID for domain %s is: %s\n", name, sid_str);
673 static int net_setlocalsid(int argc, const char **argv)
678 || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
679 || (!string_to_sid(&sid, argv[0]))
680 || (sid.num_auths != 4)) {
681 d_printf("usage: net setlocalsid S-1-5-21-x-y-z\n");
685 if (!secrets_store_domain_sid(global_myname(), &sid)) {
686 DEBUG(0,("Can't store domain SID as a pdc/bdc.\n"));
693 static int net_setdomainsid(int argc, const char **argv)
698 || (strncmp(argv[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
699 || (!string_to_sid(&sid, argv[0]))
700 || (sid.num_auths != 4)) {
701 d_printf("usage: net setdomainsid S-1-5-21-x-y-z\n");
705 if (!secrets_store_domain_sid(lp_workgroup(), &sid)) {
706 DEBUG(0,("Can't store domain SID.\n"));
713 static int net_getdomainsid(int argc, const char **argv)
718 if(!initialize_password_db(False, NULL)) {
719 DEBUG(0, ("WARNING: Could not open passdb - domain sid may not reflect passdb\n"
720 "backend knowledge (such as the sid stored in LDAP)\n"));
723 /* first check to see if we can even access secrets, so we don't
724 panic when we can't. */
726 if (!secrets_init()) {
727 d_fprintf(stderr, "Unable to open secrets.tdb. Can't fetch domain"
728 "SID for name: %s\n", get_global_sam_name());
732 /* Generate one, if it doesn't exist */
733 get_global_sam_sid();
735 if (!secrets_fetch_domain_sid(global_myname(), &domain_sid)) {
736 d_fprintf(stderr, "Could not fetch local SID\n");
739 sid_to_string(sid_str, &domain_sid);
740 d_printf("SID for domain %s is: %s\n", global_myname(), sid_str);
742 if (!secrets_fetch_domain_sid(opt_workgroup, &domain_sid)) {
743 d_fprintf(stderr, "Could not fetch domain SID\n");
747 sid_to_string(sid_str, &domain_sid);
748 d_printf("SID for domain %s is: %s\n", opt_workgroup, sid_str);
753 #ifdef WITH_FAKE_KASERVER
755 int net_help_afs(int argc, const char **argv)
757 d_printf(" net afs key filename\n"
758 "\tImports a OpenAFS KeyFile into our secrets.tdb\n\n");
759 d_printf(" net afs impersonate <user> <cell>\n"
760 "\tCreates a token for user@cell\n\n");
764 static int net_afs_key(int argc, const char **argv)
767 struct afs_keyfile keyfile;
770 d_printf("usage: 'net afs key <keyfile> cell'\n");
774 if (!secrets_init()) {
775 d_fprintf(stderr, "Could not open secrets.tdb\n");
779 if ((fd = open(argv[0], O_RDONLY, 0)) < 0) {
780 d_fprintf(stderr, "Could not open %s\n", argv[0]);
784 if (read(fd, &keyfile, sizeof(keyfile)) != sizeof(keyfile)) {
785 d_fprintf(stderr, "Could not read keyfile\n");
789 if (!secrets_store_afs_keyfile(argv[1], &keyfile)) {
790 d_fprintf(stderr, "Could not write keyfile to secrets.tdb\n");
797 static int net_afs_impersonate(int argc, const char **argv)
802 fprintf(stderr, "Usage: net afs impersonate <user> <cell>\n");
806 token = afs_createtoken_str(argv[0], argv[1]);
809 fprintf(stderr, "Could not create token\n");
813 if (!afs_settoken_str(token)) {
814 fprintf(stderr, "Could not set token into kernel\n");
818 printf("Success: %s@%s\n", argv[0], argv[1]);
822 static int net_afs(int argc, const char **argv)
824 struct functable func[] = {
825 {"key", net_afs_key},
826 {"impersonate", net_afs_impersonate},
827 {"help", net_help_afs},
830 return net_run_function(argc, argv, func, net_help_afs);
833 #endif /* WITH_FAKE_KASERVER */
835 static bool search_maxrid(struct pdb_search *search, const char *type,
838 struct samr_displayentry *entries;
839 uint32 i, num_entries;
841 if (search == NULL) {
842 d_fprintf(stderr, "get_maxrid: Could not search %s\n", type);
846 num_entries = pdb_search_entries(search, 0, 0xffffffff, &entries);
847 for (i=0; i<num_entries; i++)
848 *max_rid = MAX(*max_rid, entries[i].rid);
849 pdb_search_destroy(search);
853 static uint32 get_maxrid(void)
857 if (!search_maxrid(pdb_search_users(0), "users", &max_rid))
860 if (!search_maxrid(pdb_search_groups(), "groups", &max_rid))
863 if (!search_maxrid(pdb_search_aliases(get_global_sam_sid()),
864 "aliases", &max_rid))
870 static int net_maxrid(int argc, const char **argv)
875 DEBUG(0, ("usage: net maxrid\n"));
879 if ((rid = get_maxrid()) == 0) {
880 DEBUG(0, ("can't get current maximum rid\n"));
884 d_printf("Currently used maximum rid: %d\n", rid);
889 /****************************************************************************
890 ****************************************************************************/
892 const char *net_prompt_pass(const char *user)
895 const char *pass = NULL;
901 if (opt_machine_pass) {
905 asprintf(&prompt, "Enter %s's password:", user);
910 pass = getpass(prompt);
916 /* main function table */
917 static struct functable net_func[] = {
922 /* eventually these should auto-choose the transport ... */
924 {"SHARE", net_share},
925 {"SESSION", net_rap_session},
926 {"SERVER", net_rap_server},
927 {"DOMAIN", net_rap_domain},
928 {"PRINTQ", net_rap_printq},
930 {"GROUP", net_group},
931 {"GROUPMAP", net_groupmap},
933 {"VALIDATE", net_rap_validate},
934 {"GROUPMEMBER", net_rap_groupmember},
935 {"ADMIN", net_rap_admin},
936 {"SERVICE", net_rap_service},
937 {"PASSWORD", net_rap_password},
938 {"CHANGETRUSTPW", net_changetrustpw},
939 {"CHANGESECRETPW", net_changesecretpw},
941 {"LOOKUP", net_lookup},
943 {"CACHE", net_cache},
944 {"GETLOCALSID", net_getlocalsid},
945 {"SETLOCALSID", net_setlocalsid},
946 {"SETDOMAINSID", net_setdomainsid},
947 {"GETDOMAINSID", net_getdomainsid},
948 {"MAXRID", net_maxrid},
949 {"IDMAP", net_idmap},
950 {"STATUS", net_status},
951 {"USERSHARE", net_usershare},
952 {"USERSIDLIST", net_usersidlist},
954 #ifdef WITH_FAKE_KASERVER
963 /****************************************************************************
965 ****************************************************************************/
966 int main(int argc, const char **argv)
972 const char ** argv_new;
975 struct poptOption long_options[] = {
976 {"help", 'h', POPT_ARG_NONE, 0, 'h'},
977 {"workgroup", 'w', POPT_ARG_STRING, &opt_target_workgroup},
978 {"user", 'U', POPT_ARG_STRING, &opt_user_name, 'U'},
979 {"ipaddress", 'I', POPT_ARG_STRING, 0,'I'},
980 {"port", 'p', POPT_ARG_INT, &opt_port},
981 {"myname", 'n', POPT_ARG_STRING, &opt_requester_name},
982 {"server", 'S', POPT_ARG_STRING, &opt_host},
983 {"container", 'c', POPT_ARG_STRING, &opt_container},
984 {"comment", 'C', POPT_ARG_STRING, &opt_comment},
985 {"maxusers", 'M', POPT_ARG_INT, &opt_maxusers},
986 {"flags", 'F', POPT_ARG_INT, &opt_flags},
987 {"long", 'l', POPT_ARG_NONE, &opt_long_list_entries},
988 {"reboot", 'r', POPT_ARG_NONE, &opt_reboot},
989 {"force", 'f', POPT_ARG_NONE, &opt_force},
990 {"stdin", 'i', POPT_ARG_NONE, &opt_stdin},
991 {"timeout", 't', POPT_ARG_INT, &opt_timeout},
992 {"machine-pass",'P', POPT_ARG_NONE, &opt_machine_pass},
993 {"myworkgroup", 'W', POPT_ARG_STRING, &opt_workgroup},
994 {"verbose", 'v', POPT_ARG_NONE, &opt_verbose},
995 {"test", 'T', POPT_ARG_NONE, &opt_testmode},
996 /* Options for 'net groupmap set' */
997 {"local", 'L', POPT_ARG_NONE, &opt_localgroup},
998 {"domain", 'D', POPT_ARG_NONE, &opt_domaingroup},
999 {"ntname", 'N', POPT_ARG_STRING, &opt_newntname},
1000 {"rid", 'R', POPT_ARG_INT, &opt_rid},
1001 /* Options for 'net rpc share migrate' */
1002 {"acls", 0, POPT_ARG_NONE, &opt_acls},
1003 {"attrs", 0, POPT_ARG_NONE, &opt_attrs},
1004 {"timestamps", 0, POPT_ARG_NONE, &opt_timestamps},
1005 {"exclude", 'e', POPT_ARG_STRING, &opt_exclude},
1006 {"destination", 0, POPT_ARG_STRING, &opt_destination},
1007 {"tallocreport", 0, POPT_ARG_NONE, &do_talloc_report},
1013 TALLOC_CTX *frame = talloc_stackframe();
1015 zero_addr(&opt_dest_ip);
1019 /* set default debug level to 0 regardless of what smb.conf sets */
1020 DEBUGLEVEL_CLASS[DBGC_ALL] = 0;
1023 pc = poptGetContext(NULL, argc, (const char **) argv, long_options,
1024 POPT_CONTEXT_KEEP_FIRST);
1026 while((opt = poptGetNextOpt(pc)) != -1) {
1029 net_help(argc, argv);
1033 if (!interpret_string_addr(&opt_dest_ip,
1034 poptGetOptArg(pc), 0)) {
1035 d_fprintf(stderr, "\nInvalid ip address specified\n");
1041 opt_user_specified = True;
1042 opt_user_name = SMB_STRDUP(opt_user_name);
1043 p = strchr(opt_user_name,'%');
1050 d_fprintf(stderr, "\nInvalid option %s: %s\n",
1051 poptBadOption(pc, 0), poptStrerror(opt));
1052 net_help(argc, argv);
1058 * Don't load debug level from smb.conf. It should be
1059 * set by cmdline arg or remain default (0)
1061 AllowDebugChange = False;
1062 lp_load(dyn_CONFIGFILE,True,False,False,True);
1064 argv_new = (const char **)poptGetArgs(pc);
1067 for (i=0; i<argc; i++) {
1068 if (argv_new[i] == NULL) {
1074 if (do_talloc_report) {
1075 talloc_enable_leak_report();
1078 if (opt_requester_name) {
1079 set_global_myname(opt_requester_name);
1082 if (!opt_user_name && getenv("LOGNAME")) {
1083 opt_user_name = getenv("LOGNAME");
1086 if (!opt_workgroup) {
1087 opt_workgroup = smb_xstrdup(lp_workgroup());
1090 if (!opt_target_workgroup) {
1091 opt_target_workgroup = smb_xstrdup(lp_workgroup());
1099 /* this makes sure that when we do things like call scripts,
1100 that it won't assert becouse we are not root */
1103 if (opt_machine_pass) {
1104 /* it is very useful to be able to make ads queries as the
1105 machine account for testing purposes and for domain leave */
1107 net_use_krb_machine_account();
1110 if (!opt_password) {
1111 opt_password = getenv("PASSWD");
1114 rc = net_run_function(argc_new-1, argv_new+1, net_func, net_help);
1116 DEBUG(2,("return code = %d\n", rc));