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