summaryrefslogtreecommitdiffabout
path: root/src/config.c
blob: 57cdc7a54b85b816752e07ad5c20721441cee197 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
1231
1232
1233
1234
1235
1236
1237
1238
1239
1240
1241
1242
1243
1244
1245
1246
1247
1248
1249
1250
1251
1252
1253
1254
1255
1256
1257
1258
1259
1260
1261
1262
1263
1264
1265
1266
1267
1268
1269
1270
1271
1272
1273
1274
1275
1276
1277
1278
1279
1280
1281
1282
1283
1284
1285
1286
1287
1288
1289
1290
1291
1292
1293
1294
1295
1296
1297
1298
1299
1300
1301
1302
1303
1304
1305
1306
1307
1308
1309
1310
1311
1312
1313
1314
1315
1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
1328
1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
1363
1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
1379
1380
1381
1382
1383
1384
1385
1386
1387
1388
1389
1390
1391
1392
1393
1394
1395
1396
1397
1398
1399
1400
1401
1402
1403
1404
1405
1406
1407
1408
1409
1410
1411
1412
1413
1414
1415
1416
1417
1418
1419
1420
1421
1422
1423
1424
1425
1426
1427
1428
/* wydawca - automatic release submission daemon
   Copyright (C) 2007-2013, 2017 Sergey Poznyakoff

   Wydawca 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.

   Wydawca 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 wydawca. If not, see <http://www.gnu.org/licenses/>. */

#include "wydawca.h"
#include "sql.h"


struct keyword {
	char *name;
	int tok;
};

static int
keyword_to_tok(const char *str, struct keyword *kw, int *pres)
{
	for (; kw->name; kw++)
		if (strcmp(kw->name, str) == 0) {
			*pres = kw->tok;
			return 0;
		}
	return 1;
}

static int
tok_to_keyword(int tok, struct keyword *kw, const char **pres)
{
	for (; kw->name; kw++)
		if (kw->tok == tok) {
			*pres = kw->name;
			return 0;
		}
	return 1;
}

static struct keyword kwfac[] = {
	{ "USER",    LOG_USER },
	{ "DAEMON",  LOG_DAEMON },
	{ "AUTH",    LOG_AUTH },
	{ "AUTHPRIV",LOG_AUTHPRIV },
	{ "MAIL",    LOG_MAIL },
	{ "CRON",    LOG_CRON },
	{ "LOCAL0",  LOG_LOCAL0 },
	{ "LOCAL1",  LOG_LOCAL1 },
	{ "LOCAL2",  LOG_LOCAL2 },
	{ "LOCAL3",  LOG_LOCAL3 },
	{ "LOCAL4",  LOG_LOCAL4 },
	{ "LOCAL5",  LOG_LOCAL5 },
	{ "LOCAL6",  LOG_LOCAL6 },
	{ "LOCAL7",  LOG_LOCAL7 },
	{ NULL }
};

static struct keyword kwpri[] = {
	{ "EMERG", LOG_EMERG },
	{ "ALERT", LOG_ALERT },
	{ "CRIT", LOG_CRIT },
	{ "ERR", LOG_ERR },
	{ "WARNING", LOG_WARNING },
	{ "NOTICE", LOG_NOTICE },
	{ "INFO", LOG_INFO },
	{ "DEBUG", LOG_DEBUG },
	{ NULL }
};

int
wy_strtofac(const char *str)
{
	int res;
	if (keyword_to_tok(str, kwfac, &res))
		return -1;
	return res;
}

int
wy_strtopri(const char *str)
{
	int res;
	if (keyword_to_tok(str, kwpri, &res))
		return -1;
	return res;
}

const char *
wy_pritostr(int pri)
{
	const char *res;
	if (tok_to_keyword(pri, kwpri, &res))
		return NULL;
	return res;
}

const char *
wy_factostr(int fac)
{
	const char *res;
	if (tok_to_keyword(fac, kwfac, &res))
		return NULL;
	return res;
}

static struct archive_descr default_archive_descr = {
	archive_none,
	NULL,
	no_backups
};

static struct dictionary *default_dictionary[dictionary_count];
struct notification *default_notification = NULL;

/* safe_file_name: convert a file name possibly containig relative
   specs (../) into a safer form using only direct descendence.
   Strip trailing delimiter if present, unless it is the only character
   left. E.g.:

	 /home/user/../smith   -->   /home/smith
	 /home/user/../..      -->   /
	 ../file               -->   NULL
*/
char *
safe_file_name(char *file_name)
{
	int len;
	char *p;

	if (!file_name)
		return file_name;

	len = strlen(file_name);

	/* Empty string is returned as is */
	if (len == 0)
		return file_name;

	/* delete trailing delimiter if any */
	if (len && file_name[len - 1] == '/')
		file_name[len - 1] = 0;

	/* Eliminate any ./ and /../ */
	for (p = strchr(file_name, '.'); p; p = strchr(p, '.')) {
		if (p[1] == '/' && (p == file_name || p[-1] == '/')) {
			char *q, *s;

			s = p + 2;
			q = p;
			while ((*q++ = *s++)) ;
			continue;
		} else if (p[1] == '.' && (p[2] == 0 || p[2] == '/')) {
			if (p == file_name)
				return NULL;
			if (p[-1] == '/') {
				/* found */
				char *q, *s;

				s = p + 2;

				/* Find previous delimiter */
				for (q = p - 2; *q != '/' && q >= file_name;
				     q--) ;

				if (q < file_name) {
					q = file_name;
					s++;
				}

				/* Copy stuff */
				p = q;
				while ((*q++ = *s++)) ;
				continue;
			}
		}

		p++;
	}

	if (file_name[0] == 0) {
		file_name[0] = '/';
		file_name[1] = 0;
	}

	return file_name;
}

