Commit 1a016bfd authored by Andrew Tridgell's avatar Andrew Tridgell

- changed the log messages to show the requested path

- some more paranoid buffer size checks
- separate open syslog call
- handle systems without LOG_NDELAY
parent e42c9458
...@@ -107,12 +107,7 @@ static int get_secret(int module, char *user, char *secret, int len) ...@@ -107,12 +107,7 @@ static int get_secret(int module, char *user, char *secret, int len)
close(fd); close(fd);
if (!found) return 0; if (!found) return 0;
if (strlen(pass) > len-1) { strlcpy(secret, pass, len);
memset(line, 0, sizeof(line));
return 0;
}
strcpy(secret, pass);
return 1; return 1;
} }
......
...@@ -103,8 +103,8 @@ static int rsync_module(int fd, int i) ...@@ -103,8 +103,8 @@ static int rsync_module(int fd, int i)
char *argv[MAX_ARGS]; char *argv[MAX_ARGS];
char **argp; char **argp;
char line[MAXPATHLEN]; char line[MAXPATHLEN];
uid_t uid; uid_t uid = (uid_t)-2;
gid_t gid; gid_t gid = (gid_t)-2;
char *p; char *p;
char *addr = client_addr(fd); char *addr = client_addr(fd);
char *host = client_name(fd); char *host = client_name(fd);
...@@ -133,8 +133,6 @@ static int rsync_module(int fd, int i) ...@@ -133,8 +133,6 @@ static int rsync_module(int fd, int i)
return -1; return -1;
} }
rprintf(FINFO,"rsync on module %s from %s (%s)\n",
name, host, addr);
module_id = i; module_id = i;
...@@ -167,22 +165,28 @@ static int rsync_module(int fd, int i) ...@@ -167,22 +165,28 @@ static int rsync_module(int fd, int i)
p = lp_exclude(i); p = lp_exclude(i);
add_exclude_line(p); add_exclude_line(p);
log_open();
if (chroot(lp_path(i))) { if (chroot(lp_path(i))) {
rprintf(FERROR,"chroot %s failed\n", lp_path(i));
io_printf(fd,"@ERROR: chroot failed\n"); io_printf(fd,"@ERROR: chroot failed\n");
return -1; return -1;
} }
if (chdir("/")) { if (chdir("/")) {
rprintf(FERROR,"chdir %s failed\n", lp_path(i));
io_printf(fd,"@ERROR: chdir failed\n"); io_printf(fd,"@ERROR: chdir failed\n");
return -1; return -1;
} }
if (setgid(gid)) { if (setgid(gid) || getgid() != gid) {
rprintf(FERROR,"setgid %d failed\n", gid);
io_printf(fd,"@ERROR: setgid failed\n"); io_printf(fd,"@ERROR: setgid failed\n");
return -1; return -1;
} }
if (setuid(uid)) { if (setuid(uid) || getuid() != uid) {
rprintf(FERROR,"setuid %d failed\n", uid);
io_printf(fd,"@ERROR: setuid failed\n"); io_printf(fd,"@ERROR: setuid failed\n");
return -1; return -1;
} }
...@@ -206,7 +210,11 @@ static int rsync_module(int fd, int i) ...@@ -206,7 +210,11 @@ static int rsync_module(int fd, int i)
} }
if (start_glob) { if (start_glob) {
rprintf(FINFO,"transferring %s\n",p); if (start_glob == 1) {
rprintf(FINFO,"rsync on %s from %s (%s)\n",
p, host, addr);
start_glob++;
}
glob_expand(name, argv, &argc, MAX_ARGS); glob_expand(name, argv, &argc, MAX_ARGS);
} else { } else {
argc++; argc++;
...@@ -319,6 +327,8 @@ static int start_daemon(int fd) ...@@ -319,6 +327,8 @@ static int start_daemon(int fd)
int daemon_main(void) int daemon_main(void)
{ {
log_open();
if (is_a_socket(STDIN_FILENO)) { if (is_a_socket(STDIN_FILENO)) {
/* we are running via inetd */ /* we are running via inetd */
return start_daemon(STDIN_FILENO); return start_daemon(STDIN_FILENO);
......
...@@ -616,7 +616,7 @@ struct file_list *send_file_list(int f,int argc,char *argv[]) ...@@ -616,7 +616,7 @@ struct file_list *send_file_list(int f,int argc,char *argv[])
thus getting their permissions right */ thus getting their permissions right */
*p = 0; *p = 0;
if (strcmp(lastpath,fname)) { if (strcmp(lastpath,fname)) {
strcpy(lastpath, fname); strlcpy(lastpath, fname, sizeof(lastpath)-1);
*p = '/'; *p = '/';
for (p=fname+1; (p=strchr(p,'/')); p++) { for (p=fname+1; (p=strchr(p,'/')); p++) {
*p = 0; *p = 0;
......
...@@ -583,7 +583,7 @@ static BOOL lp_do_parameter(int snum, char *parmname, char *parmvalue) ...@@ -583,7 +583,7 @@ static BOOL lp_do_parameter(int snum, char *parmname, char *parmvalue)
break; break;
case P_GSTRING: case P_GSTRING:
strcpy((char *)parm_ptr,parmvalue); strlcpy((char *)parm_ptr,parmvalue,sizeof(pstring)-1);
break; break;
case P_ENUM: case P_ENUM:
......
...@@ -24,6 +24,30 @@ ...@@ -24,6 +24,30 @@
#include "rsync.h" #include "rsync.h"
void log_open(void)
{
static int initialised;
int options = LOG_PID;
if (initialised) return;
initialised = 1;
#ifdef LOG_NDELAY
options |= LOG_NDELAY;
#endif
#ifdef LOG_DAEMON
openlog("rsyncd", options, lp_syslog_facility());
#else
openlog("rsyncd", options);
#endif
#ifndef LOG_NDELAY
syslog(LOG_INFO,"rsyncd started\n");
#endif
}
/* this is the rsync debugging function. Call it with FINFO or FERROR */ /* this is the rsync debugging function. Call it with FINFO or FERROR */
void rprintf(int fd, const char *format, ...) void rprintf(int fd, const char *format, ...)
{ {
...@@ -44,19 +68,10 @@ void rprintf(int fd, const char *format, ...) ...@@ -44,19 +68,10 @@ void rprintf(int fd, const char *format, ...)
buf[len] = 0; buf[len] = 0;
if (am_daemon) { if (am_daemon) {
static int initialised;
int priority = LOG_INFO; int priority = LOG_INFO;
if (fd == FERROR) priority = LOG_WARNING; if (fd == FERROR) priority = LOG_WARNING;
if (!initialised) { log_open();
initialised = 1;
#ifdef LOG_DAEMON
openlog("rsyncd", LOG_PID, lp_syslog_facility());
#else
openlog("rsyncd", LOG_PID);
#endif
}
syslog(priority, "%s", buf); syslog(priority, "%s", buf);
return; return;
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment