5166e5f9a1d092fff39e1eec5f4bcf7c73a51d70
[gentoo.git] / net-misc / ntp / files / ntp-4.2.8_p9-fix-build-wo-ssl-or-libressl.patch
1 Fix building with libressl or without SSL.
2
3 Origin: http://bugs.ntp.org/attachment.cgi?id=1481
4
5 LibreSSL fix from Joe Kappus (https://bugs.gentoo.org/show_bug.cgi?id=600668#c2)
6
7 diff -Nru a/include/ntp_md5.h b/include/ntp_md5.h
8 --- a/include/ntp_md5.h 2016-11-23 08:35:18.248130387 +0100
9 +++ b/include/ntp_md5.h 2016-11-23 08:35:18.248130387 +0100
10 @@ -8,6 +8,7 @@
11  
12  #ifdef OPENSSL
13  # include "openssl/evp.h"
14 +# include "libssl_compat.h"
15  #else  /* !OPENSSL follows */
16  /*
17   * Provide OpenSSL-alike MD5 API if we're not using OpenSSL
18 @@ -23,6 +24,9 @@
19  # endif
20  
21    typedef MD5_CTX                      EVP_MD_CTX;
22 +
23 +# define EVP_MD_CTX_free(c)            free(c)
24 +# define EVP_MD_CTX_new()              calloc(1, sizeof(MD5_CTX))
25  # define EVP_get_digestbynid(t)                NULL
26  # define EVP_md5()                     NULL
27  # define EVP_MD_CTX_init(c)
28 diff -Nru a/libntp/a_md5encrypt.c b/libntp/a_md5encrypt.c
29 --- a/libntp/a_md5encrypt.c     2016-11-23 08:35:18.248130387 +0100
30 +++ b/libntp/a_md5encrypt.c     2016-11-23 08:35:18.248130387 +0100
31 @@ -11,7 +11,6 @@
32  #include "ntp.h"
33  #include "ntp_md5.h"   /* provides OpenSSL digest API */
34  #include "isc/string.h"
35 -#include "libssl_compat.h"
36  /*
37   * MD5authencrypt - generate message digest
38   *
39 diff -Nru a/libntp/libssl_compat.c b/libntp/libssl_compat.c
40 --- a/libntp/libssl_compat.c    2016-11-23 08:35:18.248130387 +0100
41 +++ b/libntp/libssl_compat.c    2016-11-23 08:35:18.248130387 +0100
42 @@ -15,15 +15,18 @@
43   * ---------------------------------------------------------------------
44   */
45  #include "config.h"
46 -
47 -#include <string.h>
48 -#include <openssl/bn.h>
49 -#include <openssl/evp.h>
50 -
51  #include "ntp_types.h"
52  
53  /* ----------------------------------------------------------------- */
54 -#if OPENSSL_VERSION_NUMBER < 0x10100000L
55 +#ifdef OPENSSL
56 +# include <string.h>
57 +# include <openssl/bn.h>
58 +# include <openssl/evp.h>
59 +#endif
60 +/* ----------------------------------------------------------------- */
61 +
62 +/* ----------------------------------------------------------------- */
63 +#if defined(OPENSSL) && (OPENSSL_VERSION_NUMBER < 0x10100000L || defined LIBRESSL_VERSION_NUMBER)
64  /* ----------------------------------------------------------------- */
65  
66  #include "libssl_compat.h"
67 @@ -325,7 +328,7 @@
68  }
69  
70  /* ----------------------------------------------------------------- */
71 -#else /* OPENSSL_VERSION_NUMBER >= v1.1.0 */
72 +#else /* OPENSSL && OPENSSL_VERSION_NUMBER >= v1.1.0 */
73  /* ----------------------------------------------------------------- */
74  
75  NONEMPTY_TRANSLATION_UNIT
76 diff -Nru a/ntpd/ntp_control.c b/ntpd/ntp_control.c
77 --- a/ntpd/ntp_control.c        2016-11-23 08:35:18.256130015 +0100
78 +++ b/ntpd/ntp_control.c        2016-11-23 08:35:18.260129828 +0100
79 @@ -33,8 +33,6 @@
80  # include "ntp_syscall.h"
81  #endif
82  
83 -#include "libssl_compat.h"
84 -
85  /*
86   * Structure to hold request procedure information
87   */
88 @@ -1653,8 +1651,10 @@
89  }
90  
91  /*
92 - * ctl_putcal - write a decoded calendar data into the response
93 + * ctl_putcal - write a decoded calendar data into the response.
94 + * only used with AUTOKEY currently, so compiled conditional
95   */
96 +#ifdef AUTOKEY
97  static void
98  ctl_putcal(
99         const char *tag,
100 @@ -1678,6 +1678,7 @@
101  
102         return;
103  }
104 +#endif
105  
106  /*
107   * ctl_putfs - write a decoded filestamp into the response
108 @@ -1838,7 +1839,7 @@
109         char *  oplim;
110         char *  iptr;
111         char *  iplim;
112 -       char *  past_eq;
113 +       char *  past_eq = NULL;
114  
115         optr = output;
116         oplim = output + sizeof(output);
117 diff -Nru a/ntpd/ntp_io.c b/ntpd/ntp_io.c
118 --- a/ntpd/ntp_io.c     2016-11-23 08:35:18.268129456 +0100
119 +++ b/ntpd/ntp_io.c     2016-11-23 08:35:18.272129269 +0100
120 @@ -516,13 +516,17 @@
121  /*
122   * function to dump the contents of the interface structure
123   * for debugging use only.
124 + * We face a dilemma here -- sockets are FDs under POSIX and
125 + * actually HANDLES under Windows. So we use '%lld' as format
126 + * and cast the value to 'long long'; this should not hurt
127 + * with UNIX-like systems and does not truncate values on Win64.
128   */
129  void
130  interface_dump(const endpt *itf)
131  {
132         printf("Dumping interface: %p\n", itf);
133 -       printf("fd = %d\n", itf->fd);
134 -       printf("bfd = %d\n", itf->bfd);
135 +       printf("fd = %lld\n", (long long)itf->fd);
136 +       printf("bfd = %lld\n", (long long)itf->bfd);
137         printf("sin = %s,\n", stoa(&itf->sin));
138         sockaddr_dump(&itf->sin);
139         printf("bcast = %s,\n", stoa(&itf->bcast));
140 @@ -570,11 +574,11 @@
141  static void
142  print_interface(const endpt *iface, const char *pfx, const char *sfx)
143  {
144 -       printf("%sinterface #%d: fd=%d, bfd=%d, name=%s, flags=0x%x, ifindex=%u, sin=%s",
145 +       printf("%sinterface #%d: fd=%lld, bfd=%lld, name=%s, flags=0x%x, ifindex=%u, sin=%s",
146                pfx,
147                iface->ifnum,
148 -              iface->fd,
149 -              iface->bfd,
150 +              (long long)iface->fd,
151 +              (long long)iface->bfd,
152                iface->name,
153                iface->flags,
154                iface->ifindex,
155 diff -Nru a/ntpd/ntp_proto.c b/ntpd/ntp_proto.c
156 --- a/ntpd/ntp_proto.c  2016-11-23 08:35:18.280128897 +0100
157 +++ b/ntpd/ntp_proto.c  2016-11-23 08:35:18.284128711 +0100
158 @@ -4054,7 +4054,7 @@
159                     ntoa(&peer->srcadr), peer->hmode, xkeyid, sendlen,
160                     peer->keynumber));
161  #else  /* !AUTOKEY follows */
162 -       DPRINTF(1, ("peer_xmit: at %ld %s->%s mode %d keyid %08x len %d\n",
163 +       DPRINTF(1, ("peer_xmit: at %ld %s->%s mode %d keyid %08x len %zu\n",
164                     current_time, peer->dstadr ?
165                     ntoa(&peer->dstadr->sin) : "-",
166                     ntoa(&peer->srcadr), peer->hmode, xkeyid, sendlen));
167 diff -Nru a/ports/winnt/ntpd/ntp_iocompletionport.c b/ports/winnt/ntpd/ntp_iocompletionport.c
168 --- a/ports/winnt/ntpd/ntp_iocompletionport.c   2016-11-23 08:35:18.288128524 +0100
169 +++ b/ports/winnt/ntpd/ntp_iocompletionport.c   2016-11-23 08:35:18.288128524 +0100
170 @@ -1391,8 +1391,7 @@
171                 goto fail;
172         }
173  
174 -       ;
175 -       if ( ! (rio->ioreg_ctx = iopad = iohpCreate(rio))) {
176 +       if (NULL == (rio->ioreg_ctx = iopad = iohpCreate(rio))) {
177                 msyslog(LOG_ERR, "%s: Failed to create shared lock",
178                         msgh);
179                 goto fail;
180 @@ -1401,13 +1400,13 @@
181         iopad->riofd      = rio->fd;
182         iopad->rsrc.rio   = rio;
183  
184 -       if (!(rio->device_ctx = DevCtxAttach(serial_devctx(h)))) {
185 +       if (NULL == (rio->device_ctx = DevCtxAttach(serial_devctx(h)))) {
186                 msyslog(LOG_ERR, "%s: Failed to allocate device context",
187                         msgh);
188                 goto fail;
189         }
190  
191 -       if ( ! (lpo = IoCtxAlloc(iopad, rio->device_ctx))) {
192 +       if (NULL == (lpo = IoCtxAlloc(iopad, rio->device_ctx))) {
193                 msyslog(LOG_ERR, "%: Failed to allocate IO context",
194                         msgh);
195                 goto fail;
196 @@ -1594,7 +1593,6 @@
197         static const char * const msg =
198                 "OnSocketSend: send to socket failed";
199  
200 -       IoHndPad_T *    iopad   = NULL;
201         endpt *         ep      = NULL;
202         int             rc;
203  
204 @@ -1662,7 +1660,7 @@
205  
206         INSIST(hndIOCPLPort && hMainRpcDone);
207         if (iopad)
208 -               iocpl_notify(iopad, OnInterfaceDetach, -1);
209 +               iocpl_notify(iopad, OnInterfaceDetach, (UINT_PTR)-1);
210  }
211  
212  /* --------------------------------------------------------------------
213 diff -Nru a/sntp/crypto.c b/sntp/crypto.c
214 --- a/sntp/crypto.c     2016-11-23 08:35:18.288128524 +0100
215 +++ b/sntp/crypto.c     2016-11-23 08:35:18.288128524 +0100
216 @@ -2,7 +2,7 @@
217  #include "crypto.h"
218  #include <ctype.h>
219  #include "isc/string.h"
220 -#include "libssl_compat.h"
221 +#include "ntp_md5.h"
222  
223  struct key *key_ptr;
224  size_t key_cnt = 0;
225 diff -urN ntp-4.2.8p9/include/libssl_compat.h ntp-4.2.8p9_fixed/include/libssl_compat.h
226 --- a/include/libssl_compat.h   2016-11-21 07:28:40.000000000 -0500
227 +++ b/include/libssl_compat.h   2016-11-23 12:10:33.014148604 -0500
228 @@ -25,7 +25,7 @@
229  #include "openssl/rsa.h"
230  
231  /* ----------------------------------------------------------------- */
232 -#if OPENSSL_VERSION_NUMBER < 0x10100000L
233 +#if (OPENSSL_VERSION_NUMBER < 0x10100000L || defined LIBRESSL_VERSION_NUMBER)
234  /* ----------------------------------------------------------------- */
235  
236  # include <openssl/objects.h>