/* Same as safe_file_name, but returns an allocated copy. */
char *
safe_file_name_alloc(const char *file_name)
{
	char *s = grecs_strdup(file_name);
	char *ns = safe_file_name(s);
	if (!ns)
		free(s);
	return ns;
}

static struct keyword event_tab[] = {
	{ "success",                 wy_ev_success },
	{ "bad-ownership",           wy_ev_bad_ownership },
	{ "bad-directive-signature", wy_ev_bad_directive_signature },
	{ "bad-detached-signature",  wy_ev_bad_detached_signature },
	{ "check-failure",           wy_ev_check_fail },
	{ "statistics",              wy_ev_statistics },
	{NULL}
};

const char *
wy_event_str(enum wy_event evt)
{
	const char *ret;
	if (tok_to_keyword(evt, event_tab, &ret)) {
		grecs_error(NULL, 0,
			    _("INTERNAL ERROR: "
			      "unknown notification event number: %d"),
			    evt);
		return NULL;
	}
	return ret;
}

int
string_to_wy_event(grecs_locus_t *locus, const char *val,
			     enum wy_event *pret)
{
	int res;
	if (keyword_to_tok(val, event_tab, &res)) {
		grecs_error(locus, 0,
			    _("unknown notification event: %s"), val);
		return 1;
	}
	*pret = res;
	return 0;
}


int
wy_assert_string_arg(grecs_locus_t *locus,
		     enum grecs_callback_command cmd,
		     const grecs_value_t *value)
{
	if (cmd != grecs_callback_set_value) {
		grecs_error(locus, 0, _("Unexpected block statement"));
		return 1;
	}
	if (!value || value->type != GRECS_TYPE_STRING) {
		grecs_error(&value->locus, 0,
			    _("expected scalar value as a tag"));
		return 1;
	}
	return 0;
}

grecs_value_t *
get_arg(grecs_value_t *value, unsigned n, int type)
{
	if (!value || value->type != GRECS_TYPE_ARRAY || n >= value->v.arg.c) {
		grecs_error(&value->locus, 0, _("not enough arguments"));
		return NULL;
	}
	value = value->v.arg.v[n];
	if (value->type != type) {
		grecs_error(&value->locus, 0, _("argument %d has wrong type"),
			    n);
		return NULL;
	}
	return value;
}

static int
cb_interval(enum grecs_callback_command cmd, grecs_node_t *node,
	    void *varptr, void *cb_data)
{
	int rc;
	time_t interval;
	const char *endp;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	/* FIXME 1: Support arrays */
	if (wy_assert_string_arg(locus, cmd, value))
		return 1;

	/* FIXME 2: Support ISO intervals? */
	rc = parse_time_interval(value->v.string, &interval, &endp);
	if (rc)
		grecs_error(&value->locus, 0,
			    _("unrecognized interval format (near `%s')"),
			    endp);
	else
		*(time_t *) varptr = interval;
	return 0;
}

static int
cb_absolute_name(enum grecs_callback_command cmd,
		 grecs_node_t *node,
		 void *varptr, void *cb_data)
{
	char *word;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	/* FIXME 1: Support arrays */
	if (wy_assert_string_arg(locus, cmd, value))
		return 1;

	word = safe_file_name((char *)value->v.string);
	if (!word || word[0] != '/')
		grecs_error(&value->locus, 0,
			    _("must be an absolute file name"));
	else
		*(char **)varptr = word;
	return 0;
}

static int
cb_set_umask(enum grecs_callback_command cmd,
	     grecs_node_t *node,
	     void *varptr, void *cb_data)
{
	char *p;
	mode_t m;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	if (wy_assert_string_arg(locus, cmd, value))
		return 1;
	m = strtoul(value->v.string, &p, 8) & 0777;
	if (*p)
		grecs_error(&value->locus, 0, _("invalid umask (near %s)"), p);
	else
		umask(m);
	return 0;
}

static struct keyword stat_tab[] = {
	{ "errors",              STAT_ERRORS },
	{ "warnings",            STAT_WARNINGS },
	{ "bad-signatures",      STAT_BAD_SIGNATURE },
	{ "access-violations",   STAT_ACCESS_VIOLATIONS },
	{ "complete-triplets",   STAT_COMPLETE_TRIPLETS },
	{ "incomplete-triplets", STAT_INCOMPLETE_TRIPLETS },
	{ "bad-triplets",        STAT_BAD_TRIPLETS },
	{ "expired-triplets",    STAT_EXPIRED_TRIPLETS },
	{ "triplet-success",     STAT_TRIPLET_SUCCESS },
	{ "uploads",             STAT_UPLOADS },
	{ "archives",            STAT_ARCHIVES },
	{ "symlinks",            STAT_SYMLINKS },
	{ "rmsymlinks",          STAT_RMSYMLINKS },
	{ NULL },
};

