diff --git a/clientserver.c b/clientserver.c index 18a2258..70c28b9 100644 --- a/clientserver.c +++ b/clientserver.c @@ -671,11 +671,41 @@ static int rsync_module(int f_in, int f_out, int i, char *addr, char *host) * a warning, unless a "require chroot" flag is set, * in which case we fail. */ + time_t current_time = 0; + struct tm* local_tm; + char envtz[sizeof("UTC-hh:mm:ss")]; + int hour, min, sec; + + /* Do libc's timezone initialization before it gets lost + * because of chroot. */ + tzset(); + current_time = time(NULL); + local_tm = localtime(¤t_time); + long timezone = -local_tm->tm_gmtoff; + if (chroot(module_chdir)) { rsyserr(FLOG, errno, "chroot %s failed", module_chdir); io_printf(f_out, "@ERROR: chroot failed\n"); return -1; } + + /* Set TZ env variable according to data we got + * before chroot. */ + hour = timezone; + if (hour < 0) { + hour = -hour; + } + if (hour < 25*60*60) { + sec = hour % 60; + hour /= 60; + min = hour % 60; + hour /= 60; + if (timezone < 0) { + hour = -hour; + } + snprintf(envtz, sizeof(envtz), "UTC%+d:%d:%d", hour, min, sec); + setenv("TZ", envtz, 1); + } module_chdir = module_dir; }