Skip to content

Commit 727cb98

Browse files
committed
ctl_zoneinfo,http_tzdist: use and require zoneinfo_dir for tzdist service
1 parent cd5b403 commit 727cb98

File tree

4 files changed

+33
-22
lines changed

4 files changed

+33
-22
lines changed

Diff for: imap/ctl_zoneinfo.c

+12-7
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ int main(int argc, char **argv)
8888
{
8989
int opt, r = 0;
9090
char *alt_config = NULL, *pub = NULL, *ver = NULL, *winfile = NULL;
91-
char prefix[2048];
91+
const char *zoneinfo_dir = NULL;
9292
enum { REBUILD, WINZONES, NONE } op = NONE;
9393

9494
while ((opt = getopt(argc, argv, "C:r:vw:")) != EOF) {
@@ -130,7 +130,12 @@ int main(int argc, char **argv)
130130
signals_set_shutdown(&shut_down);
131131
signals_add_handlers(0);
132132

133-
snprintf(prefix, sizeof(prefix), "%s%s", config_dir, FNAME_ZONEINFODIR);
133+
zoneinfo_dir = config_getstring(IMAPOPT_ZONEINFO_DIR);
134+
if (!zoneinfo_dir) {
135+
fprintf(stderr, "zoneinfo_dir must be set for tzdist service\n");
136+
cyrus_done();
137+
return EX_CONFIG;
138+
}
134139

135140
switch (op) {
136141
case REBUILD: {
@@ -150,7 +155,7 @@ int main(int argc, char **argv)
150155
hash_insert(INFO_TZID, info, &tzentries);
151156

152157
/* Add LEAP record (last updated and hash) */
153-
snprintf(buf, sizeof(buf), "%s%s", prefix, FNAME_LEAPSECFILE);
158+
snprintf(buf, sizeof(buf), "%s%s", zoneinfo_dir, FNAME_LEAPSECFILE);
154159
if (verbose) printf("Processing leap seconds file %s\n", buf);
155160
if (!(fp = fopen(buf, "r"))) {
156161
fprintf(stderr, "Could not open leap seconds file %s\n", buf);
@@ -187,7 +192,7 @@ int main(int argc, char **argv)
187192
}
188193

189194
/* Add ZONE/LINK records */
190-
do_zonedir(prefix, &tzentries, info);
195+
do_zonedir(zoneinfo_dir, &tzentries, info);
191196

192197
zoneinfo_open(NULL);
193198

@@ -243,8 +248,8 @@ int main(int argc, char **argv)
243248
goto done;
244249
}
245250

246-
if (chdir(prefix)) {
247-
fprintf(stderr, "chdir(%s) failed\n", prefix);
251+
if (chdir(zoneinfo_dir)) {
252+
fprintf(stderr, "chdir(%s) failed\n", zoneinfo_dir);
248253
goto done;
249254
}
250255

@@ -371,7 +376,7 @@ void do_zonedir(const char *dir, struct hash_table *tzentries,
371376

372377
/* Isolate alias in path */
373378
path[plen-4] = '\0'; /* Trim ".ics" */
374-
alias = path + strlen(config_dir) + strlen("zoneinfo") + 2;
379+
alias = path + strlen(dir) + 1;
375380

376381
if (verbose) printf("\tLINK: %s -> %s\n", alias, tzid);
377382

Diff for: imap/http_tzdist.c

+14-10
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,7 @@ static time_t compile_time;
8585
static unsigned synctoken_prefix;
8686
static ptrarray_t *leap_seconds = NULL;
8787
static int geo_enabled = 0;
88+
static const char *zoneinfo_dir = NULL;
8889
static void tzdist_init(struct buf *serverinfo);
8990
static void tzdist_shutdown(void);
9091
static int meth_get(struct transaction_t *txn, void *params);
@@ -193,8 +194,7 @@ static void open_shape_file(struct buf *serverinfo)
193194
buf_printf(serverinfo, " ShapeLib/%s", SHAPELIB_VERSION);
194195

195196
/* Open the tz_world shape files */
196-
snprintf(buf, sizeof(buf), "%s%s%s",
197-
config_dir, FNAME_ZONEINFODIR, FNAME_WORLD_SHAPEFILE);
197+
snprintf(buf, sizeof(buf), "%s%s", zoneinfo_dir, FNAME_WORLD_SHAPEFILE);
198198
if (!(tz_world.shp = SHPOpen(buf, "rb"))) {
199199
syslog(LOG_ERR, "Failed to open file %s", buf);
200200
return;
@@ -224,8 +224,7 @@ static void open_shape_file(struct buf *serverinfo)
224224
geo_enabled = tz_world.valid = 1;
225225

226226
/* Open the tz_antarctica shape files (optional) */
227-
snprintf(buf, sizeof(buf), "%s%s%s",
228-
config_dir, FNAME_ZONEINFODIR, FNAME_AQ_SHAPEFILE);
227+
snprintf(buf, sizeof(buf), "%s%s", zoneinfo_dir, FNAME_AQ_SHAPEFILE);
229228
if (!(tz_aq.shp = SHPOpen(buf, "rb"))) {
230229
syslog(LOG_NOTICE, "Failed to open file %s", buf);
231230
return;
@@ -601,8 +600,7 @@ static void read_leap_seconds()
601600
char buf[1024];
602601
struct leapsec *leap;
603602

604-
snprintf(buf, sizeof(buf), "%s%s%s",
605-
config_dir, FNAME_ZONEINFODIR, FNAME_LEAPSECFILE);
603+
snprintf(buf, sizeof(buf), "%s%s", zoneinfo_dir, FNAME_LEAPSECFILE);
606604
if (!(fp = fopen(buf, "r"))) {
607605
syslog(LOG_ERR, "Failed to open file %s", buf);
608606
return;
@@ -651,6 +649,14 @@ static void tzdist_init(struct buf *serverinfo __attribute__((unused)))
651649
return;
652650
}
653651

652+
/* Find configured zoneinfo_zir */
653+
zoneinfo_dir = config_getstring(IMAPOPT_ZONEINFO_DIR);
654+
if (!zoneinfo_dir) {
655+
syslog(LOG_ERR, "zoneinfo_dir must be set for tzdist service");
656+
namespace_tzdist.enabled = 0;
657+
return;
658+
}
659+
654660
compile_time = calc_compile_time(__TIME__, __DATE__);
655661

656662
buf_printf(&buf, "Cyrus TZdist: %s", config_servername);
@@ -1866,8 +1872,7 @@ static int action_get(struct transaction_t *txn)
18661872

18671873
/* Open, mmap, and parse the file */
18681874
buf_reset(&pathbuf);
1869-
buf_printf(&pathbuf, "%s%s/%s.ics",
1870-
config_dir, FNAME_ZONEINFODIR, tzid);
1875+
buf_printf(&pathbuf, "%s/%s.ics", zoneinfo_dir, tzid);
18711876
path = buf_cstring(&pathbuf);
18721877
if ((fd = open(path, O_RDONLY)) == -1) return HTTP_SERVER_ERROR;
18731878

@@ -2075,8 +2080,7 @@ static int action_expand(struct transaction_t *txn)
20752080

20762081
/* Open, mmap, and parse the file */
20772082
buf_reset(&pathbuf);
2078-
buf_printf(&pathbuf, "%s%s/%s.ics",
2079-
config_dir, FNAME_ZONEINFODIR, tzid);
2083+
buf_printf(&pathbuf, "%s/%s.ics", zoneinfo_dir, tzid);
20802084
path = buf_cstring(&pathbuf);
20812085
if ((fd = open(path, O_RDONLY)) == -1) return HTTP_SERVER_ERROR;
20822086

Diff for: imap/zoneinfo_db.h

-3
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,6 @@
4848

4949
#include "annotate.h" /* for strlist functionality */
5050

51-
/* name of the zoneinfo directory */
52-
#define FNAME_ZONEINFODIR "/zoneinfo"
53-
5451
/* name of the NIST leap seconds file (provided with IANA tzdata) */
5552
#define FNAME_LEAPSECFILE "/leap-seconds.list"
5653

Diff for: lib/imapoptions

+7-2
Original file line numberDiff line numberDiff line change
@@ -2881,7 +2881,8 @@ of the incoming network interface, or if no record is found, the
28812881
INBOX, NOT an email address! */
28822882

28832883
{ "zoneinfo_db", "twoskip", STRINGLIST("flat", "skiplist", "twoskip", "zeroskip"), "3.1.6" }
2884-
/* The cyrusdb backend to use for zoneinfo. */
2884+
/* The cyrusdb backend to use for zoneinfo. This database is used by the
2885+
"tzdist" \fIhttp_modules\fR, and is managed by \fBctl_zoneinfo(8)\fR.*/
28852886

28862887
{ "zoneinfo_db_path", NULL, STRING, "2.5.0" }
28872888
/* The absolute path to the zoneinfo db file. If not specified,
@@ -2890,7 +2891,11 @@ of the incoming network interface, or if no record is found, the
28902891
{ "zoneinfo_dir", NULL, STRING, "3.2.0" }
28912892
/* The absolute path to the zoneinfo directory, containing timezone
28922893
definitions as generated by the vzic tool. If not specified, whatever
2893-
definitions libical finds will be used. */
2894+
definitions libical finds will be used.
2895+
.PP
2896+
If you are providing a Time Zone Data Distribution Service (i.e. you have
2897+
"tzdist" listed in \fIhttp_modules\fR), then this configuration option MUST
2898+
be specified. */
28942899

28952900
{ "object_storage_enabled", 0, SWITCH, "3.0.0" }
28962901
/* Is Object storage enabled for this server. You also need to have

0 commit comments

Comments
 (0)