120-add-tftp-no-fail-to-ignore-missing-tftp-root.patch 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193
  1. From 56920681eaf2c5eb08fc75baee4939d15d03b0ea Mon Sep 17 00:00:00 2001
  2. From: Stefan Tomanek <[email protected]>
  3. Date: Tue, 31 Mar 2015 22:32:11 +0100
  4. Subject: [PATCH] add --tftp-no-fail to ignore missing tftp root
  5. (cherry picked from commit 30d0879ed55cb67b1b735beab3d93f3bb3ef1dd2)
  6. Conflicts:
  7. CHANGELOG
  8. src/dnsmasq.c
  9. src/dnsmasq.h
  10. src/option.c
  11. ---
  12. dnsmasq.conf.example | 3 +++
  13. man/dnsmasq.8 | 3 +++
  14. src/dnsmasq.c | 42 +++++++++++++++++++++++++++++++-----------
  15. src/dnsmasq.h | 4 +++-
  16. src/option.c | 3 +++
  17. 5 files changed, 43 insertions(+), 12 deletions(-)
  18. diff --git a/dnsmasq.conf.example b/dnsmasq.conf.example
  19. index 1bd305d..67be99a 100644
  20. --- a/dnsmasq.conf.example
  21. +++ b/dnsmasq.conf.example
  22. @@ -486,6 +486,9 @@
  23. # Set the root directory for files available via FTP.
  24. #tftp-root=/var/ftpd
  25. +# Do not abort if the tftp-root is unavailable
  26. +#tftp-no-fail
  27. +
  28. # Make the TFTP server more secure: with this set, only files owned by
  29. # the user dnsmasq is running as will be send over the net.
  30. #tftp-secure
  31. diff --git a/man/dnsmasq.8 b/man/dnsmasq.8
  32. index 0b8e04f..2ff4b96 100644
  33. --- a/man/dnsmasq.8
  34. +++ b/man/dnsmasq.8
  35. @@ -1670,6 +1670,9 @@ Absolute paths (starting with /) are allowed, but they must be within
  36. the tftp-root. If the optional interface argument is given, the
  37. directory is only used for TFTP requests via that interface.
  38. .TP
  39. +.B --tftp-no-fail
  40. +Do not abort startup if specified tftp root directories are inaccessible.
  41. +.TP
  42. .B --tftp-unique-root
  43. Add the IP address of the TFTP client as a path component on the end
  44. of the TFTP-root (in standard dotted-quad format). Only valid if a
  45. diff --git a/src/dnsmasq.c b/src/dnsmasq.c
  46. index 5c7750d..b6fa285 100644
  47. --- a/src/dnsmasq.c
  48. +++ b/src/dnsmasq.c
  49. @@ -58,6 +58,9 @@ int main (int argc, char **argv)
  50. struct dhcp_context *context;
  51. struct dhcp_relay *relay;
  52. #endif
  53. +#ifdef HAVE_TFTP
  54. + int tftp_prefix_missing = 0;
  55. +#endif
  56. #ifdef LOCALEDIR
  57. setlocale(LC_ALL, "");
  58. @@ -623,7 +626,7 @@ int main (int argc, char **argv)
  59. #endif
  60. #ifdef HAVE_TFTP
  61. - if (option_bool(OPT_TFTP))
  62. + if (option_bool(OPT_TFTP))
  63. {
  64. DIR *dir;
  65. struct tftp_prefix *p;
  66. @@ -632,24 +635,33 @@ int main (int argc, char **argv)
  67. {
  68. if (!((dir = opendir(daemon->tftp_prefix))))
  69. {
  70. - send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
  71. - _exit(0);
  72. + tftp_prefix_missing = 1;
  73. + if (!option_bool(OPT_TFTP_NO_FAIL))
  74. + {
  75. + send_event(err_pipe[1], EVENT_TFTP_ERR, errno, daemon->tftp_prefix);
  76. + _exit(0);
  77. + }
  78. }
  79. closedir(dir);
  80. }
  81. -
  82. +
  83. for (p = daemon->if_prefix; p; p = p->next)
  84. {
  85. + p->missing = 0;
  86. if (!((dir = opendir(p->prefix))))
  87. - {
  88. - send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
  89. - _exit(0);
  90. - }
  91. + {
  92. + p->missing = 1;
  93. + if (!option_bool(OPT_TFTP_NO_FAIL))
  94. + {
  95. + send_event(err_pipe[1], EVENT_TFTP_ERR, errno, p->prefix);
  96. + _exit(0);
  97. + }
  98. + }
  99. closedir(dir);
  100. }
  101. }
  102. #endif
  103. -
  104. +
  105. if (daemon->port == 0)
  106. my_syslog(LOG_INFO, _("started, version %s DNS disabled"), VERSION);
  107. else if (daemon->cachesize != 0)
  108. @@ -743,8 +755,9 @@ int main (int argc, char **argv)
  109. #endif
  110. #ifdef HAVE_TFTP
  111. - if (option_bool(OPT_TFTP))
  112. - {
  113. + if (option_bool(OPT_TFTP))
  114. + {
  115. + struct tftp_prefix *p;
  116. #ifdef FD_SETSIZE
  117. if (FD_SETSIZE < (unsigned)max_fd)
  118. max_fd = FD_SETSIZE;
  119. @@ -754,7 +767,14 @@ int main (int argc, char **argv)
  120. daemon->tftp_prefix ? _("root is ") : _("enabled"),
  121. daemon->tftp_prefix ? daemon->tftp_prefix: "",
  122. option_bool(OPT_TFTP_SECURE) ? _("secure mode") : "");
  123. +
  124. + if (tftp_prefix_missing)
  125. + my_syslog(MS_TFTP | LOG_WARNING, _("warning: %s inaccessible"), daemon->tftp_prefix);
  126. + for (p = daemon->if_prefix; p; p = p->next)
  127. + if (p->missing)
  128. + my_syslog(MS_TFTP | LOG_WARNING, _("warning: TFTP directory %s inaccessible"), p->prefix);
  129. +
  130. /* This is a guess, it assumes that for small limits,
  131. disjoint files might be served, but for large limits,
  132. a single file will be sent to may clients (the file only needs
  133. diff --git a/src/dnsmasq.h b/src/dnsmasq.h
  134. index 1dd61c5..086cb67 100644
  135. --- a/src/dnsmasq.h
  136. +++ b/src/dnsmasq.h
  137. @@ -238,7 +238,8 @@ struct event_desc {
  138. #define OPT_DNSSEC_NO_SIGN 48
  139. #define OPT_LOCAL_SERVICE 49
  140. #define OPT_LOOP_DETECT 50
  141. -#define OPT_LAST 51
  142. +#define OPT_TFTP_NO_FAIL 51
  143. +#define OPT_LAST 52
  144. /* extra flags for my_syslog, we use a couple of facilities since they are known
  145. not to occupy the same bits as priorities, no matter how syslog.h is set up. */
  146. @@ -888,6 +889,7 @@ struct addr_list {
  147. struct tftp_prefix {
  148. char *interface;
  149. char *prefix;
  150. + int missing;
  151. struct tftp_prefix *next;
  152. };
  153. diff --git a/src/option.c b/src/option.c
  154. index 209fa69..fa5e4d3 100644
  155. --- a/src/option.c
  156. +++ b/src/option.c
  157. @@ -147,6 +147,7 @@ struct myoption {
  158. #define LOPT_LOCAL_SERVICE 335
  159. #define LOPT_DNSSEC_TIME 336
  160. #define LOPT_LOOP_DETECT 337
  161. +#define LOPT_TFTP_NO_FAIL 338
  162. #ifdef HAVE_GETOPT_LONG
  163. static const struct option opts[] =
  164. @@ -227,6 +228,7 @@ static const struct myoption opts[] =
  165. { "dhcp-ignore-names", 2, 0, LOPT_NO_NAMES },
  166. { "enable-tftp", 2, 0, LOPT_TFTP },
  167. { "tftp-secure", 0, 0, LOPT_SECURE },
  168. + { "tftp-no-fail", 0, 0, LOPT_TFTP_NO_FAIL },
  169. { "tftp-unique-root", 0, 0, LOPT_APREF },
  170. { "tftp-root", 1, 0, LOPT_PREFIX },
  171. { "tftp-max", 1, 0, LOPT_TFTP_MAX },
  172. @@ -402,6 +404,7 @@ static struct {
  173. { LOPT_PREFIX, ARG_DUP, "<dir>[,<iface>]", gettext_noop("Export files by TFTP only from the specified subtree."), NULL },
  174. { LOPT_APREF, OPT_TFTP_APREF, NULL, gettext_noop("Add client IP address to tftp-root."), NULL },
  175. { LOPT_SECURE, OPT_TFTP_SECURE, NULL, gettext_noop("Allow access only to files owned by the user running dnsmasq."), NULL },
  176. + { LOPT_TFTP_NO_FAIL, OPT_TFTP_NO_FAIL, NULL, gettext_noop("Do not terminate the service if TFTP directories are inaccessible."), NULL },
  177. { LOPT_TFTP_MAX, ARG_ONE, "<integer>", gettext_noop("Maximum number of conncurrent TFTP transfers (defaults to %s)."), "#" },
  178. { LOPT_NOBLOCK, OPT_TFTP_NOBLOCK, NULL, gettext_noop("Disable the TFTP blocksize extension."), NULL },
  179. { LOPT_TFTP_LC, OPT_TFTP_LC, NULL, gettext_noop("Convert TFTP filenames to lowercase"), NULL },
  180. --
  181. 2.1.4