From ac15eb8e5140850bd5752811f4672ebc0be3c6f8 Mon Sep 17 00:00:00 2001 From: Art Cancro Date: Sun, 18 Jan 2009 05:35:55 +0000 Subject: [PATCH] * During server startup, if config.c_default_cal_zone is an empty string, run a shell script which attempts to determine the name of the time zone in use on the underlying host system. The script scans the files in /usr/share/zoneinfo and looks for a file whose md5sum matches that of /etc/localtime. This is a kludge but it should work 99% of the time. --- citadel/citadel_dirs.c | 7 ++++++ citadel/citadel_dirs.h | 1 + citadel/guesstimezone.sh | 33 ++++++++++++++++++++++++++ citadel/modules/upgrade/serv_upgrade.c | 25 +++++++++++++++++++ 4 files changed, 66 insertions(+) create mode 100755 citadel/guesstimezone.sh diff --git a/citadel/citadel_dirs.c b/citadel/citadel_dirs.c index b6bfe5762..0b8e40192 100644 --- a/citadel/citadel_dirs.c +++ b/citadel/citadel_dirs.c @@ -66,6 +66,7 @@ char file_crpt_file_csr[PATH_MAX]=""; char file_crpt_file_cer[PATH_MAX]=""; char file_chkpwd[PATH_MAX]=""; char file_base64[PATH_MAX]=""; +char file_guesstimezone[PATH_MAX]=""; char file_funambol_msg[PATH_MAX] = ""; char file_dpsam_conf[PATH_MAX] = ""; char file_dspam_log[PATH_MAX] = ""; @@ -228,6 +229,11 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char *ctd "%sbase64", ctdl_utilbin_dir); + snprintf(file_guesstimezone, + sizeof file_guesstimezone, + "%sguesstimezone.sh", + ctdl_utilbin_dir); + snprintf(file_dpsam_conf, sizeof file_dpsam_conf, "%sdspam.conf", @@ -292,6 +298,7 @@ void calc_dirs_n_files(int relh, int home, const char *relhome, const char *ctd DBG_PRINT(file_crpt_file_cer); DBG_PRINT(file_chkpwd); DBG_PRINT(file_base64); + DBG_PRINT(file_guesstimezone); DBG_PRINT(file_funambol_msg); } diff --git a/citadel/citadel_dirs.h b/citadel/citadel_dirs.h index d8a9038fa..cebf4fb91 100644 --- a/citadel/citadel_dirs.h +++ b/citadel/citadel_dirs.h @@ -48,6 +48,7 @@ extern char file_crpt_file_csr[PATH_MAX]; extern char file_crpt_file_cer[PATH_MAX]; extern char file_chkpwd[PATH_MAX]; extern char file_base64[PATH_MAX]; +extern char file_guesstimezone[PATH_MAX]; extern char file_dpsam_conf[PATH_MAX]; extern char file_dspam_log[PATH_MAX]; diff --git a/citadel/guesstimezone.sh b/citadel/guesstimezone.sh new file mode 100755 index 000000000..90493fd17 --- /dev/null +++ b/citadel/guesstimezone.sh @@ -0,0 +1,33 @@ +#!/bin/sh + +# guesstimezone.sh - an ugly hack of a script to try to guess the time +# zone currently in use on the host system, and output its name. + +# Copyright (c) by Art Cancro + +# This program is free software; you can redistribute it and/or modify it +# under the terms of the GNU General Public License as published by the Free +# Software Foundation; either version 3 of the License, or (at your option) +# any later version. + +# This program is distributed in the hope that it will be useful, but WITHOUT +# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or +# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for +# more details. + +# You should have received a copy of the GNU General Public License along +# with this program; if not, write to the Free Software Foundation, Inc., +# 675 Mass Ave, Cambridge, MA 02139, USA. + +md5sum /dev/null 2>/dev/null || exit 1 + +LOCALTIMESUM=`md5sum /etc/localtime | awk ' { print $1 } ' 2>/dev/null` +find /usr/share/zoneinfo -type f -print | while read filename +do + THISTIMESUM=`md5sum $filename | awk ' { print $1 } '` + if [ $LOCALTIMESUM = $THISTIMESUM ] ; then + echo $filename | cut -c21- + exit 0 + fi +done 2>/dev/null +exit 2 diff --git a/citadel/modules/upgrade/serv_upgrade.c b/citadel/modules/upgrade/serv_upgrade.c index a173024b0..0b09d9f57 100644 --- a/citadel/modules/upgrade/serv_upgrade.c +++ b/citadel/modules/upgrade/serv_upgrade.c @@ -195,6 +195,27 @@ void convert_ctdluid_to_minusone(void) { return; } + +/* + * Attempt to guess the name of the time zone currently in use + * on the underlying host system. + */ +void guess_time_zone(void) { + FILE *fp; + char buf[PATH_MAX]; + + fp = popen(file_guesstimezone, "r"); + if (fp) { + if (fgets(buf, sizeof buf, fp) && (strlen(buf) > 2)) { + buf[strlen(buf)-1] = 0; + safestrncpy(config.c_default_cal_zone, buf, sizeof config.c_default_cal_zone); + CtdlLogPrintf(CTDL_INFO, "Configuring timezone: %s\n", config.c_default_cal_zone); + } + fclose(fp); + } +} + + /* * Do various things to our configuration file */ @@ -230,6 +251,10 @@ void update_config(void) { config.c_xmpp_s2s_port = 5269; } + if (IsEmptyStr(config.c_default_cal_zone)) { + guess_time_zone(); + } + put_config(); } -- 2.30.2