bcm53xx: build image for ASUS RT-AC56U
[openwrt/openwrt.git] / package / network / services / dnsmasq / patches / 120-add-tftp-no-fail-to-ignore-missing-tftp-root.patch
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
5
6 (cherry picked from commit 30d0879ed55cb67b1b735beab3d93f3bb3ef1dd2)
7
8 Conflicts:
9 CHANGELOG
10 src/dnsmasq.c
11 src/dnsmasq.h
12 src/option.c
13 ---
14 dnsmasq.conf.example | 3 +++
15 man/dnsmasq.8 | 3 +++
16 src/dnsmasq.c | 42 +++++++++++++++++++++++++++++++-----------
17 src/dnsmasq.h | 4 +++-
18 src/option.c | 3 +++
19 5 files changed, 43 insertions(+), 12 deletions(-)
20
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
25 @@ -486,6 +486,9 @@
26 # Set the root directory for files available via FTP.
27 #tftp-root=/var/ftpd
28
29 +# Do not abort if the tftp-root is unavailable
30 +#tftp-no-fail
31 +
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.
34 #tftp-secure
35 diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
36 index 0b8e04f..2ff4b96 100644
37 --- a/man/dnsmasq.8
38 +++ b/man/dnsmasq.8
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.
42 .TP
43 +.B --tftp-no-fail
44 +Do not abort startup if specified tftp root directories are inaccessible.
45 +.TP
46 .B --tftp-unique-root
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
51 --- a/src/dnsmasq.c
52 +++ b/src/dnsmasq.c
53 @@ -58,6 +58,9 @@ int main (int argc, char **argv)
54 struct dhcp_context *context;
55 struct dhcp_relay *relay;
56 #endif
57 +#ifdef HAVE_TFTP
58 + int tftp_prefix_missing = 0;
59 +#endif
60
61 #ifdef LOCALEDIR
62 setlocale(LC_ALL, "");
63 @@ -623,7 +626,7 @@ int main (int argc, char **argv)
64 #endif
65
66 #ifdef HAVE_TFTP
67 - if (option_bool(OPT_TFTP))
68 + if (option_bool(OPT_TFTP))
69 {
70 DIR *dir;
71 struct tftp_prefix *p;
72 @@ -632,24 +635,33 @@ int main (int argc, char **argv)
73 {
74 if (!((dir = opendir(daemon->tftp_prefix))))
75 {
76 - send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
77 - _exit(0);
78 + tftp_prefix_missing = 1;
79 + if (!option_bool(OPT_TFTP_NO_FAIL))
80 + {
81 + send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
82 + _exit(0);
83 + }
84 }
85 closedir(dir);
86 }
87 -
88 +
89 for (p = daemon->if_prefix; p; p = p->next)
90 {
91 + p->missing = 0;
92 if (!((dir = opendir(p->prefix))))
93 - {
94 - send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
95 - _exit(0);
96 - }
97 + {
98 + p->missing = 1;
99 + if (!option_bool(OPT_TFTP_NO_FAIL))
100 + {
101 + send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
102 + _exit(0);
103 + }
104 + }
105 closedir(dir);
106 }
107 }
108 #endif
109 -
110 +
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)
115 #endif
116
117 #ifdef HAVE_TFTP
118 - if (option_bool(OPT_TFTP))
119 - {
120 + if (option_bool(OPT_TFTP))
121 + {
122 + struct tftp_prefix *p;
123 #ifdef FD_SETSIZE
124 if (FD_SETSIZE < (unsigned)max_fd)
125 max_fd = FD_SETSIZE;
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") : "");
130 +
131 + if (tftp_prefix_missing)
132 + my_syslog(MS_TFTP | LOG_WARNING, _("warning: %s inaccessible"), daemon->tftp_prefix);
133
134 + for (p = daemon->if_prefix; p; p = p->next)
135 + if (p->missing)
136 + my_syslog(MS_TFTP | LOG_WARNING, _("warning: TFTP directory %s inaccessible"), p->prefix);
137 +
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
143 --- a/src/dnsmasq.h
144 +++ b/src/dnsmasq.h
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
149 -#define OPT_LAST 51
150 +#define OPT_TFTP_NO_FAIL 51
151 +#define OPT_LAST 52
152
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 {
156 struct tftp_prefix {
157 char *interface;
158 char *prefix;
159 + int missing;
160 struct tftp_prefix *next;
161 };
162
163 diff --git a/src/option.c b/src/option.c
164 index 209fa69..fa5e4d3 100644
165 --- a/src/option.c
166 +++ b/src/option.c
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
172
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 },
191 --
192 2.1.4
193