From 3939b2b7583a8c901ed09ea88ff62a6edcc147a6 Mon Sep 17 00:00:00 2001 From: Simone Caronni Date: Tue, 10 Jul 2012 14:46:48 +0200 Subject: [PATCH] Fix bsmtp upstream bug sending mails to ipv4/ipv6 hosts --- bacula-5.2.10-bsmtp.patch | 148 ++++++++++++++++++++++++++++++++++++++ bacula.spec | 5 +- 2 files changed, 152 insertions(+), 1 deletion(-) create mode 100644 bacula-5.2.10-bsmtp.patch diff --git a/bacula-5.2.10-bsmtp.patch b/bacula-5.2.10-bsmtp.patch new file mode 100644 index 0000000..7ec7b38 --- /dev/null +++ b/bacula-5.2.10-bsmtp.patch @@ -0,0 +1,148 @@ +--- manpages/bsmtp.1.old.old 2012-06-28 16:52:03.000000000 +0200 ++++ manpages/bsmtp.1 2012-07-10 14:39:27.818315931 +0200 +@@ -2,7 +2,7 @@ + .\" First parameter, NAME, should be all caps + .\" Second parameter, SECTION, should be 1-8, maybe w/ subsection + .\" other parameters are allowed: see man(7), man(1) +-.TH BSMTP 1 "6 December 2009" "Kern Sibbald" "Network backup, recovery and verification" ++.TH BSMTP 1 "3 July 2012" "Kern Sibbald" "Network backup, recovery and verification" + .\" Please adjust this date whenever revising the manpage. + .\" + .SH NAME +@@ -23,9 +23,18 @@ + + .SH OPTIONS + .TP ++.B \-4 ++Forces bsmtp to use IPv4 addresses only. ++.TP ++.B \-6 ++Forces bsmtp to use IPv6 addresses only. ++.TP + .B \-8 + Encode the mail in UTF-8. + .TP ++.B \-a ++Use any ip protocol for address resolution. ++.TP + .B \-c + Set the \fBCc:\fR header. + .TP +@@ -115,4 +124,4 @@ + .nh + . + .SH SEE ALSO +-.BR "bacula-dir" "(8) " +\ No newline at end of file ++.BR "bacula-dir" "(8) " +--- src/tools/bsmtp.c.old 2012-06-28 16:52:03.000000000 +0200 ++++ src/tools/bsmtp.c 2012-07-10 14:39:27.967318985 +0200 +@@ -85,6 +85,12 @@ + #define MAXSTRING 254 + #endif + ++enum resolv_type { ++ RESOLV_PROTO_ANY, ++ RESOLV_PROTO_IPV4, ++ RESOLV_PROTO_IPV6 ++}; ++ + static FILE *sfp; + static FILE *rfp; + +@@ -97,6 +103,7 @@ + static int mailport = 25; + static char my_hostname[MAXSTRING]; + static bool content_utf8 = false; ++static resolv_type default_resolv_type = RESOLV_PROTO_IPV4; + + /* + * Take input that may have names and other stuff and strip +@@ -185,7 +192,12 @@ + fprintf(stderr, + _("\n" + "Usage: %s [-f from] [-h mailhost] [-s subject] [-c copy] [recipient ...]\n" ++" -4 forces bsmtp to use IPv4 addresses only.\n" ++#ifdef HAVE_IPV6 ++" -6 forces bsmtp to use IPv6 addresses only.\n" ++#endif + " -8 set charset to UTF-8\n" ++" -a use any ip protocol for address resolution\n" + " -c set the Cc: field\n" + " -d set debug level to \n" + " -dt print a timestamp in debug output\n" +@@ -277,6 +289,11 @@ + struct hostent *hp; + struct sockaddr_in sin; + #endif ++#ifdef HAVE_IPV6 ++ const char *options = "468ac:d:f:h:r:s:l:?"; ++#else ++ const char *options = "48ac:d:f:h:r:s:l:?"; ++#endif + + setlocale(LC_ALL, "en_US"); + bindtextdomain("bacula", LOCALEDIR); +@@ -285,11 +302,26 @@ + my_name_is(argc, argv, "bsmtp"); + maxlines = 0; + +- while ((ch = getopt(argc, argv, "8c:d:f:h:r:s:l:?")) != -1) { ++ while ((ch = getopt(argc, argv, options)) != -1) { + switch (ch) { ++ case '4': ++ default_resolv_type = RESOLV_PROTO_IPV4; ++ break; ++ ++#ifdef HAVE_IPV6 ++ case '6': ++ default_resolv_type = RESOLV_PROTO_IPV6; ++ break; ++#endif ++ + case '8': + content_utf8 = true; + break; ++ ++ case 'a': ++ default_resolv_type = RESOLV_PROTO_ANY; ++ break; ++ + case 'c': + Dmsg1(20, "cc=%s\n", optarg); + cc_addr = optarg; +@@ -430,16 +462,31 @@ + lookup_host: + #ifdef HAVE_GETADDRINFO + memset(&hints, 0, sizeof(struct addrinfo)); +- hints.ai_family = AF_UNSPEC; ++ switch (default_resolv_type) { ++ case RESOLV_PROTO_ANY: ++ hints.ai_family = AF_UNSPEC; ++ break; ++ case RESOLV_PROTO_IPV4: ++ hints.ai_family = AF_INET; ++ break; ++#ifdef HAVE_IPV6 ++ case RESOLV_PROTO_IPV6: ++ hints.ai_family = AF_INET6; ++ break; ++#endif ++ default: ++ hints.ai_family = AF_UNSPEC; ++ break; ++ } + hints.ai_socktype = SOCK_STREAM; +- hints.ai_protocol = IPPROTO_TCP; ++ hints.ai_protocol = 0; + hints.ai_flags = 0; + snprintf(mail_port, sizeof(mail_port), "%d", mailport); + + if ((res = getaddrinfo(mailhost, mail_port, &hints, &ai)) != 0) { + Pmsg2(0, _("Error unknown mail host \"%s\": ERR=%s\n"), + mailhost, gai_strerror(res)); +- if (!strcasecmp(mailhost, "localhost")) { ++ if (strcasecmp(mailhost, "localhost")) { + Pmsg0(0, _("Retrying connection using \"localhost\".\n")); + mailhost = "localhost"; + goto lookup_host; diff --git a/bacula.spec b/bacula.spec index 518769f..41fb319 100644 --- a/bacula.spec +++ b/bacula.spec @@ -33,6 +33,7 @@ Patch2: bacula-5.2.2-queryfile.patch Patch3: bacula-5.2.4-log-path.patch Patch4: bacula-5.0.3-sqlite-priv.patch Patch5: bacula-5.2.7-bat-build.patch +Patch6: bacula-5.2.10-bsmtp.patch BuildRequires: desktop-file-utils BuildRequires: perl @@ -291,6 +292,7 @@ Provides check_bacula support for Nagios. %patch3 -p1 -b .log-path %patch4 -p0 -b .priv %patch5 -p1 -b .bat-build +%patch6 -p0 -b .bsmtp # Remove execution permissions from files we're packaging as docs later on find updatedb -type f | xargs chmod -x @@ -844,7 +846,8 @@ fi %changelog * Tue Jul 10 2012 Simone Caronni - 5.2.10-2 -- Add nss-lookup.target as required to service filesi (rhbz#838828). +- Add nss-lookup.target as required to service files (rhbz#838828). +- Fix bsmtp upstream bug sending mails to ipv4/ipv6 hosts. * Mon Jul 02 2012 Simone Caronni - 5.2.10-1 - Update to 5.2.10.