1 From 56920681eaf2c5eb08fc75baee4939d15d03b0ea 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] add --tftp-no-fail to ignore missing tftp root
6 (cherry picked from commit 30d0879ed55cb67b1b735beab3d93f3bb3ef1dd2)
14 dnsmasq.conf.example | 3 +++
16 src/dnsmasq.c | 42 +++++++++++++++++++++++++++++++-----------
17 src/dnsmasq.h | 4 +++-
19 5 files changed, 43 insertions(+), 12 deletions(-)
21 diff --git a/dnsmasq.conf.example b/dnsmasq.conf.example
22 index 1bd305d..67be99a 100644
23 --- a/dnsmasq.conf.example
24 +++ b/dnsmasq.conf.example
26 # Set the root directory for files available via FTP.
29 +# Do not abort if the tftp-root is unavailable
32 # Make the TFTP server more secure: with this set, only files owned by
33 # the user dnsmasq is running as will be send over the net.
35 diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
36 index 0b8e04f..2ff4b96 100644
39 @@ -1670,6 +1670,9 @@ Absolute paths (starting with /) are allowed, but they must be within
40 the tftp-root. If the optional interface argument is given, the
41 directory is only used for TFTP requests via that interface.
44 +Do not abort startup if specified tftp root directories are inaccessible.
47 Add the IP address of the TFTP client as a path component on the end
48 of the TFTP-root (in standard dotted-quad format). Only valid if a
49 diff --git a/src/dnsmasq.c b/src/dnsmasq.c
50 index 5c7750d..b6fa285 100644
53 @@ -58,6 +58,9 @@ int main (int argc, char **argv)
54 struct dhcp_context *context;
55 struct dhcp_relay *relay;
58 + int tftp_prefix_missing = 0;
62 setlocale(LC_ALL, "");
63 @@ -623,7 +626,7 @@ int main (int argc, char **argv)
67 - if (option_bool(OPT_TFTP))
68 + if (option_bool(OPT_TFTP))
71 struct tftp_prefix *p;
72 @@ -632,24 +635,33 @@ int main (int argc, char **argv)
74 if (!((dir = opendir(daemon->tftp_prefix))))
76 - send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
78 + tftp_prefix_missing = 1;
79 + if (!option_bool(OPT_TFTP_NO_FAIL))
81 + send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
89 for (p = daemon->if_prefix; p; p = p->next)
92 if (!((dir = opendir(p->prefix))))
94 - send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
99 + if (!option_bool(OPT_TFTP_NO_FAIL))
101 + send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
111 if (daemon->port == 0)
112 my_syslog(LOG_INFO, _("started, version %s DNS disabled"), VERSION);
113 else if (daemon->cachesize != 0)
114 @@ -743,8 +755,9 @@ int main (int argc, char **argv)
118 - if (option_bool(OPT_TFTP))
120 + if (option_bool(OPT_TFTP))
122 + struct tftp_prefix *p;
124 if (FD_SETSIZE < (unsigned)max_fd)
126 @@ -754,7 +767,14 @@ int main (int argc, char **argv)
127 daemon->tftp_prefix ? _("root is ") : _("enabled"),
128 daemon->tftp_prefix ? daemon->tftp_prefix: "",
129 option_bool(OPT_TFTP_SECURE) ? _("secure mode") : "");
131 + if (tftp_prefix_missing)
132 + my_syslog(MS_TFTP | LOG_WARNING, _("warning: %s inaccessible"), daemon->tftp_prefix);
134 + for (p = daemon->if_prefix; p; p = p->next)
136 + my_syslog(MS_TFTP | LOG_WARNING, _("warning: TFTP directory %s inaccessible"), p->prefix);
138 /* This is a guess, it assumes that for small limits,
139 disjoint files might be served, but for large limits,
140 a single file will be sent to may clients (the file only needs
141 diff --git a/src/dnsmasq.h b/src/dnsmasq.h
142 index 1dd61c5..086cb67 100644
145 @@ -238,7 +238,8 @@ struct event_desc {
146 #define OPT_DNSSEC_NO_SIGN 48
147 #define OPT_LOCAL_SERVICE 49
148 #define OPT_LOOP_DETECT 50
150 +#define OPT_TFTP_NO_FAIL 51
153 /* extra flags for my_syslog, we use a couple of facilities since they are known
154 not to occupy the same bits as priorities, no matter how syslog.h is set up. */
155 @@ -888,6 +889,7 @@ struct addr_list {
160 struct tftp_prefix *next;
163 diff --git a/src/option.c b/src/option.c
164 index 209fa69..fa5e4d3 100644
167 @@ -147,6 +147,7 @@ struct myoption {
168 #define LOPT_LOCAL_SERVICE 335
169 #define LOPT_DNSSEC_TIME 336
170 #define LOPT_LOOP_DETECT 337
171 +#define LOPT_TFTP_NO_FAIL 338
173 #ifdef HAVE_GETOPT_LONG
174 static const struct option opts[] =
175 @@ -227,6 +228,7 @@ static const struct myoption opts[] =
176 { "dhcp-ignore-names", 2, 0, LOPT_NO_NAMES },
177 { "enable-tftp", 2, 0, LOPT_TFTP },
178 { "tftp-secure", 0, 0, LOPT_SECURE },
179 + { "tftp-no-fail", 0, 0, LOPT_TFTP_NO_FAIL },
180 { "tftp-unique-root", 0, 0, LOPT_APREF },
181 { "tftp-root", 1, 0, LOPT_PREFIX },
182 { "tftp-max", 1, 0, LOPT_TFTP_MAX },
183 @@ -402,6 +404,7 @@ static struct {
184 { LOPT_PREFIX, ARG_DUP, "<dir>[,<iface>]", gettext_noop("Export files by TFTP only from the specified subtree."), NULL },
185 { LOPT_APREF, OPT_TFTP_APREF, NULL, gettext_noop("Add client IP address to tftp-root."), NULL },
186 { LOPT_SECURE, OPT_TFTP_SECURE, NULL, gettext_noop("Allow access only to files owned by the user running dnsmasq."), NULL },
187 + { LOPT_TFTP_NO_FAIL, OPT_TFTP_NO_FAIL, NULL, gettext_noop("Do not terminate the service if TFTP directories are inaccessible."), NULL },
188 { LOPT_TFTP_MAX, ARG_ONE, "<integer>", gettext_noop("Maximum number of conncurrent TFTP transfers (defaults to %s)."), "#" },
189 { LOPT_NOBLOCK, OPT_TFTP_NOBLOCK, NULL, gettext_noop("Disable the TFTP blocksize extension."), NULL },
190 { LOPT_TFTP_LC, OPT_TFTP_LC, NULL, gettext_noop("Convert TFTP filenames to lowercase"), NULL },