From 874895d51a4b65e39762f06eea84b7d4a7755a3f Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Wed, 13 May 1998 15:44:04 +0000 Subject: [PATCH] added globbing support in the rsync daemon. This will allow you to specify wildcards when grabbing files from a anon rsync daemon. --- clientserver.c | 32 +++++++++++++++++++++++++------- configure.in | 2 +- main.c | 24 ------------------------ rsync.h | 6 +++++- 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 diff --git a/main.c b/main.c index b4c514fd..401955eb 100644 --- a/main.c +++ b/main.c @@ -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 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 0) { dir = argv[0]; argc--; diff --git a/rsync.h b/rsync.h index bbfe689c..13116707 100644 --- a/rsync.h +++ b/rsync.h @@ -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 +#endif + /* these are needed for the uid/gid mapping code */ #include #include diff --git a/util.c b/util.c index 7d15a8a6..8546e4a7 100644 --- a/util.c +++ b/util.c @@ -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