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
;
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 ****************************************************************************/
164 NTSTATUS
connect_to_service(struct cli_state
**c
,
165 struct sockaddr_storage
*server_ss
,
166 const char *server_name
,
167 const char *service_name
,
168 const char *service_type
)
172 opt_password
= net_prompt_pass(opt_user_name
);
174 return NT_STATUS_NO_MEMORY
;
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
);
182 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");
202 nt_status
= cli_force_encryption(*c
,
207 if (NT_STATUS_EQUAL(nt_status
,NT_STATUS_NOT_SUPPORTED
)) {
208 d_printf("Encryption required and "
209 "server that doesn't support "
210 "UNIX extensions - failing connect\n");
211 } else if (NT_STATUS_EQUAL(nt_status
,NT_STATUS_UNKNOWN_REVISION
)) {
212 d_printf("Encryption required and "
213 "can't get UNIX CIFS extensions "
214 "version from server.\n");
215 } else if (NT_STATUS_EQUAL(nt_status
,NT_STATUS_UNSUPPORTED_COMPRESSION
)) {
216 d_printf("Encryption required and "
217 "share %s doesn't support "
218 "encryption.\n", service_name
);
219 } else if (!NT_STATUS_IS_OK(nt_status
)) {
220 d_printf("Encryption required and "
221 "setup failed with error %s.\n",
222 nt_errstr(nt_status
));
225 if (!NT_STATUS_IS_OK(nt_status
)) {
234 /****************************************************************************
235 Connect to \\server\ipc$.
236 ****************************************************************************/
238 NTSTATUS
connect_to_ipc(struct cli_state
**c
,
239 struct sockaddr_storage
*server_ss
,
240 const char *server_name
)
242 return connect_to_service(c
, server_ss
, server_name
, "IPC$", "IPC");
245 /****************************************************************************
246 Connect to \\server\ipc$ anonymously.
247 ****************************************************************************/
249 NTSTATUS
connect_to_ipc_anonymous(struct cli_state
**c
,
250 struct sockaddr_storage
*server_ss
,
251 const char *server_name
)
255 nt_status
= cli_full_connection(c
, opt_requester_name
, server_name
,
259 "", 0, Undefined
, NULL
);
261 if (NT_STATUS_IS_OK(nt_status
)) {
264 DEBUG(1,("Cannot connect to server (anonymously). Error was %s\n", nt_errstr(nt_status
)));
269 /****************************************************************************
270 Return malloced user@realm for krb5 login.
271 ****************************************************************************/
273 static char *get_user_and_realm(const char *username
)
275 char *user_and_realm
= NULL
;
280 if (strchr_m(username
, '@')) {
281 user_and_realm
= SMB_STRDUP(username
);
283 if (asprintf(&user_and_realm
, "%s@%s", username
, lp_realm()) == -1) {
284 user_and_realm
= NULL
;
287 return user_and_realm
;
290 /****************************************************************************
291 Connect to \\server\ipc$ using KRB5.
292 ****************************************************************************/
294 NTSTATUS
connect_to_ipc_krb5(struct cli_state
**c
,
295 struct sockaddr_storage
*server_ss
,
296 const char *server_name
)
299 char *user_and_realm
= NULL
;
301 opt_password
= net_prompt_pass(opt_user_name
);
303 return NT_STATUS_NO_MEMORY
;
306 user_and_realm
= get_user_and_realm(opt_user_name
);
307 if (!user_and_realm
) {
308 return NT_STATUS_NO_MEMORY
;
311 nt_status
= cli_full_connection(c
, NULL
, server_name
,
314 user_and_realm
, opt_workgroup
,
315 opt_password
, CLI_FULL_CONNECTION_USE_KERBEROS
,
318 SAFE_FREE(user_and_realm
);
320 if (!NT_STATUS_IS_OK(nt_status
)) {
321 DEBUG(1,("Cannot connect to server using kerberos. Error was %s\n", nt_errstr(nt_status
)));
326 nt_status
= cli_cm_force_encryption(*c
,
331 if (!NT_STATUS_IS_OK(nt_status
)) {
341 * Connect a server and open a given pipe
343 * @param cli_dst A cli_state
344 * @param pipe The pipe to open
345 * @param got_pipe boolean that stores if we got a pipe
347 * @return Normal NTSTATUS return.
349 NTSTATUS
connect_dst_pipe(struct cli_state
**cli_dst
, struct rpc_pipe_client
**pp_pipe_hnd
, int pipe_num
)
352 char *server_name
= SMB_STRDUP("127.0.0.1");
353 struct cli_state
*cli_tmp
= NULL
;
354 struct rpc_pipe_client
*pipe_hnd
= NULL
;
356 if (server_name
== NULL
) {
357 return NT_STATUS_NO_MEMORY
;
360 if (opt_destination
) {
361 SAFE_FREE(server_name
);
362 if ((server_name
= SMB_STRDUP(opt_destination
)) == NULL
) {
363 return NT_STATUS_NO_MEMORY
;
367 /* make a connection to a named pipe */
368 nt_status
= connect_to_ipc(&cli_tmp
, NULL
, server_name
);
369 if (!NT_STATUS_IS_OK(nt_status
)) {
370 SAFE_FREE(server_name
);
374 pipe_hnd
= cli_rpc_pipe_open_noauth(cli_tmp
, pipe_num
, &nt_status
);
376 DEBUG(0, ("couldn't not initialize pipe\n"));
377 cli_shutdown(cli_tmp
);
378 SAFE_FREE(server_name
);
383 *pp_pipe_hnd
= pipe_hnd
;
384 SAFE_FREE(server_name
);
389 /****************************************************************************
390 Use the local machine account (krb) and password for this session.
391 ****************************************************************************/
393 int net_use_krb_machine_account(void)
395 char *user_name
= NULL
;
397 if (!secrets_init()) {
398 d_fprintf(stderr
, "ERROR: Unable to open secrets database\n");
402 opt_password
= secrets_fetch_machine_password(opt_target_workgroup
, NULL
, NULL
);
403 if (asprintf(&user_name
, "%s$@%s", global_myname(), lp_realm()) == -1) {
406 opt_user_name
= user_name
;
410 /****************************************************************************
411 Use the machine account name and password for this session.
412 ****************************************************************************/
414 int net_use_machine_account(void)
416 char *user_name
= NULL
;
418 if (!secrets_init()) {
419 d_fprintf(stderr
, "ERROR: Unable to open secrets database\n");
423 opt_password
= secrets_fetch_machine_password(opt_target_workgroup
, NULL
, NULL
);
424 if (asprintf(&user_name
, "%s$", global_myname()) == -1) {
427 opt_user_name
= user_name
;
431 bool net_find_server(const char *domain
,
433 struct sockaddr_storage
*server_ss
,
436 const char *d
= domain
? domain
: opt_target_workgroup
;
439 *server_name
= SMB_STRDUP(opt_host
);
443 *server_ss
= opt_dest_ip
;
445 char addr
[INET6_ADDRSTRLEN
];
446 print_sockaddr(addr
, sizeof(addr
), &opt_dest_ip
);
447 *server_name
= SMB_STRDUP(addr
);
449 } else if (*server_name
) {
450 /* resolve the IP address */
451 if (!resolve_name(*server_name
, server_ss
, 0x20)) {
452 DEBUG(1,("Unable to resolve server name\n"));
455 } else if (flags
& NET_FLAGS_PDC
) {
457 struct sockaddr_storage pdc_ss
;
459 if (!get_pdc_ip(d
, &pdc_ss
)) {
460 DEBUG(1,("Unable to resolve PDC server address\n"));
464 if (is_zero_addr(&pdc_ss
)) {
468 if (!name_status_find(d
, 0x1b, 0x20, &pdc_ss
, dc_name
)) {
472 *server_name
= SMB_STRDUP(dc_name
);
474 } else if (flags
& NET_FLAGS_DMB
) {
475 struct sockaddr_storage msbrow_ss
;
476 char addr
[INET6_ADDRSTRLEN
];
478 /* if (!resolve_name(MSBROWSE, &msbrow_ip, 1)) */
479 if (!resolve_name(d
, &msbrow_ss
, 0x1B)) {
480 DEBUG(1,("Unable to resolve domain browser via name lookup\n"));
483 *server_ss
= msbrow_ss
;
484 print_sockaddr(addr
, sizeof(addr
), server_ss
);
485 *server_name
= SMB_STRDUP(addr
);
486 } else if (flags
& NET_FLAGS_MASTER
) {
487 struct sockaddr_storage brow_ss
;
488 char addr
[INET6_ADDRSTRLEN
];
489 if (!resolve_name(d
, &brow_ss
, 0x1D)) {
490 /* go looking for workgroups */
491 DEBUG(1,("Unable to resolve master browser via name lookup\n"));
494 *server_ss
= brow_ss
;
495 print_sockaddr(addr
, sizeof(addr
), server_ss
);
496 *server_name
= SMB_STRDUP(addr
);
497 } else if (!(flags
& NET_FLAGS_LOCALHOST_DEFAULT_INSANE
)) {
498 if (!interpret_string_addr(server_ss
,
499 "127.0.0.1", AI_NUMERICHOST
)) {
500 DEBUG(1,("Unable to resolve 127.0.0.1\n"));
503 *server_name
= SMB_STRDUP("127.0.0.1");
506 if (!server_name
|| !*server_name
) {
507 DEBUG(1,("no server to connect to\n"));
514 bool net_find_pdc(struct sockaddr_storage
*server_ss
,
516 const char *domain_name
)
518 if (!get_pdc_ip(domain_name
, server_ss
)) {
521 if (is_zero_addr(server_ss
)) {
525 if (!name_status_find(domain_name
, 0x1b, 0x20, server_ss
, server_name
)) {
532 NTSTATUS
net_make_ipc_connection(unsigned flags
, struct cli_state
**pcli
)
534 return net_make_ipc_connection_ex(NULL
, NULL
, NULL
, flags
, pcli
);
537 NTSTATUS
net_make_ipc_connection_ex(const char *domain
, const char *server
,
538 struct sockaddr_storage
*pss
, unsigned flags
,
539 struct cli_state
**pcli
)
541 char *server_name
= NULL
;
542 struct sockaddr_storage server_ss
;
543 struct cli_state
*cli
= NULL
;
546 if ( !server
|| !pss
) {
547 if (!net_find_server(domain
, flags
, &server_ss
, &server_name
)) {
548 d_fprintf(stderr
, "Unable to find a suitable server\n");
549 nt_status
= NT_STATUS_UNSUCCESSFUL
;
553 server_name
= SMB_STRDUP( server
);
557 if (flags
& NET_FLAGS_ANONYMOUS
) {
558 nt_status
= connect_to_ipc_anonymous(&cli
, &server_ss
, server_name
);
560 nt_status
= connect_to_ipc(&cli
, &server_ss
, server_name
);
563 /* store the server in the affinity cache if it was a PDC */
565 if ( (flags
& NET_FLAGS_PDC
) && NT_STATUS_IS_OK(nt_status
) )
566 saf_store( cli
->server_domain
, cli
->desthost
);
568 SAFE_FREE(server_name
);
569 if (!NT_STATUS_IS_OK(nt_status
)) {
570 d_fprintf(stderr
, "Connection failed: %s\n",
571 nt_errstr(nt_status
));
582 static int net_user(int argc
, const char **argv
)
584 if (net_ads_check() == 0)
585 return net_ads_user(argc
, argv
);
587 /* if server is not specified, default to PDC? */
588 if (net_rpc_check(NET_FLAGS_PDC
))
589 return net_rpc_user(argc
, argv
);
591 return net_rap_user(argc
, argv
);
594 static int net_group(int argc
, const char **argv
)
596 if (net_ads_check() == 0)
597 return net_ads_group(argc
, argv
);
599 if (argc
== 0 && net_rpc_check(NET_FLAGS_PDC
))
600 return net_rpc_group(argc
, argv
);
602 return net_rap_group(argc
, argv
);
605 static int net_join(int argc
, const char **argv
)
607 if (net_ads_check_our_domain() == 0) {
608 if (net_ads_join(argc
, argv
) == 0)
611 d_fprintf(stderr
, "ADS join did not work, falling back to RPC...\n");
613 return net_rpc_join(argc
, argv
);
616 static int net_changetrustpw(int argc
, const char **argv
)
618 if (net_ads_check_our_domain() == 0)
619 return net_ads_changetrustpw(argc
, argv
);
621 return net_rpc_changetrustpw(argc
, argv
);
624 static void set_line_buffering(FILE *f
)
626 setvbuf(f
, NULL
, _IOLBF
, 0);
629 static int net_changesecretpw(int argc
, const char **argv
)
632 uint32 sec_channel_type
= SEC_CHAN_WKSTA
;
636 set_line_buffering(stdin
);
637 set_line_buffering(stdout
);
638 set_line_buffering(stderr
);
641 trust_pw
= get_pass("Enter machine password: ", opt_stdin
);
643 if (!secrets_store_machine_password(trust_pw
, lp_workgroup(), sec_channel_type
)) {
644 d_fprintf(stderr
, "Unable to write the machine account password in the secrets database");
648 d_printf("Modified trust account password in secrets database\n");
652 d_printf("Machine account password change requires the -f flag.\n");
653 d_printf("Do NOT use this function unless you know what it does!\n");
654 d_printf("This function will change the ADS Domain member machine account password in the secrets.tdb file!\n");
660 static int net_share(int argc
, const char **argv
)
662 if (net_rpc_check(0))
663 return net_rpc_share(argc
, argv
);
664 return net_rap_share(argc
, argv
);
667 static int net_file(int argc
, const char **argv
)
669 if (net_rpc_check(0))
670 return net_rpc_file(argc
, argv
);
671 return net_rap_file(argc
, argv
);
675 Retrieve our local SID or the SID for the specified name
677 static int net_getlocalsid(int argc
, const char **argv
)
687 name
= global_myname();
690 if(!initialize_password_db(False
, NULL
)) {
691 DEBUG(0, ("WARNING: Could not open passdb - local sid may not reflect passdb\n"
692 "backend knowledge (such as the sid stored in LDAP)\n"));
695 /* first check to see if we can even access secrets, so we don't
696 panic when we can't. */
698 if (!secrets_init()) {
699 d_fprintf(stderr
, "Unable to open secrets.tdb. Can't fetch domain SID for name: %s\n", name
);
703 /* Generate one, if it doesn't exist */
704 get_global_sam_sid();
706 if (!secrets_fetch_domain_sid(name
, &sid
)) {
707 DEBUG(0, ("Can't fetch domain SID for name: %s\n", name
));
710 sid_to_fstring(sid_str
, &sid
);
711 d_printf("SID for domain %s is: %s\n", name
, sid_str
);
715 static int net_setlocalsid(int argc
, const char **argv
)
720 || (strncmp(argv
[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
721 || (!string_to_sid(&sid
, argv
[0]))
722 || (sid
.num_auths
!= 4)) {
723 d_printf("usage: net setlocalsid S-1-5-21-x-y-z\n");
727 if (!secrets_store_domain_sid(global_myname(), &sid
)) {
728 DEBUG(0,("Can't store domain SID as a pdc/bdc.\n"));
735 static int net_setdomainsid(int argc
, const char **argv
)
740 || (strncmp(argv
[0], "S-1-5-21-", strlen("S-1-5-21-")) != 0)
741 || (!string_to_sid(&sid
, argv
[0]))
742 || (sid
.num_auths
!= 4)) {
743 d_printf("usage: net setdomainsid S-1-5-21-x-y-z\n");
747 if (!secrets_store_domain_sid(lp_workgroup(), &sid
)) {
748 DEBUG(0,("Can't store domain SID.\n"));
755 static int net_getdomainsid(int argc
, const char **argv
)
761 d_printf("usage: net getdomainsid\n");
765 if(!initialize_password_db(False
, NULL
)) {
766 DEBUG(0, ("WARNING: Could not open passdb - domain SID may "
767 "not reflect passdb\n"
768 "backend knowledge (such as the SID stored in "
772 /* first check to see if we can even access secrets, so we don't
773 panic when we can't. */
775 if (!secrets_init()) {
776 d_fprintf(stderr
, "Unable to open secrets.tdb. Can't fetch domain"
777 "SID for name: %s\n", get_global_sam_name());
781 /* Generate one, if it doesn't exist */
782 get_global_sam_sid();
784 if (!secrets_fetch_domain_sid(global_myname(), &domain_sid
)) {
785 d_fprintf(stderr
, "Could not fetch local SID\n");
788 sid_to_fstring(sid_str
, &domain_sid
);
789 d_printf("SID for local machine %s is: %s\n", global_myname(), sid_str
);
791 if (!secrets_fetch_domain_sid(opt_workgroup
, &domain_sid
)) {
792 d_fprintf(stderr
, "Could not fetch domain SID\n");
796 sid_to_fstring(sid_str
, &domain_sid
);
797 d_printf("SID for domain %s is: %s\n", opt_workgroup
, sid_str
);
802 #ifdef WITH_FAKE_KASERVER
804 int net_help_afs(int argc
, const char **argv
)
806 d_printf(" net afs key filename\n"
807 "\tImports a OpenAFS KeyFile into our secrets.tdb\n\n");
808 d_printf(" net afs impersonate <user> <cell>\n"
809 "\tCreates a token for user@cell\n\n");
813 static int net_afs_key(int argc
, const char **argv
)
816 struct afs_keyfile keyfile
;
819 d_printf("usage: 'net afs key <keyfile> cell'\n");
823 if (!secrets_init()) {
824 d_fprintf(stderr
, "Could not open secrets.tdb\n");
828 if ((fd
= open(argv
[0], O_RDONLY
, 0)) < 0) {
829 d_fprintf(stderr
, "Could not open %s\n", argv
[0]);
833 if (read(fd
, &keyfile
, sizeof(keyfile
)) != sizeof(keyfile
)) {
834 d_fprintf(stderr
, "Could not read keyfile\n");
838 if (!secrets_store_afs_keyfile(argv
[1], &keyfile
)) {
839 d_fprintf(stderr
, "Could not write keyfile to secrets.tdb\n");
846 static int net_afs_impersonate(int argc
, const char **argv
)
851 fprintf(stderr
, "Usage: net afs impersonate <user> <cell>\n");
855 token
= afs_createtoken_str(argv
[0], argv
[1]);
858 fprintf(stderr
, "Could not create token\n");
862 if (!afs_settoken_str(token
)) {
863 fprintf(stderr
, "Could not set token into kernel\n");
867 printf("Success: %s@%s\n", argv
[0], argv
[1]);
871 static int net_afs(int argc
, const char **argv
)
873 struct functable func
[] = {
874 {"key", net_afs_key
},
875 {"impersonate", net_afs_impersonate
},
876 {"help", net_help_afs
},
879 return net_run_function(argc
, argv
, func
, net_help_afs
);
882 #endif /* WITH_FAKE_KASERVER */
884 static bool search_maxrid(struct pdb_search
*search
, const char *type
,
887 struct samr_displayentry
*entries
;
888 uint32 i
, num_entries
;
890 if (search
== NULL
) {
891 d_fprintf(stderr
, "get_maxrid: Could not search %s\n", type
);
895 num_entries
= pdb_search_entries(search
, 0, 0xffffffff, &entries
);
896 for (i
=0; i
<num_entries
; i
++)
897 *max_rid
= MAX(*max_rid
, entries
[i
].rid
);
898 pdb_search_destroy(search
);
902 static uint32
get_maxrid(void)
906 if (!search_maxrid(pdb_search_users(0), "users", &max_rid
))
909 if (!search_maxrid(pdb_search_groups(), "groups", &max_rid
))
912 if (!search_maxrid(pdb_search_aliases(get_global_sam_sid()),
913 "aliases", &max_rid
))
919 static int net_maxrid(int argc
, const char **argv
)
924 DEBUG(0, ("usage: net maxrid\n"));
928 if ((rid
= get_maxrid()) == 0) {
929 DEBUG(0, ("can't get current maximum rid\n"));
933 d_printf("Currently used maximum rid: %d\n", rid
);
938 /****************************************************************************
939 ****************************************************************************/
941 const char *net_prompt_pass(const char *user
)
944 const char *pass
= NULL
;
950 if (opt_machine_pass
) {
954 asprintf(&prompt
, "Enter %s's password:", user
);
959 pass
= getpass(prompt
);
965 /* main function table */
966 static struct functable net_func
[] = {
971 /* eventually these should auto-choose the transport ... */
973 {"SHARE", net_share
},
974 {"SESSION", net_rap_session
},
975 {"SERVER", net_rap_server
},
976 {"DOMAIN", net_rap_domain
},
977 {"PRINTQ", net_rap_printq
},
979 {"GROUP", net_group
},
980 {"GROUPMAP", net_groupmap
},
982 {"VALIDATE", net_rap_validate
},
983 {"GROUPMEMBER", net_rap_groupmember
},
984 {"ADMIN", net_rap_admin
},
985 {"SERVICE", net_rap_service
},
986 {"PASSWORD", net_rap_password
},
987 {"CHANGETRUSTPW", net_changetrustpw
},
988 {"CHANGESECRETPW", net_changesecretpw
},
990 {"LOOKUP", net_lookup
},
993 {"CACHE", net_cache
},
994 {"GETLOCALSID", net_getlocalsid
},
995 {"SETLOCALSID", net_setlocalsid
},
996 {"SETDOMAINSID", net_setdomainsid
},
997 {"GETDOMAINSID", net_getdomainsid
},
998 {"MAXRID", net_maxrid
},
999 {"IDMAP", net_idmap
},
1000 {"STATUS", net_status
},
1001 {"USERSHARE", net_usershare
},
1002 {"USERSIDLIST", net_usersidlist
},
1004 #ifdef WITH_FAKE_KASERVER
1013 /****************************************************************************
1015 ****************************************************************************/
1016 int main(int argc
, const char **argv
)
1022 const char ** argv_new
;
1025 struct poptOption long_options
[] = {
1026 {"help", 'h', POPT_ARG_NONE
, 0, 'h'},
1027 {"workgroup", 'w', POPT_ARG_STRING
, &opt_target_workgroup
},
1028 {"user", 'U', POPT_ARG_STRING
, &opt_user_name
, 'U'},
1029 {"ipaddress", 'I', POPT_ARG_STRING
, 0,'I'},
1030 {"port", 'p', POPT_ARG_INT
, &opt_port
},
1031 {"myname", 'n', POPT_ARG_STRING
, &opt_requester_name
},
1032 {"server", 'S', POPT_ARG_STRING
, &opt_host
},
1033 {"encrypt", 'e', POPT_ARG_NONE
, NULL
, 'e', "Encrypt SMB transport (UNIX extended servers only)" },
1034 {"container", 'c', POPT_ARG_STRING
, &opt_container
},
1035 {"comment", 'C', POPT_ARG_STRING
, &opt_comment
},
1036 {"maxusers", 'M', POPT_ARG_INT
, &opt_maxusers
},
1037 {"flags", 'F', POPT_ARG_INT
, &opt_flags
},
1038 {"long", 'l', POPT_ARG_NONE
, &opt_long_list_entries
},
1039 {"reboot", 'r', POPT_ARG_NONE
, &opt_reboot
},
1040 {"force", 'f', POPT_ARG_NONE
, &opt_force
},
1041 {"stdin", 'i', POPT_ARG_NONE
, &opt_stdin
},
1042 {"timeout", 't', POPT_ARG_INT
, &opt_timeout
},
1043 {"machine-pass",'P', POPT_ARG_NONE
, &opt_machine_pass
},
1044 {"myworkgroup", 'W', POPT_ARG_STRING
, &opt_workgroup
},
1045 {"verbose", 'v', POPT_ARG_NONE
, &opt_verbose
},
1046 {"test", 'T', POPT_ARG_NONE
, &opt_testmode
},
1047 /* Options for 'net groupmap set' */
1048 {"local", 'L', POPT_ARG_NONE
, &opt_localgroup
},
1049 {"domain", 'D', POPT_ARG_NONE
, &opt_domaingroup
},
1050 {"ntname", 'N', POPT_ARG_STRING
, &opt_newntname
},
1051 {"rid", 'R', POPT_ARG_INT
, &opt_rid
},
1052 /* Options for 'net rpc share migrate' */
1053 {"acls", 0, POPT_ARG_NONE
, &opt_acls
},
1054 {"attrs", 0, POPT_ARG_NONE
, &opt_attrs
},
1055 {"timestamps", 0, POPT_ARG_NONE
, &opt_timestamps
},
1056 {"exclude", 'X', POPT_ARG_STRING
, &opt_exclude
},
1057 {"destination", 0, POPT_ARG_STRING
, &opt_destination
},
1058 {"tallocreport", 0, POPT_ARG_NONE
, &do_talloc_report
},
1064 TALLOC_CTX
*frame
= talloc_stackframe();
1066 zero_addr(&opt_dest_ip
);
1070 /* set default debug level to 0 regardless of what smb.conf sets */
1071 DEBUGLEVEL_CLASS
[DBGC_ALL
] = 0;
1074 pc
= poptGetContext(NULL
, argc
, (const char **) argv
, long_options
,
1075 POPT_CONTEXT_KEEP_FIRST
);
1077 while((opt
= poptGetNextOpt(pc
)) != -1) {
1080 net_help(argc
, argv
);
1087 if (!interpret_string_addr(&opt_dest_ip
,
1088 poptGetOptArg(pc
), 0)) {
1089 d_fprintf(stderr
, "\nInvalid ip address specified\n");
1095 opt_user_specified
= True
;
1096 opt_user_name
= SMB_STRDUP(opt_user_name
);
1097 p
= strchr(opt_user_name
,'%');
1104 d_fprintf(stderr
, "\nInvalid option %s: %s\n",
1105 poptBadOption(pc
, 0), poptStrerror(opt
));
1106 net_help(argc
, argv
);
1112 * Don't load debug level from smb.conf. It should be
1113 * set by cmdline arg or remain default (0)
1115 AllowDebugChange
= False
;
1116 lp_load(get_dyn_CONFIGFILE(),True
,False
,False
,True
);
1118 argv_new
= (const char **)poptGetArgs(pc
);
1121 for (i
=0; i
<argc
; i
++) {
1122 if (argv_new
[i
] == NULL
) {
1128 if (do_talloc_report
) {
1129 talloc_enable_leak_report();
1132 if (opt_requester_name
) {
1133 set_global_myname(opt_requester_name
);
1136 if (!opt_user_name
&& getenv("LOGNAME")) {
1137 opt_user_name
= getenv("LOGNAME");
1140 if (!opt_workgroup
) {
1141 opt_workgroup
= smb_xstrdup(lp_workgroup());
1144 if (!opt_target_workgroup
) {
1145 opt_target_workgroup
= smb_xstrdup(lp_workgroup());
1153 /* this makes sure that when we do things like call scripts,
1154 that it won't assert becouse we are not root */
1157 if (opt_machine_pass
) {
1158 /* it is very useful to be able to make ads queries as the
1159 machine account for testing purposes and for domain leave */
1161 net_use_krb_machine_account();
1164 if (!opt_password
) {
1165 opt_password
= getenv("PASSWD");
1168 rc
= net_run_function(argc_new
-1, argv_new
+1, net_func
, net_help
);
1170 DEBUG(2,("return code = %d\n", rc
));