]> git.ipfire.org Git - ipfire-2.x.git/blob - src/patches/dnsmasq/0068-add-tftp-no-fail-to-ignore-missing-tftp-root.patch
Merge remote-tracking branch 'earl/tor' into next
[ipfire-2.x.git] / src / patches / dnsmasq / 0068-add-tftp-no-fail-to-ignore-missing-tftp-root.patch
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 68/98] add --tftp-no-fail to ignore missing tftp root
5
6 ---
7 CHANGELOG | 3 +++
8 dnsmasq.conf.example | 3 +++
9 man/dnsmasq.8 | 3 +++
10 src/dnsmasq.c | 40 ++++++++++++++++++++++++++++++----------
11 src/dnsmasq.h | 4 +++-
12 src/option.c | 3 +++
13 6 files changed, 45 insertions(+), 11 deletions(-)
14
15 diff --git a/CHANGELOG b/CHANGELOG
16 index 4f4fa305deaa..34432ae4807f 100644
17 --- a/CHANGELOG
18 +++ b/CHANGELOG
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.
23 +
24 + Add --tftp-no-fail option. Thanks to Stefan Tomanek for
25 + the patch.
26
27
28 version 2.72
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
33 @@ -486,6 +486,9 @@
34 # Set the root directory for files available via FTP.
35 #tftp-root=/var/ftpd
36
37 +# Do not abort if the tftp-root is unavailable
38 +#tftp-no-fail
39 +
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.
42 #tftp-secure
43 diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
44 index 1f1dd7b69c53..6b4626cc0aad 100644
45 --- a/man/dnsmasq.8
46 +++ b/man/dnsmasq.8
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.
50 .TP
51 +.B --tftp-no-fail
52 +Do not abort startup if specified tftp root directories are inaccessible.
53 +.TP
54 .B --tftp-unique-root
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
59 --- a/src/dnsmasq.c
60 +++ b/src/dnsmasq.c
61 @@ -58,6 +58,9 @@ int main (int argc, char **argv)
62 struct dhcp_context *context;
63 struct dhcp_relay *relay;
64 #endif
65 +#ifdef HAVE_TFTP
66 + int tftp_prefix_missing = 0;
67 +#endif
68
69 #ifdef LOCALEDIR
70 setlocale(LC_ALL, "");
71 @@ -636,7 +639,7 @@ int main (int argc, char **argv)
72 #endif
73
74 #ifdef HAVE_TFTP
75 - if (option_bool(OPT_TFTP))
76 + if (option_bool(OPT_TFTP))
77 {
78 DIR *dir;
79 struct tftp_prefix *p;
80 @@ -645,24 +648,33 @@ int main (int argc, char **argv)
81 {
82 if (!((dir = opendir(daemon->tftp_prefix))))
83 {
84 - send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
85 - _exit(0);
86 + tftp_prefix_missing = 1;
87 + if (!option_bool(OPT_TFTP_NO_FAIL))
88 + {
89 + send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
90 + _exit(0);
91 + }
92 }
93 closedir(dir);
94 }
95 -
96 +
97 for (p = daemon->if_prefix; p; p = p->next)
98 {
99 + p->missing = 0;
100 if (!((dir = opendir(p->prefix))))
101 - {
102 - send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
103 - _exit(0);
104 - }
105 + {
106 + p->missing = 1;
107 + if (!option_bool(OPT_TFTP_NO_FAIL))
108 + {
109 + send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
110 + _exit(0);
111 + }
112 + }
113 closedir(dir);
114 }
115 }
116 #endif
117 -
118 +
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)
123
124 #ifdef HAVE_TFTP
125 if (option_bool(OPT_TFTP))
126 - {
127 + {
128 + struct tftp_prefix *p;
129 #ifdef FD_SETSIZE
130 if (FD_SETSIZE < (unsigned)max_fd)
131 max_fd = FD_SETSIZE;
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") : "");
136 +
137 + if (tftp_prefix_missing)
138 + my_syslog(MS_TFTP | LOG_WARNING, _("warning: %s inaccessible"), daemon->tftp_prefix);
139
140 + for (p = daemon->if_prefix; p; p = p->next)
141 + if (p->missing)
142 + my_syslog(MS_TFTP | LOG_WARNING, _("warning: TFTP directory %s inaccessible"), p->prefix);
143 +
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
149 --- a/src/dnsmasq.h
150 +++ b/src/dnsmasq.h
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
155 -#define OPT_LAST 52
156 +#define OPT_TFTP_NO_FAIL 52
157 +#define OPT_LAST 53
158
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 {
162 struct tftp_prefix {
163 char *interface;
164 char *prefix;
165 + int missing;
166 struct tftp_prefix *next;
167 };
168
169 diff --git a/src/option.c b/src/option.c
170 index 3009eb545fde..f91cfbb1aa54 100644
171 --- a/src/option.c
172 +++ b/src/option.c
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
178
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 },
197 --
198 2.1.0
199