~ubuntu-branches/ubuntu/wily/maradns/wily-proposed

« back to all changes in this revision

Viewing changes to .pc/config_pollution.patch/deadwood-3.2.07/src/DwMararc.h

  • Committer: Package Import Robot
  • Author(s): Dariusz Dwornikowski, Tomasz Buchert, Dariusz Dwornikowski
  • Date: 2015-03-27 18:34:08 UTC
  • mfrom: (1.2.12)
  • Revision ID: package-import@ubuntu.com-20150327183408-wnfachdkdjt96yu6
Tags: 2.0.11-1
[ Tomasz Buchert ]
* Imported Upstream version 2.0.11

[ Dariusz Dwornikowski ]
* d/patches: 
  - refreshed all patches for new deadwood version
  - removed generating of random prime on build (Closes: #785536) 
* d/rules: date taken from changelog (Closes: #785535)

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* Copyright (c) 2007-2014 Sam Trenholme
 
2
 *
 
3
 * TERMS
 
4
 *
 
5
 * Redistribution and use in source and binary forms, with or without
 
6
 * modification, are permitted provided that the following conditions
 
7
 * are met:
 
8
 *
 
9
 * 1. Redistributions of source code must retain the above copyright
 
10
 *    notice, this list of conditions and the following disclaimer.
 
11
 * 2. Redistributions in binary form must reproduce the above copyright
 
12
 *    notice, this list of conditions and the following disclaimer in the
 
13
 *    documentation and/or other materials provided with the distribution.
 
14
 *
 
15
 * This software is provided 'as is' with no guarantees of correctness or
 
16
 * fitness for purpose.
 
17
 */
 
18
 
 
19
#ifndef __MARARC_H_DEFINED__
 
20
#define __MARARC_H_DEFINED__
 
21
 
 
22
#include "DwStr.h"
 
23
#include "DwDict.h"
 
24
 
 
25
/* Some constants pointing to mararc parameters */
 
26
 
 
27
/* mararc string parameters */
 
28
#define DWM_S_bind_address 0
 
29
#define DWM_S_ipv4_bind_addresses 1
 
30
#define DWM_S_chroot_dir 2
 
31
#define DWM_S_recursive_acl 3
 
32
#define DWM_S_random_seed_file 4
 
33
#define DWM_S_cache_file 5
 
34
#define DWM_S_ip_blacklist 6
 
35
 
 
36
/* mararc dictionary parameters */
 
37
#define DWM_D_upstream_servers 0
 
38
#define DWM_D_root_servers 1
 
39
 
 
40
/* mararc numeric parameters */
 
41
#define DWM_N_maxprocs 0
 
42
#define DWM_N_timeout_seconds 1
 
43
#define DWM_N_dns_port 2
 
44
#define DWM_N_upstream_port 3
 
45
#define DWM_N_handle_overload 4
 
46
#define DWM_N_handle_noreply 5
 
47
#define DWM_N_recurse_min_bind_port 6
 
48
#define DWM_N_recurse_number_ports 7
 
49
#define DWM_N_hash_magic_number 8
 
50
#define DWM_N_maximum_cache_elements 9
 
51
#define DWM_N_maradns_uid 10
 
52
#define DWM_N_maradns_gid 11
 
53
#define DWM_N_resurrections 12
 
54
#define DWM_N_num_retries 13
 
55
#define DWM_N_verbose_level 14
 
56
#define DWM_N_max_tcp_procs 15
 
57
#define DWM_N_timeout_seconds_tcp 16
 
58
#define DWM_N_tcp_listen 17
 
59
#define DWM_N_max_ar_chain 18
 
60
#define DWM_N_ttl_age 19
 
61
#define DWM_N_max_inflights 20
 
62
#define DWM_N_deliver_all 21
 
63
#define DWM_N_filter_rfc1918 22
 
64
#define DWM_N_ns_glueless_type 23
 
65
#define DWM_N_reject_aaaa 24
 
66
#define DWM_N_reject_mx 25
 
67
#define DWM_N_truncation_hack 26
 
68
#define DWM_N_reject_ptr 27
 
69
#define DWM_N_min_ttl_incomplete_cname 28
 
70
#define DWM_N_max_ttl 29
 
71
 
 
72
/* Number of string parameters in the mararc file */
 
73
#define KEY_S_COUNT 7
 
74
/* Number of dictionary parameters in the mararc file */
 
75
#define KEY_D_COUNT 2
 
76
/* Number of numeric parameters in the mararc file */
 
77
#define KEY_N_COUNT 30
 
78
 
 
79
#ifndef MINGW
 
80
/* Location of files we read when we run execfile("foo") */
 
81
#define EXECFILE_DIR "/etc/deadwood/execfile/"
 
82
#endif /* MINGW */
 
83
 
 
84
#ifdef MARARC_C
 
85
dw_str *key_s[KEY_S_COUNT + 1]; /* All of the string dwood2rc parameters */
 
86
dwd_dict *key_d[KEY_D_COUNT + 1]; /* The dictionary dwood2rc parameters */
 
87
int32_t key_n[KEY_N_COUNT + 1]; /* The numeric dwood2rc parameters */
 
88
 
 
89
char *key_s_names[KEY_S_COUNT + 1] = {
 
90
        "bind_address", /* IP addresses to bind to */
 
91
        "ipv4_bind_addresses", /* IP Addresses to bind to (newer name) */
 
92
        "chroot_dir", /* Where we run Deadwood from */
 
93
        "recursive_acl", /* IPs that we allow recursive queries from */
 
94
        "random_seed_file", /* File with seed/key for random number
 
95
                             * generator */
 
96
        "cache_file", /* File with a copy of Deadwood's cache */
 
97
        "ip_blacklist", /* If an answer has any of these IPs, make it a
 
98
                         * "not there" answer */
 
99
        0 };
 
100
 
 
101
char *key_d_names[KEY_D_COUNT + 1] = {
 
102
        "upstream_servers", /* Recursive upstream DNS servers */
 
103
        "root_servers", /* Non-recursive root DNS servers */
 
104
        0 };
 
105
 
 
106
char *key_n_names[KEY_N_COUNT + 1] = {
 
107
        "maxprocs", /* The maximum number of outstanding queries we can
 
108
                     * have */
 
109
        "timeout_seconds", /* How long we wait for a reply from the remote
 
110
                            * server */
 
111
        "dns_port", /* The port we bind to */
 
112
        "upstream_port", /* The port we connect to when connecting upstream */
 
113
        "handle_overload", /* Reply when overloaded */
 
114
        "handle_noreply", /* Reply when no reply from upstream */
 
115
        "recurse_min_bind_port", /* The lowest numbered port deadwood will
 
116
                                  * bind to */
 
117
        "recurse_number_ports", /* The number of ports deadwood is allowed
 
118
                                 * to bind to */
 
119
        "hash_magic_number", /* A large 31-bit prime number that the hash
 
120
                              * compression function uses */
 
121
        "maximum_cache_elements", /* Maximum number of elements in cache */
 
122
        "maradns_uid", /* Numeric User ID Deadwood runs as */
 
123
        "maradns_gid", /* Numeric Group ID Deadwood runs as */
 
124
        "resurrections", /* Whether to look up expired records if we can't
 
125
                          * connect to upstream */
 
126
        "num_retries", /* Number of times we try to connect to an upstream
 
127
                        * server before giving up */
 
128
        "verbose_level", /* How verbose our logging should be */
 
129
        "max_tcp_procs", /* The maximum number of pending TCP queries we
 
130
                          * can have */
 
131
        "timeout_seconds_tcp", /* Timeout in seconds for active TCP
 
132
                                * connections */
 
133
        "tcp_listen", /* Whether to enable DNS-over-TCP */
 
134
        "max_ar_chain", /* Is RR rotation enabled (1) or disabled (2) */
 
135
        "ttl_age", /* Whether to enable (1) or disable (0) TTL aging */
 
136
        "max_inflights", /* Maximum number of in-flight requests we allow
 
137
                          * a single upstream query to have. */
 
138
        "deliver_all", /* Deliver non-cachable replies */
 
139
        "filter_rfc1918", /* Don't allow RFC1918 IPs in DNS replies */
 
140
        "ns_glueless_type", /* Query type to find NS glue */
 
141
        "reject_aaaa", /* Whether to reply to AAAA queries with a
 
142
                        * synthetic "not there" reply */
 
143
        "reject_mx", /* Whether to reject MX queries with no reply and
 
144
                      * logging the query (to help find spam zombies) */
 
145
        "truncation_hack", /* Whether to use 1st answer in truncated UDP
 
146
                            * replies (if present) */
 
147
        "reject_ptr", /* Whether to reject PTR queries and send out a
 
148
                         synthetic "not there" reply */
 
149
        "min_ttl_incomplete_cname", /* How long to store incomplete CNAME
 
150
                                     * records in the cache, in seconds */
 
151
        "max_ttl", /* Maximum allowed TTL */
 
152
        0 };
 
153
 
 
154
#endif /* MARARC_C */
 
155
 
 
156
/* Various character classes used by the Mararc parser's finite state
 
157
 * machine */
 
158
 
 
159
#define dwm_is_alpha(c)      (c >= 'a' && c <= 'z') || \
 
160
                             (c >= 'A' && c <= 'Z') || \
 
161
                             c == '_'
 
162
 
 
163
#define dwm_is_alphanum(c)   (c >= 'a' && c <= 'z') || \
 
164
                             (c >= 'A' && c <= 'Z') || \
 
165
                             (c >= '0' && c <= '9') || \
 
166
                             c == '_'
 
167
 
 
168
#define dwm_is_alphastart(c) (c >= 'a' && c <= 'z') || \
 
169
                             (c >= 'A' && c <= 'Z')
 
170
 
 
171
#define dwm_is_dname(c)      (c >= 'a' && c <= 'z') || \
 
172
                             (c >= 'A' && c <= 'Z') || \
 
173
                             (c >= '0' && c <= '9') || \
 
174
                             c == '-' || c == '.' || c == '_'
 
175
 
 
176
#define dwm_is_instring(c)   (c >= ' ' && c <= '~' && c != '#' && c != '"')
 
177
 
 
178
#define dwm_is_whitespace(c) (c == ' ' || c == '\t')
 
179
 
 
180
#define dwm_is_any(c)        (c >= ' ' && c <= '~') || c == '\t' || c > 127
 
181
 
 
182
#define dwm_is_dnamestart(c) (c >= 'a' && c <= 'z') || \
 
183
                             (c >= 'A' && c <= 'Z') || \
 
184
                             (c >= '0' && c <= '9')
 
185
 
 
186
#define dwm_is_number(c)     (c >= '0' && c <= '9')
 
187
 
 
188
/* Limits to the number of states, actions, and pattern per state we can
 
189
 * have */
 
190
 
 
191
/* Maximum number of states */
 
192
#define DWM_MAX_STATES 52
 
193
/* Maximum number of patterns per state */
 
194
#define DWM_MAX_PATTERNS 8
 
195
 
 
196
/* The actual state machine that we use to parse a MaraRC file; this is
 
197
 * described in the file doc/internals/MARARC.parser */
 
198
 
 
199
#define dwm_machine "a Hb Y1c Wxb Rxp T;\n" \
 
200
                    "b Xb Rxp T;\n" \
 
201
                    "c B1c Wd =e [f +g (y\n" \
 
202
                    "d Wd =e [f +g\n" \
 
203
                    "e We N4h Qi {6w\n" \
 
204
                    "f Wf Qn\n" \
 
205
                    "g =5e\n" \
 
206
                    "h N4h Wk Hb Rxp T;\n" \
 
207
                    "i I3m\n" \
 
208
                    "k Wk Hb Rxp T;\n" \
 
209
                    "m I3m Qk\n" \
 
210
                    "n .2o S2p -2p\n" \
 
211
                    "o Qq\n" \
 
212
                    "p D2p Qq\n" \
 
213
                    "q Wq ]r\n" \
 
214
                    "r Wr =s +t\n" \
 
215
                    "s Ws Qu\n" \
 
216
                    "t =5s\n" \
 
217
                    "u I3v\n" \
 
218
                    "v I3v Qk\n" \
 
219
                    "w }k\n" \
 
220
                    "xp T;\n" \
 
221
                    "y Qz\n" \
 
222
                    "z I7z Qxa\n" \
 
223
                    "xa )k\n" \
 
224
                    "xb Hb Wxb Y8xb Rxp T;\n"
 
225
 
 
226
/* A tokenized single state in the finite state machine */
 
227
typedef struct {
 
228
        char pattern[DWM_MAX_PATTERNS + 1];
 
229
        char action[DWM_MAX_PATTERNS + 1];
 
230
        char newstate[DWM_MAX_PATTERNS + 1];
 
231
        } dwm_fs;
 
232
 
 
233
/* Parse a mararc file; this should only be called once when executing
 
234
 * deadwood.  Note that this is the *only* public method in this entire
 
235
 * file; all other functions in this file should only be called from
 
236
 * other functions in this file.
 
237
 * Input: c string that points to mararc file
 
238
 * Output: 1 on success; program exits on mararc parse error */
 
239
int dwm_parse_mararc(char *name);
 
240
 
 
241
/* Fetch a value from a given dictionary variable (num is the number for
 
242
 * the dictionary variable we are seeking a given value for, given the
 
243
 * dictionary variable and the key inside that variable) */
 
244
dw_str *dwm_dict_fetch(int num, dw_str *key);
 
245
 
 
246
/* For a given dictionary variable, and a key, return (as a *copied* dw_str
 
247
 * object) the next key or 0 if we're at the last key.  If the key given to
 
248
 * this function is 0, return the first key. */
 
249
dw_str *dwm_dict_nextkey(int num, dw_str *key);
 
250
 
 
251
/* Private function: Parse a single file */
 
252
int dwm_parse_file(char *name);
 
253
 
 
254
#endif /* __MARARC_H_DEFINED__ */