1 From 30d0879ed55cb67b1b735beab3d93f3bb3ef1dd2 Mon Sep 17 00:00:00 2001
2 From: Stefan Tomanek <stefan.tomanek+dnsmasq@wertarbyte.de>
3 Date: Tue, 31 Mar 2015 22:32:11 +0100
4 Subject: [PATCH 068/113] add --tftp-no-fail to ignore missing tftp root
8 dnsmasq.conf.example | 3 +++
10 src/dnsmasq.c | 40 ++++++++++++++++++++++++++++++----------
11 src/dnsmasq.h | 4 +++-
13 6 files changed, 45 insertions(+), 11 deletions(-)
15 diff --git a/CHANGELOG b/CHANGELOG
16 index 4f4fa305deaa..34432ae4807f 100644
19 @@ -72,6 +72,9 @@ version 2.73
20 on systems without an RTC, whilst allowing DNS queries before the
21 clock is valid so that NTP can run. Thanks to
22 Kevin Darbyshire-Bryant for developing this idea.
24 + Add --tftp-no-fail option. Thanks to Stefan Tomanek for
29 diff --git a/dnsmasq.conf.example b/dnsmasq.conf.example
30 index 1bd305dbdbad..67be99acb028 100644
31 --- a/dnsmasq.conf.example
32 +++ b/dnsmasq.conf.example
34 # Set the root directory for files available via FTP.
37 +# Do not abort if the tftp-root is unavailable
40 # Make the TFTP server more secure: with this set, only files owned by
41 # the user dnsmasq is running as will be send over the net.
43 diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
44 index 1f1dd7b69c53..6b4626cc0aad 100644
47 @@ -1711,6 +1711,9 @@ Absolute paths (starting with /) are allowed, but they must be within
48 the tftp-root. If the optional interface argument is given, the
49 directory is only used for TFTP requests via that interface.
52 +Do not abort startup if specified tftp root directories are inaccessible.
55 Add the IP address of the TFTP client as a path component on the end
56 of the TFTP-root (in standard dotted-quad format). Only valid if a
57 diff --git a/src/dnsmasq.c b/src/dnsmasq.c
58 index b784951950d4..0d4d4558a2e2 100644
61 @@ -58,6 +58,9 @@ int main (int argc, char **argv)
62 struct dhcp_context *context;
63 struct dhcp_relay *relay;
66 + int tftp_prefix_missing = 0;
70 setlocale(LC_ALL, "");
71 @@ -636,7 +639,7 @@ int main (int argc, char **argv)
75 - if (option_bool(OPT_TFTP))
76 + if (option_bool(OPT_TFTP))
79 struct tftp_prefix *p;
80 @@ -645,24 +648,33 @@ int main (int argc, char **argv)
82 if (!((dir = opendir(daemon->tftp_prefix))))
84 - send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
86 + tftp_prefix_missing = 1;
87 + if (!option_bool(OPT_TFTP_NO_FAIL))
89 + send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
97 for (p = daemon->if_prefix; p; p = p->next)
100 if (!((dir = opendir(p->prefix))))
102 - send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
107 + if (!option_bool(OPT_TFTP_NO_FAIL))
109 + send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
119 if (daemon->port == 0)
120 my_syslog(LOG_INFO, _("started, version %s DNS disabled"), VERSION);
121 else if (daemon->cachesize != 0)
122 @@ -772,7 +784,8 @@ int main (int argc, char **argv)
125 if (option_bool(OPT_TFTP))
128 + struct tftp_prefix *p;
130 if (FD_SETSIZE < (unsigned)max_fd)
132 @@ -782,7 +795,14 @@ int main (int argc, char **argv)
133 daemon->tftp_prefix ? _("root is ") : _("enabled"),
134 daemon->tftp_prefix ? daemon->tftp_prefix: "",
135 option_bool(OPT_TFTP_SECURE) ? _("secure mode") : "");
137 + if (tftp_prefix_missing)
138 + my_syslog(MS_TFTP | LOG_WARNING, _("warning: %s inaccessible"), daemon->tftp_prefix);
140 + for (p = daemon->if_prefix; p; p = p->next)
142 + my_syslog(MS_TFTP | LOG_WARNING, _("warning: TFTP directory %s inaccessible"), p->prefix);
144 /* This is a guess, it assumes that for small limits,
145 disjoint files might be served, but for large limits,
146 a single file will be sent to may clients (the file only needs
147 diff --git a/src/dnsmasq.h b/src/dnsmasq.h
148 index de95d0e875e3..42952fc76c7a 100644
151 @@ -240,7 +240,8 @@ struct event_desc {
152 #define OPT_LOCAL_SERVICE 49
153 #define OPT_LOOP_DETECT 50
154 #define OPT_EXTRALOG 51
156 +#define OPT_TFTP_NO_FAIL 52
159 /* extra flags for my_syslog, we use a couple of facilities since they are known
160 not to occupy the same bits as priorities, no matter how syslog.h is set up. */
161 @@ -901,6 +902,7 @@ struct addr_list {
166 struct tftp_prefix *next;
169 diff --git a/src/option.c b/src/option.c
170 index 3009eb545fde..f91cfbb1aa54 100644
173 @@ -153,6 +153,7 @@ struct myoption {
174 #define LOPT_DHOPT_INOTIFY 341
175 #define LOPT_HOST_INOTIFY 342
176 #define LOPT_DNSSEC_STAMP 343
177 +#define LOPT_TFTP_NO_FAIL 344
179 #ifdef HAVE_GETOPT_LONG
180 static const struct option opts[] =
181 @@ -235,6 +236,7 @@ static const struct myoption opts[] =
182 { "dhcp-ignore-names", 2, 0, LOPT_NO_NAMES },
183 { "enable-tftp", 2, 0, LOPT_TFTP },
184 { "tftp-secure", 0, 0, LOPT_SECURE },
185 + { "tftp-no-fail", 0, 0, LOPT_TFTP_NO_FAIL },
186 { "tftp-unique-root", 0, 0, LOPT_APREF },
187 { "tftp-root", 1, 0, LOPT_PREFIX },
188 { "tftp-max", 1, 0, LOPT_TFTP_MAX },
189 @@ -419,6 +421,7 @@ static struct {
190 { LOPT_PREFIX, ARG_DUP, "<dir>[,<iface>]", gettext_noop("Export files by TFTP only from the specified subtree."), NULL },
191 { LOPT_APREF, OPT_TFTP_APREF, NULL, gettext_noop("Add client IP address to tftp-root."), NULL },
192 { LOPT_SECURE, OPT_TFTP_SECURE, NULL, gettext_noop("Allow access only to files owned by the user running dnsmasq."), NULL },
193 + { LOPT_TFTP_NO_FAIL, OPT_TFTP_NO_FAIL, NULL, gettext_noop("Do not terminate the service if TFTP directories are inaccessible."), NULL },
194 { LOPT_TFTP_MAX, ARG_ONE, "<integer>", gettext_noop("Maximum number of conncurrent TFTP transfers (defaults to %s)."), "#" },
195 { LOPT_NOBLOCK, OPT_TFTP_NOBLOCK, NULL, gettext_noop("Disable the TFTP blocksize extension."), NULL },
196 { LOPT_TFTP_LC, OPT_TFTP_LC, NULL, gettext_noop("Convert TFTP filenames to lowercase"), NULL },