From a4ffe59c60445c8b54e80b9fab3a0a099c6a8883 Mon Sep 17 00:00:00 2001 From: Olly Betts Date: Tue, 1 May 2018 14:37:08 +1200 Subject: [PATCH] net rpc share allowedusers: Allow restricting shares The help already implies that you can specify "targets" for net rpc share allowedusers, but actually the tail end of the command line is just ignored. This patch allows a list of shares to be specified, and only those shares are checked, which can be much faster if you're only interested in a few shares on a server which exports lots. This subcommand already accepts an optional filename for the output of net usersidlist, with a default of stdin. Typically you'd just pipe one command to the other so stdin is most likely what you want. This patch adds support for a filename of "-" to mean stdin so that you can specify stdin explicitly when you provide a list of shares, since in this case the filename can't be omitted. Signed-off-by: Olly Betts --- source3/utils/net_rpc.c | 19 ++++++++++++++++++- source3/utils/net_share.c | 17 +++++++++-------- 2 files changed, 27 insertions(+), 9 deletions(-) diff --git a/source3/utils/net_rpc.c b/source3/utils/net_rpc.c index b99a036f..4f37e3d4 100644 --- a/source3/utils/net_rpc.c +++ b/source3/utils/net_rpc.c @@ -5232,7 +5232,13 @@ static NTSTATUS rpc_share_allowedusers_internals(struct net_context *c, if (argc == 0) { f = stdin; } else { - f = fopen(argv[0], "r"); + if (strcmp(argv[0], "-") == 0) { + f = stdin; + } else { + f = fopen(argv[0], "r"); + } + argv++; + argc--; } if (f == NULL) { @@ -5261,6 +5267,17 @@ static NTSTATUS rpc_share_allowedusers_internals(struct net_context *c, b = pipe_hnd->binding_handle; + if (argc != 0) { + /* Show results only for shares listed on the command line. */ + while (*argv) { + const char * netname = *argv++; + d_printf("%s\n", netname); + show_userlist(pipe_hnd, cli, mem_ctx, netname, + num_tokens, tokens); + } + goto done; + } + /* Issue the NetShareEnum RPC call and retrieve the response */ nt_status = dcerpc_srvsvc_NetShareEnumAll(b, talloc_tos(), diff --git a/source3/utils/net_share.c b/source3/utils/net_share.c index 6eca9d64..56bb2c99 100644 --- a/source3/utils/net_share.c +++ b/source3/utils/net_share.c @@ -28,14 +28,15 @@ int net_share_usage(struct net_context *c, int argc, const char **argv) "\tenumerates all exported resources (network shares) " "on target server\n\n" "net [] share ADD [misc. options] [targets]" - "\n\tadds a share from a server (makes the export active)\n\n" - "net [] share DELETE [misc. options] [targets]" - "\n\tdeletes a share from a server (makes the export inactive)\n\n" - "net [] share ALLOWEDUSERS [] " - "[misc. options] [targets]" - "\n\tshows a list of all shares together with all users allowed to" - "\n\taccess them. This needs the output of 'net usersidlist' on" - "\n\tstdin or in .\n\n" + "\n\tadds a share from a server (makes the export active)\n\n" + "net [] share DELETE [misc. options] [targets]" + "\n\tdeletes a share from a server (makes the export inactive)\n\n" + "net [] share ALLOWEDUSERS [misc. options] [|- " + " [targets]]" + "\n\tshows a list of shares (either from [targets] or by default all" + "\n\tshares) together with all users allowed to access them. This" + "\n\tneeds the output of 'net usersidlist' on stdin or in ." + "\n\n" "net [] share MIGRATE FILES [misc. options] [targets]" "\n\tMigrates files from remote to local server\n\n" "net [] share MIGRATE SHARES [misc. options] [targets]" -- 2.17.0