static int
parse_single_statmask(grecs_locus_t *locus, const grecs_value_t *val,
		      unsigned long *pmask, int *invert)
{
	const char *arg;
	int x;

	if (val->type != GRECS_TYPE_STRING) {
		grecs_error(&val->locus, 0,
			    _("expected scalar value but found list"));
		return 1;
	}

	arg = val->v.string;

	if (strcmp(arg, "all") == 0) {
		*pmask = STAT_MASK_ALL;
		*invert = 1;
		return 0;
	} else if (strcmp(arg, "none") == 0) {
		*pmask = STAT_MASK_NONE;
		*invert = 0;
		return 0;
	}

	if (keyword_to_tok(arg, stat_tab, &x)) {
		grecs_error(&val->locus, 0, _("unknown statistics type: %s"),
			    arg);
		return 1;
	}
	*pmask = STAT_MASK(x);
	return 0;
}

static int
parse_statmask(grecs_locus_t *loc, grecs_value_t *val, unsigned long *pmask)
{
	int err = 0;
	int invert = 0;
	unsigned long mask = 0;
	int i;
	struct grecs_list_entry *ep;

	switch (val->type) {
	case GRECS_TYPE_STRING:
		err = parse_single_statmask(loc, val, &mask, &invert);
		break;

	case GRECS_TYPE_ARRAY:
		for (i = 0; i < val->v.arg.c; i++) {
			unsigned long x;
			if (parse_single_statmask(loc, val->v.arg.v[i],
						  &x, &invert))
				err = 1;
			else if (invert)
				mask &= ~x;
			else
				mask |= x;
		}
		break;

	case GRECS_TYPE_LIST:
		for (ep = val->v.list->head; ep; ep = ep->next) {
			const grecs_value_t *vp = ep->data;
			unsigned long x;

			if (parse_single_statmask(loc, vp, &x, &invert))
				err = 1;
			else if (invert)
				mask &= ~x;
			else
				mask |= x;
		}
		break;
	}
	if (!err)
		*pmask = mask;
	return err;
}

int
wy_cb_statistics(enum grecs_callback_command cmd, grecs_node_t *node,
		 void *varptr, void *cb_data)
{
	return parse_statmask(&node->locus, node->v.value, varptr);
}


static int
cb_sql_host(enum grecs_callback_command cmd, grecs_node_t *node,
	    void *varptr, void *cb_data)
{
	struct sqlconn *pconn = varptr;
	char *p;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	if (wy_assert_string_arg(locus, cmd, value))
		return 1;

	p = strchr(value->v.string, ':');
	if (p) {
		/* FIXME: Modifies constant string */
		*p++ = 0;
		if (p[0] == '/') {
			pconn->socket = grecs_strdup(p);
			pconn->host = grecs_strdup("localhost");
		} else {
			char *end;
			unsigned long n = strtoul(p, &end, 10);
			if (*end) {
				grecs_error(&value->locus, 0,
					    _("invalid port number (near %s)"),
					    end);
				return 0;
			}
			if (n == 0 || n > USHRT_MAX) {
				grecs_error(&value->locus, 0,
					    _("port number out of range 1..%d"),
					    USHRT_MAX);
				return 0;
			}
			pconn->port = n;
			/* Save host name */
			pconn->host = grecs_strdup(value->v.string);
		}
	} else
		pconn->host = grecs_strdup(value->v.string);
	return 0;
}

static int
cb_sql(enum grecs_callback_command cmd, grecs_node_t *node,
       void *varptr, void *cb_data)
{
	struct sqlconn *pconn;
	void **pdata = cb_data;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	switch (cmd) {
	case grecs_callback_section_begin:
		if (!value || value->type != GRECS_TYPE_STRING) {
			grecs_error(value ? &value->locus : locus, 0,
				    _("tag must be a string"));
			return 0;
		}
		pconn = grecs_zalloc(sizeof(*pconn));
		pconn->ident = strdup(value->v.string);
		*pdata = pconn;
		break;

	case grecs_callback_section_end:
		pconn = *pdata;
		sql_register_conn(pconn);
		free(pconn);
		*pdata = NULL;
		break;

	case grecs_callback_set_value:
		grecs_error(locus, 0, _("invalid use of block statement"));
	}
	return 0;
}

