diff options
author | Jim McDonough <jmcd@samba.org> | 2002-05-31 17:03:48 +0000 |
---|---|---|
committer | Jim McDonough <jmcd@samba.org> | 2002-05-31 17:03:48 +0000 |
commit | 1b9c519dc964791273186cced8d17fd9c7793ce9 (patch) | |
tree | e26d8418b2a5d8d0b53ade15659486cdfae7de78 /source3/utils | |
parent | e01175020613858f78f3fd604b758d9f6eae6f9e (diff) | |
download | samba-1b9c519dc964791273186cced8d17fd9c7793ce9.tar.gz samba-1b9c519dc964791273186cced8d17fd9c7793ce9.tar.bz2 samba-1b9c519dc964791273186cced8d17fd9c7793ce9.zip |
Enable net rpc share and net rpc file commands (list subcommands only), and
autoselect for this subcommand when appropriate.
(This used to be commit 77418256d3162b41a672a25f7e512999f1193926)
Diffstat (limited to 'source3/utils')
-rw-r--r-- | source3/utils/net.c | 26 | ||||
-rw-r--r-- | source3/utils/net.h | 3 | ||||
-rw-r--r-- | source3/utils/net_help.c | 56 | ||||
-rw-r--r-- | source3/utils/net_rap.c | 39 | ||||
-rw-r--r-- | source3/utils/net_rpc.c | 200 |
5 files changed, 271 insertions, 53 deletions
diff --git a/source3/utils/net.c b/source3/utils/net.c index b6998efdf7..e132b8d6e3 100644 --- a/source3/utils/net.c +++ b/source3/utils/net.c @@ -297,10 +297,8 @@ static int net_group(int argc, const char **argv) if (net_ads_check() == 0) return net_ads_group(argc, argv); - - /* if server is not specified, default to PDC? */ - /* not implemented yet if (net_rpc_check(NET_FLAGS_PDC)) - return net_rpc_group(argc, argv); */ + if (argc == 0 && net_rpc_check(NET_FLAGS_PDC)) + return net_rpc_group(argc, argv); return net_rap_group(argc, argv); } @@ -316,6 +314,22 @@ static int net_join(int argc, const char **argv) return net_rpc_join(argc, argv); } +static int net_share(int argc, const char **argv) +{ + /* only share list is implemented in RPC */ + if (argc == 0 && net_rpc_check(0)) + return net_rpc_share(argc, argv); + return net_rap_share(argc, argv); +} + +static int net_file(int argc, const char **argv) +{ + /* only file list is implemented in RPC */ + if (argc == 0 && net_rpc_check(0)) + return net_rpc_file(argc, argv); + return net_rap_file(argc, argv); +} + /* main function table */ static struct functable net_func[] = { {"RPC", net_rpc}, @@ -323,8 +337,8 @@ static struct functable net_func[] = { {"ADS", net_ads}, /* eventually these should auto-choose the transport ... */ - {"FILE", net_rap_file}, - {"SHARE", net_rap_share}, + {"FILE", net_file}, + {"SHARE", net_share}, {"SESSION", net_rap_session}, {"SERVER", net_rap_server}, {"DOMAIN", net_rap_domain}, diff --git a/source3/utils/net.h b/source3/utils/net.h index af6f153f7b..5a53740679 100644 --- a/source3/utils/net.h +++ b/source3/utils/net.h @@ -49,3 +49,6 @@ extern char *opt_host; extern char *opt_user_name; extern char *opt_password; extern BOOL opt_user_specified; + +extern const char *share_type[]; + diff --git a/source3/utils/net_help.c b/source3/utils/net_help.c index 31065a26b8..18a89a9cb7 100644 --- a/source3/utils/net_help.c +++ b/source3/utils/net_help.c @@ -63,12 +63,12 @@ static int help_usage(int argc, const char **argv) int net_help_user(int argc, const char **argv) { - d_printf("\nnet [method] user [misc. options] [targets]\n\tList users\n"); - d_printf("\nnet [method] user DELETE <name> [misc. options] [targets]"\ + d_printf("\nnet <method> user [misc. options] [targets]\n\tList users\n"); + d_printf("\nnet <method> user DELETE <name> [misc. options] [targets]"\ "\n\tDelete specified user\n"); - d_printf("\nnet [method] user INFO <name> [misc. options] [targets]"\ + d_printf("\nnet <method> user INFO <name> [misc. options] [targets]"\ "\n\tList the domain groups of the specified user\n"); - d_printf("\nnet [method] user ADD <name> [-F user flags] [misc. options]"\ + d_printf("\nnet <method> user ADD <name> [password] [-F user flags] [misc. options]"\ " [targets]\n\tAdd specified user\n"); net_common_methods_usage(argc, argv); @@ -80,11 +80,11 @@ int net_help_user(int argc, const char **argv) int net_help_group(int argc, const char **argv) { - d_printf("net [method] group [misc. options] [targets]"\ + d_printf("net <method> group [misc. options] [targets]"\ "\n\tList user groups\n\n"); - d_printf("net [method] group DELETE <name> [misc. options] [targets]"\ + d_printf("net <method> group DELETE <name> [misc. options] [targets]"\ "\n\tDelete specified group\n"); - d_printf("\nnet [method] group ADD <name> [-C comment]"\ + d_printf("\nnet <method> group ADD <name> [-C comment]"\ " [misc. options] [targets]\n\tCreate specified group\n"); net_common_methods_usage(argc, argv); net_common_flags_usage(argc, argv); @@ -93,6 +93,38 @@ int net_help_group(int argc, const char **argv) return -1; } +int net_help_share(int argc, const char **argv) +{ + d_printf( + "\nnet <method> share [misc. options] [targets] \n" + "\tenumerates all exported resources (network shares) " + "on target server\n" + "\nnet [rap] share ADD <name=serverpath> [misc. options] [targets]" + "\n\tAdds a share from a server (makes the export active)\n" + "\nnet [rap] share DELETE <sharename> [misc. options] [targets]\n" + "\n\tDeletes a share from a server (makes the export inactive)\n"); + net_common_methods_usage(argc, argv); + net_common_flags_usage(argc, argv); + d_printf( + "\t-C or --comment=<comment>\tdescriptive comment (for add only)\n" + "\t-M or --maxusers=<num>\t\tmax users allowed for share\n"); + return -1; +} + +int net_help_file(int argc, const char **argv) +{ + d_printf("net <method> file [misc. options] [targets]\n"\ + "\tlists all open files on file server\n\n"); + d_printf("net [rap] file USER <username> [misc. options] [targets]\n"\ + "\tlists all files opened by username on file server\n\n"); + d_printf("net [rap] file CLOSE <id> [misc. options] [targets]\n"\ + "\tcloses specified file on target server\n"); + + net_common_methods_usage(argc, argv); + net_common_flags_usage(argc, argv); + return -1; +} + static int net_usage(int argc, const char **argv) { d_printf(" net time\t\tto view or set time information\n"\ @@ -101,9 +133,9 @@ static int net_usage(int argc, const char **argv) " net group\t\tto manage groups\n"\ " net join\t\tto join a domain\n"\ "\n"\ - " net ads [command]\tto run ADS commands\n"\ - " net rap [command]\tto run RAP (pre-RPC) commands\n"\ - " net rpc [command]\tto run RPC commands\n"\ + " net ads <command>\tto run ADS commands\n"\ + " net rap <command>\tto run RAP (pre-RPC) commands\n"\ + " net rpc <command>\tto run RPC commands\n"\ "\n"\ "Type \"net help <option>\" to get more information on that option\n"); return -1; @@ -119,8 +151,8 @@ int net_help(int argc, const char **argv) {"RAP", net_rap_help}, {"RPC", net_rpc_help}, - {"FILE", net_rap_file_usage}, - {"SHARE", net_rap_share_usage}, + {"FILE", net_help_file}, + {"SHARE", net_help_share}, {"SESSION", net_rap_session_usage}, {"SERVER", net_rap_server_usage}, {"DOMAIN", net_rap_domain_usage}, diff --git a/source3/utils/net_rap.c b/source3/utils/net_rap.c index 248e601df9..b9eac1f077 100644 --- a/source3/utils/net_rap.c +++ b/source3/utils/net_rap.c @@ -35,7 +35,7 @@ #define ERRMSG_BOTH_SERVER_IPADDRESS "\nTarget server and IP address both "\ "specified. Do not set both at the same time. The target IP address was used\n" -static const char *share_type[] = { +const char *share_type[] = { "Disk", "Print", "Dev", @@ -50,15 +50,7 @@ static int errmsg_not_implemented(void) int net_rap_file_usage(int argc, const char **argv) { - d_printf("net rap file [misc. options] [targets]\n"\ - "\tlists all open files on file server\n\n"); - d_printf("net rap file USER <username> [misc. options] [targets]\n"\ - "\tlists all files opened by username on file server\n\n"); - d_printf("net rap file CLOSE <id> [misc. options] [targets]\n"\ - "\tcloses specified file on target server\n"); - - net_common_flags_usage(argc, argv); - return -1; + return net_help_file(argc, argv); } /*************************************************************************** @@ -67,7 +59,7 @@ int net_rap_file_usage(int argc, const char **argv) static void file_fn(const char * pPath, const char * pUser, uint16 perms, uint16 locks, uint32 id) { - d_printf("\t%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n", + d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n", id, pUser, perms, locks, pPath); } @@ -143,8 +135,8 @@ int net_rap_file(int argc, const char **argv) /* list open files */ d_printf( "\nEnumerating open files on remote server:\n\n"\ - "\n\tFileId Opened by Perms Locks Path \n"\ - "\t------ --------- ----- ----- ---- \n"); + "\nFileId Opened by Perms Locks Path \n"\ + "------ --------- ----- ----- ---- \n"); ret = cli_NetFileEnum(cli, NULL, NULL, file_fn); cli_shutdown(cli); return ret; @@ -155,23 +147,7 @@ int net_rap_file(int argc, const char **argv) int net_rap_share_usage(int argc, const char **argv) { - d_printf( - "\nnet [rap] share [misc. options] [targets] \n"\ - "\tenumerates all exported resources (network shares) "\ - "on target server\n"); - d_printf( - "\nnet rap share ADD <name=serverpath> [misc. options] [targets]"\ - "\n\tAdds a share from a server (makes the export active)\n"); - d_printf( - "\nnet rap share DELETE <sharename> [misc. options] [targets]\n"\ - "\tor"\ - "\nnet rap share CLOSE <sharename> [misc. options] [targets]"\ - "\n\tDeletes a share from a server (makes the export inactive)\n"); - net_common_flags_usage(argc, argv); - d_printf( - "\t-C or --comment=<comment>\tdescriptive comment (for add only)\n"); - d_printf("\t-M or --maxusers=<num>\t\tmax users allowed for share\n"); - return -1; + return net_help_share(argc, argv); } static void long_share_fn(const char *share_name, uint32 type, @@ -672,8 +648,9 @@ static int rap_user_add(int argc, const char **argv) userinfo.priv = 1; userinfo.home_dir = NULL; userinfo.logon_script = NULL; - + ret = cli_NetUserAdd(cli, &userinfo); + cli_shutdown(cli); return ret; } diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c index 471e414683..a7414958d1 100644 --- a/source3/utils/net_rpc.c +++ b/source3/utils/net_rpc.c @@ -2,6 +2,7 @@ Samba Unix/Linux SMB client library Distributed SMB/CIFS Server Management Utility Copyright (C) 2001 Andrew Bartlett (abartlet@samba.org) + Copyright (C) 2002 Jim McDonough (jmcd@us.ibm.com) This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -859,6 +860,189 @@ int net_rpc_group(int argc, const char **argv) return net_run_function(argc, argv, func, rpc_group_usage); } +/****************************************************************************/ + +static int rpc_share_usage(int argc, const char **argv) +{ + return net_help_share(argc, argv); +} + +static void display_share_info_1(SRV_SHARE_INFO_1 *info1) +{ + fstring netname = "", remark = ""; + + rpcstr_pull_unistr2_fstring(netname, &info1->info_1_str.uni_netname); + rpcstr_pull_unistr2_fstring(remark, &info1->info_1_str.uni_remark); + + if (opt_long_list_entries) { + d_printf("%-12.12s %-8.8s %-50.50s\n", + netname, share_type[info1->info_1.type], remark); + } else { + d_printf("%-12.12s\n", netname); + } + +} + +/** + * List shares on a remote RPC server + * + * All paramaters are provided by the run_rpc_command funcion, except for + * argc, argv which are passes through. + * + * @param domain_sid The domain sid acquired from the remote server + * @param cli A cli_state connected to the server. + * @param mem_ctx Talloc context, destoyed on completion of the function. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * + * @return Normal NTSTATUS return. + **/ + +static NTSTATUS +rpc_share_list_internals(const DOM_SID *domain_sid, struct cli_state *cli, + TALLOC_CTX *mem_ctx, int argc, const char **argv) +{ + SRV_SHARE_INFO_CTR ctr; + WERROR result; + ENUM_HND hnd; + uint32 preferred_len = 0xffffffff, i; + + init_enum_hnd(&hnd, 0); + + result = cli_srvsvc_net_share_enum( + cli, mem_ctx, 1, &ctr, preferred_len, &hnd); + + if (!W_ERROR_IS_OK(result)) + goto done; + + /* Display results */ + + if (opt_long_list_entries) { + d_printf( + "\nEnumerating shared resources (exports) on remote server:\n\n"\ + "\nShare name Type Description\n"\ + "---------- ---- -----------\n"); + } + for (i = 0; i < ctr.num_entries; i++) + display_share_info_1(&ctr.share.info1[i]); + done: + return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + +/** + * 'net rpc share' entrypoint. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + **/ + +int net_rpc_share(int argc, const char **argv) +{ + struct functable func[] = { +#if 0 + {"add", rpc_share_add}, + {"delete", rpc_share_delete}, +#endif + {NULL, NULL} + }; + + if (argc == 0) + return run_rpc_command(PIPE_SRVSVC, 0, + rpc_share_list_internals, + argc, argv); + + return net_run_function(argc, argv, func, rpc_share_usage); +} + +/****************************************************************************/ + +static int rpc_file_usage(int argc, const char **argv) +{ + return net_help_file(argc, argv); +} + +static void display_file_info_3(FILE_INFO_3 *info3, FILE_INFO_3_STR *str3) +{ + fstring user = "", path = ""; + + rpcstr_pull_unistr2_fstring(user, &str3->uni_user_name); + rpcstr_pull_unistr2_fstring(path, &str3->uni_path_name); + + d_printf("%-7.1d %-20.20s 0x%-4.2x %-6.1d %s\n", + info3->id, user, info3->perms, info3->num_locks, path); +} + +/** + * List open files on a remote RPC server + * + * All paramaters are provided by the run_rpc_command funcion, except for + * argc, argv which are passes through. + * + * @param domain_sid The domain sid acquired from the remote server + * @param cli A cli_state connected to the server. + * @param mem_ctx Talloc context, destoyed on completion of the function. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + * + * @return Normal NTSTATUS return. + **/ + +static NTSTATUS +rpc_file_list_internals(const DOM_SID *domain_sid, struct cli_state *cli, + TALLOC_CTX *mem_ctx, int argc, const char **argv) +{ + SRV_FILE_INFO_CTR ctr; + WERROR result; + ENUM_HND hnd; + uint32 preferred_len = 0xffffffff, i; + + init_enum_hnd(&hnd, 0); + + result = cli_srvsvc_net_file_enum( + cli, mem_ctx, 3, &ctr, preferred_len, &hnd); + + if (!W_ERROR_IS_OK(result)) + goto done; + + /* Display results */ + + d_printf( + "\nEnumerating open files on remote server:\n\n"\ + "\nFileId Opened by Perms Locks Path"\ + "\n------ --------- ----- ----- ---- \n"); + for (i = 0; i < ctr.num_entries; i++) + display_file_info_3(&ctr.file.info3[i].info_3, + &ctr.file.info3[i].info_3_str); + done: + return W_ERROR_IS_OK(result) ? NT_STATUS_OK : NT_STATUS_UNSUCCESSFUL; +} + + +/** + * 'net rpc file' entrypoint. + * @param argc Standard main() style argc + * @param argv Standard main() style argv. Initial components are already + * stripped + **/ + +int net_rpc_file(int argc, const char **argv) +{ + struct functable func[] = { +#if 0 + {"close", rpc_file_close}, +#endif + {NULL, NULL} + }; + + if (argc == 0) + return run_rpc_command(PIPE_SRVSVC, 0, + rpc_file_list_internals, + argc, argv); + + return net_run_function(argc, argv, func, rpc_file_usage); +} /****************************************************************************/ @@ -1425,10 +1609,14 @@ int net_rpc_usage(int argc, const char **argv) { d_printf(" net rpc join \t\t\tto join a domain \n"); d_printf(" net rpc user \t\t\tto add, delete and list users\n"); + d_printf(" net rpc group \t\tto list groups\n"); + d_printf(" net rpc share \t\tto list shares\n"); + d_printf(" net rpc file \t\t\tto list open files\n"); d_printf(" net rpc changetrustpw \tto change the trust account password\n"); - d_printf(" net rpc trustdom \t\tto create trusting domain's account or establish trust\n"); - d_printf(" net rpc abortshutdown \tto to abort the shutdown of a remote server\n"); - d_printf(" net rpc shutdown \t\tto to shutdown a remote server\n"); + d_printf(" net rpc trustdom \t\tto create trusting domain's account\n" + "\t\t\t\t\tor establish trust\n"); + d_printf(" net rpc abortshutdown \tto abort the shutdown of a remote server\n"); + d_printf(" net rpc shutdown \t\tto shutdown a remote server\n"); d_printf("\n"); d_printf("'net rpc shutdown' also accepts the following miscellaneous options:\n"); /* misc options */ d_printf("\t-r or --reboot\trequest remote server reboot on shutdown\n"); @@ -1451,7 +1639,9 @@ int net_rpc_help(int argc, const char **argv) { struct functable func[] = { {"join", rpc_join_usage}, - {"user", net_help_user}, + {"user", rpc_user_usage}, + {"group", rpc_group_usage}, + {"share", rpc_share_usage}, /*{"changetrustpw", rpc_changetrustpw_usage}, */ {"trustdom", rpc_trustdom_usage}, /*{"abortshutdown", rpc_shutdown_abort_usage},*/ @@ -1481,6 +1671,8 @@ int net_rpc(int argc, const char **argv) {"join", net_rpc_join}, {"user", net_rpc_user}, {"group", net_rpc_group}, + {"share", net_rpc_share}, + {"file", net_rpc_file}, {"changetrustpw", rpc_changetrustpw}, {"trustdom", rpc_trustdom}, {"abortshutdown", rpc_shutdown_abort}, |