From 943882a289da2ad2d6ae1ef9c8bba494d769ba50 Mon Sep 17 00:00:00 2001 From: Andrew Tridgell Date: Sat, 23 May 1998 05:57:08 +0000 Subject: [PATCH] - don't allow chown for the group of a file if running as a daemon and uid!=0 - reset am_root after startup as a daemon --- clientserver.c | 3 +++ rsync.c | 6 ++++-- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/clientserver.c b/clientserver.c index b8baa331..7ce08e6d 100644 --- a/clientserver.c +++ b/clientserver.c @@ -121,6 +121,7 @@ static int rsync_module(int fd, int i) char *request=NULL; extern int am_sender; extern int remote_version; + extern int am_root; if (!allow_access(addr, host, lp_hosts_allow(i), lp_hosts_deny(i))) { rprintf(FERROR,"rsync denied on module %s from %s (%s)\n", @@ -204,6 +205,8 @@ static int rsync_module(int fd, int i) return -1; } + am_root = (getuid() == 0); + io_printf(fd,"@RSYNCD: OK\n"); argv[argc++] = "rsyncd"; diff --git a/rsync.c b/rsync.c index 6644f141..2f772ace 100644 --- a/rsync.c +++ b/rsync.c @@ -267,6 +267,7 @@ static int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st, { int updated = 0; STRUCT_STAT st2; + extern int am_daemon; if (dry_run) return 0; @@ -300,8 +301,9 @@ static int set_perms(char *fname,struct file_struct *file,STRUCT_STAT *st, } #endif - if ((am_root && preserve_uid && st->st_uid != file->uid) || - (preserve_gid && st->st_gid != file->gid)) { + if ((am_root || !am_daemon) && + ((am_root && preserve_uid && st->st_uid != file->uid) || + (preserve_gid && st->st_gid != file->gid))) { if (do_lchown(fname, (am_root&&preserve_uid)?file->uid:-1, preserve_gid?file->gid:-1) != 0) { -- 2.34.1