static struct grecs_keyword sql_kw[] = {
	{ "config-file", N_("file"),
	  N_("Read MySQL configuration from <file>"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct sqlconn, config_file) },
	{ "config-group", N_("name"),
	  N_("Read the named group from the SQL configuration file"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct sqlconn, config_group) },
	{ "host", N_("host"),
	  N_("Set SQL server hostname or IP address"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, 0, cb_sql_host },
	{ "database", N_("dbname"), N_("Set database name"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct sqlconn, database), },
	{ "user", N_("name"), N_("Set SQL user name"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct sqlconn, user) },
	{ "password", N_("arg"), N_("Set SQL user password"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct sqlconn, password) },
	{ "ssl-ca", N_("file"),
	  N_("File name of the Certificate Authority (CA) certificate"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct sqlconn, cacert) },
	{ NULL }
};

static int
cb_syslog_facility(enum grecs_callback_command cmd, grecs_node_t *node,
		   void *varptr, void *cb_data)
{
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;
	int fac;
	
	if (wy_assert_string_arg(locus, cmd, value))
		return 1;

	fac = wy_strtofac(value->v.string);
	if (fac == -1)
		grecs_error(&value->locus, 0,
			    _("Unknown syslog facility `%s'"),
			    value->v.string);
	else
		*(int*)varptr = fac;
	return 0;
}

static struct grecs_keyword syslog_kw[] = {
	{ "facility",
	  N_("name"),
	  N_("Set syslog facility. Arg is one of the following: user, daemon, "
	     "auth, authpriv, mail, cron, local0 through local7 "
	     "(case-insensitive), or a facility number."),
	  grecs_type_string, GRECS_DFLT,
	  &wy_log_facility, 0, cb_syslog_facility },
	{ "tag", N_("string"), N_("Tag syslog messages with this string"),
	  grecs_type_string, GRECS_DFLT,
	  &wy_syslog_tag },
	{ "print-priority", N_("arg"),
	  N_("Prefix each message with its priority"),
	  grecs_type_bool, GRECS_DFLT,
	  &syslog_include_prio },
	{ NULL },
};

static struct keyword backup_tab[] = {
	{ "none",     no_backups },
	{ "off",      no_backups },
	{ "simple",   simple_backups },
	{ "never",    simple_backups },
	{ "existing", numbered_existing_backups },
	{ "nil",      numbered_existing_backups },
	{ "numbered", numbered_backups },
	{ "t",        numbered_backups },
	{ NULL }
};

static enum backup_type
get_backup_version(grecs_locus_t *locus, const char *ctx, const char *version)
{
	int d;

	if (version == 0 || *version == 0)
		return numbered_existing_backups;
	else if (keyword_to_tok(version, backup_tab, &d)) {
		if (ctx)
			grecs_error(locus, 0,
				    _("%s: ambiguous backup type `%s'"), ctx,
				    version);
		else
			grecs_error(locus, 0, _("ambiguous backup type `%s'"),
				    version);
		return no_backups;
	}
	return d;
}

static int
cb_backup(enum grecs_callback_command cmd, grecs_node_t *node,
	  void *varptr, void *cb_data)
{
	enum backup_type *ptype = varptr;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	if (wy_assert_string_arg(locus, cmd, value))
		return 1;
	*ptype = get_backup_version(&value->locus, NULL, value->v.string);
	return 0;
}

static struct grecs_keyword archive_kw[] = {
	{ "name", N_("file-or-dir"),
	  N_("Name of archive file or directory"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct archive_descr, name) },
	{ "backup", N_("type"),
	  N_("Define backup type"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct archive_descr, backup_type),
	  cb_backup },
	{ NULL }
};

static int
cb_archive(enum grecs_callback_command cmd, grecs_node_t *node,
	   void *varptr, void *cb_data)
{
	struct archive_descr *arch = varptr;
	void **pdata = cb_data;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	switch (cmd) {
	case grecs_callback_section_begin:
		*pdata = arch;
		/* fallthrough */
	case grecs_callback_set_value:
		if (!value) {
			grecs_error(locus, 0, _("expected tag"));
			return 1;
		}

		if (value->type != GRECS_TYPE_STRING) {
			grecs_error(&value->locus, 0,
				    _("expected scalar value but found list"));
			return 1;
		}

		if (strcmp(value->v.string, "none") == 0)
			arch->type = archive_none;
		else if (strcmp(value->v.string, "tar") == 0)
			arch->type = archive_tar;
		else if (strcmp(value->v.string, "directory") == 0)
			arch->type = archive_directory;
		else {
			grecs_error(&value->locus, 0,
				    _("unknown archive type"));
			return 1;
		}
		if (cmd == grecs_callback_section_begin)
			return 0;
		break;

	case grecs_callback_section_end:
		break;
	}

	if (arch->type == archive_none)
		return 0;

	if (arch->name == NULL) {
		grecs_error(locus, 0, _("at least archive name must be set"));
		return 1;
	}

	if (arch->type == archive_tar && arch->backup_type != no_backups) {
		grecs_warning(locus, 0,
			      _("backup type ignored for this archive type"));
		return 1;
	}

	return 0;
}

static int
cb_event(enum grecs_callback_command cmd, grecs_node_t *node,
	 void *varptr, void *cb_data)
{
	enum wy_event *pev = varptr;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	if (wy_assert_string_arg(locus, cmd, value))
		return 1;
	string_to_wy_event(&value->locus, value->v.string, pev);
	return 0;
}

static int
cb_statistics(enum grecs_callback_command cmd, grecs_node_t *node,
	      void *varptr, void *cb_data)
{
	return parse_statmask(&node->locus, node->v.value, varptr);
}

static struct grecs_keyword notify_event_kw[] = {
	{ "event", N_("ev-id"),
	  N_("Event on which to notify"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct notification, ev), cb_event },
	{ "module", N_("name"),
	  N_("Name of the module to invoke on event"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct notification, modname) },
	{ "module-config", NULL,
	  N_("Module-specific configuration data"),
	  grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL, NULL },
	{ "statistics", N_("items"),
	  N_("Send mail if one or more of these items are set"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct notification, statmask), cb_statistics },

