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 2 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, write to the Free Software
26 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
28 /*****************************************************/
30 /* Distributed SMB/CIFS Server Management Utility */
32 /* The intent was to make the syntax similar */
33 /* to the NET utility (first developed in DOS */
34 /* with additional interesting & useful functions */
35 /* added in later SMB server network operating */
38 /*****************************************************/
41 #include "utils/net.h"
43 /***********************************************************************/
44 /* Beginning of internationalization section. Translatable constants */
45 /* should be kept in this area and referenced in the rest of the code. */
47 /* No functions, outside of Samba or LSB (Linux Standards Base) should */
48 /* be used (if possible). */
49 /***********************************************************************/
51 #define YES_STRING "Yes"
52 #define NO_STRING "No"
54 /************************************************************************************/
55 /* end of internationalization section */
56 /************************************************************************************/
58 /* Yes, these buggers are globals.... */
59 const char *opt_requester_name
= NULL
;
60 const char *opt_host
= NULL
;
61 const char *opt_password
= NULL
;
62 const char *opt_user_name
= NULL
;
63 BOOL opt_user_specified
= False
;
64 const char *opt_workgroup
= NULL
;
65 int opt_long_list_entries
= 0;
71 int opt_maxusers
= -1;
72 const char *opt_comment
= "";
73 const char *opt_container
= NULL
;
76 const char *opt_target_workgroup
= NULL
;
77 int opt_machine_pass
= 0;
78 BOOL opt_localgroup
= False
;
79 BOOL opt_domaingroup
= False
;
80 static BOOL do_talloc_report
=False
;
81 const char *opt_newntname
= "";
85 int opt_timestamps
= 0;
86 const char *opt_exclude
= NULL
;
87 const char *opt_destination
= NULL
;
89 BOOL opt_have_ip
= False
;
90 struct in_addr opt_dest_ip
;
92 extern struct in_addr loopback_ip
;
93 extern BOOL AllowDebugChange
;
95 uint32
get_sec_channel_type(const char *param
)
97 if (!(param
&& *param
)) {
98 return get_default_sec_channel();
100 if (strequal(param
, "PDC")) {
102 } else if (strequal(param
, "BDC")) {
104 } else if (strequal(param
, "MEMBER")) {
105 return SEC_CHAN_WKSTA
;
107 } else if (strequal(param
, "DOMAIN")) {
108 return SEC_CHAN_DOMAIN
;
111 return get_default_sec_channel();
117 run a function from a function table. If not found then
118 call the specified usage function
120 int net_run_function(int argc
, const char **argv
, struct functable
*table
,
121 int (*usage_fn
)(int argc
, const char **argv
))
126 d_printf("\nUsage: \n");
127 return usage_fn(argc
, argv
);
129 for (i
=0; table
[i
].funcname
; i
++) {
130 if (StrCaseCmp(argv
[0], table
[i
].funcname
) == 0)
131 return table
[i
].fn(argc
-1, argv
+1);
133 d_fprintf(stderr
, "No command: %s\n", argv
[0]);
134 return usage_fn(argc
, argv
);
138 * run a function from a function table.
140 int net_run_function2(int argc
, const char **argv
, const char *whoami
,
141 struct functable2
*table
)
146 for (i
=0; table
[i
].funcname
; i
++) {
147 if (StrCaseCmp(argv
[0], table
[i
].funcname
) == 0)
148 return table
[i
].fn(argc
-1, argv
+1);
152 for (i
=0; table
[i
].funcname
!= NULL
; i
++) {
153 d_printf("%s %-15s %s\n", whoami
, table
[i
].funcname
,
160 /****************************************************************************
161 connect to \\server\service
162 ****************************************************************************/
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 if (!opt_password
&& !opt_machine_pass
) {
171 char *pass
= getpass("Password:");
173 opt_password
= SMB_STRDUP(pass
);
177 nt_status
= cli_full_connection(c
, NULL
, server_name
,
179 service_name
, service_type
,
180 opt_user_name
, opt_workgroup
,
181 opt_password
, 0, Undefined
, NULL
);
183 if (NT_STATUS_IS_OK(nt_status
)) {
186 d_fprintf(stderr
, "Could not connect to server %s\n", server_name
);
188 /* Display a nicer message depending on the result */
190 if (NT_STATUS_V(nt_status
) ==
191 NT_STATUS_V(NT_STATUS_LOGON_FAILURE
))
192 d_fprintf(stderr
, "The username or password was not correct.\n");
194 if (NT_STATUS_V(nt_status
) ==
195 NT_STATUS_V(NT_STATUS_ACCOUNT_LOCKED_OUT
))
196 d_fprintf(stderr
, "The account was locked out.\n");
198 if (NT_STATUS_V(nt_status
) ==
199 NT_STATUS_V(NT_STATUS_ACCOUNT_DISABLED
))
200 d_fprintf(stderr
, "The account was disabled.\n");
207 /****************************************************************************
208 connect to \\server\ipc$
209 ****************************************************************************/
210 NTSTATUS
connect_to_ipc(struct cli_state
**c
, struct in_addr
*server_ip
,
211 const char *server_name
)
213 return connect_to_service(c
, server_ip
, server_name
, "IPC$", "IPC");
216 /****************************************************************************
217 connect to \\server\ipc$ anonymously
218 ****************************************************************************/
219 NTSTATUS
connect_to_ipc_anonymous(struct cli_state
**c
,
220 struct in_addr
*server_ip
, const char *server_name
)
224 nt_status
= cli_full_connection(c
, opt_requester_name
, server_name
,
228 "", 0, Undefined
, NULL
);
230 if (NT_STATUS_IS_OK(nt_status
)) {
233 DEBUG(1,("Cannot connect to server (anonymously). Error was %s\n", nt_errstr(nt_status
)));
238 /****************************************************************************
239 connect to \\server\ipc$ using KRB5
240 ****************************************************************************/
241 NTSTATUS
connect_to_ipc_krb5(struct cli_state
**c
,
242 struct in_addr
*server_ip
, const char *server_name
)
246 nt_status
= cli_full_connection(c
, NULL
, server_name
,
249 opt_user_name
, opt_workgroup
,
250 opt_password
, CLI_FULL_CONNECTION_USE_KERBEROS
,
253 if (NT_STATUS_IS_OK(nt_status
)) {
256 DEBUG(1,("Cannot connect to server using kerberos. Error was %s\n", nt_errstr(nt_status
)));
262 * Connect a server and open a given pipe
264 * @param cli_dst A cli_state
265 * @param pipe The pipe to open
266 * @param got_pipe boolean that stores if we got a pipe
268 * @return Normal NTSTATUS return.
270 NTSTATUS
connect_dst_pipe(struct cli_state
**cli_dst
, struct rpc_pipe_client
**pp_pipe_hnd
, int pipe_num
)
273 char *server_name
= SMB_STRDUP("127.0.0.1");
274 struct cli_state
*cli_tmp
= NULL
;
275 struct rpc_pipe_client
*pipe_hnd
= NULL
;
277 if (server_name
== NULL
) {
278 return NT_STATUS_NO_MEMORY
;
281 if (opt_destination
) {
282 SAFE_FREE(server_name
);
283 if ((server_name
= SMB_STRDUP(opt_destination
)) == NULL
) {
284 return NT_STATUS_NO_MEMORY
;
288 /* make a connection to a named pipe */
289 nt_status
= connect_to_ipc(&cli_tmp
, NULL
, server_name
);
290 if (!NT_STATUS_IS_OK(nt_status
)) {
291 SAFE_FREE(server_name
);
295 pipe_hnd
= cli_rpc_pipe_open_noauth(cli_tmp
, pipe_num
, &nt_status
);
297 DEBUG(0, ("couldn't not initialize pipe\n"));
298 cli_shutdown(cli_tmp
);
299 SAFE_FREE(server_name
);
304 *pp_pipe_hnd
= pipe_hnd
;
305 SAFE_FREE(server_name
);
310 /****************************************************************************
311 Use the local machine's password for this session.
312 ****************************************************************************/
314 int net_use_machine_password(void)
316 char *user_name
= NULL
;
318 if (!secrets_init()) {
319 d_fprintf(stderr
, "ERROR: Unable to open secrets database\n");
324 opt_password
= secrets_fetch_machine_password(opt_target_workgroup
, NULL
, NULL
);
325 if (asprintf(&user_name
, "%s$@%s", global_myname(), lp_realm()) == -1) {
328 opt_user_name
= user_name
;
332 BOOL
net_find_server(const char *domain
, unsigned flags
, struct in_addr
*server_ip
, char **server_name
)
334 const char *d
= domain
? domain
: opt_target_workgroup
;
337 *server_name
= SMB_STRDUP(opt_host
);
341 *server_ip
= opt_dest_ip
;
343 *server_name
= SMB_STRDUP(inet_ntoa(opt_dest_ip
));
345 } else if (*server_name
) {
346 /* resolve the IP address */
347 if (!resolve_name(*server_name
, server_ip
, 0x20)) {
348 DEBUG(1,("Unable to resolve server name\n"));
351 } else if (flags
& NET_FLAGS_PDC
) {
352 struct in_addr pdc_ip
;
354 if (get_pdc_ip(d
, &pdc_ip
)) {
357 if (is_zero_ip(pdc_ip
))
360 if ( !name_status_find(d
, 0x1b, 0x20, pdc_ip
, dc_name
) )
363 *server_name
= SMB_STRDUP(dc_name
);
366 } else if (flags
& NET_FLAGS_DMB
) {
367 struct in_addr msbrow_ip
;
368 /* if (!resolve_name(MSBROWSE, &msbrow_ip, 1)) */
369 if (!resolve_name(d
, &msbrow_ip
, 0x1B)) {
370 DEBUG(1,("Unable to resolve domain browser via name lookup\n"));
373 *server_ip
= msbrow_ip
;
375 *server_name
= SMB_STRDUP(inet_ntoa(opt_dest_ip
));
376 } else if (flags
& NET_FLAGS_MASTER
) {
377 struct in_addr brow_ips
;
378 if (!resolve_name(d
, &brow_ips
, 0x1D)) {
379 /* go looking for workgroups */
380 DEBUG(1,("Unable to resolve master browser via name lookup\n"));
383 *server_ip
= brow_ips
;
385 *server_name
= SMB_STRDUP(inet_ntoa(opt_dest_ip
));
386 } else if (!(flags
& NET_FLAGS_LOCALHOST_DEFAULT_INSANE
)) {
387 *server_ip
= loopback_ip
;
388 *server_name
= SMB_STRDUP("127.0.0.1");
391 if (!server_name
|| !*server_name
) {
392 DEBUG(1,("no server to connect to\n"));
400 BOOL
net_find_pdc(struct in_addr
*server_ip
, fstring server_name
, const char *domain_name
)
402 if (get_pdc_ip(domain_name
, server_ip
)) {
403 if (is_zero_ip(*server_ip
))
406 if (!name_status_find(domain_name
, 0x1b, 0x20, *server_ip
, server_name
))
415 struct cli_state
*net_make_ipc_connection( unsigned flags
)
417 return net_make_ipc_connection_ex( NULL
, NULL
, NULL
, flags
);
420 struct cli_state
*net_make_ipc_connection_ex( const char *domain
, const char *server
,
421 struct in_addr
*ip
, unsigned flags
)
423 char *server_name
= NULL
;
424 struct in_addr server_ip
;
425 struct cli_state
*cli
= NULL
;
428 if ( !server
|| !ip
) {
429 if (!net_find_server(domain
, flags
, &server_ip
, &server_name
)) {
430 d_fprintf(stderr
, "Unable to find a suitable server\n");
434 server_name
= SMB_STRDUP( server
);
438 if (flags
& NET_FLAGS_ANONYMOUS
) {
439 nt_status
= connect_to_ipc_anonymous(&cli
, &server_ip
, server_name
);
441 nt_status
= connect_to_ipc(&cli
, &server_ip
, server_name
);
444 /* store the server in the affinity cache if it was a PDC */
446 if ( (flags
& NET_FLAGS_PDC
) && NT_STATUS_IS_OK(nt_status
) )
447 saf_store( cli
->server_domain
, cli
->desthost
);
449 SAFE_FREE(server_name
);
450 if (NT_STATUS_IS_OK(nt_status
)) {
453 d_fprintf(stderr
, "Connection failed: %s\n",
454 nt_errstr(nt_status
));
459 static int net_user(int argc
, const char **argv
)
461 if (net_ads_check() == 0)
462 return net_ads_user(argc
, argv
);
464 /* if server is not specified, default to PDC? */
465 if (net_rpc_check(NET_FLAGS_PDC
))
466 return net_rpc_user(argc
, argv
);
468 return net_rap_user(argc
, argv
);
471 static int net_group(int argc
, const char **argv
)
473 if (net_ads_check() == 0)
474 return net_ads_group(argc
, argv
);
476 if (argc
== 0 && net_rpc_check(NET_FLAGS_PDC
))
477 return net_rpc_group(argc
, argv
);
479 return net_rap_group(argc
, argv
);
482 static int net_join(int argc
, const char **argv
)
484 if (net_ads_check_our_domain() == 0) {
485 if (net_ads_join(argc
, argv
) == 0)
488 d_fprintf(stderr
, "ADS join did not work, falling back to RPC...\n");
490 return net_rpc_join(argc
, argv
);
493 static int net_changetrustpw(int argc
, const char **argv
)
495 if (net_ads_check_our_domain() == 0)
496 return net_ads_changetrustpw(argc
, argv
);
498 return net_rpc_changetrustpw(argc
, argv
);
501 static void set_line_buffering(FILE *f
)
503 setvbuf(f
, NULL
, _IOLBF
, 0);
506 static int net_changesecretpw(int argc
, const char **argv
)
509 uint32 sec_channel_type
= SEC_CHAN_WKSTA
;
513 set_line_buffering(stdin
);
514 set_line_buffering(stdout
);
515 set_line_buffering(stderr
);
518 trust_pw
= get_pass("Enter machine password: ", opt_stdin
);
520 if (!secrets_store_machine_password(trust_pw
, lp_workgroup(), sec_channel_type
)) {
521 d_fprintf(stderr
, "Unable to write the machine account password in the secrets database");
525 d_printf("Modified trust account password in secrets database\n");
529 d_printf("Machine account password change requires the -f flag.\n");
530 d_printf("Do NOT use this function unless you know what it does!\n");
531 d_printf("This function will change the ADS Domain member machine account password in the secrets.tdb file!\n");
537 static int net_share(int argc
, const char **argv
)
539 if (net_rpc_check(0))
540 return net_rpc_share(argc
, argv
);
541 return net_rap_share(argc
, argv
);
544 static int net_file(int argc
, const char **argv
)
546 if (net_rpc_check(0))
547 return net_rpc_file(argc
, argv
);
548 return net_rap_file(argc
, argv
);
552 Retrieve our local SID or the SID for the specified name
554 static int net_getlocalsid(int argc
, const char **argv
)
564 name
= global_myname();
567 if(!initialize_password_db(False
)) {
568 DEBUG(0, ("WARNING: Could not open passdb - local sid may not reflect passdb\n"
569 "backend knowlege (such as the sid stored in LDAP)\n"));
572 /* first check to see if we can even access secrets, so we don't
573 panic when we can't. */
575 if (!secrets_init()) {
576 d_fprintf(stderr
, "Unable to open secrets.tdb. Can't fetch domain SID for name: %s\n", name
);
580 /* Generate one, if it doesn't exist */
581 get_global_sam_sid();
583 if (!secrets_fetch_domain_sid(name
, &sid
)) {
584 DEBUG(0, ("Can't fetch domain SID for name: %s\n", name
));
587 sid_to_string(sid_str
, &sid
);
588 d_printf("SID for domain %s is: %s\n", name
, sid_str
);
592 static int net_setlocalsid(int argc
, const char **argv
)
597 || (strncmp(argv
[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
598 || (!string_to_sid(&sid
, argv
[0]))
599 || (sid
.num_auths
!= 4)) {
600 d_printf("usage: net setlocalsid S-1-5-21-x-y-z\n");
604 if (!secrets_store_domain_sid(global_myname(), &sid
)) {
605 DEBUG(0,("Can't store domain SID as a pdc/bdc.\n"));
612 static int net_setdomainsid(int argc
, const char **argv
)
617 || (strncmp(argv
[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
618 || (!string_to_sid(&sid
, argv
[0]))
619 || (sid
.num_auths
!= 4)) {
620 d_printf("usage: net setdomainsid S-1-5-21-x-y-z\n");
624 if (!secrets_store_domain_sid(lp_workgroup(), &sid
)) {
625 DEBUG(0,("Can't store domain SID.\n"));
632 static int net_getdomainsid(int argc
, const char **argv
)
637 if(!initialize_password_db(False
)) {
638 DEBUG(0, ("WARNING: Could not open passdb - domain sid may not reflect passdb\n"
639 "backend knowlege (such as the sid stored in LDAP)\n"));
642 /* Generate one, if it doesn't exist */
643 get_global_sam_sid();
645 if (!secrets_fetch_domain_sid(global_myname(), &domain_sid
)) {
646 d_fprintf(stderr
, "Could not fetch local SID\n");
649 sid_to_string(sid_str
, &domain_sid
);
650 d_printf("SID for domain %s is: %s\n", global_myname(), sid_str
);
652 if (!secrets_fetch_domain_sid(opt_workgroup
, &domain_sid
)) {
653 d_fprintf(stderr
, "Could not fetch domain SID\n");
657 sid_to_string(sid_str
, &domain_sid
);
658 d_printf("SID for domain %s is: %s\n", opt_workgroup
, sid_str
);
663 #ifdef WITH_FAKE_KASERVER
665 int net_help_afs(int argc
, const char **argv
)
667 d_printf(" net afs key filename\n"
668 "\tImports a OpenAFS KeyFile into our secrets.tdb\n\n");
669 d_printf(" net afs impersonate <user> <cell>\n"
670 "\tCreates a token for user@cell\n\n");
674 static int net_afs_key(int argc
, const char **argv
)
677 struct afs_keyfile keyfile
;
680 d_printf("usage: 'net afs key <keyfile> cell'\n");
684 if (!secrets_init()) {
685 d_fprintf(stderr
, "Could not open secrets.tdb\n");
689 if ((fd
= open(argv
[0], O_RDONLY
, 0)) < 0) {
690 d_fprintf(stderr
, "Could not open %s\n", argv
[0]);
694 if (read(fd
, &keyfile
, sizeof(keyfile
)) != sizeof(keyfile
)) {
695 d_fprintf(stderr
, "Could not read keyfile\n");
699 if (!secrets_store_afs_keyfile(argv
[1], &keyfile
)) {
700 d_fprintf(stderr
, "Could not write keyfile to secrets.tdb\n");
707 static int net_afs_impersonate(int argc
, const char **argv
)
712 fprintf(stderr
, "Usage: net afs impersonate <user> <cell>\n");
716 token
= afs_createtoken_str(argv
[0], argv
[1]);
719 fprintf(stderr
, "Could not create token\n");
723 if (!afs_settoken_str(token
)) {
724 fprintf(stderr
, "Could not set token into kernel\n");
728 printf("Success: %s@%s\n", argv
[0], argv
[1]);
732 static int net_afs(int argc
, const char **argv
)
734 struct functable func
[] = {
735 {"key", net_afs_key
},
736 {"impersonate", net_afs_impersonate
},
737 {"help", net_help_afs
},
740 return net_run_function(argc
, argv
, func
, net_help_afs
);
743 #endif /* WITH_FAKE_KASERVER */
745 static BOOL
search_maxrid(struct pdb_search
*search
, const char *type
,
748 struct samr_displayentry
*entries
;
749 uint32 i
, num_entries
;
751 if (search
== NULL
) {
752 d_fprintf(stderr
, "get_maxrid: Could not search %s\n", type
);
756 num_entries
= pdb_search_entries(search
, 0, 0xffffffff, &entries
);
757 for (i
=0; i
<num_entries
; i
++)
758 *max_rid
= MAX(*max_rid
, entries
[i
].rid
);
759 pdb_search_destroy(search
);
763 static uint32
get_maxrid(void)
767 if (!search_maxrid(pdb_search_users(0), "users", &max_rid
))
770 if (!search_maxrid(pdb_search_groups(), "groups", &max_rid
))
773 if (!search_maxrid(pdb_search_aliases(get_global_sam_sid()),
774 "aliases", &max_rid
))
780 static int net_maxrid(int argc
, const char **argv
)
785 DEBUG(0, ("usage: net maxrid\n"));
789 if ((rid
= get_maxrid()) == 0) {
790 DEBUG(0, ("can't get current maximum rid\n"));
794 d_printf("Currently used maximum rid: %d\n", rid
);
799 /* main function table */
800 static struct functable net_func
[] = {
805 /* eventually these should auto-choose the transport ... */
807 {"SHARE", net_share
},
808 {"SESSION", net_rap_session
},
809 {"SERVER", net_rap_server
},
810 {"DOMAIN", net_rap_domain
},
811 {"PRINTQ", net_rap_printq
},
813 {"GROUP", net_group
},
814 {"GROUPMAP", net_groupmap
},
816 {"VALIDATE", net_rap_validate
},
817 {"GROUPMEMBER", net_rap_groupmember
},
818 {"ADMIN", net_rap_admin
},
819 {"SERVICE", net_rap_service
},
820 {"PASSWORD", net_rap_password
},
821 {"CHANGETRUSTPW", net_changetrustpw
},
822 {"CHANGESECRETPW", net_changesecretpw
},
824 {"LOOKUP", net_lookup
},
826 {"CACHE", net_cache
},
827 {"GETLOCALSID", net_getlocalsid
},
828 {"SETLOCALSID", net_setlocalsid
},
829 {"SETDOMAINSID", net_setdomainsid
},
830 {"GETDOMAINSID", net_getdomainsid
},
831 {"MAXRID", net_maxrid
},
832 {"IDMAP", net_idmap
},
833 {"STATUS", net_status
},
834 {"USERSHARE", net_usershare
},
835 {"USERSIDLIST", net_usersidlist
},
836 #ifdef WITH_FAKE_KASERVER
845 /****************************************************************************
847 ****************************************************************************/
848 int main(int argc
, const char **argv
)
854 const char ** argv_new
;
857 struct poptOption long_options
[] = {
858 {"help", 'h', POPT_ARG_NONE
, 0, 'h'},
859 {"workgroup", 'w', POPT_ARG_STRING
, &opt_target_workgroup
},
860 {"user", 'U', POPT_ARG_STRING
, &opt_user_name
, 'U'},
861 {"ipaddress", 'I', POPT_ARG_STRING
, 0,'I'},
862 {"port", 'p', POPT_ARG_INT
, &opt_port
},
863 {"myname", 'n', POPT_ARG_STRING
, &opt_requester_name
},
864 {"server", 'S', POPT_ARG_STRING
, &opt_host
},
865 {"container", 'c', POPT_ARG_STRING
, &opt_container
},
866 {"comment", 'C', POPT_ARG_STRING
, &opt_comment
},
867 {"maxusers", 'M', POPT_ARG_INT
, &opt_maxusers
},
868 {"flags", 'F', POPT_ARG_INT
, &opt_flags
},
869 {"long", 'l', POPT_ARG_NONE
, &opt_long_list_entries
},
870 {"reboot", 'r', POPT_ARG_NONE
, &opt_reboot
},
871 {"force", 'f', POPT_ARG_NONE
, &opt_force
},
872 {"stdin", 'i', POPT_ARG_NONE
, &opt_stdin
},
873 {"timeout", 't', POPT_ARG_INT
, &opt_timeout
},
874 {"machine-pass",'P', POPT_ARG_NONE
, &opt_machine_pass
},
875 {"myworkgroup", 'W', POPT_ARG_STRING
, &opt_workgroup
},
876 {"verbose", 'v', POPT_ARG_NONE
, &opt_verbose
},
877 /* Options for 'net groupmap set' */
878 {"local", 'L', POPT_ARG_NONE
, &opt_localgroup
},
879 {"domain", 'D', POPT_ARG_NONE
, &opt_domaingroup
},
880 {"ntname", 'N', POPT_ARG_STRING
, &opt_newntname
},
881 {"rid", 'R', POPT_ARG_INT
, &opt_rid
},
882 /* Options for 'net rpc share migrate' */
883 {"acls", 0, POPT_ARG_NONE
, &opt_acls
},
884 {"attrs", 0, POPT_ARG_NONE
, &opt_attrs
},
885 {"timestamps", 0, POPT_ARG_NONE
, &opt_timestamps
},
886 {"exclude", 'e', POPT_ARG_STRING
, &opt_exclude
},
887 {"destination", 0, POPT_ARG_STRING
, &opt_destination
},
888 {"tallocreport", 0, POPT_ARG_NONE
, &do_talloc_report
},
894 zero_ip(&opt_dest_ip
);
898 /* set default debug level to 0 regardless of what smb.conf sets */
899 DEBUGLEVEL_CLASS
[DBGC_ALL
] = 0;
902 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
,
903 POPT_CONTEXT_KEEP_FIRST
);
905 while((opt
= poptGetNextOpt(pc
)) != -1) {
908 net_help(argc
, argv
);
912 opt_dest_ip
= *interpret_addr2(poptGetOptArg(pc
));
913 if (is_zero_ip(opt_dest_ip
))
914 d_fprintf(stderr
, "\nInvalid ip address specified\n");
919 opt_user_specified
= True
;
920 opt_user_name
= SMB_STRDUP(opt_user_name
);
921 p
= strchr(opt_user_name
,'%');
928 d_fprintf(stderr
, "\nInvalid option %s: %s\n",
929 poptBadOption(pc
, 0), poptStrerror(opt
));
930 net_help(argc
, argv
);
936 * Don't load debug level from smb.conf. It should be
937 * set by cmdline arg or remain default (0)
939 AllowDebugChange
= False
;
940 lp_load(dyn_CONFIGFILE
,True
,False
,False
,True
);
942 argv_new
= (const char **)poptGetArgs(pc
);
945 for (i
=0; i
<argc
; i
++) {
946 if (argv_new
[i
] == NULL
) {
952 if (do_talloc_report
) {
953 talloc_enable_leak_report();
956 if (opt_requester_name
) {
957 set_global_myname(opt_requester_name
);
960 if (!opt_user_name
&& getenv("LOGNAME")) {
961 opt_user_name
= getenv("LOGNAME");
964 if (!opt_workgroup
) {
965 opt_workgroup
= smb_xstrdup(lp_workgroup());
968 if (!opt_target_workgroup
) {
969 opt_target_workgroup
= smb_xstrdup(lp_workgroup());
977 /* this makes sure that when we do things like call scripts,
978 that it won't assert becouse we are not root */
981 if (opt_machine_pass
) {
982 /* it is very useful to be able to make ads queries as the
983 machine account for testing purposes and for domain leave */
985 net_use_machine_password();
989 opt_password
= getenv("PASSWD");
992 rc
= net_run_function(argc_new
-1, argv_new
+1, net_func
, net_help
);
994 DEBUG(2,("return code = %d\n", rc
));