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