	{ NULL }
};

static int
cb_notify_event(enum grecs_callback_command cmd, grecs_node_t *node,
		void *varptr, void *cb_data)
{
	struct notification *ntf;
	void **pdata = cb_data;
	grecs_locus_t *locus = &node->locus;

	switch (cmd) {
	case grecs_callback_section_begin:
		ntf = grecs_zalloc(sizeof(*ntf));
		ntf->modnode = grecs_find_node(node->down, "module-config");
		*pdata = ntf;
		break;

	case grecs_callback_section_end:
		ntf = *pdata;
		if (!ntf->modname)
			grecs_error(locus, 0, _("missing module name"));
		else {
			/* FIXME: Check if the module is defined. Better yer,
			   delay this check until config_finish */
			struct notification **p =
				(struct notification **)varptr;
			ntf->next = *p;
			*p = ntf;
			/* FIXME: check ev and tgt? */
		}
		break;

	case grecs_callback_set_value:
		grecs_error(locus, 0, _("invalid use of block statement"));
	}
	return 0;
}

static enum dictionary_type
string_to_dictionary_type(const char *str)
{
	if (strcmp(str, "sql") == 0)
		return dictionary_sql;
	else if (strcmp(str, "builtin") == 0)
		return dictionary_builtin;
	else if (strcmp(str, "external") == 0)
		return dictionary_external;
	else
		return dictionary_none;
}

static int
cb_dictionary_type(enum grecs_callback_command cmd, grecs_node_t *node,
		   void *varptr, void *cb_data)
{
	enum dictionary_type *ptype = varptr;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	if (wy_assert_string_arg(locus, cmd, value))
		return 1;
	*ptype = string_to_dictionary_type(value->v.string);
	if (*ptype == dictionary_none)
		grecs_error(&value->locus, 0,
			    _("unknown dictionary type: %s"), value->v.string);
	return 0;
}

static int
cb_dictionary_params(enum grecs_callback_command cmd, grecs_node_t *node,
		     void *varptr, void *cb_data)
{
	struct dictionary *meth = varptr;
	size_t size;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	if (cmd != grecs_callback_set_value) {
		grecs_error(locus, 0, _("Unexpected block statement"));
		return 1;
	}
	if (!value || value->type != GRECS_TYPE_LIST) {
		grecs_error(value ? &value->locus : locus, 0,
			    _("expected list value"));
		return 1;
	}

	size = grecs_list_size(value->v.list);
	if (size == 0) {
		meth->parmc = 0;
		meth->parmv = NULL;
	} else {
		int i;
		struct grecs_list_entry *ep;

		meth->parmc = size;
		meth->parmv = grecs_calloc(size + 1, sizeof(meth->parmv[0]));

		for (i = 0, ep = value->v.list->head; ep; ep = ep->next, i++) {
			const grecs_value_t *vp = ep->data;

			if (wy_assert_string_arg(locus, cmd, vp))
				break;

			meth->parmv[i] = grecs_strdup(vp->v.string);
		}
		meth->parmv[i] = NULL;
	}
	return 0;
}

static struct grecs_keyword dictionary_kw[] = {
	{ "type", N_("type"),
	  N_("Dictionary type"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct dictionary, type),
	  cb_dictionary_type },
	{ "query", N_("string"), N_("Query template"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct dictionary, query) },
	{ "params", N_("arg"), N_("Set dictionary parameters"),
	  grecs_type_string, GRECS_LIST,
	  NULL, 0, cb_dictionary_params },
	{ NULL }
};

int
string_to_dictionary_id(grecs_locus_t *locus,
			const char *str, enum dictionary_id *idp)
{
	static struct keyword id_tab[] = {
		{"project-uploader", project_uploader_dict},
		{"project-owner", project_owner_dict},
		{NULL}
	};
	int res;

	if (keyword_to_tok(str, id_tab, &res)) {
		grecs_error(locus, 0, _("unknown dictionary ID: %s"), str);
		return 1;
	}
	*idp = res;
	return 0;
}

static int
cb_dictionary(enum grecs_callback_command cmd, grecs_node_t *node,
	      void *varptr, void *cb_data)
{
	struct dictionary **pmeth, *meth;
	void **pdata = cb_data;
	enum dictionary_id id;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	switch (cmd) {
	case grecs_callback_section_begin:
		if (!value || value->type != GRECS_TYPE_STRING) {
			grecs_error(value ? &value->locus : locus, 0,
				    _("tag must be a string"));
			return 0;
		}
		if (string_to_dictionary_id(&value->locus,
					    value->v.string, &id))
			return 1;
		pmeth = (struct dictionary **)varptr + id;
		*pmeth = dictionary_new(id, dictionary_builtin);
		*pdata = *pmeth;
		break;

	case grecs_callback_section_end:
		meth = *pdata;
		switch (meth->type) {
		case dictionary_sql:
			if (meth->parmc == 0 || !meth->parmv[0]) {
				grecs_error(locus, 0,
					    _("SQL connection is not "
					      "declared"));
				meth->type = dictionary_none;
			} else if (!sql_connection_exists_p(meth->parmv[0])) {
				grecs_error(locus, 0,
					    _("SQL connection `%s' "
					      "not declared"),
					    meth->parmv[0]);
				meth->type = dictionary_none;
			}
			break;

		default:
			/* FIXME: More checks ? */
			break;
		}
		*pdata = NULL;
		break;

	case grecs_callback_set_value:
		grecs_error(locus, 0, _("invalid use of block statement"));
	}
	return 0;
}

static int
cb_url(enum grecs_callback_command cmd, grecs_node_t *node,
       void *varptr, void *cb_data)
{
	wy_url_t *purl = varptr, url;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	if (wy_assert_string_arg(locus, cmd, value))
		return 1;
	url = wy_url_create(value->v.string);
	if (!url) {
		grecs_error(&value->locus, 0, _("cannot create URL `%s': %s"),
			    value->v.string, strerror(errno));
		return 1;
	}
	*purl = url;
	return 0;
}

static struct grecs_keyword spool_kw[] = {
	{ "url", N_("arg"), N_("URL corresponding to this spool"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct spool, url) },
	{ "alias", N_("arg"), N_("Aliases"),
	  grecs_type_string, GRECS_LIST,
	  NULL, offsetof(struct spool, aliases) },
	{ "source", N_("dir"), N_("Source directory"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct spool, source_dir) },
	{ "destination", N_("dir"), N_("Destination directory"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct spool, dest_url),
	  cb_url },
	{ "file-sweep-time", N_("interval"), N_("Define file sweep time"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct spool, file_sweep_time),
	  cb_interval },
	{ "inotify", NULL, N_("Enable or disable inotify for this spool"),
	  grecs_type_bool, GRECS_DFLT,
	  NULL, offsetof(struct spool, inotify_enable), },

