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