When listing a bare module name w/o -r, make sure we list the
authorWayne Davison <wayned@samba.org>
Sat, 27 Oct 2007 02:19:49 +0000 (02:19 +0000)
committerWayne Davison <wayned@samba.org>
Sat, 27 Oct 2007 02:19:49 +0000 (02:19 +0000)
contents of the module's root directory.

clientserver.c
main.c

index 20a164e..8cbde16 100644 (file)
@@ -192,21 +192,31 @@ static int exchange_protocols(int f_in, int f_out, char *buf, size_t bufsiz, int
 
 int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char *argv[])
 {
-       int i;
+       int i, modlen;
        char line[BIGPATHBUFLEN];
        char *sargs[MAX_ARGS];
        int sargc = 0;
-       char *p, *path = *argv;
+       char *p, *modname;
 
-       if (argc == 0 && !am_sender)
-               list_only |= 1;
+       assert(argc > 0);
 
-       if (*path == '/') {
+       if (**argv == '/') {
                rprintf(FERROR,
                        "ERROR: The remote path must start with a module name\n");
                return -1;
        }
 
+       if (!(p = strchr(*argv, '/')))
+               modlen = strlen(*argv);
+       else
+               modlen = p - *argv;
+
+       if (!(modname = new_array(char, modlen+1+1))) /* room for '/' & '\0' */
+               out_of_memory("start_inband_exchange");
+       strlcpy(modname, *argv, modlen + 1);
+       modname[modlen] = '/';
+       modname[modlen+1] = '\0';
+
        if (!user)
                user = getenv("USER");
        if (!user)
@@ -232,7 +242,12 @@ int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char
                        rprintf(FERROR, "internal: args[] overflowed in do_cmd()\n");
                        exit_cleanup(RERR_SYNTAX);
                }
-               sargs[sargc++] = *argv++;
+               if (list_only && strncmp(*argv, modname, modlen) == 0
+                && argv[0][modlen] == '\0')
+                       sargs[sargc++] = modname; /* we send "modname/" */
+               else
+                       sargs[sargc++] = *argv;
+               argv++;
                argc--;
        }
 
@@ -241,10 +256,7 @@ int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char
        if (verbose > 1)
                print_child_argv("sending daemon args:", sargs);
 
-       p = strchr(path, '/');
-       if (p) *p = '\0';
-       io_printf(f_out, "%s\n", path);
-       if (p) *p = '/';
+       io_printf(f_out, "%.*s\n", modlen, modname);
 
        /* Old servers may just drop the connection here,
         rather than sending a proper EXIT command.  Yuck. */
@@ -303,6 +315,8 @@ int start_inband_exchange(int f_in, int f_out, const char *user, int argc, char
                        io_start_multiplex_in();
        }
 
+       free(modname);
+
        return 0;
 }
 
diff --git a/main.c b/main.c
index 454b7ea..92b5c44 100644 (file)
--- a/main.c
+++ b/main.c
@@ -723,7 +723,7 @@ static void do_server_sender(int f_in, int f_out, int argc, char *argv[])
        argc--;
        argv++;
 
-       if (argc == 0 && (recurse || list_only)) {
+       if (argc == 0 && (recurse || xfer_dirs || list_only)) {
                argc = 1;
                argv--;
                argv[0] = ".";