	{ "dictionary", N_("ident"), N_("Define data dictionary"),
	  grecs_type_section, GRECS_DFLT,
	  NULL, offsetof(struct spool, dictionary),
	  cb_dictionary, NULL, dictionary_kw },
	{ "archive", N_("type: string"), N_("Set up archivation"),
	  grecs_type_section, GRECS_DFLT,
	  NULL, offsetof(struct spool, archive),
	  cb_archive, NULL, archive_kw },
	{ "notify-event", NULL, N_("Configure notification"),
	  grecs_type_section, GRECS_MULT,
	  NULL, offsetof(struct spool, notification),
	  cb_notify_event, NULL, notify_event_kw },
	{ "check-script", NULL, N_("A /bin/sh script to verify the tarball"),
	  grecs_type_string, GRECS_DFLT,
	  NULL, offsetof(struct spool, check_script) },
	{ NULL }
};

static int
cb_spool(enum grecs_callback_command cmd, grecs_node_t *node,
	 void *varptr, void *cb_data)
{
	struct spool *spool;
	void **pdata = cb_data;
	int rc, ec, i;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	switch (cmd) {
	case grecs_callback_section_begin:
		if (!value || value->type != GRECS_TYPE_STRING) {
			grecs_error(value ? &value->locus : locus, 0,
				    _("tag must be a string"));
			return 1;
		}
		spool = grecs_zalloc(sizeof(*spool));
		spool->tag = grecs_strdup(value->v.string);
		spool->file_sweep_time = file_sweep_time;
		spool->inotify_enable = 1;
		for (i = 0; i < NITEMS(spool->dictionary); i++)
			spool->dictionary[i] = default_dictionary[i];
		spool->archive = default_archive_descr;
		*pdata = spool;
		break;

	case grecs_callback_section_end:
		rc = 0;
		spool = *pdata;
		if (!spool->source_dir) {
			grecs_error(locus, 0, _("source is not given"));
			rc = 1;
		} else if (test_dir(spool->source_dir, &ec)) {
			if (ec)
				grecs_error(locus, ec, _("cannot access %s"),
					    spool->source_dir);
			else
				grecs_error(locus, 0,
					    _("%s is not a directory"),
					    spool->source_dir);
			rc = 1;
		}

		if (!spool->dest_url) {
			grecs_error(locus, 0, _("destination is not given"));
			rc = 1;
		} else if (url_to_vtab(spool->dest_url, &spool->vtab)) {
			grecs_error(locus, 0, _("unsupported url: %s"),
				    wy_url_printable(spool->dest_url));
			rc = 1;
		} else if (spool->vtab.test_url
			   && spool->vtab.test_url(spool->dest_url, locus))
			rc = 1;

		for (i = 0; i < dictionary_count; i++)
			if (spool->dictionary[i]->type ==
			    dictionary_external) {
				grecs_error(locus, 0,
					    _("Sorry, the dictionary type "
					      "`external' is not yet "
					      "supported"));
				rc = 1;
			}

		if (rc)
			return rc;

		if (!spool->notification)
			spool->notification = default_notification;
		spool->dest_dir = wy_url_printable(spool->dest_url);
		register_spool(spool);
		free(spool);
		*pdata = NULL;
		break;

	case grecs_callback_set_value:
		grecs_error(locus, 0, _("invalid use of block statement"));
	}
	return 0;
}

static int
cb_user(enum grecs_callback_command cmd, grecs_node_t *node,
	void *varptr, void *cb_data)
{
	struct passwd *pw;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	if (wy_assert_string_arg(locus, cmd, value))
		return 1;

	pw = getpwnam(value->v.string);
	if (!pw) {
		grecs_error(&value->locus, 0,
			    _("no such user: %s"), value->v.string);
		return 1;
	}

	wydawca_uid = pw->pw_uid;
	wydawca_gid = pw->pw_gid;
	return 0;
}

static int
cb_supp_groups(enum grecs_callback_command cmd, grecs_node_t *node,
	       void *varptr, void *cb_data)
{
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;
	
	if (cmd != grecs_callback_set_value) {
		grecs_error(locus, 0, _("Unexpected block statement"));
		return 1;
	}
	if (!value || value->type != GRECS_TYPE_LIST) {
		grecs_error(value ? &value->locus : locus, 0,
			    _("expected list value"));
		return 1;
	}

	wydawca_supp_groupc = grecs_list_size(value->v.list);
	if (wydawca_supp_groupc == 0)
		wydawca_supp_groups = NULL;
	else {
		int i;
		struct grecs_list_entry *ep;

		wydawca_supp_groups =
			grecs_calloc(wydawca_supp_groupc,
				     sizeof(wydawca_supp_groups[0]));

		for (i = 0, ep = value->v.list->head; ep; ep = ep->next, i++) {
			const grecs_value_t *vp = ep->data;
			struct group *grp;

			if (wy_assert_string_arg(locus, cmd, vp))
				break;
			grp = getgrnam(vp->v.string);
			if (!grp) {
				grecs_error(&value->locus, 0,
					    _("no such group: %s"),
					    value->v.string);
				break;
			}
			wydawca_supp_groups[i] = grp->gr_gid;
		}
	}
	return 0;
}

static struct grecs_keyword locking_kw[] = {
	{ "enable", NULL, N_("Enable or disable locking"),
	  grecs_type_bool, GRECS_DFLT, &enable_locking },
	{ "directory", N_("dir"), N_("Set directory for lock files"),
	  grecs_type_string, GRECS_DFLT, &lockdir },
	{ "expire-time", N_("interval"), N_("Define lock expiration interval"),
	  grecs_type_string, GRECS_DFLT, &lock_expire_time, 0, cb_interval },
	{ "timeout", N_("interval"), N_("Locking timeout"),
	  grecs_type_string, GRECS_DFLT, &lock_timeout, 0, cb_interval },
	{ NULL }
};

static int
cb_locking(enum grecs_callback_command cmd, grecs_node_t *node,
	   void *varptr, void *cb_data)
{
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	if (cmd == grecs_callback_set_value) {
		if (!value || value->type != GRECS_TYPE_STRING) {
			grecs_error(value ? &value->locus : locus, 0,
				    _("expected scalar value as a tag"));
			return 1;
		}
		grecs_string_convert(&enable_locking, grecs_type_bool,
				     value->v.string, locus);
	}
	return 0;
}

static int
cb_load_path(enum grecs_callback_command cmd, grecs_node_t *node,
	     void *varptr, void *cb_data)
{
	struct grecs_list **lpp = varptr, *lp;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	if (*lpp)
		lp = *lpp;
	else {
		lp = _grecs_simple_list_create(1);
		*lpp = lp;
	}
	switch (value->type) {
	case GRECS_TYPE_STRING:
		grecs_list_append(lp, grecs_strdup(value->v.string));
		break;

	case GRECS_TYPE_LIST: {
		struct grecs_list_entry *ep;

		for (ep = value->v.list->head; ep; ep = ep->next) {
			const grecs_value_t *vp = ep->data;

			if (vp->type != GRECS_TYPE_STRING) {
				grecs_error(&vp->locus, 0,
					    _("list element must be a string"));
				return 1;
			}
			grecs_list_append(lp, grecs_strdup(vp->v.string));
		}
		break;
	}

	case GRECS_TYPE_ARRAY:
		grecs_error(locus, 0, _("too many arguments"));
		return 1;
	}
	return 0;
}

static int
cb_upload_version(enum grecs_callback_command cmd, grecs_node_t *node,
		  void *varptr, void *cb_data)
{
	unsigned *pversion = varptr, n;
	grecs_locus_t *locus = &node->locus;
	grecs_value_t *value = node->v.value;

	if (wy_assert_string_arg(locus, cmd, value))
		return 1;

	if (directive_pack_version(value->v.string, &n)) {
		grecs_error(&value->locus, 0, _("invalid version number"));
		return 0;
	}

	if (n < MIN_DIRECTIVE_VERSION) {
		grecs_error(&value->locus, 0, _("version number too low"));
		return 0;
	}

	if (n > MAX_DIRECTIVE_VERSION) {
		grecs_error(&value->locus, 0, _("version number too high"));
		return 0;
	}
	*pversion = n;
	return 0;
}

static struct grecs_keyword wydawca_kw[] = {
	{ "daemon", NULL, N_("Enable daemon mode"),
	  grecs_type_bool, GRECS_DFLT, &daemon_mode },
	{ "foreground", NULL, N_("Start in foreground even in daemon mode"),
	  grecs_type_bool, GRECS_DFLT, &foreground },
	{ "single-process", NULL, N_("Do not spawn subprocesses"),
	  grecs_type_bool, GRECS_DFLT, &single_process },
	{ "wakeup-interval", N_("time"), N_("Set wake-up interval"),
	  grecs_type_string, GRECS_DFLT, &wakeup_interval, 0, cb_interval },
	{ "pidfile", N_("file"), N_("Set pid file name"),
	  grecs_type_string, GRECS_DFLT, &pidfile },

