From f2ccff7b06a2ad762103f98a736f37da94d7cfdd Mon Sep 17 00:00:00 2001 From: Andrew Bartlett Date: Mon, 2 Jul 2012 22:31:49 +1000 Subject: [PATCH] s3-vfs: Try to be consistent about localtime vs GMT handling in vfs_shadow_copy2 With the ability to handle times a abolute time_t values since 1970 this becomes more important to get absolutly correct. Andrew Bartlett --- source3/modules/vfs_shadow_copy2.c | 31 +++++++++++++++++++------------ 1 file changed, 19 insertions(+), 12 deletions(-) diff --git a/source3/modules/vfs_shadow_copy2.c b/source3/modules/vfs_shadow_copy2.c index 227453d2779..7c42052af73 100644 --- a/source3/modules/vfs_shadow_copy2.c +++ b/source3/modules/vfs_shadow_copy2.c @@ -150,27 +150,34 @@ static char *shadow_copy2_insert_string(TALLOC_CTX *mem_ctx, { const char *fmt; struct tm snap_tm; - fstring gmt; - size_t gmt_len; + fstring snaptime_string; + size_t snaptime_len; - if (localtime_r(&snapshot, &snap_tm) == 0) { - DEBUG(10, ("gmtime_r failed\n")); - return NULL; - } fmt = lp_parm_const_string(SNUM(handle->conn), "shadow", "format", GMT_FORMAT); if (lp_parm_bool(SNUM(handle->conn), "shadow", "sscanf", false)) { - gmt_len = snprintf(gmt, sizeof(gmt), fmt, + snaptime_len = snprintf(snaptime_string, sizeof(snaptime_string), fmt, (unsigned long)snapshot); - if (gmt_len == 0) { + if (snaptime_len <= 0) { DEBUG(10, ("snprintf failed\n")); return NULL; } } else { - gmt_len = strftime(gmt, sizeof(gmt), fmt, + if (lp_parm_bool(SNUM(handle->conn), "shadow", "localtime", false)) { + if (localtime_r(&snapshot, &snap_tm) == 0) { + DEBUG(10, ("gmtime_r failed\n")); + return NULL; + } + } else { + if (gmtime_r(&snapshot, &snap_tm) == 0) { + DEBUG(10, ("gmtime_r failed\n")); + return NULL; + } + } + snaptime_len = strftime(snaptime_string, sizeof(snaptime_string), fmt, &snap_tm); - if (gmt_len == 0) { + if (snaptime_len == 0) { DEBUG(10, ("strftime failed\n")); return NULL; } @@ -179,7 +186,7 @@ static char *shadow_copy2_insert_string(TALLOC_CTX *mem_ctx, lp_parm_const_string( SNUM(handle->conn), "shadow", "snapdir", ".snapshots"), - gmt); + snaptime_string); } static bool shadow_copy2_strip_snapshot(TALLOC_CTX *mem_ctx, @@ -207,7 +214,7 @@ static bool shadow_copy2_strip_snapshot(TALLOC_CTX *mem_ctx, goto no_snapshot; } tm.tm_isdst = -1; - timestamp = mktime(&tm); + timestamp = timegm(&tm); if (timestamp == (time_t)-1) { goto no_snapshot; } -- 2.11.4.GIT