forked from DataSoft/Honeyd
-
Notifications
You must be signed in to change notification settings - Fork 0
/
parse.y
1267 lines (1170 loc) · 27 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
/*
* Copyright (c) 2002, 2003, 2004 Niels Provos <[email protected]>
* All rights reserved.
*
* 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 2 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
* 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 2 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., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
%{
#include <sys/types.h>
#include "config.h"
#ifdef HAVE_SYS_TIME_H
#include <sys/time.h>
#endif
#include <sys/tree.h>
#include <sys/queue.h>
#include <stdio.h>
#include <stdlib.h>
#include <err.h>
#include <stdarg.h>
#include <string.h>
#include <errno.h>
#include <time.h>
#include <pcap.h>
#include <dnet.h>
#include <event.h>
#include "honeyd.h"
#include "personality.h"
#include "router.h"
#include "plugins_config.h"
#include "plugins.h"
#include "template.h"
#include "condition.h"
#include "interface.h"
#include "ethernet.h"
#include "pfvar.h"
#include "dhcpclient.h"
#include "subsystem.h"
#include "util.h"
#ifdef HAVE_PYTHON
#include "pyextend.h"
#endif
int hydlex(void);
int hydparse(void);
int hyderror(char *, ...);
int hydwarn(char *, ...);
int hydprintf(char *, ...);
void *hyd_scan_string(char *);
int hyd_delete_buffer(void *);
#define yylex hydlex
#define yyparse hydparse
#define yy_scan_string hyd_scan_string
#define yy_delete_buffer hyd_delete_buffer
#define yyerror hyderror
#define yywarn hydwarn
#define yyprintf hydprintf
#define yyin hydin
extern int honeyd_verify_config;
pf_osfp_t pfctl_get_fingerprint(const char *);
struct action *honeyd_protocol(struct template *, int);
void port_action_clone(struct action *, struct action *);
static void dhcp_template(struct template *tmpl,
char *interface, char *mac_addr);
static struct evbuffer *buffer = NULL;
int lineno;
char *filename;
int errors = 0;
int curtype = -1; /* Lex sets it to SOCK_STREAM or _DGRAM */
%}
%token CREATE ADD BCAST PORT SRCPORT DSTPORT BIND CLONE DOT FILTERED OPEN CLOSED DEFAULT SET ACTION
%token PERSONALITY RANDOM ANNOTATE NO FINSCAN FRAGMENT DROP OLD NEW COLON
%token PROXY UPTIME DROPRATE IN SYN UID GID ROUTE ENTRY LINK NET UNREACH
%token SLASH LATENCY MS LOSS BANDWIDTH SUBSYSTEM OPTION TO SHARED NETWORK
%token SPOOF FROM TEMPLATE BROADCAST
%token TUNNEL TARPIT DYNAMIC USE IF OTHERWISE EQUAL SOURCE OS IP BETWEEN
%token DELETE LIST ETHERNET DHCP ON MAXFDS RESTART DEBUG
%token DASH TIME INTERNAL
%token <string> STRING
%token <string> CMDSTRING
%token <string> IPSTRING
%token <number> NUMBER
%token <number> PROTO
%token <floatp> FLOAT
%type <addr> ipaddr
%type <addr> ipnet
%type <ai> ipaddrplusport
%type <action> action
%type <tmpl> template
%type <pers> personality
%type <number> finscan;
%type <fragp> fragment;
%type <floatp> rate;
%type <drop> randomearlydrop;
%type <number> latency;
%type <number> bandwidth;
%type <number> packetloss;
%type <number> shared;
%type <number> restart;
%type <number> flags;
%type <condition> condition;
%type <timecondition> timecondition;
%type <time> time;
%union {
char *string;
int number;
struct link_drop drop;
struct addr addr;
struct action action;
struct template *tmpl;
struct personality *pers;
struct addrinfo *ai;
enum fragpolicy fragp;
float floatp;
struct condition condition;
struct tm time;
struct condition_time timecondition;
}
%%
config : /* empty */
| config creation
| config addition
| config newbcast
| config delete
| config subsystem
| config binding
| config set
| config annotate
| config route
| config option
| config ui
;
creation : CREATE STRING
{
if (template_create($2) == NULL)
yyerror("Template \"%s\" exists already", $2);
free($2);
}
| CREATE TEMPLATE
{
if (template_create("template") == NULL)
yyerror("Template \"template\" exists already");
}
| CREATE DEFAULT
{
if (template_create("default") == NULL)
yyerror("Template \"default\" exists already");
}
| DYNAMIC STRING
{
struct template *tmpl;
if ((tmpl = template_create($2)) == NULL)
yyerror("Template \"%s\" exists already", $2);
tmpl->flags |= TEMPLATE_DYNAMIC;
free($2);
}
;
delete : DELETE template
{
if ($2 != NULL)
template_free($2);
}
| DELETE template PROTO PORT NUMBER
{
struct port *port;
if ((port = port_find($2, $3, $5)) == NULL) {
yyerror("Cannot find port %d in \"%s\"",
$5, $2->name);
} else {
port_free($2, port);
}
}
;
newbcast : BCAST template SRCPORT NUMBER DSTPORT NUMBER TIME NUMBER action
{
struct action *action;
if ($2 == NULL) {
yyerror("No template");
break;
}
bcast_insert($2, $4, $6, $8, &$9);
}
;
addition : ADD template PROTO PORT NUMBER action
{
struct action *action;
if ($2 == NULL) {
yyerror("No template");
break;
}
if ((action = honeyd_protocol($2, $3)) == NULL) {
yyerror("Bad protocol");
break;
}
if ($2 != NULL && template_add($2, $3, $5, &$6) == -1)
yyerror("Cannot add port %d to template \"%s\"",
$5, $2 != NULL ? $2->name : "<unknown>");
if ($6.action)
free($6.action);
}
| ADD template USE template IF condition
{
if ($2 == NULL || $4 == NULL)
break;
if (!($2->flags & TEMPLATE_DYNAMIC))
yyerror("Cannot add templates to non-dynamic template \"%s\"", $2->name);
template_insert_dynamic($2, $4, &$6);
}
| ADD template OTHERWISE USE template
{
if ($2 == NULL || $5 == NULL)
break;
if (!($2->flags & TEMPLATE_DYNAMIC))
yyerror("Cannot add templates to non-dynamic template \"%s\"", $2->name);
template_insert_dynamic($2, $5, NULL);
}
;
subsystem : ADD template SUBSYSTEM CMDSTRING shared restart
{
int flags = 0;
if ($5)
flags |= SUBSYSTEM_SHARED;
if ($6)
flags |= SUBSYSTEM_RESTART;
$4[strlen($4) - 1] = '\0';
if ($2 != NULL &&
template_subsystem($2, $4+1, flags) == -1)
yyerror("Can not add subsystem \"%s\" to template \"%s\"",
$4+1, $2 != NULL ? $2->name : "<unknown>");
free($4);
}
;
binding : BIND ipaddr template
{
/* Bind to an IP address and start subsystems */
if ($3 == NULL) {
yyerror("Unknown template");
break;
}
if ($3->ethernet_addr != NULL) {
struct interface *inter;
inter = interface_find_responsible(&$2);
if (inter == NULL ||
inter->if_ent.intf_link_addr.addr_type != ADDR_TYPE_ETH) {
yyerror("Template \"%s\" is configured with "
"ethernet address but there is no "
"interface that can reach %s",
$3->name, addr_ntoa(&$2));
break;
} else {
$3->addrbits = inter->if_addrbits;
}
}
if (template_clone(addr_ntoa(&$2), $3, NULL, 1) == NULL) {
yyerror("Binding to %s failed", addr_ntoa(&$2));
break;
}
}
| BIND condition ipaddr template
{
struct template *tmpl;
/* Special magic */
if ((tmpl = template_find(addr_ntoa(&$3))) != NULL) {
if (!(tmpl->flags & TEMPLATE_DYNAMIC)) {
yyerror("Template \"%s\" already specified as "
"non-dynamic template", addr_ntoa(&$3));
break;
}
} else if ((tmpl = template_create(addr_ntoa(&$3))) == NULL) {
yyerror("Could not create template \"%s\"",
addr_ntoa(&$3));
break;
}
tmpl->flags |= TEMPLATE_DYNAMIC;
/*
* Add this point we do have the right template.
* We just need to add the proper condition.
*/
template_insert_dynamic(tmpl, $4, &$2);
}
| BIND ipaddr TO STRING
{
struct interface *inter;
struct template *tmpl;
/* Bind an IP address to an external interface */
if ((inter = interface_find($4)) == NULL) {
yyerror("Interface \"%s\" does not exist.", $4);
free($4);
break;
}
if (inter->if_ent.intf_link_addr.addr_type != ADDR_TYPE_ETH) {
yyerror("Interface \"%s\" does not support ARP.", $4);
free($4);
break;
}
if ((tmpl = template_create(addr_ntoa(&$2))) == NULL) {
yyerror("Template \"%s\" exists already",
addr_ntoa(&$2));
break;
}
/* Make this template external. */
tmpl->flags |= TEMPLATE_EXTERNAL;
tmpl->inter = inter;
free($4);
}
| DHCP template ON STRING
{
/* Automagically assign DHCP address */
dhcp_template($2, $4, NULL);
free($4);
}
| DHCP template ON STRING ETHERNET CMDSTRING
{
/* Automagically assign DHCP address with MAC address */
$6[strlen($6) - 1] = '\0';
dhcp_template($2, $4, $6 + 1);
free($4);
free($6);
}
| CLONE STRING template
{
/* Just clone. This is not the final destination yet */
if ($3 == NULL || template_clone($2, $3, NULL, 0) == NULL)
yyerror("Cloning to %s failed", $2);
free($2);
}
| SET template SPOOF FROM ipaddr
{
if ($2 == NULL) {
yyerror("No template");
break;
}
$2->spoof.new_src = $5;
}
| SET template SPOOF TO ipaddr
{
if ($2 == NULL) {
yyerror("No template");
break;
}
$2->spoof.new_dst = $5;
}
| SET template SPOOF FROM ipaddr TO ipaddr
{
if ($2 == NULL) {
yyerror("No template");
break;
}
$2->spoof.new_src = $5;
$2->spoof.new_dst = $7;
}
;
set : SET template DEFAULT PROTO ACTION action
{
struct action *action;
if ($2 == NULL) {
yyerror("No template");
break;
}
if ((action = honeyd_protocol($2, $4)) == NULL) {
yyerror("Bad protocol");
break;
}
port_action_clone(action, &$6);
if ($6.action != NULL)
free($6.action);
}
| SET template PERSONALITY personality
{
if ($2 == NULL || $4 == NULL)
break;
$2->person = personality_clone($4);
}
| SET template ETHERNET CMDSTRING
{
extern int need_arp;
if ($2 == NULL || $4 == NULL)
break;
$4[strlen($4) - 1] = '\0';
$2->ethernet_addr = ethernetcode_make_address($4 + 1);
if ($2->ethernet_addr == NULL) {
yyerror("Unknown ethernet vendor \"%s\"", $4 + 1);
}
/*** small patch to make sure the ethernet adress is used ***/
/*** even if none were set in the default template ***/
struct addr addr;
struct in_addr inp;
if(inet_aton($2->name, &inp) != 0)
{
addr_pack(&addr, ADDR_TYPE_IP, IP_ADDR_BITS, &inp.s_addr, IP_ADDR_LEN);
template_post_arp($2, &addr);
}
/*** end patch ***/
free ($4);
need_arp = 1;
}
| SET template UPTIME NUMBER
{
if ($2 == NULL || $4 == 0)
break;
$2->timestamp = $4 * 2;
}
| SET template DROPRATE IN rate
{
if ($2 == NULL)
break;
if ($5 > 100) {
yyerror("Droprate too high: %f", $5);
break;
}
$2->drop_inrate = $5 * 100;
}
| SET template DROPRATE SYN rate
{
if ($2 == NULL)
break;
if ($5 > 100) {
yyerror("Droprate too high: %f", $5);
break;
}
$2->drop_synrate = $5 * 100;
}
| SET template MAXFDS NUMBER
{
if ($2 == NULL)
break;
if ($4 <= 3) {
yyerror("Bad number of max file descriptors %d", $4);
break;
}
$2->max_nofiles = $4;
}
| SET template UID NUMBER
{
if ($2 == NULL)
break;
if (!$4) {
yyerror("Bad uid %d", $4);
break;
}
$2->uid = $4;
honeyd_use_uid($4);
}
| SET template UID NUMBER GID NUMBER
{
if ($2 == NULL)
break;
if (!$4 || !$6) {
yyerror("Bad uid %d, gid %d", $4, $6);
break;
}
$2->uid = $4;
$2->gid = $6;
honeyd_use_uid($4);
honeyd_use_gid($6);
}
;
annotate : ANNOTATE personality finscan
{
if ($2 == NULL)
break;
$2->disallow_finscan = !$3;
}
| ANNOTATE personality fragment
{
if ($2 == NULL)
break;
$2->fragp = $3;
}
;
route : ROUTE ENTRY ipaddr
{
if (router_start(&$3, NULL) == -1)
yyerror("Defining entry point failed: %s",
addr_ntoa(&$3));
}
| ROUTE ENTRY ipaddr NETWORK ipnet
{
if (router_start(&$3, &$5) == -1)
yyerror("Defining entry point failed: %s",
addr_ntoa(&$3));
}
| ROUTE ipaddr ADD NET ipnet ipaddr latency packetloss bandwidth randomearlydrop
{
struct router *r, *newr;
struct addr defroute;
if ((r = router_find(&$2)) == NULL &&
(r = router_new(&$2)) == NULL) {
yyerror("Cannot make forward reference for router %s",
addr_ntoa(&$2));
break;
}
if ((newr = router_find(&$6)) == NULL)
newr = router_new(&$6);
if (router_add_net(r, &$5, newr, $7, $8, $9, &$10) == -1)
yyerror("Could not add route to %s", addr_ntoa(&$5));
if ($9 == 0 && $10.high != 0)
yywarn("Ignoring drop between statement without "
"specified bandwidth.");
addr_pton("0.0.0.0/0", &defroute);
defroute.addr_bits = 0; /* work around libdnet bug */
/* Only insert a reverse route, if the current route is
* not the default route.
*/
if (addr_cmp(&defroute, &$5) != 0 &&
router_add_net(newr, &defroute, r, $7, $8, $9, &$10) == -1)
yyerror("Could not add default route to %s",
addr_ntoa(&$5));
}
| ROUTE ipaddr ADD NET ipnet TUNNEL ipaddr ipaddr
{
struct router *r;
if ((r = router_find(&$2)) == NULL &&
(r = router_new(&$2)) == NULL) {
yyerror("Cannot make forward reference for router %s",
addr_ntoa(&$2));
break;
}
if (router_add_tunnel(r, &$5, &$7, &$8) == -1)
yyerror("Could not add tunnel to %s", addr_ntoa(&$8));
}
| ROUTE ipaddr LINK ipnet
{
struct router *r;
if ((r = router_find(&$2)) == NULL &&
(r = router_new(&$2)) == NULL) {
yyerror("Cannot make forward reference for router %s",
addr_ntoa(&$2));
break;
}
if (router_add_link(r, &$4) == -1)
yyerror("Could not add link %s", addr_ntoa(&$4));
}
| ROUTE ipaddr UNREACH ipnet
{
struct router *r;
if ((r = router_find(&$2)) == NULL &&
(r = router_new(&$2)) == NULL) {
yyerror("Cannot make forward reference for router %s",
addr_ntoa(&$2));
break;
}
if (router_add_unreach(r, &$4) == -1)
yyerror("Could not add unreachable net %s",
addr_ntoa(&$4));
}
;
finscan : FINSCAN { $$ = 1; }
| NO FINSCAN { $$ = 0; }
;
fragment : FRAGMENT DROP { $$ = FRAG_DROP; }
| FRAGMENT OLD { $$ = FRAG_OLD; }
| FRAGMENT NEW { $$ = FRAG_NEW; }
;
ipaddr : IPSTRING
{
if (addr_pton($1, &$$) < 0)
yyerror("Illegal IP address %s", $1);
free($1);
}
| CMDSTRING
{
struct addrinfo ai, *aitop;
memset(&ai, 0, sizeof (ai));
ai.ai_family = AF_INET;
ai.ai_socktype = 0;
ai.ai_flags = 0;
/* Remove quotation marks */
$1[strlen($1) - 1] = '\0';
if (getaddrinfo($1+1, NULL, &ai, &aitop) != 0) {
yyerror("getaddrinfo failed: %s", $1+1);
break;
}
addr_ston(aitop->ai_addr, &$$);
freeaddrinfo(aitop);
free($1);
}
;
ipnet : ipaddr SLASH NUMBER
{
char src[25];
struct addr b;
snprintf(src, sizeof(src), "%s/%d",
addr_ntoa(&$1), $3);
if (addr_pton(src, &$$) < 0)
yyerror("Illegal IP network %s", src);
/* Fix libdnet error */
if ($3 == 0)
$$.addr_bits = 0;
/* Test if this is a legal network */
addr_net(&$$, &b);
b.addr_bits = $$.addr_bits;
if (memcmp(&$$.addr_ip, &b.addr_ip, IP_ADDR_LEN)) {
$$ = b;
yywarn("Bad network mask in %s", src);
}
}
;
ipaddrplusport : ipaddr COLON NUMBER
{
if (curtype == -1) {
yyerror("Bad port type");
break;
}
$$ = cmd_proxy_getinfo(addr_ntoa(&$1), curtype, $3);
curtype = -1;
if ($$ == NULL)
yyerror("Illegal IP address port pair");
}
;
action : flags STRING
{
memset(&$$, 0, sizeof($$));
$$.action = $2;
$$.flags = $1;
$$.status = PORT_OPEN;
}
| flags CMDSTRING
{
memset(&$$, 0, sizeof($$));
$2[strlen($2) - 1] = '\0';
if (($$.action = strdup($2 + 1)) == NULL)
yyerror("Out of memory");
$$.status = PORT_OPEN;
$$.flags = $1;
free($2);
}
| flags INTERNAL CMDSTRING
{
#ifdef HAVE_PYTHON
memset(&$$, 0, sizeof($$));
$3[strlen($3) - 1] = '\0';
if (($$.action_extend = pyextend_load_module($3+1)) == NULL)
yyerror("Bad python module: \"%s\"", $3+1);
$$.status = PORT_PYTHON;
$$.flags = $1;
free($3);
#else
yyerror("Python support is not available.");
#endif
}
| flags PROXY ipaddrplusport
{
memset(&$$, 0, sizeof($$));
$$.status = PORT_PROXY;
$$.action = NULL;
$$.aitop = $3;
$$.flags = $1;
}
| flags PROXY STRING COLON NUMBER
{
memset(&$$, 0, sizeof($$));
$$.status = PORT_PROXY;
$$.action = NULL;
$$.aitop = NULL;
$$.flags = $1;
if ($3[0] != '$') {
if (curtype == -1) {
yyerror("Bad port type");
break;
}
$$.aitop = cmd_proxy_getinfo($3, curtype, $5);
curtype = -1;
if ($$.aitop == NULL)
yyerror("Illegal host name in proxy");
} else {
char proxy[1024];
snprintf(proxy, sizeof(proxy), "%s:%d", $3, $5);
$$.action = strdup(proxy);
if ($$.action == NULL)
yyerror("Out of memory");
}
free($3);
}
| flags PROXY STRING COLON STRING
{
char proxy[1024];
memset(&$$, 0, sizeof($$));
$$.status = PORT_PROXY;
$$.action = NULL;
$$.aitop = NULL;
$$.flags = $1;
snprintf(proxy, sizeof(proxy), "%s:%s", $3, $5);
$$.action = strdup(proxy);
if ($$.action == NULL)
yyerror("Out of memory");
free($3);
free($5);
}
| flags PROXY ipaddr COLON STRING
{
char proxy[1024];
memset(&$$, 0, sizeof($$));
$$.status = PORT_PROXY;
$$.action = NULL;
$$.aitop = NULL;
$$.flags = $1;
snprintf(proxy, sizeof(proxy), "%s:%s", addr_ntoa(&$3), $5);
$$.action = strdup(proxy);
if ($$.action == NULL)
yyerror("Out of memory");
free($5);
}
| FILTERED
{
memset(&$$, 0, sizeof($$));
$$.status = PORT_FILTERED;
$$.action = NULL;
}
| CLOSED
{
memset(&$$, 0, sizeof($$));
$$.status = PORT_CLOSED;
$$.action = NULL;
}
| flags OPEN
{
memset(&$$, 0, sizeof($$));
$$.status = PORT_OPEN;
$$.action = NULL;
$$.flags = $1;
}
;
template : STRING
{
$$ = template_find($1);
if ($$ == NULL)
yyerror("Unknown template \"%s\"", $1);
free($1);
}
| TEMPLATE
{
$$ = template_find("template");
if ($$ == NULL)
yyerror("Unknown template \"%s\"", "template");
}
| DEFAULT
{
$$ = template_find("default");
if ($$ == NULL)
yyerror("Unknown template \"%s\"", "default");
}
| ipaddr
{
$$ = template_find(addr_ntoa(&$1));
if ($$ == NULL)
yyerror("Unknown template \"%s\"", addr_ntoa(&$1));
}
;
personality : CMDSTRING
{
$1[strlen($1) - 1] = '\0';
$$ = personality_find($1+1);
if ($$ == NULL)
yyerror("Unknown personality \"%s\"", $1+1);
free($1);
}
| RANDOM
{
$$ = personality_random();
if ($$ == NULL)
yyerror("Random personality failed");
}
;
rate : FLOAT
{
$$ = $1;
}
| NUMBER
{
$$ = $1;
}
;
latency : /* empty */ { $$ = 0; }
| LATENCY NUMBER MS
{
$$ = $2;
}
;
packetloss : /* empty */ { $$ = 0; }
| LOSS rate
{
$$ = $2 * 100;
}
;
bandwidth : /* empty */ { $$ = 0; }
| BANDWIDTH NUMBER NUMBER
{
$$ = $2 * $3;
}
| BANDWIDTH NUMBER
{
$$ = $2;
}
;
randomearlydrop : /* empty */ { memset(&$$, 0, sizeof($$)); }
| DROP BETWEEN NUMBER MS DASH NUMBER MS
{
if ($6 <= $3)
yyerror("Incorrect thresholds. First number needs to "
"be smaller than second number.");
$$.low = $3;
$$.high = $6;
}
;
option : OPTION STRING STRING NUMBER
{
struct honeyd_plugin_cfg cfg;
memset(&cfg, 0, sizeof(struct honeyd_plugin_cfg));
cfg.cfg_int = $4;
cfg.cfg_type = HD_CONFIG_INT;
plugins_config_item_add($2, $3, &cfg);
free($2); free($3);
}
| OPTION STRING STRING FLOAT
{
struct honeyd_plugin_cfg cfg;
memset(&cfg, 0, sizeof(struct honeyd_plugin_cfg));
cfg.cfg_flt = $4;
cfg.cfg_type = HD_CONFIG_FLT;
plugins_config_item_add($2, $3, &cfg);
free($2); free($3);
}
| OPTION STRING STRING STRING
{
struct honeyd_plugin_cfg cfg;
memset(&cfg, 0, sizeof(struct honeyd_plugin_cfg));
cfg.cfg_str = $4;
cfg.cfg_type = HD_CONFIG_STR;
plugins_config_item_add($2, $3, &cfg);
free($2); free($3); free($4);
}
/* Make file names work */
| OPTION STRING STRING SLASH STRING
{
struct honeyd_plugin_cfg cfg;
char path[MAXPATHLEN];
snprintf(path, sizeof(path), "/%s", $5);
memset(&cfg, 0, sizeof(struct honeyd_plugin_cfg));
cfg.cfg_str = path;
cfg.cfg_type = HD_CONFIG_STR;
plugins_config_item_add($2, $3, &cfg);
free($2); free($3); free($5);
}
;
ui : LIST TEMPLATE
{
template_list_glob(buffer, "*");
}
| LIST TEMPLATE CMDSTRING
{
$3[strlen($3)-1] = '\0';
template_list_glob(buffer, $3+1);
free ($3);
}
| LIST TEMPLATE STRING
{
template_list_glob(buffer, $3);
}
| LIST SUBSYSTEM
{
template_subsystem_list_glob(buffer, "*");
}
| LIST SUBSYSTEM STRING
{
template_subsystem_list_glob(buffer, $3);
}
| LIST SUBSYSTEM CMDSTRING
{
$3[strlen($3)-1] = '\0';
template_subsystem_list_glob(buffer, $3+1);
free($3);
}
| DEBUG STRING NUMBER
{
if (strcasecmp($2, "fd") == 0) {
yyprintf("%d: %d\n", $3, fdshare_inspect($3));
} else if (strcasecmp($2, "trace") == 0) {
struct evbuffer *evbuf = evbuffer_new();
if (evbuf == NULL)
err(1, "%s: malloc");
trace_inspect($3, evbuf);
yyprintf("%s", evbuffer_pullup(evbuf, -1));
evbuffer_free(evbuf);
} else {
yyerror("Unsupported debug command: \"%s\"\n", $2);
}
free($2);
};
shared : /* Empty */
{
$$ = 0;
}
| SHARED
{
$$ = 1;
}
;
restart : /* Empty */
{
$$ = 0;
}
| RESTART
{
$$ = 1;
}
;
flags : /* Empty */
{
$$ = 0;
}
| TARPIT
{