	{ "module-prepend-load-path", N_("path"),
	  N_("List of directories searched for modules prior to "
	     "the default module directory"),
	  grecs_type_string, GRECS_LIST|GRECS_AGGR,
	  &module_prepend_load_path, 0, cb_load_path },
	{ "module-load-path", N_("path"),
	  N_("List of directories searched for database modules."),
	  grecs_type_string, GRECS_LIST|GRECS_AGGR,
	  &module_load_path, 0, cb_load_path },
	
	{ "module", N_("name: string> <path: string"),
	  N_("Load the specified module"),
	  grecs_type_string, GRECS_MULT, NULL, 0, cb_module },
	{ "module-init", N_("modname"),
	  N_("Module-specific initialization data"),
	  grecs_type_section, GRECS_INAC, NULL, 0, NULL, NULL, NULL },

	{ "inotify", NULL, N_("Enable or disable inotify support"),
	  grecs_type_bool, GRECS_DFLT, &inotify_enable },

	{ "user", N_("name"), N_("Run with UID and GID of this user"),
	  grecs_type_string, GRECS_DFLT, NULL, 0, cb_user },
	{ "group", NULL, N_("Retain these supplementary groups"),
	  grecs_type_string, GRECS_LIST, NULL, 0, cb_supp_groups },

