Simon Kelley | 6174435 | 2013-01-31 14:34:40 +0000 | [diff] [blame] | 1 | /* dnsmasq is Copyright (c) 2000-2013 Simon Kelley |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 2 | |
| 3 | This program is free software; you can redistribute it and/or modify |
| 4 | it under the terms of the GNU General Public License as published by |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 5 | the Free Software Foundation; version 2 dated June, 1991, or |
| 6 | (at your option) version 3 dated 29 June, 2007. |
| 7 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 8 | This program is distributed in the hope that it will be useful, |
| 9 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 10 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 11 | GNU General Public License for more details. |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 12 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 13 | You should have received a copy of the GNU General Public License |
| 14 | along with this program. If not, see <http://www.gnu.org/licenses/>. |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 17 | /* define this to get facilitynames */ |
| 18 | #define SYSLOG_NAMES |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 19 | #include "dnsmasq.h" |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 20 | #include <setjmp.h> |
| 21 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 22 | static volatile int mem_recover = 0; |
| 23 | static jmp_buf mem_jmp; |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 24 | static int one_file(char *file, int hard_opt); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 25 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 26 | /* Solaris headers don't have facility names. */ |
| 27 | #ifdef HAVE_SOLARIS_NETWORK |
| 28 | static const struct { |
| 29 | char *c_name; |
| 30 | unsigned int c_val; |
| 31 | } facilitynames[] = { |
| 32 | { "kern", LOG_KERN }, |
| 33 | { "user", LOG_USER }, |
| 34 | { "mail", LOG_MAIL }, |
| 35 | { "daemon", LOG_DAEMON }, |
| 36 | { "auth", LOG_AUTH }, |
| 37 | { "syslog", LOG_SYSLOG }, |
| 38 | { "lpr", LOG_LPR }, |
| 39 | { "news", LOG_NEWS }, |
| 40 | { "uucp", LOG_UUCP }, |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 41 | { "audit", LOG_AUDIT }, |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 42 | { "cron", LOG_CRON }, |
| 43 | { "local0", LOG_LOCAL0 }, |
| 44 | { "local1", LOG_LOCAL1 }, |
| 45 | { "local2", LOG_LOCAL2 }, |
| 46 | { "local3", LOG_LOCAL3 }, |
| 47 | { "local4", LOG_LOCAL4 }, |
| 48 | { "local5", LOG_LOCAL5 }, |
| 49 | { "local6", LOG_LOCAL6 }, |
| 50 | { "local7", LOG_LOCAL7 }, |
| 51 | { NULL, 0 } |
| 52 | }; |
| 53 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 54 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 55 | #ifndef HAVE_GETOPT_LONG |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 56 | struct myoption { |
| 57 | const char *name; |
| 58 | int has_arg; |
| 59 | int *flag; |
| 60 | int val; |
| 61 | }; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 62 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 63 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 64 | #define OPTSTRING "951yZDNLERKzowefnbvhdkqr:m:p:c:l:s:i:t:u:g:a:x:S:C:A:T:H:Q:I:B:F:G:O:M:X:V:U:j:P:J:W:Y:2:4:6:7:8:0:3:" |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 65 | |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 66 | /* options which don't have a one-char version */ |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 67 | #define LOPT_RELOAD 256 |
| 68 | #define LOPT_NO_NAMES 257 |
| 69 | #define LOPT_TFTP 258 |
| 70 | #define LOPT_SECURE 259 |
| 71 | #define LOPT_PREFIX 260 |
| 72 | #define LOPT_PTR 261 |
| 73 | #define LOPT_BRIDGE 262 |
| 74 | #define LOPT_TFTP_MAX 263 |
Simon Kelley | 6b01084 | 2007-02-12 20:32:07 +0000 | [diff] [blame] | 75 | #define LOPT_FORCE 264 |
| 76 | #define LOPT_NOBLOCK 265 |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 77 | #define LOPT_LOG_OPTS 266 |
| 78 | #define LOPT_MAX_LOGS 267 |
| 79 | #define LOPT_CIRCUIT 268 |
| 80 | #define LOPT_REMOTE 269 |
| 81 | #define LOPT_SUBSCR 270 |
| 82 | #define LOPT_INTNAME 271 |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 83 | #define LOPT_BANK 272 |
| 84 | #define LOPT_DHCP_HOST 273 |
| 85 | #define LOPT_APREF 274 |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 86 | #define LOPT_OVERRIDE 275 |
| 87 | #define LOPT_TFTPPORTS 276 |
| 88 | #define LOPT_REBIND 277 |
| 89 | #define LOPT_NOLAST 278 |
| 90 | #define LOPT_OPTS 279 |
| 91 | #define LOPT_DHCP_OPTS 280 |
| 92 | #define LOPT_MATCH 281 |
| 93 | #define LOPT_BROADCAST 282 |
| 94 | #define LOPT_NEGTTL 283 |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 95 | #define LOPT_ALTPORT 284 |
| 96 | #define LOPT_SCRIPTUSR 285 |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 97 | #define LOPT_LOCAL 286 |
| 98 | #define LOPT_NAPTR 287 |
| 99 | #define LOPT_MINPORT 288 |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 100 | #define LOPT_DHCP_FQDN 289 |
| 101 | #define LOPT_CNAME 290 |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 102 | #define LOPT_PXE_PROMT 291 |
| 103 | #define LOPT_PXE_SERV 292 |
| 104 | #define LOPT_TEST 293 |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 105 | #define LOPT_TAG_IF 294 |
| 106 | #define LOPT_PROXY 295 |
| 107 | #define LOPT_GEN_NAMES 296 |
| 108 | #define LOPT_MAXTTL 297 |
| 109 | #define LOPT_NO_REBIND 298 |
| 110 | #define LOPT_LOC_REBND 299 |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 111 | #define LOPT_ADD_MAC 300 |
Giovanni Bajo | 237724c | 2012-04-05 02:46:52 +0200 | [diff] [blame^] | 112 | #define LOPT_SEC_PROXY 301 |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 113 | #define LOPT_INCR_ADDR 302 |
| 114 | #define LOPT_CONNTRACK 303 |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 115 | #define LOPT_FQDN 304 |
| 116 | #define LOPT_LUASCRIPT 305 |
Simon Kelley | c5ad4e7 | 2012-02-24 16:06:20 +0000 | [diff] [blame] | 117 | #define LOPT_RA 306 |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 118 | #define LOPT_DUID 307 |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 119 | #define LOPT_HOST_REC 308 |
Simon Kelley | 61ce600 | 2012-04-20 21:28:49 +0100 | [diff] [blame] | 120 | #define LOPT_TFTP_LC 309 |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 121 | #define LOPT_RR 310 |
Simon Kelley | 54dd393 | 2012-06-20 11:23:38 +0100 | [diff] [blame] | 122 | #define LOPT_CLVERBIND 311 |
Simon Kelley | 1d86041 | 2012-09-20 20:48:04 +0100 | [diff] [blame] | 123 | #define LOPT_MAXCTTL 312 |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 124 | #define LOPT_AUTHZONE 313 |
| 125 | #define LOPT_AUTHSERV 314 |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 126 | #define LOPT_AUTHTTL 315 |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 127 | #define LOPT_AUTHSOA 316 |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 128 | #define LOPT_AUTHSFS 317 |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 129 | #define LOPT_AUTHPEER 318 |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 130 | #define LOPT_IPSET 319 |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 131 | #define LOPT_SYNTH 320 |
Simon Kelley | c630924 | 2013-03-07 20:59:28 +0000 | [diff] [blame] | 132 | #ifdef OPTION6_PREFIX_CLASS |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 133 | #define LOPT_PREF_CLSS 321 |
Simon Kelley | c630924 | 2013-03-07 20:59:28 +0000 | [diff] [blame] | 134 | #endif |
Simon Kelley | 8d03046 | 2013-07-29 15:41:26 +0100 | [diff] [blame] | 135 | #define LOPT_FAST_RA 322 |
Simon Kelley | 1697269 | 2006-10-16 20:04:18 +0100 | [diff] [blame] | 136 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 137 | #ifdef HAVE_GETOPT_LONG |
| 138 | static const struct option opts[] = |
| 139 | #else |
| 140 | static const struct myoption opts[] = |
| 141 | #endif |
| 142 | { |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 143 | { "version", 0, 0, 'v' }, |
| 144 | { "no-hosts", 0, 0, 'h' }, |
| 145 | { "no-poll", 0, 0, 'n' }, |
| 146 | { "help", 0, 0, 'w' }, |
| 147 | { "no-daemon", 0, 0, 'd' }, |
| 148 | { "log-queries", 0, 0, 'q' }, |
| 149 | { "user", 2, 0, 'u' }, |
| 150 | { "group", 2, 0, 'g' }, |
| 151 | { "resolv-file", 2, 0, 'r' }, |
| 152 | { "mx-host", 1, 0, 'm' }, |
| 153 | { "mx-target", 1, 0, 't' }, |
| 154 | { "cache-size", 2, 0, 'c' }, |
| 155 | { "port", 1, 0, 'p' }, |
| 156 | { "dhcp-leasefile", 2, 0, 'l' }, |
| 157 | { "dhcp-lease", 1, 0, 'l' }, |
| 158 | { "dhcp-host", 1, 0, 'G' }, |
| 159 | { "dhcp-range", 1, 0, 'F' }, |
| 160 | { "dhcp-option", 1, 0, 'O' }, |
| 161 | { "dhcp-boot", 1, 0, 'M' }, |
| 162 | { "domain", 1, 0, 's' }, |
| 163 | { "domain-suffix", 1, 0, 's' }, |
| 164 | { "interface", 1, 0, 'i' }, |
| 165 | { "listen-address", 1, 0, 'a' }, |
| 166 | { "bogus-priv", 0, 0, 'b' }, |
| 167 | { "bogus-nxdomain", 1, 0, 'B' }, |
| 168 | { "selfmx", 0, 0, 'e' }, |
| 169 | { "filterwin2k", 0, 0, 'f' }, |
| 170 | { "pid-file", 2, 0, 'x' }, |
| 171 | { "strict-order", 0, 0, 'o' }, |
| 172 | { "server", 1, 0, 'S' }, |
| 173 | { "local", 1, 0, LOPT_LOCAL }, |
| 174 | { "address", 1, 0, 'A' }, |
| 175 | { "conf-file", 2, 0, 'C' }, |
| 176 | { "no-resolv", 0, 0, 'R' }, |
| 177 | { "expand-hosts", 0, 0, 'E' }, |
| 178 | { "localmx", 0, 0, 'L' }, |
| 179 | { "local-ttl", 1, 0, 'T' }, |
| 180 | { "no-negcache", 0, 0, 'N' }, |
| 181 | { "addn-hosts", 1, 0, 'H' }, |
| 182 | { "query-port", 1, 0, 'Q' }, |
| 183 | { "except-interface", 1, 0, 'I' }, |
| 184 | { "no-dhcp-interface", 1, 0, '2' }, |
| 185 | { "domain-needed", 0, 0, 'D' }, |
| 186 | { "dhcp-lease-max", 1, 0, 'X' }, |
| 187 | { "bind-interfaces", 0, 0, 'z' }, |
| 188 | { "read-ethers", 0, 0, 'Z' }, |
| 189 | { "alias", 1, 0, 'V' }, |
| 190 | { "dhcp-vendorclass", 1, 0, 'U' }, |
| 191 | { "dhcp-userclass", 1, 0, 'j' }, |
| 192 | { "dhcp-ignore", 1, 0, 'J' }, |
| 193 | { "edns-packet-max", 1, 0, 'P' }, |
| 194 | { "keep-in-foreground", 0, 0, 'k' }, |
| 195 | { "dhcp-authoritative", 0, 0, 'K' }, |
| 196 | { "srv-host", 1, 0, 'W' }, |
| 197 | { "localise-queries", 0, 0, 'y' }, |
| 198 | { "txt-record", 1, 0, 'Y' }, |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 199 | { "dns-rr", 1, 0, LOPT_RR }, |
Simon Kelley | ad09427 | 2012-08-10 17:10:54 +0100 | [diff] [blame] | 200 | { "enable-dbus", 2, 0, '1' }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 201 | { "bootp-dynamic", 2, 0, '3' }, |
| 202 | { "dhcp-mac", 1, 0, '4' }, |
| 203 | { "no-ping", 0, 0, '5' }, |
| 204 | { "dhcp-script", 1, 0, '6' }, |
| 205 | { "conf-dir", 1, 0, '7' }, |
| 206 | { "log-facility", 1, 0 ,'8' }, |
| 207 | { "leasefile-ro", 0, 0, '9' }, |
| 208 | { "dns-forward-max", 1, 0, '0' }, |
| 209 | { "clear-on-reload", 0, 0, LOPT_RELOAD }, |
| 210 | { "dhcp-ignore-names", 2, 0, LOPT_NO_NAMES }, |
Simon Kelley | 2937f8a | 2013-07-29 19:49:07 +0100 | [diff] [blame] | 211 | { "enable-tftp", 2, 0, LOPT_TFTP }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 212 | { "tftp-secure", 0, 0, LOPT_SECURE }, |
| 213 | { "tftp-unique-root", 0, 0, LOPT_APREF }, |
| 214 | { "tftp-root", 1, 0, LOPT_PREFIX }, |
| 215 | { "tftp-max", 1, 0, LOPT_TFTP_MAX }, |
Simon Kelley | 61ce600 | 2012-04-20 21:28:49 +0100 | [diff] [blame] | 216 | { "tftp-lowercase", 0, 0, LOPT_TFTP_LC }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 217 | { "ptr-record", 1, 0, LOPT_PTR }, |
| 218 | { "naptr-record", 1, 0, LOPT_NAPTR }, |
| 219 | { "bridge-interface", 1, 0 , LOPT_BRIDGE }, |
| 220 | { "dhcp-option-force", 1, 0, LOPT_FORCE }, |
| 221 | { "tftp-no-blocksize", 0, 0, LOPT_NOBLOCK }, |
| 222 | { "log-dhcp", 0, 0, LOPT_LOG_OPTS }, |
| 223 | { "log-async", 2, 0, LOPT_MAX_LOGS }, |
| 224 | { "dhcp-circuitid", 1, 0, LOPT_CIRCUIT }, |
| 225 | { "dhcp-remoteid", 1, 0, LOPT_REMOTE }, |
| 226 | { "dhcp-subscrid", 1, 0, LOPT_SUBSCR }, |
| 227 | { "interface-name", 1, 0, LOPT_INTNAME }, |
| 228 | { "dhcp-hostsfile", 1, 0, LOPT_DHCP_HOST }, |
| 229 | { "dhcp-optsfile", 1, 0, LOPT_DHCP_OPTS }, |
| 230 | { "dhcp-no-override", 0, 0, LOPT_OVERRIDE }, |
| 231 | { "tftp-port-range", 1, 0, LOPT_TFTPPORTS }, |
| 232 | { "stop-dns-rebind", 0, 0, LOPT_REBIND }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 233 | { "rebind-domain-ok", 1, 0, LOPT_NO_REBIND }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 234 | { "all-servers", 0, 0, LOPT_NOLAST }, |
| 235 | { "dhcp-match", 1, 0, LOPT_MATCH }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 236 | { "dhcp-broadcast", 2, 0, LOPT_BROADCAST }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 237 | { "neg-ttl", 1, 0, LOPT_NEGTTL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 238 | { "max-ttl", 1, 0, LOPT_MAXTTL }, |
Simon Kelley | 1d86041 | 2012-09-20 20:48:04 +0100 | [diff] [blame] | 239 | { "max-cache-ttl", 1, 0, LOPT_MAXCTTL }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 240 | { "dhcp-alternate-port", 2, 0, LOPT_ALTPORT }, |
| 241 | { "dhcp-scriptuser", 1, 0, LOPT_SCRIPTUSR }, |
| 242 | { "min-port", 1, 0, LOPT_MINPORT }, |
| 243 | { "dhcp-fqdn", 0, 0, LOPT_DHCP_FQDN }, |
| 244 | { "cname", 1, 0, LOPT_CNAME }, |
| 245 | { "pxe-prompt", 1, 0, LOPT_PXE_PROMT }, |
| 246 | { "pxe-service", 1, 0, LOPT_PXE_SERV }, |
| 247 | { "test", 0, 0, LOPT_TEST }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 248 | { "tag-if", 1, 0, LOPT_TAG_IF }, |
| 249 | { "dhcp-proxy", 2, 0, LOPT_PROXY }, |
| 250 | { "dhcp-generate-names", 2, 0, LOPT_GEN_NAMES }, |
| 251 | { "rebind-localhost-ok", 0, 0, LOPT_LOC_REBND }, |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 252 | { "add-mac", 0, 0, LOPT_ADD_MAC }, |
Giovanni Bajo | 237724c | 2012-04-05 02:46:52 +0200 | [diff] [blame^] | 253 | { "proxy-dnssec", 0, 0, LOPT_SEC_PROXY }, |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 254 | { "dhcp-sequential-ip", 0, 0, LOPT_INCR_ADDR }, |
| 255 | { "conntrack", 0, 0, LOPT_CONNTRACK }, |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 256 | { "dhcp-client-update", 0, 0, LOPT_FQDN }, |
| 257 | { "dhcp-luascript", 1, 0, LOPT_LUASCRIPT }, |
Simon Kelley | c5ad4e7 | 2012-02-24 16:06:20 +0000 | [diff] [blame] | 258 | { "enable-ra", 0, 0, LOPT_RA }, |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 259 | { "dhcp-duid", 1, 0, LOPT_DUID }, |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 260 | { "host-record", 1, 0, LOPT_HOST_REC }, |
Simon Kelley | 54dd393 | 2012-06-20 11:23:38 +0100 | [diff] [blame] | 261 | { "bind-dynamic", 0, 0, LOPT_CLVERBIND }, |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 262 | { "auth-zone", 1, 0, LOPT_AUTHZONE }, |
| 263 | { "auth-server", 1, 0, LOPT_AUTHSERV }, |
| 264 | { "auth-ttl", 1, 0, LOPT_AUTHTTL }, |
| 265 | { "auth-soa", 1, 0, LOPT_AUTHSOA }, |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 266 | { "auth-sec-servers", 1, 0, LOPT_AUTHSFS }, |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 267 | { "auth-peer", 1, 0, LOPT_AUTHPEER }, |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 268 | { "ipset", 1, 0, LOPT_IPSET }, |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 269 | { "synth-domain", 1, 0, LOPT_SYNTH }, |
Simon Kelley | c630924 | 2013-03-07 20:59:28 +0000 | [diff] [blame] | 270 | #ifdef OPTION6_PREFIX_CLASS |
| 271 | { "dhcp-prefix-class", 1, 0, LOPT_PREF_CLSS }, |
| 272 | #endif |
Simon Kelley | 8d03046 | 2013-07-29 15:41:26 +0100 | [diff] [blame] | 273 | { "force-fast-ra", 0, 0, LOPT_FAST_RA }, |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 274 | { NULL, 0, 0, 0 } |
| 275 | }; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 276 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 277 | |
| 278 | #define ARG_DUP OPT_LAST |
| 279 | #define ARG_ONE OPT_LAST + 1 |
| 280 | #define ARG_USED_CL OPT_LAST + 2 |
| 281 | #define ARG_USED_FILE OPT_LAST + 3 |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 282 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 283 | static struct { |
| 284 | int opt; |
| 285 | unsigned int rept; |
| 286 | char * const flagdesc; |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 287 | char * const desc; |
| 288 | char * const arg; |
| 289 | } usage[] = { |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 290 | { 'a', ARG_DUP, "<ipaddr>", gettext_noop("Specify local address(es) to listen on."), NULL }, |
| 291 | { 'A', ARG_DUP, "/<domain>/<ipaddr>", gettext_noop("Return ipaddr for all hosts in specified domains."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 292 | { 'b', OPT_BOGUSPRIV, NULL, gettext_noop("Fake reverse lookups for RFC1918 private address ranges."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 293 | { 'B', ARG_DUP, "<ipaddr>", gettext_noop("Treat ipaddr as NXDOMAIN (defeats Verisign wildcard)."), NULL }, |
| 294 | { 'c', ARG_ONE, "<integer>", gettext_noop("Specify the size of the cache in entries (defaults to %s)."), "$" }, |
| 295 | { 'C', ARG_DUP, "<path>", gettext_noop("Specify configuration file (defaults to %s)."), CONFFILE }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 296 | { 'd', OPT_DEBUG, NULL, gettext_noop("Do NOT fork into the background: run in debug mode."), NULL }, |
| 297 | { 'D', OPT_NODOTS_LOCAL, NULL, gettext_noop("Do NOT forward queries with no domain part."), NULL }, |
| 298 | { 'e', OPT_SELFMX, NULL, gettext_noop("Return self-pointing MX records for local hosts."), NULL }, |
| 299 | { 'E', OPT_EXPAND, NULL, gettext_noop("Expand simple names in /etc/hosts with domain-suffix."), NULL }, |
| 300 | { 'f', OPT_FILTER, NULL, gettext_noop("Don't forward spurious DNS requests from Windows hosts."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 301 | { 'F', ARG_DUP, "<ipaddr>,...", gettext_noop("Enable DHCP in the range given with lease duration."), NULL }, |
| 302 | { 'g', ARG_ONE, "<groupname>", gettext_noop("Change to this group after startup (defaults to %s)."), CHGRP }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 303 | { 'G', ARG_DUP, "<hostspec>", gettext_noop("Set address or hostname for a specified machine."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 304 | { LOPT_DHCP_HOST, ARG_DUP, "<path>", gettext_noop("Read DHCP host specs from file."), NULL }, |
| 305 | { LOPT_DHCP_OPTS, ARG_DUP, "<path>", gettext_noop("Read DHCP option specs from file."), NULL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 306 | { LOPT_TAG_IF, ARG_DUP, "tag-expression", gettext_noop("Evaluate conditional tag expression."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 307 | { 'h', OPT_NO_HOSTS, NULL, gettext_noop("Do NOT load %s file."), HOSTSFILE }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 308 | { 'H', ARG_DUP, "<path>", gettext_noop("Specify a hosts file to be read in addition to %s."), HOSTSFILE }, |
| 309 | { 'i', ARG_DUP, "<interface>", gettext_noop("Specify interface(s) to listen on."), NULL }, |
| 310 | { 'I', ARG_DUP, "<interface>", gettext_noop("Specify interface(s) NOT to listen on.") , NULL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 311 | { 'j', ARG_DUP, "set:<tag>,<class>", gettext_noop("Map DHCP user class to tag."), NULL }, |
| 312 | { LOPT_CIRCUIT, ARG_DUP, "set:<tag>,<circuit>", gettext_noop("Map RFC3046 circuit-id to tag."), NULL }, |
| 313 | { LOPT_REMOTE, ARG_DUP, "set:<tag>,<remote>", gettext_noop("Map RFC3046 remote-id to tag."), NULL }, |
| 314 | { LOPT_SUBSCR, ARG_DUP, "set:<tag>,<remote>", gettext_noop("Map RFC3993 subscriber-id to tag."), NULL }, |
| 315 | { 'J', ARG_DUP, "tag:<tag>...", gettext_noop("Don't do DHCP for hosts with tag set."), NULL }, |
| 316 | { LOPT_BROADCAST, ARG_DUP, "[=tag:<tag>...]", gettext_noop("Force broadcast replies for hosts with tag set."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 317 | { 'k', OPT_NO_FORK, NULL, gettext_noop("Do NOT fork into the background, do NOT run in debug mode."), NULL }, |
| 318 | { 'K', OPT_AUTHORITATIVE, NULL, gettext_noop("Assume we are the only DHCP server on the local network."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 319 | { 'l', ARG_ONE, "<path>", gettext_noop("Specify where to store DHCP leases (defaults to %s)."), LEASEFILE }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 320 | { 'L', OPT_LOCALMX, NULL, gettext_noop("Return MX records for local hosts."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 321 | { 'm', ARG_DUP, "<host_name>,<target>,<pref>", gettext_noop("Specify an MX record."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 322 | { 'M', ARG_DUP, "<bootp opts>", gettext_noop("Specify BOOTP options to DHCP server."), NULL }, |
| 323 | { 'n', OPT_NO_POLL, NULL, gettext_noop("Do NOT poll %s file, reload only on SIGHUP."), RESOLVFILE }, |
| 324 | { 'N', OPT_NO_NEG, NULL, gettext_noop("Do NOT cache failed search results."), NULL }, |
| 325 | { 'o', OPT_ORDER, NULL, gettext_noop("Use nameservers strictly in the order given in %s."), RESOLVFILE }, |
| 326 | { 'O', ARG_DUP, "<optspec>", gettext_noop("Specify options to be sent to DHCP clients."), NULL }, |
| 327 | { LOPT_FORCE, ARG_DUP, "<optspec>", gettext_noop("DHCP option sent even if the client does not request it."), NULL}, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 328 | { 'p', ARG_ONE, "<integer>", gettext_noop("Specify port to listen for DNS requests on (defaults to 53)."), NULL }, |
| 329 | { 'P', ARG_ONE, "<integer>", gettext_noop("Maximum supported UDP packet size for EDNS.0 (defaults to %s)."), "*" }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 330 | { 'q', OPT_LOG, NULL, gettext_noop("Log DNS queries."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 331 | { 'Q', ARG_ONE, "<integer>", gettext_noop("Force the originating port for upstream DNS queries."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 332 | { 'R', OPT_NO_RESOLV, NULL, gettext_noop("Do NOT read resolv.conf."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 333 | { 'r', ARG_DUP, "<path>", gettext_noop("Specify path to resolv.conf (defaults to %s)."), RESOLVFILE }, |
| 334 | { 'S', ARG_DUP, "/<domain>/<ipaddr>", gettext_noop("Specify address(es) of upstream servers with optional domains."), NULL }, |
| 335 | { LOPT_LOCAL, ARG_DUP, "/<domain>/", gettext_noop("Never forward queries to specified domains."), NULL }, |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 336 | { 's', ARG_DUP, "<domain>[,<range>]", gettext_noop("Specify the domain to be assigned in DHCP leases."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 337 | { 't', ARG_ONE, "<host_name>", gettext_noop("Specify default target in an MX record."), NULL }, |
| 338 | { 'T', ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for replies from /etc/hosts."), NULL }, |
| 339 | { LOPT_NEGTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for negative caching."), NULL }, |
| 340 | { LOPT_MAXTTL, ARG_ONE, "<integer>", gettext_noop("Specify time-to-live in seconds for maximum TTL to send to clients."), NULL }, |
| 341 | { 'u', ARG_ONE, "<username>", gettext_noop("Change to this user after startup. (defaults to %s)."), CHUSER }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 342 | { 'U', ARG_DUP, "set:<tag>,<class>", gettext_noop("Map DHCP vendor class to tag."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 343 | { 'v', 0, NULL, gettext_noop("Display dnsmasq version and copyright information."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 344 | { 'V', ARG_DUP, "<ipaddr>,<ipaddr>,<netmask>", gettext_noop("Translate IPv4 addresses from upstream servers."), NULL }, |
| 345 | { 'W', ARG_DUP, "<name>,<target>,...", gettext_noop("Specify a SRV record."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 346 | { 'w', 0, NULL, gettext_noop("Display this message. Use --help dhcp for known DHCP options."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 347 | { 'x', ARG_ONE, "<path>", gettext_noop("Specify path of PID file (defaults to %s)."), RUNFILE }, |
| 348 | { 'X', ARG_ONE, "<integer>", gettext_noop("Specify maximum number of DHCP leases (defaults to %s)."), "&" }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 349 | { 'y', OPT_LOCALISE, NULL, gettext_noop("Answer DNS queries based on the interface a query was sent to."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 350 | { 'Y', ARG_DUP, "<name>,<txt>[,<txt]", gettext_noop("Specify TXT DNS record."), NULL }, |
| 351 | { LOPT_PTR, ARG_DUP, "<name>,<target>", gettext_noop("Specify PTR DNS record."), NULL }, |
| 352 | { LOPT_INTNAME, ARG_DUP, "<name>,<interface>", gettext_noop("Give DNS name to IPv4 address of interface."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 353 | { 'z', OPT_NOWILD, NULL, gettext_noop("Bind only to interfaces in use."), NULL }, |
| 354 | { 'Z', OPT_ETHERS, NULL, gettext_noop("Read DHCP static host information from %s."), ETHERSFILE }, |
Simon Kelley | ad09427 | 2012-08-10 17:10:54 +0100 | [diff] [blame] | 355 | { '1', ARG_ONE, "[=<busname>]", gettext_noop("Enable the DBus interface for setting upstream servers, etc."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 356 | { '2', ARG_DUP, "<interface>", gettext_noop("Do not provide DHCP on this interface, only provide DNS."), NULL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 357 | { '3', ARG_DUP, "[=tag:<tag>]...", gettext_noop("Enable dynamic address allocation for bootp."), NULL }, |
| 358 | { '4', ARG_DUP, "set:<tag>,<mac address>", gettext_noop("Map MAC address (with wildcards) to option set."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 359 | { LOPT_BRIDGE, ARG_DUP, "<iface>,<alias>..", gettext_noop("Treat DHCP requests on aliases as arriving from interface."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 360 | { '5', OPT_NO_PING, NULL, gettext_noop("Disable ICMP echo address checking in the DHCP server."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 361 | { '6', ARG_ONE, "<path>", gettext_noop("Shell script to run on DHCP lease creation and destruction."), NULL }, |
| 362 | { LOPT_LUASCRIPT, ARG_DUP, "path", gettext_noop("Lua script to run on DHCP lease creation and destruction."), NULL }, |
| 363 | { LOPT_SCRIPTUSR, ARG_ONE, "<username>", gettext_noop("Run lease-change scripts as this user."), NULL }, |
| 364 | { '7', ARG_DUP, "<path>", gettext_noop("Read configuration from all the files in this directory."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 365 | { '8', ARG_ONE, "<facilty>|<file>", gettext_noop("Log to this syslog facility or file. (defaults to DAEMON)"), NULL }, |
| 366 | { '9', OPT_LEASE_RO, NULL, gettext_noop("Do not use leasefile."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 367 | { '0', ARG_ONE, "<integer>", gettext_noop("Maximum number of concurrent DNS queries. (defaults to %s)"), "!" }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 368 | { LOPT_RELOAD, OPT_RELOAD, NULL, gettext_noop("Clear DNS cache when reloading %s."), RESOLVFILE }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 369 | { LOPT_NO_NAMES, ARG_DUP, "[=tag:<tag>]...", gettext_noop("Ignore hostnames provided by DHCP clients."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 370 | { LOPT_OVERRIDE, OPT_NO_OVERRIDE, NULL, gettext_noop("Do NOT reuse filename and server fields for extra DHCP options."), NULL }, |
Simon Kelley | 2937f8a | 2013-07-29 19:49:07 +0100 | [diff] [blame] | 371 | { LOPT_TFTP, ARG_DUP, "[=<intr>[,<intr>]]", gettext_noop("Enable integrated read-only TFTP server."), NULL }, |
Simon Kelley | 8b3ae2f | 2012-06-13 13:43:49 +0100 | [diff] [blame] | 372 | { LOPT_PREFIX, ARG_DUP, "<dir>[,<iface>]", gettext_noop("Export files by TFTP only from the specified subtree."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 373 | { LOPT_APREF, OPT_TFTP_APREF, NULL, gettext_noop("Add client IP address to tftp-root."), NULL }, |
| 374 | { LOPT_SECURE, OPT_TFTP_SECURE, NULL, gettext_noop("Allow access only to files owned by the user running dnsmasq."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 375 | { LOPT_TFTP_MAX, ARG_ONE, "<integer>", gettext_noop("Maximum number of conncurrent TFTP transfers (defaults to %s)."), "#" }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 376 | { LOPT_NOBLOCK, OPT_TFTP_NOBLOCK, NULL, gettext_noop("Disable the TFTP blocksize extension."), NULL }, |
Simon Kelley | 61ce600 | 2012-04-20 21:28:49 +0100 | [diff] [blame] | 377 | { LOPT_TFTP_LC, OPT_TFTP_LC, NULL, gettext_noop("Convert TFTP filenames to lowercase"), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 378 | { LOPT_TFTPPORTS, ARG_ONE, "<start>,<end>", gettext_noop("Ephemeral port range for use by TFTP transfers."), NULL }, |
| 379 | { LOPT_LOG_OPTS, OPT_LOG_OPTS, NULL, gettext_noop("Extra logging for DHCP."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 380 | { LOPT_MAX_LOGS, ARG_ONE, "[=<integer>]", gettext_noop("Enable async. logging; optionally set queue length."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 381 | { LOPT_REBIND, OPT_NO_REBIND, NULL, gettext_noop("Stop DNS rebinding. Filter private IP ranges when resolving."), NULL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 382 | { LOPT_LOC_REBND, OPT_LOCAL_REBIND, NULL, gettext_noop("Allow rebinding of 127.0.0.0/8, for RBL servers."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 383 | { LOPT_NO_REBIND, ARG_DUP, "/<domain>/", gettext_noop("Inhibit DNS-rebind protection on this domain."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 384 | { LOPT_NOLAST, OPT_ALL_SERVERS, NULL, gettext_noop("Always perform DNS queries to all servers."), NULL }, |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 385 | { LOPT_MATCH, ARG_DUP, "set:<tag>,<optspec>", gettext_noop("Set tag if client includes matching option in request."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 386 | { LOPT_ALTPORT, ARG_ONE, "[=<ports>]", gettext_noop("Use alternative ports for DHCP."), NULL }, |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 387 | { LOPT_NAPTR, ARG_DUP, "<name>,<naptr>", gettext_noop("Specify NAPTR DNS record."), NULL }, |
| 388 | { LOPT_MINPORT, ARG_ONE, "<port>", gettext_noop("Specify lowest port available for DNS query transmission."), NULL }, |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 389 | { LOPT_DHCP_FQDN, OPT_DHCP_FQDN, NULL, gettext_noop("Use only fully qualified domain names for DHCP clients."), NULL }, |
Simon Kelley | 8ecfaa4 | 2012-01-07 15:29:48 +0000 | [diff] [blame] | 390 | { LOPT_GEN_NAMES, ARG_DUP, "[=tag:<tag>]", gettext_noop("Generate hostnames based on MAC address for nameless clients."), NULL}, |
| 391 | { LOPT_PROXY, ARG_DUP, "[=<ipaddr>]...", gettext_noop("Use these DHCP relays as full proxies."), NULL }, |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 392 | { LOPT_CNAME, ARG_DUP, "<alias>,<target>", gettext_noop("Specify alias name for LOCAL DNS name."), NULL }, |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 393 | { LOPT_PXE_PROMT, ARG_DUP, "<prompt>,[<timeout>]", gettext_noop("Prompt to send to PXE clients."), NULL }, |
| 394 | { LOPT_PXE_SERV, ARG_DUP, "<service>", gettext_noop("Boot service for PXE menu."), NULL }, |
| 395 | { LOPT_TEST, 0, NULL, gettext_noop("Check configuration syntax."), NULL }, |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 396 | { LOPT_ADD_MAC, OPT_ADD_MAC, NULL, gettext_noop("Add requestor's MAC address to forwarded DNS queries."), NULL }, |
Giovanni Bajo | 237724c | 2012-04-05 02:46:52 +0200 | [diff] [blame^] | 397 | { LOPT_SEC_PROXY, OPT_DNSSEC_PROXY, NULL, gettext_noop("Proxy DNSSEC validation results from upstream nameservers."), NULL }, |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 398 | { LOPT_INCR_ADDR, OPT_CONSEC_ADDR, NULL, gettext_noop("Attempt to allocate sequential IP addresses to DHCP clients."), NULL }, |
| 399 | { LOPT_CONNTRACK, OPT_CONNTRACK, NULL, gettext_noop("Copy connection-track mark from queries to upstream connections."), NULL }, |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 400 | { LOPT_FQDN, OPT_FQDN_UPDATE, NULL, gettext_noop("Allow DHCP clients to do their own DDNS updates."), NULL }, |
Simon Kelley | c5ad4e7 | 2012-02-24 16:06:20 +0000 | [diff] [blame] | 401 | { LOPT_RA, OPT_RA, NULL, gettext_noop("Send router-advertisements for interfaces doing DHCPv6"), NULL }, |
Simon Kelley | 8d03046 | 2013-07-29 15:41:26 +0100 | [diff] [blame] | 402 | { LOPT_FAST_RA, OPT_FAST_RA, NULL, gettext_noop("Always send frequent router-advertisements"), NULL }, |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 403 | { LOPT_DUID, ARG_ONE, "<enterprise>,<duid>", gettext_noop("Specify DUID_EN-type DHCPv6 server DUID"), NULL }, |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 404 | { LOPT_HOST_REC, ARG_DUP, "<name>,<address>", gettext_noop("Specify host (A/AAAA and PTR) records"), NULL }, |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 405 | { LOPT_RR, ARG_DUP, "<name>,<RR-number>,[<data>]", gettext_noop("Specify arbitrary DNS resource record"), NULL }, |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 406 | { LOPT_CLVERBIND, OPT_CLEVERBIND, NULL, gettext_noop("Bind to interfaces in use - check for new interfaces"), NULL }, |
Simon Kelley | 86e3b9a | 2012-11-30 13:46:48 +0000 | [diff] [blame] | 407 | { LOPT_AUTHSERV, ARG_ONE, "<NS>,<interface>", gettext_noop("Export local names to global DNS"), NULL }, |
Simon Kelley | 333b2ce | 2013-01-07 21:46:03 +0000 | [diff] [blame] | 408 | { LOPT_AUTHZONE, ARG_DUP, "<domain>,[<subnet>...]", gettext_noop("Domain to export to global DNS"), NULL }, |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 409 | { LOPT_AUTHTTL, ARG_ONE, "<integer>", gettext_noop("Set TTL for authoritative replies"), NULL }, |
| 410 | { LOPT_AUTHSOA, ARG_ONE, "<serial>[,...]", gettext_noop("Set authoritive zone information"), NULL }, |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 411 | { LOPT_AUTHSFS, ARG_DUP, "<NS>[,<NS>...]", gettext_noop("Secondary authoritative nameservers for forward domains"), NULL }, |
| 412 | { LOPT_AUTHPEER, ARG_DUP, "<ipaddr>[,<ipaddr>...]", gettext_noop("Peers which are allowed to do zone transfer"), NULL }, |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 413 | { LOPT_IPSET, ARG_DUP, "/<domain>/<ipset>[,<ipset>...]", gettext_noop("Specify ipsets to which matching domains should be added"), NULL }, |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 414 | { LOPT_SYNTH, ARG_DUP, "<domain>,<range>,[<prefix>]", gettext_noop("Specify a domain and address range for sythesised names"), NULL }, |
Simon Kelley | c630924 | 2013-03-07 20:59:28 +0000 | [diff] [blame] | 415 | #ifdef OPTION6_PREFIX_CLASS |
| 416 | { LOPT_PREF_CLSS, ARG_DUP, "set:tag,<class>", gettext_noop("Specify DHCPv6 prefix class"), NULL }, |
| 417 | #endif |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 418 | { 0, 0, NULL, NULL, NULL } |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 419 | }; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 420 | |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 421 | /* We hide metacharaters in quoted strings by mapping them into the ASCII control |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 422 | character space. Note that the \0, \t \b \r \033 and \n characters are carefully placed in the |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 423 | following sequence so that they map to themselves: it is therefore possible to call |
| 424 | unhide_metas repeatedly on string without breaking things. |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 425 | The transformation gets undone by opt_canonicalise, atoi_check and opt_string_alloc, and a |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 426 | couple of other places. |
| 427 | Note that space is included here so that |
| 428 | --dhcp-option=3, string |
| 429 | has five characters, whilst |
| 430 | --dhcp-option=3," string" |
| 431 | has six. |
| 432 | */ |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 433 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 434 | static const char meta[] = "\000123456 \b\t\n78\r90abcdefABCDE\033F:,."; |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 435 | |
| 436 | static char hide_meta(char c) |
| 437 | { |
| 438 | unsigned int i; |
| 439 | |
| 440 | for (i = 0; i < (sizeof(meta) - 1); i++) |
| 441 | if (c == meta[i]) |
| 442 | return (char)i; |
| 443 | |
| 444 | return c; |
| 445 | } |
| 446 | |
| 447 | static char unhide_meta(char cr) |
| 448 | { |
| 449 | unsigned int c = cr; |
| 450 | |
| 451 | if (c < (sizeof(meta) - 1)) |
| 452 | cr = meta[c]; |
| 453 | |
| 454 | return cr; |
| 455 | } |
| 456 | |
| 457 | static void unhide_metas(char *cp) |
| 458 | { |
| 459 | if (cp) |
| 460 | for(; *cp; cp++) |
| 461 | *cp = unhide_meta(*cp); |
| 462 | } |
| 463 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 464 | static void *opt_malloc(size_t size) |
| 465 | { |
| 466 | void *ret; |
| 467 | |
| 468 | if (mem_recover) |
| 469 | { |
| 470 | ret = whine_malloc(size); |
| 471 | if (!ret) |
| 472 | longjmp(mem_jmp, 1); |
| 473 | } |
| 474 | else |
| 475 | ret = safe_malloc(size); |
| 476 | |
| 477 | return ret; |
| 478 | } |
| 479 | |
| 480 | static char *opt_string_alloc(char *cp) |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 481 | { |
| 482 | char *ret = NULL; |
| 483 | |
| 484 | if (cp && strlen(cp) != 0) |
| 485 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 486 | ret = opt_malloc(strlen(cp)+1); |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 487 | strcpy(ret, cp); |
| 488 | |
| 489 | /* restore hidden metachars */ |
| 490 | unhide_metas(ret); |
| 491 | } |
| 492 | |
| 493 | return ret; |
| 494 | } |
| 495 | |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 496 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 497 | /* find next comma, split string with zero and eliminate spaces. |
| 498 | return start of string following comma */ |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 499 | |
| 500 | static char *split_chr(char *s, char c) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 501 | { |
| 502 | char *comma, *p; |
| 503 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 504 | if (!s || !(comma = strchr(s, c))) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 505 | return NULL; |
| 506 | |
| 507 | p = comma; |
| 508 | *comma = ' '; |
| 509 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 510 | for (; *comma == ' '; comma++); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 511 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 512 | for (; (p >= s) && *p == ' '; p--) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 513 | *p = 0; |
| 514 | |
| 515 | return comma; |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 516 | } |
| 517 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 518 | static char *split(char *s) |
| 519 | { |
| 520 | return split_chr(s, ','); |
| 521 | } |
| 522 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 523 | static char *canonicalise_opt(char *s) |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 524 | { |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 525 | char *ret; |
| 526 | int nomem; |
| 527 | |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 528 | if (!s) |
| 529 | return 0; |
| 530 | |
| 531 | unhide_metas(s); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 532 | if (!(ret = canonicalise(s, &nomem)) && nomem) |
| 533 | { |
| 534 | if (mem_recover) |
| 535 | longjmp(mem_jmp, 1); |
| 536 | else |
| 537 | die(_("could not get memory"), NULL, EC_NOMEM); |
| 538 | } |
| 539 | |
| 540 | return ret; |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 541 | } |
| 542 | |
| 543 | static int atoi_check(char *a, int *res) |
| 544 | { |
| 545 | char *p; |
| 546 | |
| 547 | if (!a) |
| 548 | return 0; |
| 549 | |
| 550 | unhide_metas(a); |
| 551 | |
| 552 | for (p = a; *p; p++) |
| 553 | if (*p < '0' || *p > '9') |
| 554 | return 0; |
| 555 | |
| 556 | *res = atoi(a); |
| 557 | return 1; |
| 558 | } |
| 559 | |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 560 | static int atoi_check16(char *a, int *res) |
| 561 | { |
| 562 | if (!(atoi_check(a, res)) || |
| 563 | *res < 0 || |
| 564 | *res > 0xffff) |
| 565 | return 0; |
| 566 | |
| 567 | return 1; |
| 568 | } |
| 569 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 570 | static void add_txt(char *name, char *txt) |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 571 | { |
| 572 | size_t len = strlen(txt); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 573 | struct txt_record *r = opt_malloc(sizeof(struct txt_record)); |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 574 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 575 | r->name = opt_string_alloc(name); |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 576 | r->next = daemon->txt; |
| 577 | daemon->txt = r; |
| 578 | r->class = C_CHAOS; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 579 | r->txt = opt_malloc(len+1); |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 580 | r->len = len+1; |
| 581 | *(r->txt) = len; |
| 582 | memcpy((r->txt)+1, txt, len); |
| 583 | } |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 584 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 585 | static void do_usage(void) |
| 586 | { |
| 587 | char buff[100]; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 588 | int i, j; |
| 589 | |
| 590 | struct { |
| 591 | char handle; |
| 592 | int val; |
| 593 | } tab[] = { |
| 594 | { '$', CACHESIZ }, |
| 595 | { '*', EDNS_PKTSZ }, |
| 596 | { '&', MAXLEASES }, |
| 597 | { '!', FTABSIZ }, |
| 598 | { '#', TFTP_MAX_CONNECTIONS }, |
| 599 | { '\0', 0 } |
| 600 | }; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 601 | |
| 602 | printf(_("Usage: dnsmasq [options]\n\n")); |
| 603 | #ifndef HAVE_GETOPT_LONG |
| 604 | printf(_("Use short options only on the command line.\n")); |
| 605 | #endif |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 606 | printf(_("Valid options are:\n")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 607 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 608 | for (i = 0; usage[i].opt != 0; i++) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 609 | { |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 610 | char *desc = usage[i].flagdesc; |
| 611 | char *eq = "="; |
| 612 | |
| 613 | if (!desc || *desc == '[') |
| 614 | eq = ""; |
| 615 | |
| 616 | if (!desc) |
| 617 | desc = ""; |
| 618 | |
| 619 | for ( j = 0; opts[j].name; j++) |
| 620 | if (opts[j].val == usage[i].opt) |
| 621 | break; |
| 622 | if (usage[i].opt < 256) |
| 623 | sprintf(buff, "-%c, ", usage[i].opt); |
| 624 | else |
| 625 | sprintf(buff, " "); |
| 626 | |
| 627 | sprintf(buff+4, "--%s%s%s", opts[j].name, eq, desc); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 628 | printf("%-40.40s", buff); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 629 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 630 | if (usage[i].arg) |
| 631 | { |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 632 | strcpy(buff, usage[i].arg); |
| 633 | for (j = 0; tab[j].handle; j++) |
| 634 | if (tab[j].handle == *(usage[i].arg)) |
| 635 | sprintf(buff, "%d", tab[j].val); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 636 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 637 | printf(_(usage[i].desc), buff); |
| 638 | printf("\n"); |
| 639 | } |
| 640 | } |
| 641 | |
Simon Kelley | c740e4f | 2012-08-09 16:19:01 +0100 | [diff] [blame] | 642 | #define ret_err(x) do { strcpy(errstr, (x)); return 0; } while (0) |
| 643 | |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 644 | char *parse_server(char *arg, union mysockaddr *addr, union mysockaddr *source_addr, char *interface, int *flags) |
| 645 | { |
| 646 | int source_port = 0, serv_port = NAMESERVER_PORT; |
| 647 | char *portno, *source; |
| 648 | #ifdef HAVE_IPV6 |
| 649 | int scope_index = 0; |
| 650 | char *scope_id; |
| 651 | #endif |
| 652 | |
| 653 | if ((source = split_chr(arg, '@')) && /* is there a source. */ |
| 654 | (portno = split_chr(source, '#')) && |
| 655 | !atoi_check16(portno, &source_port)) |
| 656 | return _("bad port"); |
| 657 | |
| 658 | if ((portno = split_chr(arg, '#')) && /* is there a port no. */ |
| 659 | !atoi_check16(portno, &serv_port)) |
| 660 | return _("bad port"); |
| 661 | |
| 662 | #ifdef HAVE_IPV6 |
| 663 | scope_id = split_chr(arg, '%'); |
| 664 | #endif |
| 665 | |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 666 | if (inet_pton(AF_INET, arg, &addr->in.sin_addr) > 0) |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 667 | { |
| 668 | addr->in.sin_port = htons(serv_port); |
| 669 | addr->sa.sa_family = source_addr->sa.sa_family = AF_INET; |
| 670 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 671 | source_addr->in.sin_len = addr->in.sin_len = sizeof(struct sockaddr_in); |
| 672 | #endif |
| 673 | source_addr->in.sin_addr.s_addr = INADDR_ANY; |
| 674 | source_addr->in.sin_port = htons(daemon->query_port); |
| 675 | |
| 676 | if (source) |
| 677 | { |
| 678 | if (flags) |
| 679 | *flags |= SERV_HAS_SOURCE; |
| 680 | source_addr->in.sin_port = htons(source_port); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 681 | if (!(inet_pton(AF_INET, source, &source_addr->in.sin_addr) > 0)) |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 682 | { |
| 683 | #if defined(SO_BINDTODEVICE) |
| 684 | source_addr->in.sin_addr.s_addr = INADDR_ANY; |
| 685 | strncpy(interface, source, IF_NAMESIZE - 1); |
| 686 | #else |
| 687 | return _("interface binding not supported"); |
| 688 | #endif |
| 689 | } |
| 690 | } |
| 691 | } |
| 692 | #ifdef HAVE_IPV6 |
| 693 | else if (inet_pton(AF_INET6, arg, &addr->in6.sin6_addr) > 0) |
| 694 | { |
| 695 | if (scope_id && (scope_index = if_nametoindex(scope_id)) == 0) |
| 696 | return _("bad interface name"); |
| 697 | |
| 698 | addr->in6.sin6_port = htons(serv_port); |
| 699 | addr->in6.sin6_scope_id = scope_index; |
| 700 | source_addr->in6.sin6_addr = in6addr_any; |
| 701 | source_addr->in6.sin6_port = htons(daemon->query_port); |
| 702 | source_addr->in6.sin6_scope_id = 0; |
| 703 | addr->sa.sa_family = source_addr->sa.sa_family = AF_INET6; |
| 704 | addr->in6.sin6_flowinfo = source_addr->in6.sin6_flowinfo = 0; |
| 705 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 706 | addr->in6.sin6_len = source_addr->in6.sin6_len = sizeof(addr->in6); |
| 707 | #endif |
| 708 | if (source) |
| 709 | { |
| 710 | if (flags) |
| 711 | *flags |= SERV_HAS_SOURCE; |
| 712 | source_addr->in6.sin6_port = htons(source_port); |
| 713 | if (inet_pton(AF_INET6, source, &source_addr->in6.sin6_addr) == 0) |
| 714 | { |
| 715 | #if defined(SO_BINDTODEVICE) |
| 716 | source_addr->in6.sin6_addr = in6addr_any; |
| 717 | strncpy(interface, source, IF_NAMESIZE - 1); |
| 718 | #else |
| 719 | return _("interface binding not supported"); |
| 720 | #endif |
| 721 | } |
| 722 | } |
| 723 | } |
| 724 | #endif |
| 725 | else |
| 726 | return _("bad address"); |
| 727 | |
| 728 | return NULL; |
| 729 | } |
| 730 | |
Simon Kelley | b5a8dd1 | 2012-12-10 11:37:25 +0000 | [diff] [blame] | 731 | #ifdef HAVE_DHCP |
| 732 | |
| 733 | static int is_tag_prefix(char *arg) |
| 734 | { |
| 735 | if (arg && (strstr(arg, "net:") == arg || strstr(arg, "tag:") == arg)) |
| 736 | return 1; |
| 737 | |
| 738 | return 0; |
| 739 | } |
| 740 | |
| 741 | static char *set_prefix(char *arg) |
| 742 | { |
| 743 | if (strstr(arg, "set:") == arg) |
| 744 | return arg+4; |
| 745 | |
| 746 | return arg; |
| 747 | } |
| 748 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 749 | /* This is too insanely large to keep in-line in the switch */ |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 750 | static int parse_dhcp_opt(char *errstr, char *arg, int flags) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 751 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 752 | struct dhcp_opt *new = opt_malloc(sizeof(struct dhcp_opt)); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 753 | char lenchar = 0, *cp; |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 754 | int addrs, digs, is_addr, is_addr6, is_hex, is_dec, is_string, dots; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 755 | char *comma = NULL; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 756 | struct dhcp_netid *np = NULL; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 757 | u16 opt_len = 0; |
| 758 | int is6 = 0; |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 759 | int option_ok = 0; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 760 | |
| 761 | new->len = 0; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 762 | new->flags = flags; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 763 | new->netid = NULL; |
| 764 | new->val = NULL; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 765 | new->opt = 0; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 766 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 767 | while (arg) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 768 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 769 | comma = split(arg); |
| 770 | |
| 771 | for (cp = arg; *cp; cp++) |
| 772 | if (*cp < '0' || *cp > '9') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 773 | break; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 774 | |
| 775 | if (!*cp) |
| 776 | { |
| 777 | new->opt = atoi(arg); |
| 778 | opt_len = 0; |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 779 | option_ok = 1; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 780 | break; |
| 781 | } |
| 782 | |
| 783 | if (strstr(arg, "option:") == arg) |
| 784 | { |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 785 | if ((new->opt = lookup_dhcp_opt(AF_INET, arg+7)) != -1) |
| 786 | { |
| 787 | opt_len = lookup_dhcp_len(AF_INET, new->opt); |
| 788 | /* option:<optname> must follow tag and vendor string. */ |
| 789 | if (!(opt_len & OT_INTERNAL) || flags == DHOPT_MATCH) |
| 790 | option_ok = 1; |
| 791 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 792 | break; |
| 793 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 794 | #ifdef HAVE_DHCP6 |
| 795 | else if (strstr(arg, "option6:") == arg) |
| 796 | { |
| 797 | for (cp = arg+8; *cp; cp++) |
| 798 | if (*cp < '0' || *cp > '9') |
| 799 | break; |
| 800 | |
| 801 | if (!*cp) |
| 802 | { |
| 803 | new->opt = atoi(arg+8); |
| 804 | opt_len = 0; |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 805 | option_ok = 1; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 806 | } |
| 807 | else |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 808 | { |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 809 | if ((new->opt = lookup_dhcp_opt(AF_INET6, arg+8)) != -1) |
| 810 | { |
| 811 | opt_len = lookup_dhcp_len(AF_INET6, new->opt); |
| 812 | if (!(opt_len & OT_INTERNAL) || flags == DHOPT_MATCH) |
| 813 | option_ok = 1; |
| 814 | } |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 815 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 816 | /* option6:<opt>|<optname> must follow tag and vendor string. */ |
| 817 | is6 = 1; |
| 818 | break; |
| 819 | } |
| 820 | #endif |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 821 | else if (strstr(arg, "vendor:") == arg) |
| 822 | { |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 823 | new->u.vendor_class = (unsigned char *)opt_string_alloc(arg+7); |
| 824 | new->flags |= DHOPT_VENDOR; |
| 825 | } |
| 826 | else if (strstr(arg, "encap:") == arg) |
| 827 | { |
| 828 | new->u.encap = atoi(arg+6); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 829 | new->flags |= DHOPT_ENCAPSULATE; |
| 830 | } |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 831 | else if (strstr(arg, "vi-encap:") == arg) |
| 832 | { |
| 833 | new->u.encap = atoi(arg+9); |
| 834 | new->flags |= DHOPT_RFC3925; |
| 835 | if (flags == DHOPT_MATCH) |
| 836 | { |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 837 | option_ok = 1; |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 838 | break; |
| 839 | } |
| 840 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 841 | else |
| 842 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 843 | new->netid = opt_malloc(sizeof (struct dhcp_netid)); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 844 | /* allow optional "net:" or "tag:" for consistency */ |
| 845 | if (is_tag_prefix(arg)) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 846 | new->netid->net = opt_string_alloc(arg+4); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 847 | else |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 848 | new->netid->net = opt_string_alloc(set_prefix(arg)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 849 | new->netid->next = np; |
| 850 | np = new->netid; |
| 851 | } |
| 852 | |
| 853 | arg = comma; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 854 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 855 | |
| 856 | #ifdef HAVE_DHCP6 |
| 857 | if (is6) |
| 858 | { |
| 859 | if (new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 860 | ret_err(_("unsupported encapsulation for IPv6 option")); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 861 | |
| 862 | if (opt_len == 0 && |
| 863 | !(new->flags & DHOPT_RFC3925)) |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 864 | opt_len = lookup_dhcp_len(AF_INET6, new->opt); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 865 | } |
| 866 | else |
| 867 | #endif |
| 868 | if (opt_len == 0 && |
| 869 | !(new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE | DHOPT_RFC3925))) |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 870 | opt_len = lookup_dhcp_len(AF_INET, new->opt); |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 871 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 872 | /* option may be missing with rfc3925 match */ |
Simon Kelley | bd08ae6 | 2013-04-19 10:22:06 +0100 | [diff] [blame] | 873 | if (!option_ok) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 874 | ret_err(_("bad dhcp-option")); |
| 875 | |
| 876 | if (comma) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 877 | { |
| 878 | /* characterise the value */ |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 879 | char c; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 880 | int found_dig = 0; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 881 | is_addr = is_addr6 = is_hex = is_dec = is_string = 1; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 882 | addrs = digs = 1; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 883 | dots = 0; |
| 884 | for (cp = comma; (c = *cp); cp++) |
| 885 | if (c == ',') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 886 | { |
| 887 | addrs++; |
| 888 | is_dec = is_hex = 0; |
| 889 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 890 | else if (c == ':') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 891 | { |
| 892 | digs++; |
| 893 | is_dec = is_addr = 0; |
| 894 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 895 | else if (c == '/') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 896 | { |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 897 | is_addr6 = is_dec = is_hex = 0; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 898 | if (cp == comma) /* leading / means a pathname */ |
| 899 | is_addr = 0; |
| 900 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 901 | else if (c == '.') |
| 902 | { |
Simon Kelley | 23245c0 | 2012-07-18 16:21:11 +0100 | [diff] [blame] | 903 | is_addr6 = is_dec = is_hex = 0; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 904 | dots++; |
| 905 | } |
| 906 | else if (c == '-') |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 907 | is_hex = is_addr = is_addr6 = 0; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 908 | else if (c == ' ') |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 909 | is_dec = is_hex = 0; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 910 | else if (!(c >='0' && c <= '9')) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 911 | { |
| 912 | is_addr = 0; |
| 913 | if (cp[1] == 0 && is_dec && |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 914 | (c == 'b' || c == 's' || c == 'i')) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 915 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 916 | lenchar = c; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 917 | *cp = 0; |
| 918 | } |
| 919 | else |
| 920 | is_dec = 0; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 921 | if (!((c >='A' && c <= 'F') || |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 922 | (c >='a' && c <= 'f') || |
| 923 | (c == '*' && (flags & DHOPT_MATCH)))) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 924 | { |
| 925 | is_hex = 0; |
| 926 | if (c != '[' && c != ']') |
| 927 | is_addr6 = 0; |
| 928 | } |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 929 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 930 | else |
| 931 | found_dig = 1; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 932 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 933 | if (!found_dig) |
| 934 | is_dec = is_addr = 0; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 935 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 936 | /* We know that some options take addresses */ |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 937 | if (opt_len & OT_ADDR_LIST) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 938 | { |
| 939 | is_string = is_dec = is_hex = 0; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 940 | |
| 941 | if (!is6 && (!is_addr || dots == 0)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 942 | ret_err(_("bad IP address")); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 943 | |
| 944 | if (is6 && !is_addr6) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 945 | ret_err(_("bad IPv6 address")); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 946 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 947 | /* or names */ |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 948 | else if (opt_len & (OT_NAME | OT_RFC1035_NAME | OT_CSTRING)) |
| 949 | is_addr6 = is_addr = is_dec = is_hex = 0; |
Simon Kelley | 23245c0 | 2012-07-18 16:21:11 +0100 | [diff] [blame] | 950 | |
| 951 | if (found_dig && (opt_len & OT_TIME) && strlen(comma) > 0) |
| 952 | { |
| 953 | int val, fac = 1; |
| 954 | |
| 955 | switch (comma[strlen(comma) - 1]) |
| 956 | { |
Simon Kelley | 4224321 | 2012-07-20 15:19:18 +0100 | [diff] [blame] | 957 | case 'w': |
| 958 | case 'W': |
| 959 | fac *= 7; |
| 960 | /* fall through */ |
Simon Kelley | 23245c0 | 2012-07-18 16:21:11 +0100 | [diff] [blame] | 961 | case 'd': |
| 962 | case 'D': |
| 963 | fac *= 24; |
| 964 | /* fall though */ |
| 965 | case 'h': |
| 966 | case 'H': |
| 967 | fac *= 60; |
| 968 | /* fall through */ |
| 969 | case 'm': |
| 970 | case 'M': |
| 971 | fac *= 60; |
| 972 | /* fall through */ |
| 973 | case 's': |
| 974 | case 'S': |
| 975 | comma[strlen(comma) - 1] = 0; |
| 976 | } |
| 977 | |
| 978 | new->len = 4; |
| 979 | new->val = opt_malloc(4); |
| 980 | val = atoi(comma); |
| 981 | *((int *)new->val) = htonl(val * fac); |
| 982 | } |
| 983 | else if (is_hex && digs > 1) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 984 | { |
| 985 | new->len = digs; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 986 | new->val = opt_malloc(new->len); |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 987 | parse_hex(comma, new->val, digs, (flags & DHOPT_MATCH) ? &new->u.wildcard_mask : NULL, NULL); |
| 988 | new->flags |= DHOPT_HEX; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 989 | } |
| 990 | else if (is_dec) |
| 991 | { |
| 992 | int i, val = atoi(comma); |
| 993 | /* assume numeric arg is 1 byte except for |
| 994 | options where it is known otherwise. |
| 995 | For vendor class option, we have to hack. */ |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 996 | if (opt_len != 0) |
| 997 | new->len = opt_len; |
| 998 | else if (val & 0xffff0000) |
| 999 | new->len = 4; |
| 1000 | else if (val & 0xff00) |
| 1001 | new->len = 2; |
| 1002 | else |
| 1003 | new->len = 1; |
| 1004 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1005 | if (lenchar == 'b') |
| 1006 | new->len = 1; |
| 1007 | else if (lenchar == 's') |
| 1008 | new->len = 2; |
| 1009 | else if (lenchar == 'i') |
| 1010 | new->len = 4; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1011 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1012 | new->val = opt_malloc(new->len); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1013 | for (i=0; i<new->len; i++) |
| 1014 | new->val[i] = val>>((new->len - i - 1)*8); |
| 1015 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1016 | else if (is_addr && !is6) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1017 | { |
| 1018 | struct in_addr in; |
| 1019 | unsigned char *op; |
| 1020 | char *slash; |
| 1021 | /* max length of address/subnet descriptor is five bytes, |
| 1022 | add one for the option 120 enc byte too */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1023 | new->val = op = opt_malloc((5 * addrs) + 1); |
Simon Kelley | 6b01084 | 2007-02-12 20:32:07 +0000 | [diff] [blame] | 1024 | new->flags |= DHOPT_ADDR; |
| 1025 | |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1026 | if (!(new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925)) && |
| 1027 | new->opt == OPTION_SIP_SERVER) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1028 | { |
Simon Kelley | 6b01084 | 2007-02-12 20:32:07 +0000 | [diff] [blame] | 1029 | *(op++) = 1; /* RFC 3361 "enc byte" */ |
| 1030 | new->flags &= ~DHOPT_ADDR; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1031 | } |
| 1032 | while (addrs--) |
| 1033 | { |
| 1034 | cp = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1035 | comma = split(cp); |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1036 | slash = split_chr(cp, '/'); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 1037 | inet_pton(AF_INET, cp, &in); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1038 | if (!slash) |
| 1039 | { |
| 1040 | memcpy(op, &in, INADDRSZ); |
| 1041 | op += INADDRSZ; |
| 1042 | } |
| 1043 | else |
| 1044 | { |
| 1045 | unsigned char *p = (unsigned char *)∈ |
| 1046 | int netsize = atoi(slash); |
| 1047 | *op++ = netsize; |
| 1048 | if (netsize > 0) |
| 1049 | *op++ = *p++; |
| 1050 | if (netsize > 8) |
| 1051 | *op++ = *p++; |
| 1052 | if (netsize > 16) |
| 1053 | *op++ = *p++; |
| 1054 | if (netsize > 24) |
| 1055 | *op++ = *p++; |
| 1056 | new->flags &= ~DHOPT_ADDR; /* cannot re-write descriptor format */ |
| 1057 | } |
| 1058 | } |
| 1059 | new->len = op - new->val; |
| 1060 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1061 | else if (is_addr6 && is6) |
| 1062 | { |
| 1063 | unsigned char *op; |
| 1064 | new->val = op = opt_malloc(16 * addrs); |
| 1065 | new->flags |= DHOPT_ADDR6; |
| 1066 | while (addrs--) |
| 1067 | { |
| 1068 | cp = comma; |
| 1069 | comma = split(cp); |
| 1070 | |
| 1071 | /* check for [1234::7] */ |
| 1072 | if (*cp == '[') |
| 1073 | cp++; |
| 1074 | if (strlen(cp) > 1 && cp[strlen(cp)-1] == ']') |
| 1075 | cp[strlen(cp)-1] = 0; |
| 1076 | |
| 1077 | if (inet_pton(AF_INET6, cp, op)) |
| 1078 | { |
| 1079 | op += IN6ADDRSZ; |
| 1080 | continue; |
| 1081 | } |
| 1082 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1083 | ret_err(_("bad IPv6 address")); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1084 | } |
| 1085 | new->len = op - new->val; |
| 1086 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1087 | else if (is_string) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1088 | { |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1089 | /* text arg */ |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1090 | if ((new->opt == OPTION_DOMAIN_SEARCH || new->opt == OPTION_SIP_SERVER) && |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1091 | !is6 && !(new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR | DHOPT_RFC3925))) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1092 | { |
| 1093 | /* dns search, RFC 3397, or SIP, RFC 3361 */ |
| 1094 | unsigned char *q, *r, *tail; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1095 | unsigned char *p, *m = NULL, *newp; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1096 | size_t newlen, len = 0; |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1097 | int header_size = (new->opt == OPTION_DOMAIN_SEARCH) ? 0 : 1; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1098 | |
| 1099 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1100 | comma = split(arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1101 | |
| 1102 | while (arg && *arg) |
| 1103 | { |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1104 | char *in, *dom = NULL; |
| 1105 | size_t domlen = 1; |
| 1106 | /* Allow "." as an empty domain */ |
| 1107 | if (strcmp (arg, ".") != 0) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1108 | { |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1109 | if (!(dom = canonicalise_opt(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1110 | ret_err(_("bad domain in dhcp-option")); |
| 1111 | |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1112 | domlen = strlen(dom) + 2; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1113 | } |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1114 | |
| 1115 | newp = opt_malloc(len + domlen + header_size); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1116 | if (m) |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1117 | { |
| 1118 | memcpy(newp, m, header_size + len); |
| 1119 | free(m); |
| 1120 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1121 | m = newp; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1122 | p = m + header_size; |
| 1123 | q = p + len; |
| 1124 | |
| 1125 | /* add string on the end in RFC1035 format */ |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1126 | for (in = dom; in && *in;) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1127 | { |
| 1128 | unsigned char *cp = q++; |
| 1129 | int j; |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1130 | for (j = 0; *in && (*in != '.'); in++, j++) |
| 1131 | *q++ = *in; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1132 | *cp = j; |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1133 | if (*in) |
| 1134 | in++; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1135 | } |
| 1136 | *q++ = 0; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1137 | free(dom); |
Simon Kelley | c52e189 | 2010-06-07 22:01:39 +0100 | [diff] [blame] | 1138 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1139 | /* Now tail-compress using earlier names. */ |
| 1140 | newlen = q - p; |
| 1141 | for (tail = p + len; *tail; tail += (*tail) + 1) |
| 1142 | for (r = p; r - p < (int)len; r += (*r) + 1) |
| 1143 | if (strcmp((char *)r, (char *)tail) == 0) |
| 1144 | { |
| 1145 | PUTSHORT((r - p) | 0xc000, tail); |
| 1146 | newlen = tail - p; |
| 1147 | goto end; |
| 1148 | } |
| 1149 | end: |
| 1150 | len = newlen; |
| 1151 | |
| 1152 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1153 | comma = split(arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1154 | } |
| 1155 | |
| 1156 | /* RFC 3361, enc byte is zero for names */ |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1157 | if (new->opt == OPTION_SIP_SERVER) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1158 | m[0] = 0; |
| 1159 | new->len = (int) len + header_size; |
| 1160 | new->val = m; |
| 1161 | } |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1162 | #ifdef HAVE_DHCP6 |
| 1163 | else if (comma && (opt_len & OT_CSTRING)) |
| 1164 | { |
| 1165 | /* length fields are two bytes so need 16 bits for each string */ |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1166 | int i, commas = 1; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1167 | unsigned char *p, *newp; |
| 1168 | |
Simon Kelley | 40ef23b | 2012-03-13 21:59:28 +0000 | [diff] [blame] | 1169 | for (i = 0; comma[i]; i++) |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1170 | if (comma[i] == ',') |
| 1171 | commas++; |
| 1172 | |
| 1173 | newp = opt_malloc(strlen(comma)+(2*commas)); |
| 1174 | p = newp; |
| 1175 | arg = comma; |
| 1176 | comma = split(arg); |
| 1177 | |
| 1178 | while (arg && *arg) |
| 1179 | { |
| 1180 | u16 len = strlen(arg); |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1181 | unhide_metas(arg); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1182 | PUTSHORT(len, p); |
| 1183 | memcpy(p, arg, len); |
| 1184 | p += len; |
| 1185 | |
| 1186 | arg = comma; |
| 1187 | comma = split(arg); |
| 1188 | } |
| 1189 | |
| 1190 | new->val = newp; |
| 1191 | new->len = p - newp; |
| 1192 | } |
| 1193 | else if (comma && (opt_len & OT_RFC1035_NAME)) |
| 1194 | { |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1195 | unsigned char *p = NULL, *newp, *end; |
| 1196 | int len = 0; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1197 | arg = comma; |
| 1198 | comma = split(arg); |
| 1199 | |
| 1200 | while (arg && *arg) |
| 1201 | { |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1202 | char *dom = canonicalise_opt(arg); |
| 1203 | if (!dom) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1204 | ret_err(_("bad domain in dhcp-option")); |
| 1205 | |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1206 | newp = opt_malloc(len + strlen(dom) + 2); |
| 1207 | |
| 1208 | if (p) |
| 1209 | { |
| 1210 | memcpy(newp, p, len); |
| 1211 | free(p); |
| 1212 | } |
| 1213 | |
| 1214 | p = newp; |
| 1215 | end = do_rfc1035_name(p + len, dom); |
| 1216 | *end++ = 0; |
| 1217 | len = end - p; |
| 1218 | free(dom); |
| 1219 | |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1220 | arg = comma; |
| 1221 | comma = split(arg); |
| 1222 | } |
| 1223 | |
Simon Kelley | 18f0fb0 | 2012-03-31 21:18:55 +0100 | [diff] [blame] | 1224 | new->val = p; |
| 1225 | new->len = len; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1226 | } |
| 1227 | #endif |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1228 | else |
| 1229 | { |
| 1230 | new->len = strlen(comma); |
| 1231 | /* keep terminating zero on string */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1232 | new->val = (unsigned char *)opt_string_alloc(comma); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1233 | new->flags |= DHOPT_STRING; |
| 1234 | } |
| 1235 | } |
| 1236 | } |
| 1237 | |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1238 | if (!is6 && |
| 1239 | ((new->len > 255) || |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 1240 | (new->len > 253 && (new->flags & (DHOPT_VENDOR | DHOPT_ENCAPSULATE))) || |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1241 | (new->len > 250 && (new->flags & DHOPT_RFC3925)))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1242 | ret_err(_("dhcp-option too long")); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1243 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1244 | if (flags == DHOPT_MATCH) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1245 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1246 | if ((new->flags & (DHOPT_ENCAPSULATE | DHOPT_VENDOR)) || |
| 1247 | !new->netid || |
| 1248 | new->netid->next) |
| 1249 | ret_err(_("illegal dhcp-match")); |
| 1250 | |
| 1251 | if (is6) |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1252 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1253 | new->next = daemon->dhcp_match6; |
| 1254 | daemon->dhcp_match6 = new; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 1255 | } |
| 1256 | else |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1257 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1258 | new->next = daemon->dhcp_match; |
| 1259 | daemon->dhcp_match = new; |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 1260 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1261 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1262 | else if (is6) |
| 1263 | { |
| 1264 | new->next = daemon->dhcp_opts6; |
| 1265 | daemon->dhcp_opts6 = new; |
| 1266 | } |
| 1267 | else |
| 1268 | { |
| 1269 | new->next = daemon->dhcp_opts; |
| 1270 | daemon->dhcp_opts = new; |
| 1271 | } |
| 1272 | |
| 1273 | return 1; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1274 | } |
| 1275 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1276 | #endif |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1277 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1278 | void set_option_bool(unsigned int opt) |
| 1279 | { |
| 1280 | if (opt < 32) |
| 1281 | daemon->options |= 1u << opt; |
| 1282 | else |
| 1283 | daemon->options2 |= 1u << (opt - 32); |
| 1284 | } |
| 1285 | |
Simon Kelley | 2b5bae9 | 2012-06-26 16:55:23 +0100 | [diff] [blame] | 1286 | void reset_option_bool(unsigned int opt) |
| 1287 | { |
| 1288 | if (opt < 32) |
| 1289 | daemon->options &= ~(1u << opt); |
| 1290 | else |
| 1291 | daemon->options2 &= ~(1u << (opt - 32)); |
| 1292 | } |
| 1293 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1294 | static int one_opt(int option, char *arg, char *errstr, char *gen_err, int command_line) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1295 | { |
| 1296 | int i; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1297 | char *comma; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1298 | |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1299 | if (option == '?') |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1300 | ret_err(gen_err); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 1301 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1302 | for (i=0; usage[i].opt != 0; i++) |
| 1303 | if (usage[i].opt == option) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1304 | { |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1305 | int rept = usage[i].rept; |
| 1306 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1307 | if (command_line) |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1308 | { |
| 1309 | /* command line */ |
| 1310 | if (rept == ARG_USED_CL) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1311 | ret_err(_("illegal repeated flag")); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1312 | if (rept == ARG_ONE) |
| 1313 | usage[i].rept = ARG_USED_CL; |
| 1314 | } |
| 1315 | else |
| 1316 | { |
| 1317 | /* allow file to override command line */ |
| 1318 | if (rept == ARG_USED_FILE) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1319 | ret_err(_("illegal repeated keyword")); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1320 | if (rept == ARG_USED_CL || rept == ARG_ONE) |
| 1321 | usage[i].rept = ARG_USED_FILE; |
| 1322 | } |
| 1323 | |
| 1324 | if (rept != ARG_DUP && rept != ARG_ONE && rept != ARG_USED_CL) |
| 1325 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1326 | set_option_bool(rept); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1327 | return 1; |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1328 | } |
| 1329 | |
| 1330 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1331 | } |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1332 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1333 | switch (option) |
| 1334 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1335 | case 'C': /* --conf-file */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1336 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1337 | char *file = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1338 | if (file) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1339 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1340 | one_file(file, 0); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1341 | free(file); |
| 1342 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1343 | break; |
| 1344 | } |
| 1345 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1346 | case '7': /* --conf-dir */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1347 | { |
| 1348 | DIR *dir_stream; |
| 1349 | struct dirent *ent; |
| 1350 | char *directory, *path; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1351 | struct list { |
| 1352 | char *suffix; |
| 1353 | struct list *next; |
| 1354 | } *ignore_suffix = NULL, *li; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1355 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1356 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1357 | if (!(directory = opt_string_alloc(arg))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1358 | break; |
| 1359 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1360 | for (arg = comma; arg; arg = comma) |
| 1361 | { |
| 1362 | comma = split(arg); |
| 1363 | li = opt_malloc(sizeof(struct list)); |
| 1364 | li->next = ignore_suffix; |
| 1365 | ignore_suffix = li; |
| 1366 | /* Have to copy: buffer is overwritten */ |
| 1367 | li->suffix = opt_string_alloc(arg); |
| 1368 | }; |
| 1369 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1370 | if (!(dir_stream = opendir(directory))) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1371 | die(_("cannot access directory %s: %s"), directory, EC_FILE); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1372 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1373 | while ((ent = readdir(dir_stream))) |
| 1374 | { |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1375 | size_t len = strlen(ent->d_name); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1376 | struct stat buf; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1377 | |
| 1378 | /* ignore emacs backups and dotfiles */ |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1379 | if (len == 0 || |
| 1380 | ent->d_name[len - 1] == '~' || |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1381 | (ent->d_name[0] == '#' && ent->d_name[len - 1] == '#') || |
| 1382 | ent->d_name[0] == '.') |
| 1383 | continue; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1384 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1385 | for (li = ignore_suffix; li; li = li->next) |
| 1386 | { |
| 1387 | /* check for proscribed suffices */ |
| 1388 | size_t ls = strlen(li->suffix); |
| 1389 | if (len > ls && |
| 1390 | strcmp(li->suffix, &ent->d_name[len - ls]) == 0) |
| 1391 | break; |
| 1392 | } |
| 1393 | if (li) |
| 1394 | continue; |
| 1395 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1396 | path = opt_malloc(strlen(directory) + len + 2); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1397 | strcpy(path, directory); |
| 1398 | strcat(path, "/"); |
| 1399 | strcat(path, ent->d_name); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1400 | |
Simon Kelley | 39595cf | 2013-02-04 21:40:07 +0000 | [diff] [blame] | 1401 | /* files must be readable */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1402 | if (stat(path, &buf) == -1) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1403 | die(_("cannot access %s: %s"), path, EC_FILE); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1404 | |
Simon Kelley | 39595cf | 2013-02-04 21:40:07 +0000 | [diff] [blame] | 1405 | /* only reg files allowed. */ |
| 1406 | if (S_ISREG(buf.st_mode)) |
| 1407 | one_file(path, 0); |
| 1408 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1409 | free(path); |
| 1410 | } |
| 1411 | |
| 1412 | closedir(dir_stream); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1413 | free(directory); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1414 | for(; ignore_suffix; ignore_suffix = li) |
| 1415 | { |
| 1416 | li = ignore_suffix->next; |
| 1417 | free(ignore_suffix->suffix); |
| 1418 | free(ignore_suffix); |
| 1419 | } |
| 1420 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1421 | break; |
| 1422 | } |
| 1423 | |
Simon Kelley | ad09427 | 2012-08-10 17:10:54 +0100 | [diff] [blame] | 1424 | case '1': /* --enable-dbus */ |
| 1425 | set_option_bool(OPT_DBUS); |
| 1426 | if (arg) |
| 1427 | daemon->dbus_name = opt_string_alloc(arg); |
| 1428 | else |
| 1429 | daemon->dbus_name = DNSMASQ_SERVICE; |
| 1430 | break; |
| 1431 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1432 | case '8': /* --log-facility */ |
| 1433 | /* may be a filename */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 1434 | if (strchr(arg, '/') || strcmp (arg, "-") == 0) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1435 | daemon->log_file = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1436 | else |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1437 | { |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1438 | #ifdef __ANDROID__ |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1439 | ret_err(_("setting log facility is not possible under Android")); |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1440 | #else |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1441 | for (i = 0; facilitynames[i].c_name; i++) |
| 1442 | if (hostname_isequal((char *)facilitynames[i].c_name, arg)) |
| 1443 | break; |
| 1444 | |
| 1445 | if (facilitynames[i].c_name) |
| 1446 | daemon->log_fac = facilitynames[i].c_val; |
| 1447 | else |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1448 | ret_err(_("bad log facility")); |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 1449 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1450 | } |
| 1451 | break; |
| 1452 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1453 | case 'x': /* --pid-file */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1454 | daemon->runfile = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1455 | break; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 1456 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1457 | case 'r': /* --resolv-file */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1458 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1459 | char *name = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1460 | struct resolvc *new, *list = daemon->resolv_files; |
| 1461 | |
| 1462 | if (list && list->is_default) |
| 1463 | { |
| 1464 | /* replace default resolv file - possibly with nothing */ |
| 1465 | if (name) |
| 1466 | { |
| 1467 | list->is_default = 0; |
| 1468 | list->name = name; |
| 1469 | } |
| 1470 | else |
| 1471 | list = NULL; |
| 1472 | } |
| 1473 | else if (name) |
| 1474 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1475 | new = opt_malloc(sizeof(struct resolvc)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1476 | new->next = list; |
| 1477 | new->name = name; |
| 1478 | new->is_default = 0; |
| 1479 | new->mtime = 0; |
| 1480 | new->logged = 0; |
| 1481 | list = new; |
| 1482 | } |
| 1483 | daemon->resolv_files = list; |
| 1484 | break; |
| 1485 | } |
| 1486 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1487 | case 'm': /* --mx-host */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1488 | { |
| 1489 | int pref = 1; |
| 1490 | struct mx_srv_record *new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1491 | char *name, *target = NULL; |
| 1492 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1493 | if ((comma = split(arg))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1494 | { |
| 1495 | char *prefstr; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1496 | if ((prefstr = split(comma)) && !atoi_check16(prefstr, &pref)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1497 | ret_err(_("bad MX preference")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1498 | } |
| 1499 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1500 | if (!(name = canonicalise_opt(arg)) || |
| 1501 | (comma && !(target = canonicalise_opt(comma)))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1502 | ret_err(_("bad MX name")); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1503 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1504 | new = opt_malloc(sizeof(struct mx_srv_record)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1505 | new->next = daemon->mxnames; |
| 1506 | daemon->mxnames = new; |
| 1507 | new->issrv = 0; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1508 | new->name = name; |
| 1509 | new->target = target; /* may be NULL */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1510 | new->weight = pref; |
| 1511 | break; |
| 1512 | } |
| 1513 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1514 | case 't': /* --mx-target */ |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1515 | if (!(daemon->mxtarget = canonicalise_opt(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1516 | ret_err(_("bad MX target")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1517 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1518 | |
| 1519 | #ifdef HAVE_DHCP |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1520 | case 'l': /* --dhcp-leasefile */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1521 | daemon->lease_file = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1522 | break; |
| 1523 | |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 1524 | /* Sorry about the gross pre-processor abuse */ |
| 1525 | case '6': /* --dhcp-script */ |
| 1526 | case LOPT_LUASCRIPT: /* --dhcp-luascript */ |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1527 | # if defined(NO_FORK) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1528 | ret_err(_("cannot run scripts under uClinux")); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1529 | # elif !defined(HAVE_SCRIPT) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1530 | ret_err(_("recompile with HAVE_SCRIPT defined to enable lease-change scripts")); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1531 | # else |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 1532 | if (option == LOPT_LUASCRIPT) |
| 1533 | # if !defined(HAVE_LUASCRIPT) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1534 | ret_err(_("recompile with HAVE_LUASCRIPT defined to enable Lua scripts")); |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 1535 | # else |
| 1536 | daemon->luascript = opt_string_alloc(arg); |
| 1537 | # endif |
| 1538 | else |
| 1539 | daemon->lease_change_command = opt_string_alloc(arg); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1540 | # endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1541 | break; |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 1542 | #endif /* HAVE_DHCP */ |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1543 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1544 | case LOPT_DHCP_HOST: /* --dhcp-hostfile */ |
| 1545 | case LOPT_DHCP_OPTS: /* --dhcp-optsfile */ |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1546 | case 'H': /* --addn-hosts */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1547 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1548 | struct hostsfile *new = opt_malloc(sizeof(struct hostsfile)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1549 | static int hosts_index = 1; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1550 | new->fname = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1551 | new->index = hosts_index++; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1552 | new->flags = 0; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1553 | if (option == 'H') |
| 1554 | { |
| 1555 | new->next = daemon->addn_hosts; |
| 1556 | daemon->addn_hosts = new; |
| 1557 | } |
| 1558 | else if (option == LOPT_DHCP_HOST) |
| 1559 | { |
| 1560 | new->next = daemon->dhcp_hosts_file; |
| 1561 | daemon->dhcp_hosts_file = new; |
| 1562 | } |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 1563 | else if (option == LOPT_DHCP_OPTS) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1564 | { |
| 1565 | new->next = daemon->dhcp_opts_file; |
| 1566 | daemon->dhcp_opts_file = new; |
| 1567 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1568 | break; |
| 1569 | } |
| 1570 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1571 | case LOPT_AUTHSERV: /* --auth-server */ |
Simon Kelley | 86e3b9a | 2012-11-30 13:46:48 +0000 | [diff] [blame] | 1572 | if (!(comma = split(arg))) |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1573 | ret_err(gen_err); |
| 1574 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1575 | daemon->authserver = opt_string_alloc(arg); |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 1576 | arg = comma; |
| 1577 | do { |
| 1578 | struct iname *new = opt_malloc(sizeof(struct iname)); |
| 1579 | comma = split(arg); |
| 1580 | new->name = NULL; |
| 1581 | unhide_metas(arg); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 1582 | if (inet_pton(AF_INET, arg, &new->addr.in.sin_addr) > 0) |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 1583 | new->addr.sa.sa_family = AF_INET; |
| 1584 | #ifdef HAVE_IPV6 |
| 1585 | else if (inet_pton(AF_INET6, arg, &new->addr.in6.sin6_addr) > 0) |
| 1586 | new->addr.sa.sa_family = AF_INET6; |
| 1587 | #endif |
| 1588 | else |
| 1589 | new->name = opt_string_alloc(arg); |
| 1590 | |
| 1591 | new->next = daemon->authinterface; |
| 1592 | daemon->authinterface = new; |
| 1593 | |
| 1594 | arg = comma; |
| 1595 | } while (arg); |
| 1596 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1597 | break; |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 1598 | |
| 1599 | case LOPT_AUTHSFS: /* --auth-sec-servers */ |
| 1600 | { |
| 1601 | struct name_list *new; |
| 1602 | |
| 1603 | do { |
| 1604 | comma = split(arg); |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 1605 | new = opt_malloc(sizeof(struct name_list)); |
Simon Kelley | e1ff419 | 2012-12-09 17:08:47 +0000 | [diff] [blame] | 1606 | new->name = opt_string_alloc(arg); |
| 1607 | new->next = daemon->secondary_forward_server; |
| 1608 | daemon->secondary_forward_server = new; |
| 1609 | arg = comma; |
| 1610 | } while (arg); |
| 1611 | break; |
| 1612 | } |
| 1613 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1614 | case LOPT_AUTHZONE: /* --auth-zone */ |
| 1615 | { |
| 1616 | struct auth_zone *new; |
| 1617 | |
| 1618 | comma = split(arg); |
Simon Kelley | 1e14cc0 | 2012-12-29 17:27:59 +0000 | [diff] [blame] | 1619 | |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 1620 | new = opt_malloc(sizeof(struct auth_zone)); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1621 | new->domain = opt_string_alloc(arg); |
| 1622 | new->subnet = NULL; |
| 1623 | new->next = daemon->auth_zones; |
| 1624 | daemon->auth_zones = new; |
| 1625 | |
| 1626 | while ((arg = comma)) |
| 1627 | { |
| 1628 | int prefixlen = 0; |
| 1629 | char *prefix; |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 1630 | struct subnet *subnet = opt_malloc(sizeof(struct subnet)); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1631 | |
| 1632 | subnet->next = new->subnet; |
| 1633 | new->subnet = subnet; |
| 1634 | |
| 1635 | comma = split(arg); |
| 1636 | prefix = split_chr(arg, '/'); |
| 1637 | |
| 1638 | if (prefix && !atoi_check(prefix, &prefixlen)) |
| 1639 | ret_err(gen_err); |
| 1640 | |
| 1641 | if (inet_pton(AF_INET, arg, &subnet->addr4)) |
| 1642 | { |
| 1643 | subnet->prefixlen = (prefixlen == 0) ? 24 : prefixlen; |
| 1644 | subnet->is6 = 0; |
| 1645 | } |
| 1646 | #ifdef HAVE_IPV6 |
| 1647 | else if (inet_pton(AF_INET6, arg, &subnet->addr6)) |
| 1648 | { |
| 1649 | subnet->prefixlen = (prefixlen == 0) ? 64 : prefixlen; |
| 1650 | subnet->is6 = 1; |
| 1651 | } |
| 1652 | #endif |
| 1653 | else |
| 1654 | ret_err(gen_err); |
| 1655 | } |
| 1656 | break; |
| 1657 | } |
| 1658 | |
| 1659 | case LOPT_AUTHSOA: /* --auth-soa */ |
| 1660 | comma = split(arg); |
Simon Kelley | 5c72bb9 | 2013-08-19 14:12:59 +0100 | [diff] [blame] | 1661 | daemon->soa_sn = (u32)atoi(arg); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1662 | if (comma) |
| 1663 | { |
Simon Kelley | 86e3b9a | 2012-11-30 13:46:48 +0000 | [diff] [blame] | 1664 | char *cp; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1665 | arg = comma; |
| 1666 | comma = split(arg); |
| 1667 | daemon->hostmaster = opt_string_alloc(arg); |
Simon Kelley | 86e3b9a | 2012-11-30 13:46:48 +0000 | [diff] [blame] | 1668 | for (cp = daemon->hostmaster; *cp; cp++) |
| 1669 | if (*cp == '@') |
| 1670 | *cp = '.'; |
| 1671 | |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1672 | if (comma) |
| 1673 | { |
| 1674 | arg = comma; |
| 1675 | comma = split(arg); |
Simon Kelley | 5c72bb9 | 2013-08-19 14:12:59 +0100 | [diff] [blame] | 1676 | daemon->soa_refresh = (u32)atoi(arg); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1677 | if (comma) |
| 1678 | { |
| 1679 | arg = comma; |
| 1680 | comma = split(arg); |
Simon Kelley | 5c72bb9 | 2013-08-19 14:12:59 +0100 | [diff] [blame] | 1681 | daemon->soa_retry = (u32)atoi(arg); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1682 | if (comma) |
| 1683 | { |
| 1684 | arg = comma; |
| 1685 | comma = split(arg); |
Simon Kelley | 5c72bb9 | 2013-08-19 14:12:59 +0100 | [diff] [blame] | 1686 | daemon->soa_expiry = (u32)atoi(arg); |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 1687 | } |
| 1688 | } |
| 1689 | } |
| 1690 | } |
| 1691 | |
| 1692 | break; |
| 1693 | |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 1694 | case 's': /* --domain */ |
| 1695 | case LOPT_SYNTH: /* --synth-domain */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1696 | if (strcmp (arg, "#") == 0) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1697 | set_option_bool(OPT_RESOLV_DOMAIN); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1698 | else |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1699 | { |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1700 | char *d; |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1701 | comma = split(arg); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 1702 | if (!(d = canonicalise_opt(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1703 | ret_err(gen_err); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1704 | else |
| 1705 | { |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1706 | if (comma) |
| 1707 | { |
Simon Kelley | 429798f | 2012-12-10 20:45:53 +0000 | [diff] [blame] | 1708 | struct cond_domain *new = opt_malloc(sizeof(struct cond_domain)); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1709 | char *netpart; |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 1710 | |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 1711 | new->prefix = NULL; |
| 1712 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1713 | unhide_metas(comma); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1714 | if ((netpart = split_chr(comma, '/'))) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1715 | { |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1716 | int msize; |
| 1717 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1718 | arg = split(netpart); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1719 | if (!atoi_check(netpart, &msize)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1720 | ret_err(gen_err); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1721 | else if (inet_pton(AF_INET, comma, &new->start)) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1722 | { |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1723 | int mask = (1 << (32 - msize)) - 1; |
| 1724 | new->is6 = 0; |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1725 | new->start.s_addr = ntohl(htonl(new->start.s_addr) & ~mask); |
| 1726 | new->end.s_addr = new->start.s_addr | htonl(mask); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1727 | if (arg) |
| 1728 | { |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 1729 | if (option != 's') |
Simon Kelley | b5a7ff4 | 2013-04-25 11:03:47 +0100 | [diff] [blame] | 1730 | { |
| 1731 | if (!(new->prefix = canonicalise_opt(arg)) || |
| 1732 | strlen(new->prefix) > MAXLABEL - INET_ADDRSTRLEN) |
| 1733 | ret_err(_("bad prefix")); |
| 1734 | } |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 1735 | else if (strcmp(arg, "local") != 0 || |
| 1736 | (msize != 8 && msize != 16 && msize != 24)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1737 | ret_err(gen_err); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1738 | else |
| 1739 | { |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 1740 | /* generate the equivalent of |
| 1741 | local=/<domain>/ |
| 1742 | local=/xxx.yyy.zzz.in-addr.arpa/ */ |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1743 | struct server *serv = opt_malloc(sizeof(struct server)); |
| 1744 | in_addr_t a = ntohl(new->start.s_addr) >> 8; |
| 1745 | char *p; |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 1746 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1747 | memset(serv, 0, sizeof(struct server)); |
| 1748 | serv->domain = d; |
| 1749 | serv->flags = SERV_HAS_DOMAIN | SERV_NO_ADDR; |
| 1750 | serv->next = daemon->servers; |
| 1751 | daemon->servers = serv; |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 1752 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1753 | serv = opt_malloc(sizeof(struct server)); |
| 1754 | memset(serv, 0, sizeof(struct server)); |
| 1755 | p = serv->domain = opt_malloc(25); /* strlen("xxx.yyy.zzz.in-addr.arpa")+1 */ |
| 1756 | |
| 1757 | if (msize == 24) |
| 1758 | p += sprintf(p, "%d.", a & 0xff); |
| 1759 | a = a >> 8; |
| 1760 | if (msize != 8) |
| 1761 | p += sprintf(p, "%d.", a & 0xff); |
| 1762 | a = a >> 8; |
| 1763 | p += sprintf(p, "%d.in-addr.arpa", a & 0xff); |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 1764 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 1765 | serv->flags = SERV_HAS_DOMAIN | SERV_NO_ADDR; |
| 1766 | serv->next = daemon->servers; |
| 1767 | daemon->servers = serv; |
| 1768 | } |
| 1769 | } |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1770 | } |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1771 | #ifdef HAVE_IPV6 |
| 1772 | else if (inet_pton(AF_INET6, comma, &new->start6)) |
| 1773 | { |
| 1774 | u64 mask = (1LLU << (128 - msize)) - 1LLU; |
| 1775 | u64 addrpart = addr6part(&new->start6); |
| 1776 | new->is6 = 1; |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 1777 | |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1778 | /* prefix==64 overflows the mask calculation above */ |
| 1779 | if (msize == 64) |
| 1780 | mask = (u64)-1LL; |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 1781 | |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1782 | new->end6 = new->start6; |
| 1783 | setaddr6part(&new->start6, addrpart & ~mask); |
| 1784 | setaddr6part(&new->end6, addrpart | mask); |
| 1785 | |
| 1786 | if (msize < 64) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1787 | ret_err(gen_err); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1788 | else if (arg) |
| 1789 | { |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 1790 | if (option != 's') |
Simon Kelley | b5a7ff4 | 2013-04-25 11:03:47 +0100 | [diff] [blame] | 1791 | { |
| 1792 | if (!(new->prefix = canonicalise_opt(arg)) || |
| 1793 | strlen(new->prefix) > MAXLABEL - INET6_ADDRSTRLEN) |
| 1794 | ret_err(_("bad prefix")); |
| 1795 | } |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 1796 | else if (strcmp(arg, "local") != 0 || ((msize & 4) != 0)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1797 | ret_err(gen_err); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1798 | else |
| 1799 | { |
Simon Kelley | 48fd1c4 | 2013-04-25 09:49:38 +0100 | [diff] [blame] | 1800 | /* generate the equivalent of |
| 1801 | local=/<domain>/ |
| 1802 | local=/xxx.yyy.zzz.ip6.arpa/ */ |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1803 | struct server *serv = opt_malloc(sizeof(struct server)); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1804 | char *p; |
Simon Kelley | ceae00d | 2012-02-09 21:28:14 +0000 | [diff] [blame] | 1805 | |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1806 | memset(serv, 0, sizeof(struct server)); |
| 1807 | serv->domain = d; |
| 1808 | serv->flags = SERV_HAS_DOMAIN | SERV_NO_ADDR; |
| 1809 | serv->next = daemon->servers; |
| 1810 | daemon->servers = serv; |
| 1811 | |
| 1812 | serv = opt_malloc(sizeof(struct server)); |
| 1813 | memset(serv, 0, sizeof(struct server)); |
| 1814 | p = serv->domain = opt_malloc(73); /* strlen("32*<n.>ip6.arpa")+1 */ |
| 1815 | |
| 1816 | for (i = msize-1; i >= 0; i -= 4) |
| 1817 | { |
| 1818 | int dig = ((unsigned char *)&new->start6)[i>>3]; |
| 1819 | p += sprintf(p, "%.1x.", (i>>2) & 1 ? dig & 15 : dig >> 4); |
| 1820 | } |
| 1821 | p += sprintf(p, "ip6.arpa"); |
| 1822 | |
| 1823 | serv->flags = SERV_HAS_DOMAIN | SERV_NO_ADDR; |
| 1824 | serv->next = daemon->servers; |
| 1825 | daemon->servers = serv; |
| 1826 | } |
| 1827 | } |
| 1828 | } |
| 1829 | #endif |
| 1830 | else |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1831 | ret_err(gen_err); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1832 | } |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 1833 | else |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1834 | { |
| 1835 | arg = split(comma); |
| 1836 | if (inet_pton(AF_INET, comma, &new->start)) |
| 1837 | { |
| 1838 | new->is6 = 0; |
| 1839 | if (!arg) |
| 1840 | new->end.s_addr = new->start.s_addr; |
| 1841 | else if (!inet_pton(AF_INET, arg, &new->end)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1842 | ret_err(gen_err); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1843 | } |
| 1844 | #ifdef HAVE_IPV6 |
| 1845 | else if (inet_pton(AF_INET6, comma, &new->start6)) |
| 1846 | { |
| 1847 | new->is6 = 1; |
| 1848 | if (!arg) |
| 1849 | memcpy(&new->end6, &new->start6, IN6ADDRSZ); |
| 1850 | else if (!inet_pton(AF_INET6, arg, &new->end6)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1851 | ret_err(gen_err); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1852 | } |
| 1853 | #endif |
| 1854 | else |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1855 | ret_err(gen_err); |
Simon Kelley | d74942a | 2012-02-07 20:51:56 +0000 | [diff] [blame] | 1856 | } |
Simon Kelley | 2307eac | 2012-02-13 10:13:13 +0000 | [diff] [blame] | 1857 | |
| 1858 | new->domain = d; |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 1859 | if (option == 's') |
| 1860 | { |
| 1861 | new->next = daemon->cond_domain; |
| 1862 | daemon->cond_domain = new; |
| 1863 | } |
| 1864 | else |
| 1865 | { |
| 1866 | new->next = daemon->synth_domains; |
| 1867 | daemon->synth_domains = new; |
| 1868 | } |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1869 | } |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 1870 | else if (option == 's') |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1871 | daemon->domain_suffix = d; |
Simon Kelley | 2bb73af | 2013-04-24 17:38:19 +0100 | [diff] [blame] | 1872 | else |
| 1873 | ret_err(gen_err); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 1874 | } |
| 1875 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1876 | break; |
| 1877 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1878 | case 'u': /* --user */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1879 | daemon->username = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1880 | break; |
| 1881 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1882 | case 'g': /* --group */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1883 | daemon->groupname = opt_string_alloc(arg); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 1884 | daemon->group_set = 1; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1885 | break; |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 1886 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1887 | #ifdef HAVE_DHCP |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 1888 | case LOPT_SCRIPTUSR: /* --scriptuser */ |
| 1889 | daemon->scriptuser = opt_string_alloc(arg); |
| 1890 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 1891 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1892 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1893 | case 'i': /* --interface */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1894 | do { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1895 | struct iname *new = opt_malloc(sizeof(struct iname)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1896 | comma = split(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1897 | new->next = daemon->if_names; |
| 1898 | daemon->if_names = new; |
| 1899 | /* new->name may be NULL if someone does |
| 1900 | "interface=" to disable all interfaces except loop. */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1901 | new->name = opt_string_alloc(arg); |
Simon Kelley | 4ce4f37 | 2012-06-14 11:50:45 +0100 | [diff] [blame] | 1902 | new->used = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1903 | arg = comma; |
| 1904 | } while (arg); |
| 1905 | break; |
| 1906 | |
Simon Kelley | 2937f8a | 2013-07-29 19:49:07 +0100 | [diff] [blame] | 1907 | case LOPT_TFTP: /* --enable-tftp */ |
| 1908 | set_option_bool(OPT_TFTP); |
| 1909 | if (!arg) |
| 1910 | break; |
| 1911 | /* fall through */ |
| 1912 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1913 | case 'I': /* --except-interface */ |
| 1914 | case '2': /* --no-dhcp-interface */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1915 | do { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1916 | struct iname *new = opt_malloc(sizeof(struct iname)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1917 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1918 | new->name = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1919 | if (option == 'I') |
| 1920 | { |
| 1921 | new->next = daemon->if_except; |
| 1922 | daemon->if_except = new; |
| 1923 | } |
Simon Kelley | 2937f8a | 2013-07-29 19:49:07 +0100 | [diff] [blame] | 1924 | else if (option == LOPT_TFTP) |
| 1925 | { |
| 1926 | new->next = daemon->tftp_interfaces; |
| 1927 | daemon->tftp_interfaces = new; |
| 1928 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1929 | else |
| 1930 | { |
| 1931 | new->next = daemon->dhcp_except; |
| 1932 | daemon->dhcp_except = new; |
| 1933 | } |
| 1934 | arg = comma; |
| 1935 | } while (arg); |
| 1936 | break; |
| 1937 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1938 | case 'B': /* --bogus-nxdomain */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1939 | { |
| 1940 | struct in_addr addr; |
| 1941 | unhide_metas(arg); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 1942 | if (arg && (inet_pton(AF_INET, arg, &addr) > 0)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1943 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1944 | struct bogus_addr *baddr = opt_malloc(sizeof(struct bogus_addr)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1945 | baddr->next = daemon->bogus_addr; |
| 1946 | daemon->bogus_addr = baddr; |
| 1947 | baddr->addr = addr; |
| 1948 | } |
| 1949 | else |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1950 | ret_err(gen_err); /* error */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1951 | break; |
| 1952 | } |
| 1953 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1954 | case 'a': /* --listen-address */ |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 1955 | case LOPT_AUTHPEER: /* --auth-peer */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1956 | do { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 1957 | struct iname *new = opt_malloc(sizeof(struct iname)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 1958 | comma = split(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1959 | unhide_metas(arg); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 1960 | if (arg && (inet_pton(AF_INET, arg, &new->addr.in.sin_addr) > 0)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1961 | { |
| 1962 | new->addr.sa.sa_family = AF_INET; |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 1963 | new->addr.in.sin_port = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1964 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 1965 | new->addr.in.sin_len = sizeof(new->addr.in); |
| 1966 | #endif |
| 1967 | } |
| 1968 | #ifdef HAVE_IPV6 |
| 1969 | else if (arg && inet_pton(AF_INET6, arg, &new->addr.in6.sin6_addr) > 0) |
| 1970 | { |
| 1971 | new->addr.sa.sa_family = AF_INET6; |
| 1972 | new->addr.in6.sin6_flowinfo = 0; |
| 1973 | new->addr.in6.sin6_scope_id = 0; |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 1974 | new->addr.in6.sin6_port = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1975 | #ifdef HAVE_SOCKADDR_SA_LEN |
| 1976 | new->addr.in6.sin6_len = sizeof(new->addr.in6); |
| 1977 | #endif |
| 1978 | } |
| 1979 | #endif |
| 1980 | else |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 1981 | ret_err(gen_err); |
Simon Kelley | 4ce4f37 | 2012-06-14 11:50:45 +0100 | [diff] [blame] | 1982 | |
| 1983 | new->used = 0; |
Simon Kelley | 4967876 | 2012-12-09 18:24:58 +0000 | [diff] [blame] | 1984 | if (option == 'a') |
| 1985 | { |
| 1986 | new->next = daemon->if_addrs; |
| 1987 | daemon->if_addrs = new; |
| 1988 | } |
| 1989 | else |
| 1990 | { |
| 1991 | new->next = daemon->auth_peers; |
| 1992 | daemon->auth_peers = new; |
| 1993 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 1994 | arg = comma; |
| 1995 | } while (arg); |
| 1996 | break; |
| 1997 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 1998 | case 'S': /* --server */ |
| 1999 | case LOPT_LOCAL: /* --local */ |
| 2000 | case 'A': /* --address */ |
| 2001 | case LOPT_NO_REBIND: /* --rebind-domain-ok */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2002 | { |
| 2003 | struct server *serv, *newlist = NULL; |
| 2004 | |
| 2005 | unhide_metas(arg); |
| 2006 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2007 | if (arg && (*arg == '/' || option == LOPT_NO_REBIND)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2008 | { |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2009 | int rebind = !(*arg == '/'); |
| 2010 | char *end = NULL; |
| 2011 | if (!rebind) |
| 2012 | arg++; |
| 2013 | while (rebind || (end = split_chr(arg, '/'))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2014 | { |
| 2015 | char *domain = NULL; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2016 | /* elide leading dots - they are implied in the search algorithm */ |
| 2017 | while (*arg == '.') arg++; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2018 | /* # matches everything and becomes a zero length domain string */ |
| 2019 | if (strcmp(arg, "#") == 0) |
| 2020 | domain = ""; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 2021 | else if (strlen (arg) != 0 && !(domain = canonicalise_opt(arg))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2022 | option = '?'; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2023 | serv = opt_malloc(sizeof(struct server)); |
| 2024 | memset(serv, 0, sizeof(struct server)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2025 | serv->next = newlist; |
| 2026 | newlist = serv; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2027 | serv->domain = domain; |
| 2028 | serv->flags = domain ? SERV_HAS_DOMAIN : SERV_FOR_NODOTS; |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 2029 | arg = end; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2030 | if (rebind) |
| 2031 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2032 | } |
| 2033 | if (!newlist) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2034 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2035 | } |
| 2036 | else |
| 2037 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2038 | newlist = opt_malloc(sizeof(struct server)); |
| 2039 | memset(newlist, 0, sizeof(struct server)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2040 | } |
| 2041 | |
| 2042 | if (option == 'A') |
| 2043 | { |
| 2044 | newlist->flags |= SERV_LITERAL_ADDRESS; |
| 2045 | if (!(newlist->flags & SERV_TYPE)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2046 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2047 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2048 | else if (option == LOPT_NO_REBIND) |
| 2049 | newlist->flags |= SERV_NO_REBIND; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2050 | |
| 2051 | if (!arg || !*arg) |
| 2052 | { |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2053 | if (!(newlist->flags & SERV_NO_REBIND)) |
| 2054 | newlist->flags |= SERV_NO_ADDR; /* no server */ |
| 2055 | if (newlist->flags & SERV_LITERAL_ADDRESS) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2056 | ret_err(gen_err); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2057 | } |
| 2058 | |
| 2059 | else if (strcmp(arg, "#") == 0) |
| 2060 | { |
| 2061 | newlist->flags |= SERV_USE_RESOLV; /* treat in ordinary way */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2062 | if (newlist->flags & SERV_LITERAL_ADDRESS) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2063 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2064 | } |
| 2065 | else |
| 2066 | { |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 2067 | char *err = parse_server(arg, &newlist->addr, &newlist->source_addr, newlist->interface, &newlist->flags); |
| 2068 | if (err) |
| 2069 | ret_err(err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2070 | } |
| 2071 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2072 | serv = newlist; |
| 2073 | while (serv->next) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2074 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2075 | serv->next->flags = serv->flags; |
| 2076 | serv->next->addr = serv->addr; |
| 2077 | serv->next->source_addr = serv->source_addr; |
Simon Kelley | faafb3f | 2012-09-20 14:17:39 +0100 | [diff] [blame] | 2078 | strcpy(serv->next->interface, serv->interface); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2079 | serv = serv->next; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2080 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2081 | serv->next = daemon->servers; |
| 2082 | daemon->servers = newlist; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2083 | break; |
| 2084 | } |
Jason A. Donenfeld | 13d86c7 | 2013-02-22 18:20:53 +0000 | [diff] [blame] | 2085 | |
| 2086 | case LOPT_IPSET: /* --ipset */ |
| 2087 | #ifndef HAVE_IPSET |
| 2088 | ret_err(_("recompile with HAVE_IPSET defined to enable ipset directives")); |
| 2089 | break; |
| 2090 | #else |
| 2091 | { |
| 2092 | struct ipsets ipsets_head; |
| 2093 | struct ipsets *ipsets = &ipsets_head; |
| 2094 | int size; |
| 2095 | char *end; |
| 2096 | char **sets, **sets_pos; |
| 2097 | memset(ipsets, 0, sizeof(struct ipsets)); |
| 2098 | unhide_metas(arg); |
| 2099 | if (arg && *arg == '/') |
| 2100 | { |
| 2101 | arg++; |
| 2102 | while ((end = split_chr(arg, '/'))) |
| 2103 | { |
| 2104 | char *domain = NULL; |
| 2105 | /* elide leading dots - they are implied in the search algorithm */ |
| 2106 | while (*arg == '.') |
| 2107 | arg++; |
| 2108 | /* # matches everything and becomes a zero length domain string */ |
| 2109 | if (strcmp(arg, "#") == 0 || !*arg) |
| 2110 | domain = ""; |
| 2111 | else if (strlen(arg) != 0 && !(domain = canonicalise_opt(arg))) |
| 2112 | option = '?'; |
| 2113 | ipsets->next = opt_malloc(sizeof(struct ipsets)); |
| 2114 | ipsets = ipsets->next; |
| 2115 | memset(ipsets, 0, sizeof(struct ipsets)); |
| 2116 | ipsets->domain = domain; |
| 2117 | arg = end; |
| 2118 | } |
| 2119 | } |
| 2120 | else |
| 2121 | { |
| 2122 | ipsets->next = opt_malloc(sizeof(struct ipsets)); |
| 2123 | ipsets = ipsets->next; |
| 2124 | memset(ipsets, 0, sizeof(struct ipsets)); |
| 2125 | ipsets->domain = ""; |
| 2126 | } |
| 2127 | if (!arg || !*arg) |
| 2128 | { |
| 2129 | option = '?'; |
| 2130 | break; |
| 2131 | } |
| 2132 | size = 2; |
| 2133 | for (end = arg; *end; ++end) |
| 2134 | if (*end == ',') |
| 2135 | ++size; |
| 2136 | |
| 2137 | sets = sets_pos = opt_malloc(sizeof(char *) * size); |
| 2138 | |
| 2139 | do { |
| 2140 | end = split(arg); |
| 2141 | *sets_pos++ = opt_string_alloc(arg); |
| 2142 | arg = end; |
| 2143 | } while (end); |
| 2144 | *sets_pos = 0; |
| 2145 | for (ipsets = &ipsets_head; ipsets->next; ipsets = ipsets->next) |
| 2146 | ipsets->next->sets = sets; |
| 2147 | ipsets->next = daemon->ipsets; |
| 2148 | daemon->ipsets = ipsets_head.next; |
| 2149 | |
| 2150 | break; |
| 2151 | } |
| 2152 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2153 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2154 | case 'c': /* --cache-size */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2155 | { |
| 2156 | int size; |
| 2157 | |
| 2158 | if (!atoi_check(arg, &size)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2159 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2160 | else |
| 2161 | { |
| 2162 | /* zero is OK, and means no caching. */ |
| 2163 | |
| 2164 | if (size < 0) |
| 2165 | size = 0; |
| 2166 | else if (size > 10000) |
| 2167 | size = 10000; |
| 2168 | |
| 2169 | daemon->cachesize = size; |
| 2170 | } |
| 2171 | break; |
| 2172 | } |
| 2173 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2174 | case 'p': /* --port */ |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 2175 | if (!atoi_check16(arg, &daemon->port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2176 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2177 | break; |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 2178 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 2179 | case LOPT_MINPORT: /* --min-port */ |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 2180 | if (!atoi_check16(arg, &daemon->min_port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2181 | ret_err(gen_err); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 2182 | break; |
| 2183 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2184 | case '0': /* --dns-forward-max */ |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 2185 | if (!atoi_check(arg, &daemon->ftabsize)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2186 | ret_err(gen_err); |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 2187 | break; |
| 2188 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2189 | case LOPT_MAX_LOGS: /* --log-async */ |
| 2190 | daemon->max_logs = LOG_MAX; /* default */ |
| 2191 | if (arg && !atoi_check(arg, &daemon->max_logs)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2192 | ret_err(gen_err); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2193 | else if (daemon->max_logs > 100) |
| 2194 | daemon->max_logs = 100; |
| 2195 | break; |
| 2196 | |
| 2197 | case 'P': /* --edns-packet-max */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2198 | { |
| 2199 | int i; |
| 2200 | if (!atoi_check(arg, &i)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2201 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2202 | daemon->edns_pktsz = (unsigned short)i; |
| 2203 | break; |
| 2204 | } |
| 2205 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2206 | case 'Q': /* --query-port */ |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 2207 | if (!atoi_check16(arg, &daemon->query_port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2208 | ret_err(gen_err); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 2209 | /* if explicitly set to zero, use single OS ephemeral port |
| 2210 | and disable random ports */ |
| 2211 | if (daemon->query_port == 0) |
| 2212 | daemon->osport = 1; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2213 | break; |
| 2214 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2215 | case 'T': /* --local-ttl */ |
| 2216 | case LOPT_NEGTTL: /* --neg-ttl */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2217 | case LOPT_MAXTTL: /* --max-ttl */ |
Simon Kelley | 1d86041 | 2012-09-20 20:48:04 +0100 | [diff] [blame] | 2218 | case LOPT_MAXCTTL: /* --max-cache-ttl */ |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2219 | case LOPT_AUTHTTL: /* --auth-ttl */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2220 | { |
| 2221 | int ttl; |
| 2222 | if (!atoi_check(arg, &ttl)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2223 | ret_err(gen_err); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2224 | else if (option == LOPT_NEGTTL) |
| 2225 | daemon->neg_ttl = (unsigned long)ttl; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2226 | else if (option == LOPT_MAXTTL) |
| 2227 | daemon->max_ttl = (unsigned long)ttl; |
Simon Kelley | 1d86041 | 2012-09-20 20:48:04 +0100 | [diff] [blame] | 2228 | else if (option == LOPT_MAXCTTL) |
| 2229 | daemon->max_cache_ttl = (unsigned long)ttl; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 2230 | else if (option == LOPT_AUTHTTL) |
| 2231 | daemon->auth_ttl = (unsigned long)ttl; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2232 | else |
| 2233 | daemon->local_ttl = (unsigned long)ttl; |
| 2234 | break; |
| 2235 | } |
| 2236 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2237 | #ifdef HAVE_DHCP |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2238 | case 'X': /* --dhcp-lease-max */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2239 | if (!atoi_check(arg, &daemon->dhcp_max)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2240 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2241 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2242 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2243 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2244 | #ifdef HAVE_TFTP |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2245 | case LOPT_TFTP_MAX: /* --tftp-max */ |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2246 | if (!atoi_check(arg, &daemon->tftp_max)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2247 | ret_err(gen_err); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2248 | break; |
| 2249 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2250 | case LOPT_PREFIX: /* --tftp-prefix */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2251 | comma = split(arg); |
| 2252 | if (comma) |
| 2253 | { |
| 2254 | struct tftp_prefix *new = opt_malloc(sizeof(struct tftp_prefix)); |
| 2255 | new->interface = opt_string_alloc(comma); |
| 2256 | new->prefix = opt_string_alloc(arg); |
| 2257 | new->next = daemon->if_prefix; |
| 2258 | daemon->if_prefix = new; |
| 2259 | } |
| 2260 | else |
| 2261 | daemon->tftp_prefix = opt_string_alloc(arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2262 | break; |
| 2263 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2264 | case LOPT_TFTPPORTS: /* --tftp-port-range */ |
| 2265 | if (!(comma = split(arg)) || |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 2266 | !atoi_check16(arg, &daemon->start_tftp_port) || |
| 2267 | !atoi_check16(comma, &daemon->end_tftp_port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2268 | ret_err(_("bad port range")); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2269 | |
| 2270 | if (daemon->start_tftp_port > daemon->end_tftp_port) |
| 2271 | { |
| 2272 | int tmp = daemon->start_tftp_port; |
| 2273 | daemon->start_tftp_port = daemon->end_tftp_port; |
| 2274 | daemon->end_tftp_port = tmp; |
| 2275 | } |
| 2276 | |
| 2277 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2278 | #endif |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2279 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2280 | case LOPT_BRIDGE: /* --bridge-interface */ |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2281 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2282 | struct dhcp_bridge *new = opt_malloc(sizeof(struct dhcp_bridge)); |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 2283 | if (!(comma = split(arg)) || strlen(arg) > IF_NAMESIZE - 1 ) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2284 | ret_err(_("bad bridge-interface")); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2285 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 2286 | strcpy(new->iface, arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2287 | new->alias = NULL; |
| 2288 | new->next = daemon->bridges; |
| 2289 | daemon->bridges = new; |
| 2290 | |
| 2291 | do { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2292 | arg = comma; |
| 2293 | comma = split(arg); |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 2294 | if (strlen(arg) != 0 && strlen(arg) <= IF_NAMESIZE - 1) |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2295 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2296 | struct dhcp_bridge *b = opt_malloc(sizeof(struct dhcp_bridge)); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2297 | b->next = new->alias; |
| 2298 | new->alias = b; |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 2299 | strcpy(b->iface, arg); |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2300 | } |
| 2301 | } while (comma); |
| 2302 | |
| 2303 | break; |
| 2304 | } |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 2305 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2306 | #ifdef HAVE_DHCP |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2307 | case 'F': /* --dhcp-range */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2308 | { |
| 2309 | int k, leasepos = 2; |
Simon Kelley | 8445f5d | 2012-12-17 21:54:08 +0000 | [diff] [blame] | 2310 | char *cp, *a[8] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2311 | struct dhcp_context *new = opt_malloc(sizeof(struct dhcp_context)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2312 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2313 | memset (new, 0, sizeof(*new)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2314 | new->lease_time = DEFLEASE; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2315 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2316 | if (!arg) |
| 2317 | { |
| 2318 | option = '?'; |
| 2319 | break; |
| 2320 | } |
| 2321 | |
| 2322 | while(1) |
| 2323 | { |
| 2324 | for (cp = arg; *cp; cp++) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2325 | if (!(*cp == ' ' || *cp == '.' || *cp == ':' || |
| 2326 | (*cp >= 'a' && *cp <= 'f') || (*cp >= 'A' && *cp <= 'F') || |
| 2327 | (*cp >='0' && *cp <= '9'))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2328 | break; |
| 2329 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2330 | if (*cp != ',' && (comma = split(arg))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2331 | { |
Simon Kelley | 8bc4cec | 2012-07-03 21:04:11 +0100 | [diff] [blame] | 2332 | if (is_tag_prefix(arg)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2333 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2334 | struct dhcp_netid *tt = opt_malloc(sizeof (struct dhcp_netid)); |
| 2335 | tt->net = opt_string_alloc(arg+4); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2336 | tt->next = new->filter; |
| 2337 | new->filter = tt; |
| 2338 | } |
| 2339 | else |
| 2340 | { |
| 2341 | if (new->netid.net) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2342 | ret_err(_("only one tag allowed")); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2343 | else if (strstr(arg, "set:") == arg) |
| 2344 | new->netid.net = opt_string_alloc(arg+4); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2345 | else |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2346 | new->netid.net = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2347 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2348 | arg = comma; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2349 | } |
| 2350 | else |
| 2351 | { |
| 2352 | a[0] = arg; |
| 2353 | break; |
| 2354 | } |
| 2355 | } |
| 2356 | |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 2357 | for (k = 1; k < 8; k++) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2358 | if (!(a[k] = split(a[k-1]))) |
| 2359 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2360 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2361 | if (k < 2) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2362 | ret_err(_("bad dhcp-range")); |
| 2363 | |
| 2364 | if (inet_pton(AF_INET, a[0], &new->start)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2365 | { |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2366 | new->next = daemon->dhcp; |
| 2367 | daemon->dhcp = new; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2368 | new->end = new->start; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2369 | if (strcmp(a[1], "static") == 0) |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2370 | new->flags |= CONTEXT_STATIC; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2371 | else if (strcmp(a[1], "proxy") == 0) |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2372 | new->flags |= CONTEXT_PROXY; |
| 2373 | else if (!inet_pton(AF_INET, a[1], &new->end)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2374 | ret_err(_("bad dhcp-range")); |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2375 | |
| 2376 | if (ntohl(new->start.s_addr) > ntohl(new->end.s_addr)) |
| 2377 | { |
| 2378 | struct in_addr tmp = new->start; |
| 2379 | new->start = new->end; |
| 2380 | new->end = tmp; |
| 2381 | } |
| 2382 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2383 | if (k >= 3 && strchr(a[2], '.') && |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 2384 | (inet_pton(AF_INET, a[2], &new->netmask) > 0)) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2385 | { |
| 2386 | new->flags |= CONTEXT_NETMASK; |
| 2387 | leasepos = 3; |
| 2388 | if (!is_same_net(new->start, new->end, new->netmask)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2389 | ret_err(_("inconsistent DHCP range")); |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2390 | } |
| 2391 | |
| 2392 | if (k >= 4 && strchr(a[3], '.') && |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 2393 | (inet_pton(AF_INET, a[3], &new->broadcast) > 0)) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2394 | { |
| 2395 | new->flags |= CONTEXT_BRDCAST; |
| 2396 | leasepos = 4; |
| 2397 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2398 | } |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2399 | #ifdef HAVE_DHCP6 |
| 2400 | else if (inet_pton(AF_INET6, a[0], &new->start6)) |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2401 | { |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2402 | new->prefix = 64; /* default */ |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2403 | new->end6 = new->start6; |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 2404 | new->next = daemon->dhcp6; |
| 2405 | daemon->dhcp6 = new; |
| 2406 | |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2407 | for (leasepos = 1; leasepos < k; leasepos++) |
| 2408 | { |
| 2409 | if (strcmp(a[leasepos], "static") == 0) |
| 2410 | new->flags |= CONTEXT_STATIC | CONTEXT_DHCP; |
| 2411 | else if (strcmp(a[leasepos], "ra-only") == 0 || strcmp(a[leasepos], "slaac") == 0 ) |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 2412 | new->flags |= CONTEXT_RA_ONLY | CONTEXT_RA; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2413 | else if (strcmp(a[leasepos], "ra-names") == 0) |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 2414 | new->flags |= CONTEXT_RA_NAME | CONTEXT_RA; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2415 | else if (strcmp(a[leasepos], "ra-stateless") == 0) |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 2416 | new->flags |= CONTEXT_RA_STATELESS | CONTEXT_DHCP | CONTEXT_RA; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2417 | else if (leasepos == 1 && inet_pton(AF_INET6, a[leasepos], &new->end6)) |
| 2418 | new->flags |= CONTEXT_DHCP; |
Simon Kelley | 1f77693 | 2012-12-16 19:46:08 +0000 | [diff] [blame] | 2419 | else if (strstr(a[leasepos], "constructor:") == a[leasepos]) |
| 2420 | { |
| 2421 | new->template_interface = opt_string_alloc(a[leasepos] + 12); |
| 2422 | new->flags |= CONTEXT_TEMPLATE; |
| 2423 | } |
Simon Kelley | 921360c | 2013-05-31 14:07:22 +0100 | [diff] [blame] | 2424 | else if (strstr(a[leasepos], "constructor-noauth:") == a[leasepos]) |
| 2425 | { |
| 2426 | new->template_interface = opt_string_alloc(a[leasepos] + 19); |
| 2427 | new->flags |= CONTEXT_TEMPLATE | CONTEXT_NOAUTH; |
| 2428 | } |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2429 | else |
| 2430 | break; |
| 2431 | } |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 2432 | |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2433 | /* bare integer < 128 is prefix value */ |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2434 | if (leasepos < k) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2435 | { |
| 2436 | int pref; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2437 | for (cp = a[leasepos]; *cp; cp++) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2438 | if (!(*cp >= '0' && *cp <= '9')) |
| 2439 | break; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2440 | if (!*cp && (pref = atoi(a[leasepos])) <= 128) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2441 | { |
| 2442 | new->prefix = pref; |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2443 | leasepos++; |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2444 | } |
| 2445 | } |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2446 | |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 2447 | if (new->prefix != 64) |
| 2448 | { |
| 2449 | if ((new->flags & (CONTEXT_RA_ONLY | CONTEXT_RA_NAME | CONTEXT_RA_STATELESS))) |
| 2450 | ret_err(_("prefix length must be exactly 64 for RA subnets")); |
| 2451 | else if (new->flags & CONTEXT_TEMPLATE) |
| 2452 | ret_err(_("prefix length must be exactly 64 for subnet constructors")); |
| 2453 | } |
| 2454 | |
| 2455 | if (new->prefix < 64) |
| 2456 | ret_err(_("prefix length must be at least 64")); |
| 2457 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2458 | if (!is_same_net6(&new->start6, &new->end6, new->prefix)) |
| 2459 | ret_err(_("inconsistent DHCPv6 range")); |
Simon Kelley | 6692a1a | 2013-08-20 14:41:31 +0100 | [diff] [blame] | 2460 | |
| 2461 | /* dhcp-range=:: enables DHCP stateless on any interface */ |
| 2462 | if (IN6_IS_ADDR_UNSPECIFIED(&new->start6) && !(new->flags & CONTEXT_TEMPLATE)) |
| 2463 | new->prefix = 0; |
Simon Kelley | 6640919 | 2013-08-01 20:19:32 +0100 | [diff] [blame] | 2464 | |
| 2465 | if (new->flags & CONTEXT_TEMPLATE) |
| 2466 | { |
| 2467 | struct in6_addr zero; |
| 2468 | memset(&zero, 0, sizeof(zero)); |
| 2469 | if (!is_same_net6(&zero, &new->start6, new->prefix)) |
| 2470 | ret_err(_("prefix must be zero with \"constructor:\" argument")); |
| 2471 | } |
| 2472 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2473 | if (addr6part(&new->start6) > addr6part(&new->end6)) |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2474 | { |
| 2475 | struct in6_addr tmp = new->start6; |
| 2476 | new->start6 = new->end6; |
| 2477 | new->end6 = tmp; |
| 2478 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2479 | } |
Simon Kelley | 52b92f4 | 2012-01-22 16:05:15 +0000 | [diff] [blame] | 2480 | #endif |
Simon Kelley | d9ee9c0 | 2013-04-12 11:17:55 +0100 | [diff] [blame] | 2481 | else |
| 2482 | ret_err(_("bad dhcp-range")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2483 | |
Simon Kelley | 30cd966 | 2012-03-25 20:44:38 +0100 | [diff] [blame] | 2484 | if (leasepos < k) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2485 | { |
| 2486 | if (strcmp(a[leasepos], "infinite") == 0) |
| 2487 | new->lease_time = 0xffffffff; |
Simon Kelley | c825754 | 2012-03-28 21:15:41 +0100 | [diff] [blame] | 2488 | else if (strcmp(a[leasepos], "deprecated") == 0) |
| 2489 | new->flags |= CONTEXT_DEPRECATE; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2490 | else |
| 2491 | { |
| 2492 | int fac = 1; |
| 2493 | if (strlen(a[leasepos]) > 0) |
| 2494 | { |
| 2495 | switch (a[leasepos][strlen(a[leasepos]) - 1]) |
| 2496 | { |
Simon Kelley | 4224321 | 2012-07-20 15:19:18 +0100 | [diff] [blame] | 2497 | case 'w': |
| 2498 | case 'W': |
| 2499 | fac *= 7; |
| 2500 | /* fall through */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2501 | case 'd': |
| 2502 | case 'D': |
| 2503 | fac *= 24; |
| 2504 | /* fall though */ |
| 2505 | case 'h': |
| 2506 | case 'H': |
| 2507 | fac *= 60; |
| 2508 | /* fall through */ |
| 2509 | case 'm': |
| 2510 | case 'M': |
| 2511 | fac *= 60; |
| 2512 | /* fall through */ |
| 2513 | case 's': |
| 2514 | case 'S': |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2515 | a[leasepos][strlen(a[leasepos]) - 1] = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2516 | } |
| 2517 | |
Simon Kelley | be37986 | 2012-12-23 12:01:39 +0000 | [diff] [blame] | 2518 | for (cp = a[leasepos]; *cp; cp++) |
| 2519 | if (!(*cp >= '0' && *cp <= '9')) |
| 2520 | break; |
| 2521 | |
Simon Kelley | 54dae55 | 2013-02-05 17:55:10 +0000 | [diff] [blame] | 2522 | if (*cp || (leasepos+1 < k)) |
Simon Kelley | be37986 | 2012-12-23 12:01:39 +0000 | [diff] [blame] | 2523 | ret_err(_("bad dhcp-range")); |
| 2524 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2525 | new->lease_time = atoi(a[leasepos]) * fac; |
| 2526 | /* Leases of a minute or less confuse |
| 2527 | some clients, notably Apple's */ |
| 2528 | if (new->lease_time < 120) |
| 2529 | new->lease_time = 120; |
| 2530 | } |
| 2531 | } |
| 2532 | } |
| 2533 | break; |
| 2534 | } |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 2535 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 2536 | case LOPT_BANK: |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2537 | case 'G': /* --dhcp-host */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2538 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2539 | int j, k = 0; |
Simon Kelley | 3e8ed78 | 2013-05-29 14:31:33 +0100 | [diff] [blame] | 2540 | char *a[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 2541 | struct dhcp_config *new; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2542 | struct in_addr in; |
| 2543 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2544 | new = opt_malloc(sizeof(struct dhcp_config)); |
| 2545 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2546 | new->next = daemon->dhcp_conf; |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2547 | new->flags = (option == LOPT_BANK) ? CONFIG_BANK : 0; |
| 2548 | new->hwaddr = NULL; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2549 | new->netid = NULL; |
| 2550 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2551 | if ((a[0] = arg)) |
Simon Kelley | 3e8ed78 | 2013-05-29 14:31:33 +0100 | [diff] [blame] | 2552 | for (k = 1; k < 7; k++) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2553 | if (!(a[k] = split(a[k-1]))) |
| 2554 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2555 | |
| 2556 | for (j = 0; j < k; j++) |
| 2557 | if (strchr(a[j], ':')) /* ethernet address, netid or binary CLID */ |
| 2558 | { |
| 2559 | char *arg = a[j]; |
| 2560 | |
| 2561 | if ((arg[0] == 'i' || arg[0] == 'I') && |
| 2562 | (arg[1] == 'd' || arg[1] == 'D') && |
| 2563 | arg[2] == ':') |
| 2564 | { |
| 2565 | if (arg[3] == '*') |
| 2566 | new->flags |= CONFIG_NOCLID; |
| 2567 | else |
| 2568 | { |
| 2569 | int len; |
| 2570 | arg += 3; /* dump id: */ |
| 2571 | if (strchr(arg, ':')) |
| 2572 | len = parse_hex(arg, (unsigned char *)arg, -1, NULL, NULL); |
| 2573 | else |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 2574 | { |
| 2575 | unhide_metas(arg); |
| 2576 | len = (int) strlen(arg); |
| 2577 | } |
| 2578 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2579 | if (len == -1) |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 2580 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2581 | ret_err(_("bad hex constant")); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2582 | else if ((new->clid = opt_malloc(len))) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 2583 | { |
| 2584 | new->flags |= CONFIG_CLID; |
| 2585 | new->clid_len = len; |
| 2586 | memcpy(new->clid, arg, len); |
| 2587 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2588 | } |
| 2589 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2590 | /* dhcp-host has strange backwards-compat needs. */ |
| 2591 | else if (strstr(arg, "net:") == arg || strstr(arg, "set:") == arg) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2592 | { |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2593 | struct dhcp_netid *newtag = opt_malloc(sizeof(struct dhcp_netid)); |
| 2594 | struct dhcp_netid_list *newlist = opt_malloc(sizeof(struct dhcp_netid_list)); |
| 2595 | newtag->net = opt_malloc(strlen(arg + 4) + 1); |
| 2596 | newlist->next = new->netid; |
| 2597 | new->netid = newlist; |
| 2598 | newlist->list = newtag; |
| 2599 | strcpy(newtag->net, arg+4); |
| 2600 | unhide_metas(newtag->net); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2601 | } |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 2602 | else if (strstr(arg, "tag:") == arg) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2603 | ret_err(_("cannot match tags in --dhcp-host")); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 2604 | #ifdef HAVE_DHCP6 |
| 2605 | else if (arg[0] == '[' && arg[strlen(arg)-1] == ']') |
| 2606 | { |
| 2607 | arg[strlen(arg)-1] = 0; |
| 2608 | arg++; |
| 2609 | |
| 2610 | if (!inet_pton(AF_INET6, arg, &new->addr6)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2611 | ret_err(_("bad IPv6 address")); |
Simon Kelley | 3039310 | 2013-01-17 16:34:16 +0000 | [diff] [blame] | 2612 | |
| 2613 | for (i= 0; i < 8; i++) |
| 2614 | if (new->addr6.s6_addr[i] != 0) |
| 2615 | break; |
| 2616 | |
| 2617 | /* set WILDCARD if network part all zeros */ |
| 2618 | if (i == 8) |
| 2619 | new->flags |= CONFIG_WILDCARD; |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 2620 | |
| 2621 | new->flags |= CONFIG_ADDR6; |
| 2622 | } |
| 2623 | #endif |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 2624 | else |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2625 | { |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 2626 | struct hwaddr_config *newhw = opt_malloc(sizeof(struct hwaddr_config)); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2627 | if ((newhw->hwaddr_len = parse_hex(a[j], newhw->hwaddr, DHCP_CHADDR_MAX, |
| 2628 | &newhw->wildcard_mask, &newhw->hwaddr_type)) == -1) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2629 | ret_err(_("bad hex constant")); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 2630 | else |
| 2631 | { |
| 2632 | |
| 2633 | newhw->next = new->hwaddr; |
| 2634 | new->hwaddr = newhw; |
| 2635 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2636 | } |
| 2637 | } |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 2638 | else if (strchr(a[j], '.') && (inet_pton(AF_INET, a[j], &in) > 0)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2639 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2640 | struct dhcp_config *configs; |
| 2641 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2642 | new->addr = in; |
| 2643 | new->flags |= CONFIG_ADDR; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2644 | |
| 2645 | /* If the same IP appears in more than one host config, then DISCOVER |
| 2646 | for one of the hosts will get the address, but REQUEST will be NAKed, |
| 2647 | since the address is reserved by the other one -> protocol loop. */ |
| 2648 | for (configs = daemon->dhcp_conf; configs; configs = configs->next) |
| 2649 | if ((configs->flags & CONFIG_ADDR) && configs->addr.s_addr == in.s_addr) |
| 2650 | { |
| 2651 | sprintf(errstr, _("duplicate dhcp-host IP address %s"), inet_ntoa(in)); |
| 2652 | return 0; |
| 2653 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2654 | } |
| 2655 | else |
| 2656 | { |
| 2657 | char *cp, *lastp = NULL, last = 0; |
| 2658 | int fac = 1; |
| 2659 | |
| 2660 | if (strlen(a[j]) > 1) |
| 2661 | { |
| 2662 | lastp = a[j] + strlen(a[j]) - 1; |
| 2663 | last = *lastp; |
| 2664 | switch (last) |
| 2665 | { |
Simon Kelley | 4224321 | 2012-07-20 15:19:18 +0100 | [diff] [blame] | 2666 | case 'w': |
| 2667 | case 'W': |
| 2668 | fac *= 7; |
| 2669 | /* fall through */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2670 | case 'd': |
| 2671 | case 'D': |
| 2672 | fac *= 24; |
| 2673 | /* fall through */ |
| 2674 | case 'h': |
| 2675 | case 'H': |
| 2676 | fac *= 60; |
| 2677 | /* fall through */ |
| 2678 | case 'm': |
| 2679 | case 'M': |
| 2680 | fac *= 60; |
| 2681 | /* fall through */ |
| 2682 | case 's': |
| 2683 | case 'S': |
| 2684 | *lastp = 0; |
| 2685 | } |
| 2686 | } |
| 2687 | |
| 2688 | for (cp = a[j]; *cp; cp++) |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 2689 | if (!isdigit((unsigned char)*cp) && *cp != ' ') |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2690 | break; |
| 2691 | |
| 2692 | if (*cp) |
| 2693 | { |
| 2694 | if (lastp) |
| 2695 | *lastp = last; |
| 2696 | if (strcmp(a[j], "infinite") == 0) |
| 2697 | { |
| 2698 | new->lease_time = 0xffffffff; |
| 2699 | new->flags |= CONFIG_TIME; |
| 2700 | } |
| 2701 | else if (strcmp(a[j], "ignore") == 0) |
| 2702 | new->flags |= CONFIG_DISABLE; |
| 2703 | else |
| 2704 | { |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 2705 | if (!(new->hostname = canonicalise_opt(a[j])) || |
| 2706 | !legal_hostname(new->hostname)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2707 | ret_err(_("bad DHCP host name")); |
| 2708 | |
| 2709 | new->flags |= CONFIG_NAME; |
| 2710 | new->domain = strip_hostname(new->hostname); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2711 | } |
| 2712 | } |
| 2713 | else |
| 2714 | { |
| 2715 | new->lease_time = atoi(a[j]) * fac; |
| 2716 | /* Leases of a minute or less confuse |
| 2717 | some clients, notably Apple's */ |
| 2718 | if (new->lease_time < 120) |
| 2719 | new->lease_time = 120; |
| 2720 | new->flags |= CONFIG_TIME; |
| 2721 | } |
| 2722 | } |
| 2723 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 2724 | daemon->dhcp_conf = new; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2725 | break; |
| 2726 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2727 | |
| 2728 | case LOPT_TAG_IF: /* --tag-if */ |
| 2729 | { |
| 2730 | struct tag_if *new = opt_malloc(sizeof(struct tag_if)); |
| 2731 | |
| 2732 | new->tag = NULL; |
| 2733 | new->set = NULL; |
| 2734 | new->next = NULL; |
| 2735 | |
| 2736 | /* preserve order */ |
| 2737 | if (!daemon->tag_if) |
| 2738 | daemon->tag_if = new; |
| 2739 | else |
| 2740 | { |
| 2741 | struct tag_if *tmp; |
| 2742 | for (tmp = daemon->tag_if; tmp->next; tmp = tmp->next); |
| 2743 | tmp->next = new; |
| 2744 | } |
| 2745 | |
| 2746 | while (arg) |
| 2747 | { |
| 2748 | size_t len; |
| 2749 | |
| 2750 | comma = split(arg); |
| 2751 | len = strlen(arg); |
| 2752 | |
| 2753 | if (len < 5) |
| 2754 | { |
| 2755 | new->set = NULL; |
| 2756 | break; |
| 2757 | } |
| 2758 | else |
| 2759 | { |
| 2760 | struct dhcp_netid *newtag = opt_malloc(sizeof(struct dhcp_netid)); |
| 2761 | newtag->net = opt_malloc(len - 3); |
| 2762 | strcpy(newtag->net, arg+4); |
| 2763 | unhide_metas(newtag->net); |
| 2764 | |
| 2765 | if (strstr(arg, "set:") == arg) |
| 2766 | { |
| 2767 | struct dhcp_netid_list *newlist = opt_malloc(sizeof(struct dhcp_netid_list)); |
| 2768 | newlist->next = new->set; |
| 2769 | new->set = newlist; |
| 2770 | newlist->list = newtag; |
| 2771 | } |
| 2772 | else if (strstr(arg, "tag:") == arg) |
| 2773 | { |
| 2774 | newtag->next = new->tag; |
| 2775 | new->tag = newtag; |
| 2776 | } |
| 2777 | else |
| 2778 | { |
| 2779 | new->set = NULL; |
Simon Kelley | 4dc9c65 | 2013-02-04 21:43:52 +0000 | [diff] [blame] | 2780 | free(newtag); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2781 | break; |
| 2782 | } |
| 2783 | } |
| 2784 | |
| 2785 | arg = comma; |
| 2786 | } |
| 2787 | |
| 2788 | if (!new->set) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2789 | ret_err(_("bad tag-if")); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2790 | |
| 2791 | break; |
| 2792 | } |
| 2793 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2794 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 2795 | case 'O': /* --dhcp-option */ |
| 2796 | case LOPT_FORCE: /* --dhcp-option-force */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2797 | case LOPT_OPTS: |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 2798 | case LOPT_MATCH: /* --dhcp-match */ |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2799 | return parse_dhcp_opt(errstr, arg, |
| 2800 | option == LOPT_FORCE ? DHOPT_FORCE : |
| 2801 | (option == LOPT_MATCH ? DHOPT_MATCH : |
| 2802 | (option == LOPT_OPTS ? DHOPT_BANK : 0))); |
| 2803 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2804 | case 'M': /* --dhcp-boot */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2805 | { |
| 2806 | struct dhcp_netid *id = NULL; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2807 | while (is_tag_prefix(arg)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2808 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2809 | struct dhcp_netid *newid = opt_malloc(sizeof(struct dhcp_netid)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2810 | newid->next = id; |
| 2811 | id = newid; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2812 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2813 | newid->net = opt_string_alloc(arg+4); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2814 | arg = comma; |
| 2815 | }; |
| 2816 | |
| 2817 | if (!arg) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2818 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2819 | else |
| 2820 | { |
Simon Kelley | 7de060b | 2011-08-26 17:24:52 +0100 | [diff] [blame] | 2821 | char *dhcp_file, *dhcp_sname = NULL, *tftp_sname = NULL; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2822 | struct in_addr dhcp_next_server; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2823 | struct dhcp_boot *new; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2824 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2825 | dhcp_file = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2826 | dhcp_next_server.s_addr = 0; |
| 2827 | if (comma) |
| 2828 | { |
| 2829 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2830 | comma = split(arg); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2831 | dhcp_sname = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2832 | if (comma) |
| 2833 | { |
| 2834 | unhide_metas(comma); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 2835 | if (!(inet_pton(AF_INET, comma, &dhcp_next_server) > 0)) |
| 2836 | { |
| 2837 | /* |
| 2838 | * The user may have specified the tftp hostname here. |
| 2839 | * save it so that it can be resolved/looked up during |
| 2840 | * actual dhcp_reply(). |
| 2841 | */ |
| 2842 | |
| 2843 | tftp_sname = opt_string_alloc(comma); |
| 2844 | dhcp_next_server.s_addr = 0; |
| 2845 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2846 | } |
| 2847 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2848 | |
| 2849 | new = opt_malloc(sizeof(struct dhcp_boot)); |
| 2850 | new->file = dhcp_file; |
| 2851 | new->sname = dhcp_sname; |
| 2852 | new->tftp_sname = tftp_sname; |
| 2853 | new->next_server = dhcp_next_server; |
| 2854 | new->netid = id; |
| 2855 | new->next = daemon->boot_config; |
| 2856 | daemon->boot_config = new; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2857 | } |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 2858 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2859 | break; |
| 2860 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2861 | |
| 2862 | case LOPT_PXE_PROMT: /* --pxe-prompt */ |
| 2863 | { |
| 2864 | struct dhcp_opt *new = opt_malloc(sizeof(struct dhcp_opt)); |
| 2865 | int timeout; |
| 2866 | |
| 2867 | new->netid = NULL; |
| 2868 | new->opt = 10; /* PXE_MENU_PROMPT */ |
| 2869 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2870 | while (is_tag_prefix(arg)) |
| 2871 | { |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2872 | struct dhcp_netid *nn = opt_malloc(sizeof (struct dhcp_netid)); |
| 2873 | comma = split(arg); |
| 2874 | nn->next = new->netid; |
| 2875 | new->netid = nn; |
| 2876 | nn->net = opt_string_alloc(arg+4); |
| 2877 | arg = comma; |
| 2878 | } |
| 2879 | |
| 2880 | if (!arg) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2881 | ret_err(gen_err); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2882 | else |
| 2883 | { |
| 2884 | comma = split(arg); |
| 2885 | unhide_metas(arg); |
| 2886 | new->len = strlen(arg) + 1; |
| 2887 | new->val = opt_malloc(new->len); |
| 2888 | memcpy(new->val + 1, arg, new->len - 1); |
| 2889 | |
| 2890 | new->u.vendor_class = (unsigned char *)"PXEClient"; |
| 2891 | new->flags = DHOPT_VENDOR; |
| 2892 | |
| 2893 | if (comma && atoi_check(comma, &timeout)) |
| 2894 | *(new->val) = timeout; |
| 2895 | else |
| 2896 | *(new->val) = 255; |
| 2897 | |
| 2898 | new->next = daemon->dhcp_opts; |
| 2899 | daemon->dhcp_opts = new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 2900 | daemon->enable_pxe = 1; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2901 | } |
| 2902 | |
| 2903 | break; |
| 2904 | } |
| 2905 | |
| 2906 | case LOPT_PXE_SERV: /* --pxe-service */ |
| 2907 | { |
| 2908 | struct pxe_service *new = opt_malloc(sizeof(struct pxe_service)); |
| 2909 | char *CSA[] = { "x86PC", "PC98", "IA64_EFI", "Alpha", "Arc_x86", "Intel_Lean_Client", |
| 2910 | "IA32_EFI", "BC_EFI", "Xscale_EFI", "x86-64_EFI", NULL }; |
| 2911 | static int boottype = 32768; |
| 2912 | |
| 2913 | new->netid = NULL; |
Simon Kelley | 751d6f4 | 2012-02-10 15:24:51 +0000 | [diff] [blame] | 2914 | new->sname = NULL; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2915 | new->server.s_addr = 0; |
| 2916 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2917 | while (is_tag_prefix(arg)) |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2918 | { |
| 2919 | struct dhcp_netid *nn = opt_malloc(sizeof (struct dhcp_netid)); |
| 2920 | comma = split(arg); |
| 2921 | nn->next = new->netid; |
| 2922 | new->netid = nn; |
| 2923 | nn->net = opt_string_alloc(arg+4); |
| 2924 | arg = comma; |
| 2925 | } |
| 2926 | |
| 2927 | if (arg && (comma = split(arg))) |
| 2928 | { |
| 2929 | for (i = 0; CSA[i]; i++) |
| 2930 | if (strcasecmp(CSA[i], arg) == 0) |
| 2931 | break; |
| 2932 | |
| 2933 | if (CSA[i] || atoi_check(arg, &i)) |
| 2934 | { |
| 2935 | arg = comma; |
| 2936 | comma = split(arg); |
| 2937 | |
| 2938 | new->CSA = i; |
| 2939 | new->menu = opt_string_alloc(arg); |
| 2940 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 2941 | if (!comma) |
| 2942 | { |
| 2943 | new->type = 0; /* local boot */ |
| 2944 | new->basename = NULL; |
| 2945 | } |
| 2946 | else |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2947 | { |
| 2948 | arg = comma; |
| 2949 | comma = split(arg); |
| 2950 | if (atoi_check(arg, &i)) |
| 2951 | { |
| 2952 | new->type = i; |
| 2953 | new->basename = NULL; |
| 2954 | } |
| 2955 | else |
| 2956 | { |
| 2957 | new->type = boottype++; |
| 2958 | new->basename = opt_string_alloc(arg); |
| 2959 | } |
| 2960 | |
Simon Kelley | 751d6f4 | 2012-02-10 15:24:51 +0000 | [diff] [blame] | 2961 | if (comma) |
| 2962 | { |
| 2963 | if (!inet_pton(AF_INET, comma, &new->server)) |
| 2964 | { |
| 2965 | new->server.s_addr = 0; |
| 2966 | new->sname = opt_string_alloc(comma); |
| 2967 | } |
| 2968 | |
| 2969 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2970 | } |
Simon Kelley | 751d6f4 | 2012-02-10 15:24:51 +0000 | [diff] [blame] | 2971 | |
Simon Kelley | 316e273 | 2010-01-22 20:16:09 +0000 | [diff] [blame] | 2972 | /* Order matters */ |
| 2973 | new->next = NULL; |
| 2974 | if (!daemon->pxe_services) |
| 2975 | daemon->pxe_services = new; |
| 2976 | else |
| 2977 | { |
| 2978 | struct pxe_service *s; |
| 2979 | for (s = daemon->pxe_services; s->next; s = s->next); |
| 2980 | s->next = new; |
| 2981 | } |
| 2982 | |
| 2983 | daemon->enable_pxe = 1; |
| 2984 | break; |
| 2985 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2986 | } |
| 2987 | } |
| 2988 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2989 | ret_err(gen_err); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 2990 | } |
| 2991 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2992 | case '4': /* --dhcp-mac */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2993 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 2994 | if (!(comma = split(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 2995 | ret_err(gen_err); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 2996 | else |
| 2997 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 2998 | struct dhcp_mac *new = opt_malloc(sizeof(struct dhcp_mac)); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 2999 | new->netid.net = opt_string_alloc(set_prefix(arg)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3000 | unhide_metas(comma); |
| 3001 | new->hwaddr_len = parse_hex(comma, new->hwaddr, DHCP_CHADDR_MAX, &new->mask, &new->hwaddr_type); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3002 | if (new->hwaddr_len == -1) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3003 | ret_err(gen_err); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3004 | else |
| 3005 | { |
| 3006 | new->next = daemon->dhcp_macs; |
| 3007 | daemon->dhcp_macs = new; |
| 3008 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3009 | } |
| 3010 | } |
| 3011 | break; |
Simon Kelley | c630924 | 2013-03-07 20:59:28 +0000 | [diff] [blame] | 3012 | |
| 3013 | #ifdef OPTION6_PREFIX_CLASS |
| 3014 | case LOPT_PREF_CLSS: /* --dhcp-prefix-class */ |
| 3015 | { |
| 3016 | struct prefix_class *new = opt_malloc(sizeof(struct prefix_class)); |
| 3017 | |
| 3018 | if (!(comma = split(arg)) || |
| 3019 | !atoi_check16(comma, &new->class)) |
| 3020 | ret_err(gen_err); |
| 3021 | |
| 3022 | new->tag.net = opt_string_alloc(set_prefix(arg)); |
| 3023 | new->next = daemon->prefix_classes; |
| 3024 | daemon->prefix_classes = new; |
| 3025 | |
| 3026 | break; |
| 3027 | } |
| 3028 | #endif |
| 3029 | |
| 3030 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3031 | case 'U': /* --dhcp-vendorclass */ |
| 3032 | case 'j': /* --dhcp-userclass */ |
| 3033 | case LOPT_CIRCUIT: /* --dhcp-circuitid */ |
| 3034 | case LOPT_REMOTE: /* --dhcp-remoteid */ |
| 3035 | case LOPT_SUBSCR: /* --dhcp-subscrid */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3036 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3037 | unsigned char *p; |
| 3038 | int dig = 0; |
| 3039 | struct dhcp_vendor *new = opt_malloc(sizeof(struct dhcp_vendor)); |
| 3040 | |
| 3041 | if (!(comma = split(arg))) |
| 3042 | ret_err(gen_err); |
| 3043 | |
| 3044 | new->netid.net = opt_string_alloc(set_prefix(arg)); |
| 3045 | /* check for hex string - must digits may include : must not have nothing else, |
| 3046 | only allowed for agent-options. */ |
| 3047 | |
| 3048 | arg = comma; |
| 3049 | if ((comma = split(arg))) |
| 3050 | { |
| 3051 | if (option != 'U' || strstr(arg, "enterprise:") != arg) |
| 3052 | ret_err(gen_err); |
| 3053 | else |
| 3054 | new->enterprise = atoi(arg+11); |
| 3055 | } |
| 3056 | else |
| 3057 | comma = arg; |
| 3058 | |
| 3059 | for (p = (unsigned char *)comma; *p; p++) |
| 3060 | if (isxdigit(*p)) |
| 3061 | dig = 1; |
| 3062 | else if (*p != ':') |
| 3063 | break; |
| 3064 | unhide_metas(comma); |
| 3065 | if (option == 'U' || option == 'j' || *p || !dig) |
| 3066 | { |
| 3067 | new->len = strlen(comma); |
| 3068 | new->data = opt_malloc(new->len); |
| 3069 | memcpy(new->data, comma, new->len); |
| 3070 | } |
| 3071 | else |
| 3072 | { |
| 3073 | new->len = parse_hex(comma, (unsigned char *)comma, strlen(comma), NULL, NULL); |
| 3074 | new->data = opt_malloc(new->len); |
| 3075 | memcpy(new->data, comma, new->len); |
| 3076 | } |
| 3077 | |
| 3078 | switch (option) |
| 3079 | { |
| 3080 | case 'j': |
| 3081 | new->match_type = MATCH_USER; |
| 3082 | break; |
| 3083 | case 'U': |
| 3084 | new->match_type = MATCH_VENDOR; |
| 3085 | break; |
| 3086 | case LOPT_CIRCUIT: |
| 3087 | new->match_type = MATCH_CIRCUIT; |
| 3088 | break; |
| 3089 | case LOPT_REMOTE: |
| 3090 | new->match_type = MATCH_REMOTE; |
| 3091 | break; |
| 3092 | case LOPT_SUBSCR: |
| 3093 | new->match_type = MATCH_SUBSCRIBER; |
| 3094 | break; |
| 3095 | } |
| 3096 | new->next = daemon->dhcp_vendors; |
| 3097 | daemon->dhcp_vendors = new; |
Simon Kelley | a5c72ab | 2012-02-10 13:42:47 +0000 | [diff] [blame] | 3098 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3099 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3100 | } |
| 3101 | |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 3102 | case LOPT_ALTPORT: /* --dhcp-alternate-port */ |
| 3103 | if (!arg) |
| 3104 | { |
| 3105 | daemon->dhcp_server_port = DHCP_SERVER_ALTPORT; |
| 3106 | daemon->dhcp_client_port = DHCP_CLIENT_ALTPORT; |
| 3107 | } |
| 3108 | else |
| 3109 | { |
| 3110 | comma = split(arg); |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 3111 | if (!atoi_check16(arg, &daemon->dhcp_server_port) || |
| 3112 | (comma && !atoi_check16(comma, &daemon->dhcp_client_port))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3113 | ret_err(_("invalid port number")); |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 3114 | if (!comma) |
| 3115 | daemon->dhcp_client_port = daemon->dhcp_server_port+1; |
| 3116 | } |
| 3117 | break; |
| 3118 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3119 | case 'J': /* --dhcp-ignore */ |
| 3120 | case LOPT_NO_NAMES: /* --dhcp-ignore-names */ |
| 3121 | case LOPT_BROADCAST: /* --dhcp-broadcast */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3122 | case '3': /* --bootp-dynamic */ |
| 3123 | case LOPT_GEN_NAMES: /* --dhcp-generate-names */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3124 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3125 | struct dhcp_netid_list *new = opt_malloc(sizeof(struct dhcp_netid_list)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3126 | struct dhcp_netid *list = NULL; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 3127 | if (option == 'J') |
| 3128 | { |
| 3129 | new->next = daemon->dhcp_ignore; |
| 3130 | daemon->dhcp_ignore = new; |
| 3131 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3132 | else if (option == LOPT_BROADCAST) |
| 3133 | { |
| 3134 | new->next = daemon->force_broadcast; |
| 3135 | daemon->force_broadcast = new; |
| 3136 | } |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 3137 | else if (option == '3') |
| 3138 | { |
| 3139 | new->next = daemon->bootp_dynamic; |
| 3140 | daemon->bootp_dynamic = new; |
| 3141 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3142 | else if (option == LOPT_GEN_NAMES) |
| 3143 | { |
| 3144 | new->next = daemon->dhcp_gen_names; |
| 3145 | daemon->dhcp_gen_names = new; |
| 3146 | } |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 3147 | else |
| 3148 | { |
| 3149 | new->next = daemon->dhcp_ignore_names; |
| 3150 | daemon->dhcp_ignore_names = new; |
| 3151 | } |
| 3152 | |
| 3153 | while (arg) { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3154 | struct dhcp_netid *member = opt_malloc(sizeof(struct dhcp_netid)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3155 | comma = split(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3156 | member->next = list; |
| 3157 | list = member; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3158 | if (is_tag_prefix(arg)) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 3159 | member->net = opt_string_alloc(arg+4); |
| 3160 | else |
| 3161 | member->net = opt_string_alloc(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3162 | arg = comma; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 3163 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3164 | |
| 3165 | new->list = list; |
| 3166 | break; |
| 3167 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3168 | |
| 3169 | case LOPT_PROXY: /* --dhcp-proxy */ |
| 3170 | daemon->override = 1; |
| 3171 | while (arg) { |
| 3172 | struct addr_list *new = opt_malloc(sizeof(struct addr_list)); |
| 3173 | comma = split(arg); |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 3174 | if (!(inet_pton(AF_INET, arg, &new->addr) > 0)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3175 | ret_err(_("bad dhcp-proxy address")); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3176 | new->next = daemon->override_relays; |
| 3177 | daemon->override_relays = new; |
| 3178 | arg = comma; |
| 3179 | } |
| 3180 | break; |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3181 | #endif |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3182 | |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 3183 | #ifdef HAVE_DHCP6 |
| 3184 | case LOPT_DUID: /* --dhcp-duid */ |
| 3185 | if (!(comma = split(arg)) || !atoi_check(arg, (int *)&daemon->duid_enterprise)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3186 | ret_err(_("bad DUID")); |
Simon Kelley | 8b37270 | 2012-03-09 17:45:10 +0000 | [diff] [blame] | 3187 | else |
| 3188 | { |
| 3189 | daemon->duid_config_len = parse_hex(comma,(unsigned char *)comma, strlen(comma), NULL, NULL); |
| 3190 | daemon->duid_config = opt_malloc(daemon->duid_config_len); |
| 3191 | memcpy(daemon->duid_config, comma, daemon->duid_config_len); |
| 3192 | } |
| 3193 | break; |
| 3194 | #endif |
| 3195 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3196 | case 'V': /* --alias */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3197 | { |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 3198 | char *dash, *a[3] = { NULL, NULL, NULL }; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3199 | int k = 0; |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 3200 | struct doctor *new = opt_malloc(sizeof(struct doctor)); |
| 3201 | new->next = daemon->doctors; |
| 3202 | daemon->doctors = new; |
| 3203 | new->mask.s_addr = 0xffffffff; |
| 3204 | new->end.s_addr = 0; |
| 3205 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3206 | if ((a[0] = arg)) |
| 3207 | for (k = 1; k < 3; k++) |
| 3208 | { |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3209 | if (!(a[k] = split(a[k-1]))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3210 | break; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3211 | unhide_metas(a[k]); |
| 3212 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3213 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 3214 | dash = split_chr(a[0], '-'); |
| 3215 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3216 | if ((k < 2) || |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 3217 | (!(inet_pton(AF_INET, a[0], &new->in) > 0)) || |
| 3218 | (!(inet_pton(AF_INET, a[1], &new->out) > 0))) |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 3219 | option = '?'; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3220 | |
| 3221 | if (k == 3) |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 3222 | inet_pton(AF_INET, a[2], &new->mask); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3223 | |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 3224 | if (dash && |
Simon Kelley | ddd9a6b | 2013-04-29 17:00:21 +0100 | [diff] [blame] | 3225 | (!(inet_pton(AF_INET, dash, &new->end) > 0) || |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 3226 | !is_same_net(new->in, new->end, new->mask) || |
| 3227 | ntohl(new->in.s_addr) > ntohl(new->end.s_addr))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3228 | ret_err(_("invalid alias range")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3229 | |
| 3230 | break; |
| 3231 | } |
| 3232 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3233 | case LOPT_INTNAME: /* --interface-name */ |
| 3234 | { |
| 3235 | struct interface_name *new, **up; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3236 | char *domain = NULL; |
| 3237 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3238 | comma = split(arg); |
| 3239 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3240 | if (!comma || !(domain = canonicalise_opt(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3241 | ret_err(_("bad interface name")); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3242 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3243 | new = opt_malloc(sizeof(struct interface_name)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3244 | new->next = NULL; |
Simon Kelley | 115ac3e | 2013-05-20 11:28:32 +0100 | [diff] [blame] | 3245 | new->addr4 = NULL; |
| 3246 | #ifdef HAVE_IPV6 |
| 3247 | new->addr6 = NULL; |
| 3248 | #endif |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3249 | /* Add to the end of the list, so that first name |
| 3250 | of an interface is used for PTR lookups. */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3251 | for (up = &daemon->int_names; *up; up = &((*up)->next)); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3252 | *up = new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3253 | new->name = domain; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3254 | new->intr = opt_string_alloc(comma); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3255 | break; |
| 3256 | } |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 3257 | |
| 3258 | case LOPT_CNAME: /* --cname */ |
| 3259 | { |
| 3260 | struct cname *new; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3261 | char *alias; |
| 3262 | char *target; |
| 3263 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 3264 | if (!(comma = split(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3265 | ret_err(gen_err); |
| 3266 | |
| 3267 | alias = canonicalise_opt(arg); |
| 3268 | target = canonicalise_opt(comma); |
| 3269 | |
| 3270 | if (!alias || !target) |
| 3271 | ret_err(_("bad CNAME")); |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 3272 | else |
| 3273 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3274 | for (new = daemon->cnames; new; new = new->next) |
| 3275 | if (hostname_isequal(new->alias, arg)) |
| 3276 | ret_err(_("duplicate CNAME")); |
| 3277 | new = opt_malloc(sizeof(struct cname)); |
| 3278 | new->next = daemon->cnames; |
| 3279 | daemon->cnames = new; |
| 3280 | new->alias = alias; |
| 3281 | new->target = target; |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 3282 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3283 | |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 3284 | break; |
| 3285 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3286 | |
| 3287 | case LOPT_PTR: /* --ptr-record */ |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 3288 | { |
| 3289 | struct ptr_record *new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3290 | char *dom, *target = NULL; |
| 3291 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3292 | comma = split(arg); |
| 3293 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3294 | if (!(dom = canonicalise_opt(arg)) || |
| 3295 | (comma && !(target = canonicalise_opt(comma)))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3296 | ret_err(_("bad PTR record")); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3297 | else |
| 3298 | { |
| 3299 | new = opt_malloc(sizeof(struct ptr_record)); |
| 3300 | new->next = daemon->ptr; |
| 3301 | daemon->ptr = new; |
| 3302 | new->name = dom; |
| 3303 | new->ptr = target; |
| 3304 | } |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 3305 | break; |
| 3306 | } |
| 3307 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 3308 | case LOPT_NAPTR: /* --naptr-record */ |
| 3309 | { |
| 3310 | char *a[7] = { NULL, NULL, NULL, NULL, NULL, NULL, NULL }; |
| 3311 | int k = 0; |
| 3312 | struct naptr *new; |
| 3313 | int order, pref; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3314 | char *name, *replace = NULL; |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 3315 | |
| 3316 | if ((a[0] = arg)) |
| 3317 | for (k = 1; k < 7; k++) |
| 3318 | if (!(a[k] = split(a[k-1]))) |
| 3319 | break; |
| 3320 | |
| 3321 | |
| 3322 | if (k < 6 || |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3323 | !(name = canonicalise_opt(a[0])) || |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 3324 | !atoi_check16(a[1], &order) || |
| 3325 | !atoi_check16(a[2], &pref) || |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3326 | (k == 7 && !(replace = canonicalise_opt(a[6])))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3327 | ret_err(_("bad NAPTR record")); |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 3328 | else |
| 3329 | { |
| 3330 | new = opt_malloc(sizeof(struct naptr)); |
| 3331 | new->next = daemon->naptr; |
| 3332 | daemon->naptr = new; |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3333 | new->name = name; |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 3334 | new->flags = opt_string_alloc(a[3]); |
| 3335 | new->services = opt_string_alloc(a[4]); |
| 3336 | new->regexp = opt_string_alloc(a[5]); |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3337 | new->replace = replace; |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 3338 | new->order = order; |
| 3339 | new->pref = pref; |
| 3340 | } |
| 3341 | break; |
| 3342 | } |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 3343 | |
| 3344 | case LOPT_RR: /* dns-rr */ |
| 3345 | { |
| 3346 | struct txt_record *new; |
| 3347 | size_t len; |
| 3348 | char *data; |
| 3349 | int val; |
| 3350 | |
| 3351 | comma = split(arg); |
| 3352 | data = split(comma); |
| 3353 | |
| 3354 | new = opt_malloc(sizeof(struct txt_record)); |
| 3355 | new->next = daemon->rr; |
| 3356 | daemon->rr = new; |
| 3357 | |
| 3358 | if (!atoi_check(comma, &val) || |
| 3359 | !(new->name = canonicalise_opt(arg)) || |
Simon Kelley | 51931b8 | 2012-05-29 17:06:02 +0100 | [diff] [blame] | 3360 | (data && (len = parse_hex(data, (unsigned char *)data, -1, NULL, NULL)) == -1U)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3361 | ret_err(_("bad RR record")); |
| 3362 | |
Simon Kelley | 9f7f3b1 | 2012-05-28 21:39:57 +0100 | [diff] [blame] | 3363 | new->class = val; |
| 3364 | new->len = 0; |
| 3365 | |
| 3366 | if (data) |
| 3367 | { |
| 3368 | new->txt=opt_malloc(len); |
| 3369 | new->len = len; |
| 3370 | memcpy(new->txt, data, len); |
| 3371 | } |
| 3372 | |
| 3373 | break; |
| 3374 | } |
| 3375 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3376 | case 'Y': /* --txt-record */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3377 | { |
| 3378 | struct txt_record *new; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3379 | unsigned char *p, *cnt; |
| 3380 | size_t len; |
| 3381 | |
| 3382 | comma = split(arg); |
| 3383 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3384 | new = opt_malloc(sizeof(struct txt_record)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3385 | new->next = daemon->txt; |
| 3386 | daemon->txt = new; |
| 3387 | new->class = C_IN; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3388 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3389 | if (!(new->name = canonicalise_opt(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3390 | ret_err(_("bad TXT record")); |
| 3391 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3392 | len = comma ? strlen(comma) : 0; |
| 3393 | len += (len/255) + 1; /* room for extra counts */ |
| 3394 | new->txt = p = opt_malloc(len); |
| 3395 | |
| 3396 | cnt = p++; |
| 3397 | *cnt = 0; |
| 3398 | |
| 3399 | while (comma && *comma) |
| 3400 | { |
| 3401 | unsigned char c = (unsigned char)*comma++; |
| 3402 | |
| 3403 | if (c == ',' || *cnt == 255) |
| 3404 | { |
| 3405 | if (c != ',') |
| 3406 | comma--; |
| 3407 | cnt = p++; |
| 3408 | *cnt = 0; |
| 3409 | } |
| 3410 | else |
| 3411 | { |
| 3412 | *p++ = unhide_meta(c); |
| 3413 | (*cnt)++; |
| 3414 | } |
| 3415 | } |
| 3416 | |
| 3417 | new->len = p - new->txt; |
| 3418 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3419 | break; |
| 3420 | } |
| 3421 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3422 | case 'W': /* --srv-host */ |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3423 | { |
| 3424 | int port = 1, priority = 0, weight = 0; |
| 3425 | char *name, *target = NULL; |
| 3426 | struct mx_srv_record *new; |
| 3427 | |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3428 | comma = split(arg); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3429 | |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 3430 | if (!(name = canonicalise_opt(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3431 | ret_err(_("bad SRV record")); |
| 3432 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3433 | if (comma) |
| 3434 | { |
| 3435 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3436 | comma = split(arg); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3437 | if (!(target = canonicalise_opt(arg))) |
| 3438 | ret_err(_("bad SRV target")); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3439 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3440 | if (comma) |
| 3441 | { |
| 3442 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3443 | comma = split(arg); |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 3444 | if (!atoi_check16(arg, &port)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3445 | ret_err(_("invalid port number")); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3446 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3447 | if (comma) |
| 3448 | { |
| 3449 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3450 | comma = split(arg); |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 3451 | if (!atoi_check16(arg, &priority)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3452 | ret_err(_("invalid priority")); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3453 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3454 | if (comma) |
| 3455 | { |
| 3456 | arg = comma; |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3457 | comma = split(arg); |
Simon Kelley | 1ad24ae | 2008-07-20 20:22:50 +0100 | [diff] [blame] | 3458 | if (!atoi_check16(arg, &weight)) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3459 | ret_err(_("invalid weight")); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3460 | } |
| 3461 | } |
| 3462 | } |
| 3463 | } |
| 3464 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3465 | new = opt_malloc(sizeof(struct mx_srv_record)); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3466 | new->next = daemon->mxnames; |
| 3467 | daemon->mxnames = new; |
| 3468 | new->issrv = 1; |
| 3469 | new->name = name; |
| 3470 | new->target = target; |
| 3471 | new->srvport = port; |
| 3472 | new->priority = priority; |
| 3473 | new->weight = weight; |
| 3474 | break; |
| 3475 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3476 | |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 3477 | case LOPT_HOST_REC: /* --host-record */ |
| 3478 | { |
| 3479 | struct host_record *new = opt_malloc(sizeof(struct host_record)); |
| 3480 | memset(new, 0, sizeof(struct host_record)); |
| 3481 | |
| 3482 | if (!arg || !(comma = split(arg))) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3483 | ret_err(_("Bad host-record")); |
| 3484 | |
| 3485 | while (arg) |
| 3486 | { |
| 3487 | struct all_addr addr; |
| 3488 | if (inet_pton(AF_INET, arg, &addr)) |
| 3489 | new->addr = addr.addr.addr4; |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 3490 | #ifdef HAVE_IPV6 |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3491 | else if (inet_pton(AF_INET6, arg, &addr)) |
| 3492 | new->addr6 = addr.addr.addr6; |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 3493 | #endif |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3494 | else |
| 3495 | { |
| 3496 | int nomem; |
| 3497 | char *canon = canonicalise(arg, &nomem); |
| 3498 | struct name_list *nl = opt_malloc(sizeof(struct name_list)); |
| 3499 | if (!canon) |
| 3500 | ret_err(_("Bad name in host-record")); |
| 3501 | |
| 3502 | nl->name = canon; |
| 3503 | /* keep order, so that PTR record goes to first name */ |
| 3504 | nl->next = NULL; |
| 3505 | if (!new->names) |
| 3506 | new->names = nl; |
| 3507 | else |
| 3508 | { |
| 3509 | struct name_list *tmp; |
| 3510 | for (tmp = new->names; tmp->next; tmp = tmp->next); |
| 3511 | tmp->next = nl; |
| 3512 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3513 | } |
Simon Kelley | e4807d8 | 2012-09-27 21:52:26 +0100 | [diff] [blame] | 3514 | |
| 3515 | arg = comma; |
| 3516 | comma = split(arg); |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3517 | } |
Simon Kelley | e759d42 | 2012-03-16 13:18:57 +0000 | [diff] [blame] | 3518 | |
| 3519 | /* Keep list order */ |
| 3520 | if (!daemon->host_records_tail) |
| 3521 | daemon->host_records = new; |
| 3522 | else |
| 3523 | daemon->host_records_tail->next = new; |
| 3524 | new->next = NULL; |
| 3525 | daemon->host_records_tail = new; |
| 3526 | break; |
| 3527 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3528 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3529 | default: |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3530 | ret_err(_("unsupported option (check that dnsmasq was compiled with DHCP/TFTP/DBus support)")); |
| 3531 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3532 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3533 | |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3534 | return 1; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3535 | } |
| 3536 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3537 | static void read_file(char *file, FILE *f, int hard_opt) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3538 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3539 | volatile int lineno = 0; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3540 | char *buff = daemon->namebuff; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3541 | |
| 3542 | while (fgets(buff, MAXDNAME, f)) |
| 3543 | { |
Simon Kelley | 611ebc5 | 2012-07-16 16:23:46 +0100 | [diff] [blame] | 3544 | int white, i, option = hard_opt; |
| 3545 | char *errmess, *p, *arg = NULL, *start; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3546 | size_t len; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 3547 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3548 | /* Memory allocation failure longjmps here if mem_recover == 1 */ |
Simon Kelley | 611ebc5 | 2012-07-16 16:23:46 +0100 | [diff] [blame] | 3549 | if (option != 0) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3550 | { |
| 3551 | if (setjmp(mem_jmp)) |
| 3552 | continue; |
| 3553 | mem_recover = 1; |
| 3554 | } |
| 3555 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3556 | lineno++; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3557 | errmess = NULL; |
| 3558 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3559 | /* Implement quotes, inside quotes we allow \\ \" \n and \t |
| 3560 | metacharacters get hidden also strip comments */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3561 | for (white = 1, p = buff; *p; p++) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3562 | { |
| 3563 | if (*p == '"') |
| 3564 | { |
| 3565 | memmove(p, p+1, strlen(p+1)+1); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3566 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3567 | for(; *p && *p != '"'; p++) |
| 3568 | { |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3569 | if (*p == '\\' && strchr("\"tnebr\\", p[1])) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3570 | { |
| 3571 | if (p[1] == 't') |
| 3572 | p[1] = '\t'; |
| 3573 | else if (p[1] == 'n') |
| 3574 | p[1] = '\n'; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3575 | else if (p[1] == 'b') |
| 3576 | p[1] = '\b'; |
| 3577 | else if (p[1] == 'r') |
| 3578 | p[1] = '\r'; |
Simon Kelley | 6b01084 | 2007-02-12 20:32:07 +0000 | [diff] [blame] | 3579 | else if (p[1] == 'e') /* escape */ |
| 3580 | p[1] = '\033'; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3581 | memmove(p, p+1, strlen(p+1)+1); |
| 3582 | } |
| 3583 | *p = hide_meta(*p); |
| 3584 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3585 | |
| 3586 | if (*p == 0) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3587 | { |
| 3588 | errmess = _("missing \""); |
| 3589 | goto oops; |
| 3590 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3591 | |
| 3592 | memmove(p, p+1, strlen(p+1)+1); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3593 | } |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3594 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3595 | if (isspace(*p)) |
| 3596 | { |
| 3597 | *p = ' '; |
| 3598 | white = 1; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3599 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3600 | else |
| 3601 | { |
| 3602 | if (white && *p == '#') |
| 3603 | { |
| 3604 | *p = 0; |
| 3605 | break; |
| 3606 | } |
| 3607 | white = 0; |
| 3608 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3609 | } |
| 3610 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3611 | |
| 3612 | /* strip leading spaces */ |
| 3613 | for (start = buff; *start && *start == ' '; start++); |
| 3614 | |
| 3615 | /* strip trailing spaces */ |
| 3616 | for (len = strlen(start); (len != 0) && (start[len-1] == ' '); len--); |
| 3617 | |
| 3618 | if (len == 0) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3619 | continue; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3620 | else |
| 3621 | start[len] = 0; |
| 3622 | |
Simon Kelley | 611ebc5 | 2012-07-16 16:23:46 +0100 | [diff] [blame] | 3623 | if (option != 0) |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3624 | arg = start; |
| 3625 | else if ((p=strchr(start, '='))) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3626 | { |
| 3627 | /* allow spaces around "=" */ |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3628 | for (arg = p+1; *arg == ' '; arg++); |
| 3629 | for (; p >= start && (*p == ' ' || *p == '='); p--) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3630 | *p = 0; |
| 3631 | } |
| 3632 | else |
| 3633 | arg = NULL; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 3634 | |
Simon Kelley | 611ebc5 | 2012-07-16 16:23:46 +0100 | [diff] [blame] | 3635 | if (option == 0) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3636 | { |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3637 | for (option = 0, i = 0; opts[i].name; i++) |
| 3638 | if (strcmp(opts[i].name, start) == 0) |
| 3639 | { |
| 3640 | option = opts[i].val; |
| 3641 | break; |
| 3642 | } |
| 3643 | |
| 3644 | if (!option) |
| 3645 | errmess = _("bad option"); |
| 3646 | else if (opts[i].has_arg == 0 && arg) |
| 3647 | errmess = _("extraneous parameter"); |
| 3648 | else if (opts[i].has_arg == 1 && !arg) |
| 3649 | errmess = _("missing parameter"); |
| 3650 | } |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3651 | |
| 3652 | oops: |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 3653 | if (errmess) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3654 | strcpy(daemon->namebuff, errmess); |
| 3655 | |
| 3656 | if (errmess || !one_opt(option, arg, buff, _("error"), 0)) |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3657 | { |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3658 | sprintf(daemon->namebuff + strlen(daemon->namebuff), _(" at line %d of %s"), lineno, file); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3659 | if (hard_opt != 0) |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3660 | my_syslog(LOG_ERR, "%s", daemon->namebuff); |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3661 | else |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3662 | die("%s", daemon->namebuff, EC_BADCONF); |
Simon Kelley | f2621c7 | 2007-04-29 19:47:21 +0100 | [diff] [blame] | 3663 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3664 | } |
| 3665 | |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3666 | mem_recover = 0; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3667 | fclose(f); |
| 3668 | } |
| 3669 | |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 3670 | static int one_file(char *file, int hard_opt) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3671 | { |
| 3672 | FILE *f; |
| 3673 | int nofile_ok = 0; |
| 3674 | static int read_stdin = 0; |
| 3675 | static struct fileread { |
| 3676 | dev_t dev; |
| 3677 | ino_t ino; |
| 3678 | struct fileread *next; |
| 3679 | } *filesread = NULL; |
| 3680 | |
| 3681 | if (hard_opt == '7') |
| 3682 | { |
| 3683 | /* default conf-file reading */ |
| 3684 | hard_opt = 0; |
| 3685 | nofile_ok = 1; |
| 3686 | } |
| 3687 | |
| 3688 | if (hard_opt == 0 && strcmp(file, "-") == 0) |
| 3689 | { |
| 3690 | if (read_stdin == 1) |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 3691 | return 1; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3692 | read_stdin = 1; |
| 3693 | file = "stdin"; |
| 3694 | f = stdin; |
| 3695 | } |
| 3696 | else |
| 3697 | { |
| 3698 | /* ignore repeated files. */ |
| 3699 | struct stat statbuf; |
| 3700 | |
| 3701 | if (hard_opt == 0 && stat(file, &statbuf) == 0) |
| 3702 | { |
| 3703 | struct fileread *r; |
| 3704 | |
| 3705 | for (r = filesread; r; r = r->next) |
| 3706 | if (r->dev == statbuf.st_dev && r->ino == statbuf.st_ino) |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 3707 | return 1; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3708 | |
| 3709 | r = safe_malloc(sizeof(struct fileread)); |
| 3710 | r->next = filesread; |
| 3711 | filesread = r; |
| 3712 | r->dev = statbuf.st_dev; |
| 3713 | r->ino = statbuf.st_ino; |
| 3714 | } |
| 3715 | |
| 3716 | if (!(f = fopen(file, "r"))) |
| 3717 | { |
| 3718 | if (errno == ENOENT && nofile_ok) |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 3719 | return 1; /* No conffile, all done. */ |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3720 | else |
| 3721 | { |
| 3722 | char *str = _("cannot read %s: %s"); |
| 3723 | if (hard_opt != 0) |
| 3724 | { |
| 3725 | my_syslog(LOG_ERR, str, file, strerror(errno)); |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 3726 | return 0; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3727 | } |
| 3728 | else |
| 3729 | die(str, file, EC_FILE); |
| 3730 | } |
| 3731 | } |
| 3732 | } |
| 3733 | |
| 3734 | read_file(file, f, hard_opt); |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 3735 | return 1; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3736 | } |
| 3737 | |
| 3738 | /* expand any name which is a directory */ |
| 3739 | struct hostsfile *expand_filelist(struct hostsfile *list) |
| 3740 | { |
| 3741 | int i; |
| 3742 | struct hostsfile *ah; |
| 3743 | |
| 3744 | for (i = 0, ah = list; ah; ah = ah->next) |
| 3745 | { |
| 3746 | if (i <= ah->index) |
| 3747 | i = ah->index + 1; |
| 3748 | |
| 3749 | if (ah->flags & AH_DIR) |
| 3750 | ah->flags |= AH_INACTIVE; |
| 3751 | else |
| 3752 | ah->flags &= ~AH_INACTIVE; |
| 3753 | } |
| 3754 | |
| 3755 | for (ah = list; ah; ah = ah->next) |
| 3756 | if (!(ah->flags & AH_INACTIVE)) |
| 3757 | { |
| 3758 | struct stat buf; |
| 3759 | if (stat(ah->fname, &buf) != -1 && S_ISDIR(buf.st_mode)) |
| 3760 | { |
| 3761 | DIR *dir_stream; |
| 3762 | struct dirent *ent; |
| 3763 | |
| 3764 | /* don't read this as a file */ |
| 3765 | ah->flags |= AH_INACTIVE; |
| 3766 | |
| 3767 | if (!(dir_stream = opendir(ah->fname))) |
| 3768 | my_syslog(LOG_ERR, _("cannot access directory %s: %s"), |
| 3769 | ah->fname, strerror(errno)); |
| 3770 | else |
| 3771 | { |
| 3772 | while ((ent = readdir(dir_stream))) |
| 3773 | { |
| 3774 | size_t lendir = strlen(ah->fname); |
| 3775 | size_t lenfile = strlen(ent->d_name); |
| 3776 | struct hostsfile *ah1; |
| 3777 | char *path; |
| 3778 | |
| 3779 | /* ignore emacs backups and dotfiles */ |
| 3780 | if (lenfile == 0 || |
| 3781 | ent->d_name[lenfile - 1] == '~' || |
| 3782 | (ent->d_name[0] == '#' && ent->d_name[lenfile - 1] == '#') || |
| 3783 | ent->d_name[0] == '.') |
| 3784 | continue; |
| 3785 | |
| 3786 | /* see if we have an existing record. |
| 3787 | dir is ah->fname |
| 3788 | file is ent->d_name |
| 3789 | path to match is ah1->fname */ |
| 3790 | |
| 3791 | for (ah1 = list; ah1; ah1 = ah1->next) |
| 3792 | { |
| 3793 | if (lendir < strlen(ah1->fname) && |
| 3794 | strstr(ah1->fname, ah->fname) == ah1->fname && |
| 3795 | ah1->fname[lendir] == '/' && |
| 3796 | strcmp(ah1->fname + lendir + 1, ent->d_name) == 0) |
| 3797 | { |
| 3798 | ah1->flags &= ~AH_INACTIVE; |
| 3799 | break; |
| 3800 | } |
| 3801 | } |
| 3802 | |
| 3803 | /* make new record */ |
| 3804 | if (!ah1) |
| 3805 | { |
| 3806 | if (!(ah1 = whine_malloc(sizeof(struct hostsfile)))) |
| 3807 | continue; |
| 3808 | |
| 3809 | if (!(path = whine_malloc(lendir + lenfile + 2))) |
| 3810 | { |
| 3811 | free(ah1); |
| 3812 | continue; |
| 3813 | } |
| 3814 | |
| 3815 | strcpy(path, ah->fname); |
| 3816 | strcat(path, "/"); |
| 3817 | strcat(path, ent->d_name); |
| 3818 | ah1->fname = path; |
| 3819 | ah1->index = i++; |
| 3820 | ah1->flags = AH_DIR; |
| 3821 | ah1->next = list; |
| 3822 | list = ah1; |
| 3823 | } |
| 3824 | |
| 3825 | /* inactivate record if not regular file */ |
| 3826 | if ((ah1->flags & AH_DIR) && stat(ah1->fname, &buf) != -1 && !S_ISREG(buf.st_mode)) |
| 3827 | ah1->flags |= AH_INACTIVE; |
| 3828 | |
| 3829 | } |
| 3830 | closedir(dir_stream); |
| 3831 | } |
| 3832 | } |
| 3833 | } |
| 3834 | |
| 3835 | return list; |
| 3836 | } |
| 3837 | |
| 3838 | |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3839 | #ifdef HAVE_DHCP |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3840 | void reread_dhcp(void) |
| 3841 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3842 | struct hostsfile *hf; |
| 3843 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3844 | if (daemon->dhcp_hosts_file) |
| 3845 | { |
| 3846 | struct dhcp_config *configs, *cp, **up; |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3847 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3848 | /* remove existing... */ |
| 3849 | for (up = &daemon->dhcp_conf, configs = daemon->dhcp_conf; configs; configs = cp) |
| 3850 | { |
| 3851 | cp = configs->next; |
| 3852 | |
| 3853 | if (configs->flags & CONFIG_BANK) |
| 3854 | { |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 3855 | struct hwaddr_config *mac, *tmp; |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3856 | struct dhcp_netid_list *list, *tmplist; |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 3857 | |
| 3858 | for (mac = configs->hwaddr; mac; mac = tmp) |
| 3859 | { |
| 3860 | tmp = mac->next; |
| 3861 | free(mac); |
| 3862 | } |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3863 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3864 | if (configs->flags & CONFIG_CLID) |
| 3865 | free(configs->clid); |
Simon Kelley | 8ef5ada | 2010-06-03 19:42:45 +0100 | [diff] [blame] | 3866 | |
| 3867 | for (list = configs->netid; list; list = tmplist) |
| 3868 | { |
| 3869 | free(list->list); |
| 3870 | tmplist = list->next; |
| 3871 | free(list); |
| 3872 | } |
| 3873 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3874 | if (configs->flags & CONFIG_NAME) |
| 3875 | free(configs->hostname); |
| 3876 | |
| 3877 | *up = configs->next; |
| 3878 | free(configs); |
| 3879 | } |
| 3880 | else |
| 3881 | up = &configs->next; |
| 3882 | } |
| 3883 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3884 | daemon->dhcp_hosts_file = expand_filelist(daemon->dhcp_hosts_file); |
| 3885 | for (hf = daemon->dhcp_hosts_file; hf; hf = hf->next) |
| 3886 | if (!(hf->flags & AH_INACTIVE)) |
| 3887 | { |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 3888 | if (one_file(hf->fname, LOPT_BANK)) |
| 3889 | my_syslog(MS_DHCP | LOG_INFO, _("read %s"), hf->fname); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3890 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3891 | } |
| 3892 | |
| 3893 | if (daemon->dhcp_opts_file) |
| 3894 | { |
| 3895 | struct dhcp_opt *opts, *cp, **up; |
| 3896 | struct dhcp_netid *id, *next; |
| 3897 | |
| 3898 | for (up = &daemon->dhcp_opts, opts = daemon->dhcp_opts; opts; opts = cp) |
| 3899 | { |
| 3900 | cp = opts->next; |
| 3901 | |
| 3902 | if (opts->flags & DHOPT_BANK) |
| 3903 | { |
Simon Kelley | 73a08a2 | 2009-02-05 20:28:08 +0000 | [diff] [blame] | 3904 | if ((opts->flags & DHOPT_VENDOR)) |
| 3905 | free(opts->u.vendor_class); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3906 | free(opts->val); |
| 3907 | for (id = opts->netid; id; id = next) |
| 3908 | { |
| 3909 | next = id->next; |
| 3910 | free(id->net); |
| 3911 | free(id); |
| 3912 | } |
| 3913 | *up = opts->next; |
| 3914 | free(opts); |
| 3915 | } |
| 3916 | else |
| 3917 | up = &opts->next; |
| 3918 | } |
| 3919 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3920 | daemon->dhcp_opts_file = expand_filelist(daemon->dhcp_opts_file); |
| 3921 | for (hf = daemon->dhcp_opts_file; hf; hf = hf->next) |
| 3922 | if (!(hf->flags & AH_INACTIVE)) |
| 3923 | { |
Simon Kelley | 395eb71 | 2012-07-06 22:07:05 +0100 | [diff] [blame] | 3924 | if (one_file(hf->fname, LOPT_OPTS)) |
| 3925 | my_syslog(MS_DHCP | LOG_INFO, _("read %s"), hf->fname); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3926 | } |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3927 | } |
| 3928 | } |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3929 | #endif |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3930 | |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3931 | void read_opts(int argc, char **argv, char *compile_opts) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 3932 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3933 | char *buff = opt_malloc(MAXDNAME); |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3934 | int option, conffile_opt = '7', testmode = 0; |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 3935 | char *arg, *conffile = CONFFILE; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3936 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 3937 | opterr = 0; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3938 | |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 3939 | daemon = opt_malloc(sizeof(struct daemon)); |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 3940 | memset(daemon, 0, sizeof(struct daemon)); |
| 3941 | daemon->namebuff = buff; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 3942 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 3943 | /* Set defaults - everything else is zero or NULL */ |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 3944 | daemon->cachesize = CACHESIZ; |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 3945 | daemon->ftabsize = FTABSIZ; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 3946 | daemon->port = NAMESERVER_PORT; |
Simon Kelley | 9e03894 | 2008-05-30 20:06:34 +0100 | [diff] [blame] | 3947 | daemon->dhcp_client_port = DHCP_CLIENT_PORT; |
| 3948 | daemon->dhcp_server_port = DHCP_SERVER_PORT; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 3949 | daemon->default_resolv.is_default = 1; |
| 3950 | daemon->default_resolv.name = RESOLVFILE; |
| 3951 | daemon->resolv_files = &daemon->default_resolv; |
| 3952 | daemon->username = CHUSER; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 3953 | daemon->runfile = RUNFILE; |
| 3954 | daemon->dhcp_max = MAXLEASES; |
Simon Kelley | 832af0b | 2007-01-21 20:01:28 +0000 | [diff] [blame] | 3955 | daemon->tftp_max = TFTP_MAX_CONNECTIONS; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 3956 | daemon->edns_pktsz = EDNS_PKTSZ; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3957 | daemon->log_fac = -1; |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 3958 | daemon->auth_ttl = AUTH_TTL; |
| 3959 | daemon->soa_refresh = SOA_REFRESH; |
| 3960 | daemon->soa_retry = SOA_RETRY; |
| 3961 | daemon->soa_expiry = SOA_EXPIRY; |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 3962 | add_txt("version.bind", "dnsmasq-" VERSION ); |
| 3963 | add_txt("authors.bind", "Simon Kelley"); |
| 3964 | add_txt("copyright.bind", COPYRIGHT); |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 3965 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3966 | while (1) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 3967 | { |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 3968 | #ifdef HAVE_GETOPT_LONG |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3969 | option = getopt_long(argc, argv, OPTSTRING, opts, NULL); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 3970 | #else |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3971 | option = getopt(argc, argv, OPTSTRING); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 3972 | #endif |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 3973 | |
| 3974 | if (option == -1) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3975 | { |
Simon Kelley | 572b41e | 2011-02-18 18:11:18 +0000 | [diff] [blame] | 3976 | for (; optind < argc; optind++) |
| 3977 | { |
| 3978 | unsigned char *c = (unsigned char *)argv[optind]; |
| 3979 | for (; *c != 0; c++) |
| 3980 | if (!isspace(*c)) |
| 3981 | die(_("junk found in command line"), NULL, EC_BADCONF); |
| 3982 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 3983 | break; |
| 3984 | } |
| 3985 | |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3986 | /* Copy optarg so that argv doesn't get changed */ |
| 3987 | if (optarg) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 3988 | { |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 3989 | strncpy(buff, optarg, MAXDNAME); |
| 3990 | buff[MAXDNAME-1] = 0; |
| 3991 | arg = buff; |
| 3992 | } |
| 3993 | else |
| 3994 | arg = NULL; |
| 3995 | |
| 3996 | /* command-line only stuff */ |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 3997 | if (option == LOPT_TEST) |
| 3998 | testmode = 1; |
| 3999 | else if (option == 'w') |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4000 | { |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 4001 | #ifdef HAVE_DHCP |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 4002 | if (argc == 3 && strcmp(argv[2], "dhcp") == 0) |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 4003 | display_opts(); |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 4004 | #ifdef HAVE_DHCP6 |
| 4005 | else if (argc == 3 && strcmp(argv[2], "dhcp6") == 0) |
| 4006 | display_opts6(); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 4007 | #endif |
Simon Kelley | 4cb1b32 | 2012-02-06 14:30:41 +0000 | [diff] [blame] | 4008 | else |
| 4009 | #endif |
| 4010 | do_usage(); |
| 4011 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4012 | exit(0); |
| 4013 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4014 | else if (option == 'v') |
| 4015 | { |
| 4016 | printf(_("Dnsmasq version %s %s\n"), VERSION, COPYRIGHT); |
Simon Kelley | c72daea | 2012-01-05 21:33:27 +0000 | [diff] [blame] | 4017 | printf(_("Compile time options: %s\n\n"), compile_opts); |
Simon Kelley | b8187c8 | 2005-11-26 21:46:27 +0000 | [diff] [blame] | 4018 | printf(_("This software comes with ABSOLUTELY NO WARRANTY.\n")); |
| 4019 | printf(_("Dnsmasq is free software, and you are welcome to redistribute it\n")); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4020 | printf(_("under the terms of the GNU General Public License, version 2 or 3.\n")); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4021 | exit(0); |
| 4022 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4023 | else if (option == 'C') |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4024 | { |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4025 | conffile_opt = 0; /* file must exist */ |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4026 | conffile = opt_string_alloc(arg); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4027 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4028 | else |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4029 | { |
Simon Kelley | 26128d2 | 2004-11-14 16:43:54 +0000 | [diff] [blame] | 4030 | #ifdef HAVE_GETOPT_LONG |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4031 | if (!one_opt(option, arg, daemon->namebuff, _("try --help"), 1)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4032 | #else |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4033 | if (!one_opt(option, arg, daemon->namebuff, _("try -w"), 1)) |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4034 | #endif |
Simon Kelley | c4a7f90 | 2012-07-12 20:52:12 +0100 | [diff] [blame] | 4035 | die(_("bad command line options: %s"), daemon->namebuff, EC_BADCONF); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4036 | } |
| 4037 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4038 | |
| 4039 | if (conffile) |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4040 | one_file(conffile, conffile_opt); |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4041 | |
Simon Kelley | 1a6bca8 | 2008-07-11 11:11:42 +0100 | [diff] [blame] | 4042 | /* port might not be known when the address is parsed - fill in here */ |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 4043 | if (daemon->servers) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4044 | { |
| 4045 | struct server *tmp; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 4046 | for (tmp = daemon->servers; tmp; tmp = tmp->next) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4047 | if (!(tmp->flags & SERV_HAS_SOURCE)) |
| 4048 | { |
| 4049 | if (tmp->source_addr.sa.sa_family == AF_INET) |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 4050 | tmp->source_addr.in.sin_port = htons(daemon->query_port); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4051 | #ifdef HAVE_IPV6 |
| 4052 | else if (tmp->source_addr.sa.sa_family == AF_INET6) |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 4053 | tmp->source_addr.in6.sin6_port = htons(daemon->query_port); |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4054 | #endif |
| 4055 | } |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4056 | } |
| 4057 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 4058 | if (daemon->if_addrs) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4059 | { |
| 4060 | struct iname *tmp; |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 4061 | for(tmp = daemon->if_addrs; tmp; tmp = tmp->next) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4062 | if (tmp->addr.sa.sa_family == AF_INET) |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 4063 | tmp->addr.in.sin_port = htons(daemon->port); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4064 | #ifdef HAVE_IPV6 |
| 4065 | else if (tmp->addr.sa.sa_family == AF_INET6) |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 4066 | tmp->addr.in6.sin6_port = htons(daemon->port); |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4067 | #endif /* IPv6 */ |
| 4068 | } |
Simon Kelley | 4f7b304 | 2012-11-28 21:27:02 +0000 | [diff] [blame] | 4069 | |
| 4070 | /* create default, if not specified */ |
| 4071 | if (daemon->authserver && !daemon->hostmaster) |
| 4072 | { |
| 4073 | strcpy(buff, "hostmaster."); |
| 4074 | strcat(buff, daemon->authserver); |
| 4075 | daemon->hostmaster = opt_string_alloc(buff); |
| 4076 | } |
| 4077 | |
Simon Kelley | f6b7dc4 | 2005-01-23 12:06:08 +0000 | [diff] [blame] | 4078 | /* only one of these need be specified: the other defaults to the host-name */ |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4079 | if (option_bool(OPT_LOCALMX) || daemon->mxnames || daemon->mxtarget) |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4080 | { |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 4081 | struct mx_srv_record *mx; |
| 4082 | |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4083 | if (gethostname(buff, MAXDNAME) == -1) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4084 | die(_("cannot get host-name: %s"), NULL, EC_MISC); |
Simon Kelley | f6b7dc4 | 2005-01-23 12:06:08 +0000 | [diff] [blame] | 4085 | |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 4086 | for (mx = daemon->mxnames; mx; mx = mx->next) |
| 4087 | if (!mx->issrv && hostname_isequal(mx->name, buff)) |
| 4088 | break; |
| 4089 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4090 | if ((daemon->mxtarget || option_bool(OPT_LOCALMX)) && !mx) |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 4091 | { |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4092 | mx = opt_malloc(sizeof(struct mx_srv_record)); |
Simon Kelley | 91dccd0 | 2005-03-31 17:48:32 +0100 | [diff] [blame] | 4093 | mx->next = daemon->mxnames; |
| 4094 | mx->issrv = 0; |
| 4095 | mx->target = NULL; |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4096 | mx->name = opt_string_alloc(buff); |
Simon Kelley | 91dccd0 | 2005-03-31 17:48:32 +0100 | [diff] [blame] | 4097 | daemon->mxnames = mx; |
Simon Kelley | f6b7dc4 | 2005-01-23 12:06:08 +0000 | [diff] [blame] | 4098 | } |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4099 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 4100 | if (!daemon->mxtarget) |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4101 | daemon->mxtarget = opt_string_alloc(buff); |
Simon Kelley | 0a85254 | 2005-03-23 20:28:59 +0000 | [diff] [blame] | 4102 | |
| 4103 | for (mx = daemon->mxnames; mx; mx = mx->next) |
| 4104 | if (!mx->issrv && !mx->target) |
| 4105 | mx->target = daemon->mxtarget; |
Simon Kelley | 9e4abcb | 2004-01-22 19:47:41 +0000 | [diff] [blame] | 4106 | } |
Simon Kelley | f6b7dc4 | 2005-01-23 12:06:08 +0000 | [diff] [blame] | 4107 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4108 | if (!option_bool(OPT_NO_RESOLV) && |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 4109 | daemon->resolv_files && |
| 4110 | daemon->resolv_files->next && |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4111 | option_bool(OPT_NO_POLL)) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4112 | die(_("only one resolv.conf file allowed in no-poll mode."), NULL, EC_BADCONF); |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 4113 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4114 | if (option_bool(OPT_RESOLV_DOMAIN)) |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 4115 | { |
| 4116 | char *line; |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4117 | FILE *f; |
| 4118 | |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4119 | if (option_bool(OPT_NO_RESOLV) || |
Simon Kelley | 208b65c | 2006-08-05 21:41:37 +0100 | [diff] [blame] | 4120 | !daemon->resolv_files || |
| 4121 | (daemon->resolv_files)->next) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4122 | die(_("must have exactly one resolv.conf to read domain from."), NULL, EC_BADCONF); |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 4123 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 4124 | if (!(f = fopen((daemon->resolv_files)->name, "r"))) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4125 | die(_("failed to read %s: %s"), (daemon->resolv_files)->name, EC_FILE); |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 4126 | |
| 4127 | while ((line = fgets(buff, MAXDNAME, f))) |
| 4128 | { |
| 4129 | char *token = strtok(line, " \t\n\r"); |
| 4130 | |
| 4131 | if (!token || strcmp(token, "search") != 0) |
| 4132 | continue; |
| 4133 | |
| 4134 | if ((token = strtok(NULL, " \t\n\r")) && |
Simon Kelley | 1f15b81 | 2009-10-13 17:49:32 +0100 | [diff] [blame] | 4135 | (daemon->domain_suffix = canonicalise_opt(token))) |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 4136 | break; |
| 4137 | } |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 4138 | |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 4139 | fclose(f); |
Simon Kelley | 8a911cc | 2004-03-16 18:35:52 +0000 | [diff] [blame] | 4140 | |
Simon Kelley | 3be3454 | 2004-09-11 19:12:13 +0100 | [diff] [blame] | 4141 | if (!daemon->domain_suffix) |
Simon Kelley | 5aabfc7 | 2007-08-29 11:24:47 +0100 | [diff] [blame] | 4142 | die(_("no search directive found in %s"), (daemon->resolv_files)->name, EC_MISC); |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 4143 | } |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 4144 | |
| 4145 | if (daemon->domain_suffix) |
| 4146 | { |
| 4147 | /* add domain for any srv record without one. */ |
| 4148 | struct mx_srv_record *srv; |
Simon Kelley | de37951 | 2004-06-22 20:23:33 +0100 | [diff] [blame] | 4149 | |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 4150 | for (srv = daemon->mxnames; srv; srv = srv->next) |
| 4151 | if (srv->issrv && |
| 4152 | strchr(srv->name, '.') && |
| 4153 | strchr(srv->name, '.') == strrchr(srv->name, '.')) |
| 4154 | { |
| 4155 | strcpy(buff, srv->name); |
| 4156 | strcat(buff, "."); |
| 4157 | strcat(buff, daemon->domain_suffix); |
| 4158 | free(srv->name); |
Simon Kelley | 824af85 | 2008-02-12 20:43:05 +0000 | [diff] [blame] | 4159 | srv->name = opt_string_alloc(buff); |
Simon Kelley | 3d8df26 | 2005-08-29 12:19:27 +0100 | [diff] [blame] | 4160 | } |
| 4161 | } |
Simon Kelley | 28866e9 | 2011-02-14 20:19:14 +0000 | [diff] [blame] | 4162 | else if (option_bool(OPT_DHCP_FQDN)) |
Simon Kelley | 9009d74 | 2008-11-14 20:04:27 +0000 | [diff] [blame] | 4163 | die(_("there must be a default domain when --dhcp-fqdn is set"), NULL, EC_BADCONF); |
Simon Kelley | 7622fc0 | 2009-06-04 20:32:05 +0100 | [diff] [blame] | 4164 | |
| 4165 | if (testmode) |
| 4166 | { |
| 4167 | fprintf(stderr, "dnsmasq: %s.\n", _("syntax check OK")); |
| 4168 | exit(0); |
| 4169 | } |
Simon Kelley | 849a835 | 2006-06-09 21:02:31 +0100 | [diff] [blame] | 4170 | } |