-
Notifications
You must be signed in to change notification settings - Fork 50
/
parse.y
2496 lines (2146 loc) · 46.8 KB
/
parse.y
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
/* $Id$ */
/*
* Copyright (c) 2006 Nicholas Marriott <[email protected]>
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF MIND, USE, DATA OR PROFITS, WHETHER
* IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING
* OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* Declarations */
%{
#include <sys/types.h>
#include <sys/stat.h>
#include <ctype.h>
#include <grp.h>
#include <pwd.h>
#include <string.h>
#include <syslog.h>
#include "fdm.h"
#include "deliver.h"
#include "fetch.h"
#include "match.h"
struct strb *parse_tags;
struct macros parse_macros;
struct macro *parse_last; /* last command-line argument macro */
u_int parse_ruleidx;
u_int parse_actionidx;
ARRAY_DECL(, struct rule *) parse_rulestack;
struct rule *parse_rule;
struct files parse_filestack;
struct file *parse_file;
int yyparse(void);
int
parse_conf(const char *path, struct strings *macros)
{
struct macro *macro;
FILE *f;
u_int i;
if ((f = fopen(path, "r")) == NULL)
return (-1);
ARRAY_INIT(&parse_rulestack);
parse_rule = NULL;
ARRAY_INIT(&parse_filestack);
parse_file = xmalloc(sizeof *parse_file);
parse_file->f = f;
parse_file->line = 0;
parse_file->path = path;
strb_create(&parse_tags);
default_tags(&parse_tags, NULL);
add_tag(&parse_tags, "home", "%s", conf.user_home);
TAILQ_INIT(&parse_macros);
parse_last = NULL;
for (i = 0; i < ARRAY_LENGTH(macros); i++) {
parse_last = extract_macro(ARRAY_ITEM(macros, i));
TAILQ_INSERT_TAIL(&parse_macros, parse_last, entry);
}
parse_file->line++;
yyparse();
if (!ARRAY_EMPTY(&parse_rulestack))
yyerror("missing }");
ARRAY_FREE(&parse_rulestack);
ARRAY_FREE(&parse_filestack);
xfree(parse_file);
while (!TAILQ_EMPTY(&parse_macros)) {
macro = TAILQ_FIRST(&parse_macros);
TAILQ_REMOVE(&parse_macros, macro, entry);
if (macro->type == MACRO_STRING)
xfree(macro->value.str);
xfree(macro);
}
strb_destroy(&parse_tags);
fclose(f);
return (0);
}
__dead printflike1 void
yyerror(const char *fmt, ...)
{
va_list ap;
char *s;
xasprintf(&s,
"%s: %s at line %d", parse_file->path, fmt, parse_file->line);
va_start(ap, fmt);
log_vwrite(LOG_CRIT, s, ap);
va_end(ap);
exit(1);
}
%}
%token TOKACCOUNT
%token TOKACCOUNTS
%token TOKACTION
%token TOKACTIONS
%token TOKADDHEADER
%token TOKADDTOCACHE
%token TOKAGE
%token TOKALL
%token TOKALLOWMANY
%token TOKAND
%token TOKANYNAME
%token TOKANYSIZE
%token TOKANYTYPE
%token TOKAPPEND
%token TOKATTACHMENT
%token TOKBODY
%token TOKBYTES
%token TOKCACHE
%token TOKCASE
%token TOKCMDUSER
%token TOKCOMPRESS
%token TOKCONTINUE
%token TOKCOUNT
%token TOKDAYS
%token TOKDEFUSER
%token TOKDELTOOBIG
%token TOKDISABLED
%token TOKDOMAIN
%token TOKDOTLOCK
%token TOKDROP
%token TOKEQ
%token TOKEXEC
%token TOKEXPIRE
%token TOKFCNTL
%token TOKFILEGROUP
%token TOKFILEUMASK
%token TOKFLOCK
%token TOKFOLDER
%token TOKFOLDERS
%token TOKFROM
%token TOKGIGABYTES
%token TOKGROUP
%token TOKGROUPS
%token TOKHEADER
%token TOKHEADERS
%token TOKHOURS
%token TOKIGNOREERRORS
%token TOKIMAP
%token TOKIMAPS
%token TOKIMPLACT
%token TOKIN
%token TOKINCACHE
%token TOKINSECURE
%token TOKINVALID
%token TOKKEEP
%token TOKKEY
%token TOKKILOBYTES
%token TOKLMTP
%token TOKLOCKFILE
%token TOKLOCKTIMEOUT
%token TOKLOCKTYPES
%token TOKLOCKWAIT
%token TOKLOOKUPORDER
%token TOKMAILDIR
%token TOKMAILDIRS
%token TOKMATCH
%token TOKMATCHED
%token TOKMAXSIZE
%token TOKMBOX
%token TOKMBOXES
%token TOKMEGABYTES
%token TOKMINUTES
%token TOKMONTHS
%token TOKNE
%token TOKNEWONLY
%token TOKNNTP
%token TOKNNTPS
%token TOKNOAPOP
%token TOKNOCRAMMD5
%token TOKNOCREATE
%token TOKNOLOGIN
%token TOKNONE
%token TOKNOPLAIN
%token TOKNORECEIVED
%token TOKNOT
%token TOKNOUIDL
%token TOKNOVERIFY
%token TOKXOAUTH2
%token TOKOAUTHBEARER
%token TOKOLDONLY
%token TOKOR
%token TOKPARALLELACCOUNTS
%token TOKPASS
%token TOKPASSWD
%token TOKPIPE
%token TOKPOP3
%token TOKPOP3S
%token TOKPORT
%token TOKPROXY
%token TOKPURGEAFTER
%token TOKQUEUEHIGH
%token TOKQUEUELOW
%token TOKREMOVEFROMCACHE
%token TOKREMOVEHEADER
%token TOKREMOVEHEADERS
%token TOKRETURNS
%token TOKREWRITE
%token TOKSECONDS
%token TOKSERVER
%token TOKSET
%token TOKSIZE
%token TOKSMTP
%token TOKSTARTTLS
%token TOKSTDIN
%token TOKSTDOUT
%token TOKSTRING
%token TOKSTRIPCHARACTERS
%token TOKTAG
%token TOKTAGGED
%token TOKTIMEOUT
%token TOKTO
%token TOKTOTALSIZE
%token TOKUNMATCHED
%token TOKUSER
%token TOKUSERS
%token TOKVALUE
%token TOKVERIFYCERTS
%token TOKWEEKS
%token TOKWRITE
%token TOKYEARS
%union
{
long long number;
char *string;
int flag;
u_int locks;
struct {
struct fetch *fetch;
void *data;
} fetch;
struct {
char *host;
char *port;
} server;
enum area area;
enum exprop exprop;
struct actitem *actitem;
struct actlist *actlist;
struct expr *expr;
struct expritem *expritem;
struct strings *strings;
struct replstrs *replstrs;
enum fetch_only only;
struct {
char *path;
enum fetch_only only;
} poponly;
struct {
int flags;
char *str;
} re;
gid_t localgid;
enum cmp cmp;
struct rule *rule;
struct {
char *user;
int user_netrc;
char *pass;
int pass_netrc;
} userpass;
userfunction ufn;
struct userfunctions *ufns;
}
%token NONE
%token <number> NUMBER
%token <string> STRING STRMACRO NUMMACRO
%token <string> STRCOMMAND NUMCOMMAND
%type <actitem> actitem
%type <actlist> actlist
%type <area> area
%type <cmp> cmp ltgt eqne
%type <expr> expr exprlist
%type <expritem> expritem
%type <exprop> exprop
%type <fetch> fetchtype
%type <flag> cont not disabled keep execpipe writeappend compress verify
%type <flag> apop poptype imaptype nntptype nocrammd5 noplain nologin uidl
%type <flag> starttls insecure oauthbearer xoauth2
%type <localgid> localgid
%type <locks> lock locklist
%type <number> size time numv retrc expire
%type <only> only imaponly
%type <poponly> poponly
%type <replstrs> replstrslist actions rmheaders accounts users
%type <re> casere retre
%type <rule> perform
%type <server> server
%type <string> port to from xstrv strv replstrv replpathv val optval folder1
%type <string> user
%type <strings> stringslist pathslist maildirs mboxes groups folders folderlist
%type <userpass> userpass userpassreqd userpassnetrc
%type <ufn> ufn
%type <ufns> ufnlist
%%
/* Rules */
cmds: /* empty */
| cmds account
| cmds defaction
| cmds defmacro
| cmds rule
| cmds set
| cmds close
| cmds cache
| cmds NONE
/* Plural/singular combinations. */
actionp: TOKACTION
| TOKACTIONS
userp: TOKUSER
| TOKUSERS
accountp: TOKACCOUNT
| TOKACCOUNTS
groupp: TOKGROUP
| TOKGROUPS
folderp: TOKFOLDER
| TOKFOLDERS
maildirp: TOKMAILDIR
| TOKMAILDIRS
mboxp: TOKMBOX
| TOKMBOXES
rmheaderp: TOKREMOVEHEADER
| TOKREMOVEHEADERS
val: TOKVALUE strv
{
$$ = $2;
}
| strv
{
$$ = $1;
}
optval: TOKVALUE strv
{
$$ = $2;
}
| /* empty */
{
$$ = NULL;
}
xstrv: STRCOMMAND
{
$$ = run_command($1, parse_file->path);
xfree($1);
}
| STRING
{
$$ = $1;
}
| STRMACRO
{
struct macro *macro;
if (strlen($1) > MAXNAMESIZE)
yyerror("macro name too long: %s", $1);
if ((macro = find_macro($1)) == NULL)
yyerror("undefined macro: %s", $1);
if (macro->type != MACRO_STRING)
yyerror("string macro expected: %s", $1);
$$ = xstrdup(macro->value.str);
xfree($1);
}
strv: xstrv
{
$$ = $1;
}
| strv '+' xstrv
{
size_t size;
size = strlen($1) + strlen($3) + 1;
$$ = xrealloc($1, 1, size);
strlcat($$, $3, size);
xfree($3);
}
numv: NUMCOMMAND
{
const char *errstr;
char *s;
s = run_command($1, parse_file->path);
$$ = strtonum(s, 0, LLONG_MAX, &errstr);
if (errstr != NULL)
yyerror("number is %s", errstr);
xfree(s);
xfree($1);
}
| NUMBER
{
$$ = $1;
}
| NUMMACRO
{
struct macro *macro;
if (strlen($1) > MAXNAMESIZE)
yyerror("macro name too long: %s", $1);
if ((macro = find_macro($1)) == NULL)
yyerror("undefined macro: %s", $1);
if (macro->type != MACRO_NUMBER)
yyerror("number macro expected: %s", $1);
$$ = macro->value.num;
xfree($1);
}
replstrv: strv
{
struct replstr rs;
struct userdata *ud;
if ((ud = user_lookup(conf.def_user, conf.user_order)) != NULL)
update_tags(&parse_tags, ud);
rs.str = $1;
$$ = replacestr(&rs, parse_tags, NULL, NULL);
xfree($1);
}
replpathv: strv
{
struct replpath rp;
struct userdata *ud;
if ((ud = user_lookup(conf.def_user, conf.user_order)) != NULL)
update_tags(&parse_tags, ud);
rp.str = $1;
$$ = replacepath(&rp, parse_tags, NULL, NULL, conf.user_home);
xfree($1);
}
size: numv
{
$$ = $1;
}
| numv TOKBYTES
{
$$ = $1;
}
| numv TOKKILOBYTES
{
if ($1 > LLONG_MAX / 1024)
yyerror("size is too big");
$$ = $1 * 1024;
}
| numv TOKMEGABYTES
{
if ($1 > LLONG_MAX / (1024 * 1024))
yyerror("size is too big");
$$ = $1 * (1024 * 1024);
}
| numv TOKGIGABYTES
{
if ($1 > LLONG_MAX / (1024 * 1024 * 1024))
yyerror("size is too big");
$$ = $1 * (1024 * 1024 * 1024);
}
time: numv
{
$$ = $1;
}
| numv TOKHOURS
{
if ($1 > LLONG_MAX / TIME_HOUR)
yyerror("time is too long");
$$ = $1 * TIME_HOUR;
}
| numv TOKMINUTES
{
if ($1 > LLONG_MAX / TIME_MINUTE)
yyerror("time is too long");
$$ = $1 * TIME_MINUTE;
}
| numv TOKSECONDS
{
$$ = $1;
}
| numv TOKDAYS
{
if ($1 > LLONG_MAX / TIME_DAY)
yyerror("time is too long");
$$ = $1 * TIME_DAY;
}
| numv TOKWEEKS
{
if ($1 > LLONG_MAX / TIME_WEEK)
yyerror("time is too long");
$$ = $1 * TIME_WEEK;
}
| numv TOKMONTHS
{
if ($1 > LLONG_MAX / TIME_MONTH)
yyerror("time is too long");
$$ = $1 * TIME_MONTH;
}
| numv TOKYEARS
{
if ($1 > LLONG_MAX / TIME_YEAR)
yyerror("time is too long");
$$ = $1 * TIME_YEAR;
}
expire: TOKEXPIRE time
{
#if UINT64_MAX < LLONG_MAX
if ($2 > UINT64_MAX)
yyerror("time too long");
#endif
$$ = $2;
}
| /* empty */
{
$$ = -1;
}
cache: TOKCACHE replpathv expire
{
struct cache *cache;
TAILQ_FOREACH(cache, &conf.caches, entry) {
if (strcmp(cache->path, $2) == 0)
yyerror("duplicate cache path");
}
cache = xcalloc(1, sizeof *cache);
cache->path = $2;
cache->expire = $3;
TAILQ_INSERT_TAIL(&conf.caches, cache, entry);
log_debug2("added cache \"%s\": expire %lld", cache->path, $3);
}
set: TOKSET TOKMAXSIZE size
{
if ($3 == 0)
yyerror("zero maximum size");
if ($3 > MAXMAILSIZE)
yyerror("maximum size too large: %lld", $3);
conf.max_size = $3;
}
| TOKSET TOKLOCKTYPES locklist
{
if ($3 & LOCK_FCNTL && $3 & LOCK_FLOCK)
yyerror("fcntl and flock locking cannot be used together");
conf.lock_types = $3;
}
| TOKSET TOKLOCKFILE replpathv
{
if (conf.lock_file != NULL)
xfree(conf.lock_file);
conf.lock_file = $3;
}
| TOKSET TOKLOCKWAIT
{
conf.lock_wait = 1;
}
| TOKSET TOKLOCKTIMEOUT time
{
conf.lock_timeout = $3;
}
| TOKSET TOKDELTOOBIG
{
conf.del_big = 1;
}
| TOKSET TOKIGNOREERRORS
{
conf.ignore_errors = 1;
}
| TOKSET TOKALLOWMANY
{
conf.allow_many = 1;
}
| TOKSET TOKDEFUSER strv
{
if (conf.def_user == NULL)
conf.def_user = $3;
}
| TOKSET TOKCMDUSER strv
{
if (conf.cmd_user == NULL)
conf.cmd_user = $3;
}
| TOKSET TOKSTRIPCHARACTERS strv
{
xfree(conf.strip_chars);
conf.strip_chars = $3;
}
| TOKSET TOKTIMEOUT time
{
if ($3 == 0)
yyerror("zero timeout");
if ($3 > INT_MAX / 1000)
yyerror("timeout too long: %lld", $3);
conf.timeout = $3 * 1000;
}
| TOKSET TOKQUEUEHIGH numv
{
if ($3 == 0)
yyerror("zero queue-high");
if ($3 > MAXQUEUEVALUE)
yyerror("queue-high too big: %lld", $3);
if (conf.queue_low != -1 && $3 <= conf.queue_low)
yyerror("queue-high must be larger than queue-low");
conf.queue_high = $3;
}
| TOKSET TOKQUEUELOW numv
{
if ($3 > MAXQUEUEVALUE)
yyerror("queue-low too big: %lld", $3);
if (conf.queue_high == -1)
yyerror("queue-high not specified");
if ($3 >= conf.queue_high)
yyerror("queue-low must be smaller than queue-high");
conf.queue_low = $3;
}
| TOKSET TOKPARALLELACCOUNTS numv
{
if ($3 > INT_MAX)
yyerror("parallel-accounts too big: %lld", $3);
if ($3 == 0)
yyerror("parallel-accounts cannot be zero");
conf.max_accts = $3;
}
| TOKSET TOKPROXY replstrv
{
if (conf.proxy != NULL) {
xfree(conf.proxy->server.host);
xfree(conf.proxy->server.port);
if (conf.proxy->user != NULL)
xfree(conf.proxy->user);
if (conf.proxy->pass != NULL)
xfree(conf.proxy->pass);
}
if ((conf.proxy = getproxy($3)) == NULL)
yyerror("invalid proxy");
xfree($3);
}
| TOKSET TOKVERIFYCERTS
{
conf.verify_certs = 1;
}
| TOKSET TOKIMPLACT TOKKEEP
{
conf.impl_act = DECISION_KEEP;
}
| TOKSET TOKIMPLACT TOKDROP
{
conf.impl_act = DECISION_DROP;
}
| TOKSET TOKPURGEAFTER numv
{
if ($3 == 0)
yyerror("invalid purge-after value: 0");
if ($3 > UINT_MAX)
yyerror("purge-after value too large: %lld", $3);
conf.purge_after = $3;
}
| TOKSET TOKPURGEAFTER TOKNONE
{
conf.purge_after = 0;
}
| TOKSET TOKNORECEIVED
{
conf.no_received = 1;
}
| TOKSET TOKNOCREATE
{
conf.no_create = 1;
}
| TOKSET TOKFILEGROUP TOKUSER
{
conf.file_group = -1;
}
| TOKSET TOKFILEGROUP localgid
{
conf.file_group = $3;
}
| TOKSET TOKFILEUMASK TOKUSER
{
conf.file_umask = umask(0);
umask(conf.file_umask);
}
| TOKSET TOKLOOKUPORDER ufnlist
{
ARRAY_FREEALL(conf.user_order);
conf.user_order = $3;
}
| TOKSET TOKFILEUMASK numv
{
char s[8];
u_int n;
/*
* We can't differentiate umasks in octal from normal numbers
* (requiring a leading zero a la C would be nice, but it would
* potentially break existing configs), so we need to fiddle to
* convert.
*/
memset(s, 0, sizeof s);
xsnprintf(s, sizeof s, "%03lld", $3);
if (s[3] != '\0' || s[0] < '0' || s[0] > '7' ||
s[1] < 0 || s[1] > '7' || s[2] < '0' || s[2] > '7')
yyerror("invalid umask: %s", s);
if (sscanf(s, "%o", &n) != 1)
yyerror("invalid umask: %s", s);
conf.file_umask = n;
}
defmacro: STRMACRO '=' strv
{
struct macro *macro;
if (strlen($1) > MAXNAMESIZE)
yyerror("macro name too long: %s", $1);
macro = xmalloc(sizeof *macro);
strlcpy(macro->name, $1, sizeof macro->name);
macro->type = MACRO_STRING;
macro->value.str = $3;
if (parse_last == NULL)
TAILQ_INSERT_HEAD(&parse_macros, macro, entry);
else {
TAILQ_INSERT_AFTER(
&parse_macros, parse_last, macro, entry);
}
log_debug3("added macro \"%s\": \"%s\"", macro->name,
macro->value.str);
xfree($1);
}
| NUMMACRO '=' numv
{
struct macro *macro;
if (strlen($1) > MAXNAMESIZE)
yyerror("macro name too long: %s", $1);
macro = xmalloc(sizeof *macro);
strlcpy(macro->name, $1, sizeof macro->name);
macro->type = MACRO_NUMBER;
macro->value.num = $3;
if (parse_last == NULL)
TAILQ_INSERT_HEAD(&parse_macros, macro, entry);
else {
TAILQ_INSERT_AFTER(
&parse_macros, parse_last, macro, entry);
}
log_debug3("added macro \"%s\": %lld", macro->name,
macro->value.num);
xfree($1);
}
replstrslist: replstrslist strv
{
if (*$2 == '\0')
yyerror("empty string in list");
$$ = $1;
ARRAY_EXPAND($$, 1);
ARRAY_LAST($$).str = $2;
}
| strv
{
if (*$1 == '\0')
yyerror("empty string in list");
$$ = xmalloc(sizeof *$$);
ARRAY_INIT($$);
ARRAY_EXPAND($$, 1);
ARRAY_LAST($$).str = $1;
}
stringslist: stringslist replstrv
{
if (*$2 == '\0')
yyerror("empty string in list");
$$ = $1;
ARRAY_ADD($$, $2);
}
| replstrv
{
if (*$1 == '\0')
yyerror("empty string in list");
$$ = xmalloc(sizeof *$$);
ARRAY_INIT($$);
ARRAY_ADD($$, $1);
}
pathslist: pathslist replpathv
{
if (*$2 == '\0')
yyerror("invalid path");
$$ = $1;
ARRAY_ADD($$, $2);
}
| replpathv
{
if (*$1 == '\0')
yyerror("invalid path");
$$ = xmalloc(sizeof *$$);
ARRAY_INIT($$);
ARRAY_ADD($$, $1);
}
ufn: TOKPASSWD
{
$$ = &passwd_lookup;
}
ufnlist: ufnlist ufn
{
$$ = $1;
ARRAY_ADD($$, $2);
}
| ufn
{
$$ = xmalloc(sizeof *$$);
ARRAY_INIT($$);
ARRAY_ADD($$, $1);
}
rmheaders: rmheaderp strv
{
if (*$2 == '\0')
yyerror("invalid header");
$$ = xmalloc(sizeof *$$);
ARRAY_INIT($$);
ARRAY_EXPAND($$, 1);
ARRAY_LAST($$).str = $2;
}
| rmheaderp '{' replstrslist '}'
{
$$ = $3;
}
maildirs: maildirp replpathv
{
if (*$2 == '\0')
yyerror("invalid path");
$$ = xmalloc(sizeof *$$);
ARRAY_INIT($$);
ARRAY_ADD($$, $2);
}
| maildirp '{' pathslist '}'
{
$$ = $3;
}
mboxes: mboxp replpathv
{
if (*$2 == '\0')
yyerror("invalid path");
$$ = xmalloc(sizeof *$$);
ARRAY_INIT($$);
ARRAY_ADD($$, $2);
}
| mboxp '{' pathslist '}'
{
$$ = $3;
}
folders: folderp replstrv
{
if (*$2 == '\0')
yyerror("invalid folder");
$$ = xmalloc(sizeof *$$);
ARRAY_INIT($$);
ARRAY_ADD($$, $2);
}
| folderp '{' stringslist '}'
{
$$ = $3;
}
lock: TOKFCNTL
{
$$ = LOCK_FCNTL;
}
| TOKFLOCK
{
$$ = LOCK_FLOCK;
}
| TOKDOTLOCK
{
$$ = LOCK_DOTLOCK;
}
locklist: locklist lock
{
$$ = $1 | $2;
}
| lock
{
$$ = $1;
}
| TOKNONE
{
$$ = 0;
}
localgid: replstrv
{
struct group *gr;
if (*$1 == '\0')
yyerror("invalid group");
gr = getgrnam($1);
if (gr == NULL)
yyerror("unknown group: %s", $1);
$$ = gr->gr_gid;
endgrent();
xfree($1);
}
| numv
{
struct group *gr;
if ($1 > GID_MAX)
yyerror("invalid gid: %llu", $1);
gr = getgrgid($1);
if (gr == NULL)
yyerror("unknown gid: %llu", $1);
$$ = gr->gr_gid;
endgrent();
}
user: /* empty */
{
$$ = NULL;
}
| TOKUSER strv
{
$$ = $2;
}