1 Fix building with libressl or without SSL.
3 Origin: http://bugs.ntp.org/attachment.cgi?id=1481
5 LibreSSL fix from Joe Kappus (https://bugs.gentoo.org/show_bug.cgi?id=600668#c2)
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
13 # include "openssl/evp.h"
14 +# include "libssl_compat.h"
15 #else /* !OPENSSL follows */
17 * Provide OpenSSL-alike MD5 API if we're not using OpenSSL
21 typedef MD5_CTX EVP_MD_CTX;
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
33 #include "ntp_md5.h" /* provides OpenSSL digest API */
34 #include "isc/string.h"
35 -#include "libssl_compat.h"
37 * MD5authencrypt - generate message digest
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
43 * ---------------------------------------------------------------------
48 -#include <openssl/bn.h>
49 -#include <openssl/evp.h>
51 #include "ntp_types.h"
53 /* ----------------------------------------------------------------- */
54 -#if OPENSSL_VERSION_NUMBER < 0x10100000L
57 +# include <openssl/bn.h>
58 +# include <openssl/evp.h>
60 +/* ----------------------------------------------------------------- */
62 +/* ----------------------------------------------------------------- */
63 +#if defined(OPENSSL) && (OPENSSL_VERSION_NUMBER < 0x10100000L || defined LIBRESSL_VERSION_NUMBER)
64 /* ----------------------------------------------------------------- */
66 #include "libssl_compat.h"
70 /* ----------------------------------------------------------------- */
71 -#else /* OPENSSL_VERSION_NUMBER >= v1.1.0 */
72 +#else /* OPENSSL && OPENSSL_VERSION_NUMBER >= v1.1.0 */
73 /* ----------------------------------------------------------------- */
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
80 # include "ntp_syscall.h"
83 -#include "libssl_compat.h"
86 * Structure to hold request procedure information
88 @@ -1653,8 +1651,10 @@
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
100 @@ -1678,6 +1678,7 @@
107 * ctl_putfs - write a decoded filestamp into the response
108 @@ -1838,7 +1839,7 @@
113 + char * past_eq = NULL;
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 @@
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.
130 interface_dump(const endpt *itf)
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 @@
142 print_interface(const endpt *iface, const char *pfx, const char *sfx)
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",
150 + (long long)iface->fd,
151 + (long long)iface->bfd,
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,
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 @@
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",
180 @@ -1401,13 +1400,13 @@
181 iopad->riofd = rio->fd;
182 iopad->rsrc.rio = rio;
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",
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",
196 @@ -1594,7 +1593,6 @@
197 static const char * const msg =
198 "OnSocketSend: send to socket failed";
200 - IoHndPad_T * iopad = NULL;
204 @@ -1662,7 +1660,7 @@
206 INSIST(hndIOCPLPort && hMainRpcDone);
208 - iocpl_notify(iopad, OnInterfaceDetach, -1);
209 + iocpl_notify(iopad, OnInterfaceDetach, (UINT_PTR)-1);
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
219 #include "isc/string.h"
220 -#include "libssl_compat.h"
221 +#include "ntp_md5.h"
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
229 #include "openssl/rsa.h"
231 /* ----------------------------------------------------------------- */
232 -#if OPENSSL_VERSION_NUMBER < 0x10100000L
233 +#if (OPENSSL_VERSION_NUMBER < 0x10100000L || defined LIBRESSL_VERSION_NUMBER)
234 /* ----------------------------------------------------------------- */
236 # include <openssl/objects.h>