	{ "min-version", N_("major.minor"),
	  N_("Set minimal allowed directive file version"),
	  grecs_type_string, GRECS_DFLT,
	  &min_directive_version, 0, cb_upload_version },
	{ "max-version", N_("major.minor"),
	  N_("Set maximal allowed directive file version"),
	  grecs_type_string, GRECS_DFLT,
	  &max_directive_version, 0, cb_upload_version },

	{ "locking", NULL, N_("Configure locking"),
	  grecs_type_section, GRECS_DFLT, NULL, 0,
	  cb_locking, NULL, locking_kw },

	{ "listen", N_("socket"), N_("Listen on this address"),
	  grecs_type_sockaddr, GRECS_DFLT, &listen_sockaddr, },

#ifdef WITH_LIBWRAP
	{ "tcp-wrapper", NULL, N_("Configure TCP wrappers"),
	  grecs_type_section, GRECS_DFLT, NULL, 0,
	  NULL, NULL, tcpwrapper_kw },
#endif

	/* FIXME: Must be a built-in type? */
	{ "file-sweep-time", N_("interval"), N_("Define file sweep time"),
	  grecs_type_string, GRECS_DFLT, &file_sweep_time, 0, cb_interval },
	{ "tar-program", N_("prog"), N_("Set tar invocation command line"),
	  grecs_type_string, GRECS_DFLT, &tar_command_name, 0,
	  cb_absolute_name },

	{ "umask", N_("mask: octal"), N_("Set umask"),
	  grecs_type_string, GRECS_DFLT, NULL, 0, cb_set_umask },

	{ "archive-signatures", NULL,
	  N_("Control implicit signature archivation"),
	  grecs_type_bool, GRECS_DFLT, &archive_signatures },

        { "statistics", N_("items"), N_("Print these stats at the end of run"),
	  grecs_type_string, GRECS_DFLT, &print_stats, 0, wy_cb_statistics },
	
	{ "sql", N_("id: string"), N_("Define SQL database"),
	  grecs_type_section, GRECS_DFLT, NULL, 0, cb_sql, NULL, sql_kw },

	{ "syslog", NULL, N_("Configure syslog logging"),
	  grecs_type_section, GRECS_DFLT, NULL, 0, NULL, NULL, syslog_kw },

	{ "archive", N_("type: string"), N_("Set up archivation"),
	  grecs_type_section, GRECS_DFLT, &default_archive_descr, 0,
	  cb_archive, NULL, archive_kw },

	{ "notify-event", NULL, N_("Configure notification"),
	  grecs_type_section, GRECS_DFLT, &default_notification, 0,
	  cb_notify_event, NULL, notify_event_kw },

	{ "dictionary", N_("ident"), N_("Define data dictionary"),
	  grecs_type_section, GRECS_DFLT, default_dictionary, 0,
	  cb_dictionary, NULL, dictionary_kw },

	{ "check-script", NULL, N_("A /bin/sh script to verify tarballs"),
	  grecs_type_string, GRECS_DFLT, &default_check_script },

	{ "spool", N_("tag: string"), N_("Define distribution spool"),
	  grecs_type_section, GRECS_DFLT, NULL, 0,
	  cb_spool, NULL, spool_kw },

	{ "all-spools", NULL,
	  N_("Service names that request scanning all spools"),
	  grecs_type_string, GRECS_LIST, &all_spool_aliases },

	{ "gpg-homedir", NULL, N_("GPG home directory"),
	  grecs_type_string, GRECS_DFLT, &wy_gpg_homedir },

	{NULL}
};

void
config_help()
{
	static char docstring[] =
	    N_("Configuration file structure for wydawca.\n"
	       "For more information, use `info wydawca configuration'.");
	grecs_print_docstring(docstring, 0, stdout);
	grecs_print_statement_array(wydawca_kw, 1, 0, stdout);
}

void
config_init()
{
	int i;
	struct servent *serv;

	grecs_include_path_setup(DEFAULT_VERSION_INCLUDE_DIR,
				 DEFAULT_INCLUDE_DIR, NULL);
	grecs_preprocessor = DEFAULT_PREPROCESSOR;
	grecs_log_to_stderr = 1;

	serv = getservbyname(PACKAGE, "tcp");
	if (serv != NULL)
		grecs_default_port = serv->s_port;

	for (i = 0; i < dictionary_count; i++)
		default_dictionary[i] = dictionary_new(i, dictionary_builtin);
}

void
config_finish(struct grecs_node *tree)
{
	struct grecs_node *p;

	if (grecs_tree_process(tree, wydawca_kw))
		exit(EX_CONFIG);
	for (p = tree->down; p; p = p->next) {
		if (strcmp(p->ident, "module-init") == 0) {
			if (wy_assert_string_arg(&p->v.value->locus,
						 grecs_callback_set_value,
						 p->v.value))
				continue;
			if (module_set_init(p->v.value->v.string, p))
				grecs_error(&p->v.value->locus, 0,
					    _("unknown module"));
		}
	}		
}

Return to:

Send suggestions and report system problems to the System administrator.