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