net rpc share allowedusers: Allow restricting shares
authorOlly Betts <olly@survex.com>
Tue, 1 May 2018 02:37:08 +0000 (14:37 +1200)
committerDouglas Bagnall <dbagnall@samba.org>
Fri, 30 Nov 2018 02:35:13 +0000 (03:35 +0100)
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 <olly@survex.com>
Reviewed-by: Douglas Bagnall <douglas.bagnall@catalyst.net.nz>
Reviewed-by: Andrew Bartlett <abartlet@samba.org>
source3/utils/net_rpc.c
source3/utils/net_share.c

index b2add781a2f0f1ebebddcc72228489d41a1895db..98940b84e0500f6052441a677defa136eab89e98 100644 (file)
@@ -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 (strequal(argv[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(),
index 6eca9d64ceb87a4534ff4799359cefcdb7c06731..56bb2c999ff5a5e44bc10bd84342de3c2b981426 100644 (file)
@@ -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 [<method>] share ADD <name=serverpath> [misc. options] [targets]"
-       "\n\tadds a share from a server (makes the export active)\n\n"
-       "net [<method>] share DELETE <sharename> [misc. options] [targets]"
-       "\n\tdeletes a share from a server (makes the export inactive)\n\n"
-       "net [<method>] share ALLOWEDUSERS [<filename>] "
-       "[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 <filename>.\n\n"
+        "\n\tadds a share from a server (makes the export active)\n\n"
+        "net [<method>] share DELETE <sharename> [misc. options] [targets]"
+        "\n\tdeletes a share from a server (makes the export inactive)\n\n"
+        "net [<method>] share ALLOWEDUSERS [misc. options] [<filename>|- "
+        " [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 <filename>."
+        "\n\n"
         "net [<method>] share MIGRATE FILES <sharename> [misc. options] [targets]"
         "\n\tMigrates files from remote to local server\n\n"
         "net [<method>] share MIGRATE SHARES <sharename> [misc. options] [targets]"