diff options
author | Andrew Tridgell <tridge@samba.org> | 1998-05-13 15:44:04 +0000 |
---|---|---|
committer | Andrew Tridgell <tridge@samba.org> | 1998-05-13 15:44:04 +0000 |
commit | 874895d51a4b65e39762f06eea84b7d4a7755a3f (patch) | |
tree | 1aaa1061e0f36f4a653c4a75a554cacecc1fdeff | |
parent | f855d1a309f38301bcd8898e9fbc5c70133d1f98 (diff) | |
download | rsync-874895d51a4b65e39762f06eea84b7d4a7755a3f.tar.gz |
added globbing support in the rsync daemon. This will allow you to
specify wildcards when grabbing files from a anon rsync daemon.
-rw-r--r-- | clientserver.c | 32 | ||||
-rw-r--r-- | configure.in | 2 | ||||
-rw-r--r-- | main.c | 24 | ||||
-rw-r--r-- | rsync.h | 6 | ||||
-rw-r--r-- | util.c | 28 |
5 files changed, 59 insertions, 33 deletions
diff --git a/clientserver.c b/clientserver.c index 68d631ed..8a0ef15d 100644 --- a/clientserver.c +++ b/clientserver.c @@ -109,19 +109,21 @@ static int rsync_module(int fd, int i) char *addr = client_addr(fd); char *host = client_name(fd); char *auth; + char *name = lp_name(i); + int start_glob=0; if (!allow_access(addr, host, lp_hosts_allow(i), lp_hosts_deny(i))) { rprintf(FERROR,"rsync denied on module %s from %s (%s)\n", - lp_name(i), client_name(fd), client_addr(fd)); + name, client_name(fd), client_addr(fd)); io_printf(fd,"@ERROR: access denied to %s from %s (%s)\n", - lp_name(i), client_name(fd), client_addr(fd)); + name, client_name(fd), client_addr(fd)); return -1; } if (!auth_server(fd, i, addr, "@RSYNCD: AUTHREQD ")) { rprintf(FERROR,"auth failed on module %s from %s (%s)\n", - lp_name(i), client_name(fd), client_addr(fd)); - io_printf(fd,"@ERROR: auth failed on module %s\n",lp_name(i)); + name, client_name(fd), client_addr(fd)); + io_printf(fd,"@ERROR: auth failed on module %s\n",name); return -1; } @@ -133,7 +135,7 @@ static int rsync_module(int fd, int i) } rprintf(FINFO,"rsync on module %s from %s (%s)\n", - lp_name(i), host, addr); + name, host, addr); module_id = i; @@ -191,12 +193,28 @@ static int rsync_module(int fd, int i) if (!*line) break; - argv[argc] = strdup(line); + p = line; + + if (start_glob && strncmp(p, name, strlen(name)) == 0) { + p += strlen(name); + if (!*p) p = "."; + } + + argv[argc] = strdup(p); if (!argv[argc]) { return -1; } - argc++; + if (start_glob) { + glob_expand(argv, &argc, MAX_ARGS); + } else { + argc++; + } + + if (strcmp(line,".") == 0) { + start_glob = 1; + } + if (argc == MAX_ARGS) { return -1; } diff --git a/configure.in b/configure.in index ae750e6d..fdf417e1 100644 --- a/configure.in +++ b/configure.in @@ -42,7 +42,7 @@ AC_FUNC_MMAP AC_FUNC_UTIME_NULL AC_CHECK_FUNCS(waitpid strtok pipe getcwd mkdir strdup strerror chown chmod mknod) AC_CHECK_FUNCS(fchmod fstat strchr bcopy bzero readlink link utime utimes) -AC_CHECK_FUNCS(memmove getopt_long lchown setlinebuf vsnprintf setsid) +AC_CHECK_FUNCS(memmove getopt_long lchown setlinebuf vsnprintf setsid glob) echo $ac_n "checking for working fnmatch... $ac_c" AC_TRY_RUN([#include <fnmatch.h> @@ -204,18 +204,6 @@ static void do_server_sender(int f_in, int f_out, int argc,char *argv[]) argv[i] += l+1; } - if (am_daemon) { - extern int module_id; - char *name = lp_name(module_id); - int l = strlen(name); - for (i=0;i<argc;i++) { - if (strncmp(argv[i], name, l) == 0) { - argv[i] += l; - if (!*argv[i]) argv[i] = "."; - } - } - } - if (argc == 0 && recurse) { argc=1; argv--; @@ -272,18 +260,6 @@ static void do_server_recv(int f_in, int f_out, int argc,char *argv[]) if (verbose > 2) rprintf(FINFO,"server_recv(%d) starting pid=%d\n",argc,(int)getpid()); - if (am_daemon) { - extern int module_id; - char *name = lp_name(module_id); - int i, l = strlen(name); - for (i=0;i<argc;i++) { - if (strncmp(argv[i], name, l) == 0) { - argv[i] += l; - if (!*argv[i]) argv[i] = "."; - } - } - } - if (argc > 0) { dir = argv[0]; argc--; @@ -52,7 +52,7 @@ #define CHUNK_SIZE (32*1024) #define MAX_MAP_SIZE (4*1024*1024) -#define MAX_ARGS 100 +#define MAX_ARGS 1000 #define BLOCKING_TIMEOUT 10 @@ -170,6 +170,10 @@ #include "lib/getopt.h" #endif +#ifdef HAVE_GLOB +#include <glob.h> +#endif + /* these are needed for the uid/gid mapping code */ #include <pwd.h> #include <grp.h> @@ -504,3 +504,31 @@ int lock_range(int fd, int offset, int len) return fcntl(fd,F_SETLK,&lock) == 0; } + + +void glob_expand(char **argv, int *argc, int maxargs) +{ +#ifndef HAVE_GLOB + (*argc)++; + return; +#else + glob_t globbuf; + int i; + + rprintf(FINFO,"glob(%s) -> %d\n", argv[*argc], globbuf.gl_pathc); + memset(&globbuf, 0, sizeof(globbuf)); + glob(argv[*argc], 0, NULL, &globbuf); + if (globbuf.gl_pathc == 0) { + (*argc)++; + globfree(&globbuf); + return; + } + for (i=0; i<(maxargs - (*argc)) && i<globbuf.gl_pathc;i++) { + if (i == 0) free(argv[*argc]); + argv[(*argc) + i] = strdup(globbuf.gl_pathv[i]); + if (!argv[(*argc) + i]) out_of_memory("glob_expand"); + } + globfree(&globbuf); + (*argc) += i; +#endif +} |