diff options
Diffstat (limited to 'contrib/ntp/libntp')
-rw-r--r-- | contrib/ntp/libntp/Makefile.am | 1 | ||||
-rw-r--r-- | contrib/ntp/libntp/Makefile.in | 14 | ||||
-rw-r--r-- | contrib/ntp/libntp/a_md5encrypt.c | 17 | ||||
-rw-r--r-- | contrib/ntp/libntp/authreadkeys.c | 2 | ||||
-rw-r--r-- | contrib/ntp/libntp/calyearstart.c | 2 | ||||
-rw-r--r-- | contrib/ntp/libntp/ntp_calendar.c | 40 | ||||
-rw-r--r-- | contrib/ntp/libntp/prettydate.c | 5 | ||||
-rw-r--r-- | contrib/ntp/libntp/ssl_init.c | 27 | ||||
-rw-r--r-- | contrib/ntp/libntp/syssignal.c | 7 | ||||
-rw-r--r-- | contrib/ntp/libntp/work_fork.c | 8 | ||||
-rw-r--r-- | contrib/ntp/libntp/work_thread.c | 17 | ||||
-rw-r--r-- | contrib/ntp/libntp/xsbprintf.c | 75 |
12 files changed, 182 insertions, 33 deletions
diff --git a/contrib/ntp/libntp/Makefile.am b/contrib/ntp/libntp/Makefile.am index 6f3c0ba..04b53b0 100644 --- a/contrib/ntp/libntp/Makefile.am +++ b/contrib/ntp/libntp/Makefile.am @@ -110,6 +110,7 @@ libntp_a_SRCS = \ vint64ops.c \ work_fork.c \ work_thread.c \ + xsbprintf.c \ ymd2yd.c \ $(libisc_SRCS) \ $(NULL) diff --git a/contrib/ntp/libntp/Makefile.in b/contrib/ntp/libntp/Makefile.in index 2bef787..fefd9d2 100644 --- a/contrib/ntp/libntp/Makefile.in +++ b/contrib/ntp/libntp/Makefile.in @@ -1,7 +1,7 @@ -# Makefile.in generated by automake 1.15 from Makefile.am. +# Makefile.in generated by automake 1.15.1 from Makefile.am. # @configure_input@ -# Copyright (C) 1994-2014 Free Software Foundation, Inc. +# Copyright (C) 1994-2017 Free Software Foundation, Inc. # This Makefile.in is free software; the Free Software Foundation # gives unlimited permission to copy and/or distribute it, @@ -160,7 +160,7 @@ am__libntp_a_SOURCES_DIST = systime.c a_md5encrypt.c adjtime.c \ snprintf.c socket.c socktoa.c socktohost.c ssl_init.c \ statestr.c strdup.c strl_obsd.c syssignal.c timetoa.c \ timevalops.c uglydate.c vint64ops.c work_fork.c work_thread.c \ - ymd2yd.c $(srcdir)/../lib/isc/assertions.c \ + xsbprintf.c ymd2yd.c $(srcdir)/../lib/isc/assertions.c \ $(srcdir)/../lib/isc/buffer.c \ $(srcdir)/../lib/isc/backtrace-emptytbl.c \ $(srcdir)/../lib/isc/backtrace.c \ @@ -224,8 +224,8 @@ am__objects_4 = a_md5encrypt.$(OBJEXT) adjtime.$(OBJEXT) \ ssl_init.$(OBJEXT) statestr.$(OBJEXT) strdup.$(OBJEXT) \ strl_obsd.$(OBJEXT) syssignal.$(OBJEXT) timetoa.$(OBJEXT) \ timevalops.$(OBJEXT) uglydate.$(OBJEXT) vint64ops.$(OBJEXT) \ - work_fork.$(OBJEXT) work_thread.$(OBJEXT) ymd2yd.$(OBJEXT) \ - $(am__objects_3) $(am__objects_1) + work_fork.$(OBJEXT) work_thread.$(OBJEXT) xsbprintf.$(OBJEXT) \ + ymd2yd.$(OBJEXT) $(am__objects_3) $(am__objects_1) am_libntp_a_OBJECTS = systime.$(OBJEXT) $(am__objects_4) libntp_a_OBJECTS = $(am_libntp_a_OBJECTS) libntpsim_a_AR = $(AR) $(ARFLAGS) @@ -244,7 +244,7 @@ am__libntpsim_a_SOURCES_DIST = systime_s.c a_md5encrypt.c adjtime.c \ snprintf.c socket.c socktoa.c socktohost.c ssl_init.c \ statestr.c strdup.c strl_obsd.c syssignal.c timetoa.c \ timevalops.c uglydate.c vint64ops.c work_fork.c work_thread.c \ - ymd2yd.c $(srcdir)/../lib/isc/assertions.c \ + xsbprintf.c ymd2yd.c $(srcdir)/../lib/isc/assertions.c \ $(srcdir)/../lib/isc/buffer.c \ $(srcdir)/../lib/isc/backtrace-emptytbl.c \ $(srcdir)/../lib/isc/backtrace.c \ @@ -704,6 +704,7 @@ libntp_a_SRCS = \ vint64ops.c \ work_fork.c \ work_thread.c \ + xsbprintf.c \ ymd2yd.c \ $(libisc_SRCS) \ $(NULL) @@ -876,6 +877,7 @@ distclean-compile: @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/vint64ops.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/work_fork.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/work_thread.Po@am__quote@ +@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/xsbprintf.Po@am__quote@ @AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/ymd2yd.Po@am__quote@ .c.o: diff --git a/contrib/ntp/libntp/a_md5encrypt.c b/contrib/ntp/libntp/a_md5encrypt.c index 7dc7e7e..8c046f4 100644 --- a/contrib/ntp/libntp/a_md5encrypt.c +++ b/contrib/ntp/libntp/a_md5encrypt.c @@ -12,12 +12,6 @@ #include "ntp_md5.h" /* provides OpenSSL digest API */ #include "isc/string.h" -#ifdef OPENSSL -# include "openssl/cmac.h" -# define CMAC "AES128CMAC" -# define AES_128_KEY_SIZE 16 -#endif - typedef struct { const void * buf; size_t len; @@ -28,7 +22,7 @@ typedef struct { size_t len; } rwbuffT; -#ifdef OPENSSL +#if defined(OPENSSL) && defined(ENABLE_CMAC) static size_t cmac_ctx_size( CMAC_CTX * ctx) @@ -42,7 +36,7 @@ cmac_ctx_size( } return mlen; } -#endif /*OPENSSL*/ +#endif /*OPENSSL && ENABLE_CMAC*/ static size_t make_mac( @@ -63,6 +57,7 @@ make_mac( INIT_SSL(); /* Check if CMAC key type specific code required */ +# ifdef ENABLE_CMAC if (ktype == NID_cmac) { CMAC_CTX * ctx = NULL; void const * keyptr = key->buf; @@ -100,7 +95,9 @@ make_mac( if (ctx) CMAC_CTX_cleanup(ctx); } - else { /* generic MAC handling */ + else +# endif /*ENABLE_CMAC*/ + { /* generic MAC handling */ EVP_MD_CTX * ctx = EVP_MD_CTX_new(); u_int uilen = 0; @@ -153,7 +150,7 @@ make_mac( if (ktype == NID_md5) { EVP_MD_CTX * ctx = EVP_MD_CTX_new(); - uint uilen = 0; + u_int uilen = 0; if (digest->len < 16) { msyslog(LOG_ERR, "%s", "MAC encrypt: MAC md5 buf too small."); diff --git a/contrib/ntp/libntp/authreadkeys.c b/contrib/ntp/libntp/authreadkeys.c index bd98ab2..48c5c4d 100644 --- a/contrib/ntp/libntp/authreadkeys.c +++ b/contrib/ntp/libntp/authreadkeys.c @@ -221,12 +221,14 @@ authreadkeys( log_maybe(NULL, "authreadkeys: invalid type for key %d", keyno); +# ifdef ENABLE_CMAC } else if (NID_cmac != keytype && EVP_get_digestbynid(keytype) == NULL) { log_maybe(NULL, "authreadkeys: no algorithm for key %d", keyno); keytype = 0; +# endif /* ENABLE_CMAC */ } #else /* !OPENSSL follows */ /* diff --git a/contrib/ntp/libntp/calyearstart.c b/contrib/ntp/libntp/calyearstart.c index 9e3f58f..5616c81 100644 --- a/contrib/ntp/libntp/calyearstart.c +++ b/contrib/ntp/libntp/calyearstart.c @@ -54,7 +54,7 @@ calmonthstart(u_int32 ntptime, const time_t *pivot) } /* - * calweekstart - get NTP time at midnight of the last monday on or + * calweekstart - get NTP time at midnight of the last Monday on or * before the current date. */ u_int32 diff --git a/contrib/ntp/libntp/ntp_calendar.c b/contrib/ntp/libntp/ntp_calendar.c index a550d5d..7974268 100644 --- a/contrib/ntp/libntp/ntp_calendar.c +++ b/contrib/ntp/libntp/ntp_calendar.c @@ -1832,6 +1832,7 @@ isocal_date_to_ntp( */ static int32_t s_baseday = NTP_TO_UNIX_DAYS; +static int32_t s_gpsweek = 0; int32_t basedate_eval_buildstamp(void) @@ -1873,7 +1874,7 @@ basedate_eval_string( goto buildstamp; } - rc = scanf(str, "%lu%n", &ned, &nc); + rc = sscanf(str, "%lu%n", &ned, &nc); if (rc == 1 && (size_t)nc == sl) { if (ned <= INT32_MAX) return (int32_t)ned; @@ -1901,6 +1902,7 @@ basedate_set_day( struct calendar jd; int32_t retv; + /* set NTP base date for NTP era unfolding */ if (day < NTP_TO_UNIX_DAYS) { msyslog(LOG_WARNING, "baseday_set_day: invalid day (%lu), UNIX epoch substituted", @@ -1912,6 +1914,17 @@ basedate_set_day( ntpcal_rd_to_date(&jd, day + DAY_NTP_STARTS); msyslog(LOG_INFO, "basedate set to %04hu-%02hu-%02hu", jd.year, (u_short)jd.month, (u_short)jd.monthday); + + /* set GPS base week for GPS week unfolding */ + day = ntpcal_weekday_ge(day + DAY_NTP_STARTS, CAL_SUNDAY) + - DAY_NTP_STARTS; + if (day < NTP_TO_GPS_DAYS) + day = NTP_TO_GPS_DAYS; + s_gpsweek = (day - NTP_TO_GPS_DAYS) / DAYSPERWEEK; + ntpcal_rd_to_date(&jd, day + DAY_NTP_STARTS); + msyslog(LOG_INFO, "gps base set to %04hu-%02hu-%02hu (week %d)", + jd.year, (u_short)jd.month, (u_short)jd.monthday, s_gpsweek); + return retv; } @@ -1934,4 +1947,29 @@ basedate_get_erabase(void) return retv; } +uint32_t +basedate_get_gpsweek(void) +{ + return s_gpsweek; +} + +uint32_t +basedate_expand_gpsweek( + unsigned short weekno + ) +{ + /* We do a fast modulus expansion here. Since all quantities are + * unsigned and we cannot go before the start of the GPS epoch + * anyway, and since the truncated GPS week number is 10 bit, the + * expansion becomes a simple sub/and/add sequence. + */ + #if GPSWEEKS != 1024 + # error GPSWEEKS defined wrong -- should be 1024! + #endif + + uint32_t diff; + diff = ((uint32_t)weekno - s_gpsweek) & (GPSWEEKS - 1); + return s_gpsweek + diff; +} + /* -*-EOF-*- */ diff --git a/contrib/ntp/libntp/prettydate.c b/contrib/ntp/libntp/prettydate.c index 25b085e..deacc26 100644 --- a/contrib/ntp/libntp/prettydate.c +++ b/contrib/ntp/libntp/prettydate.c @@ -170,6 +170,11 @@ common_prettydate( LIB_GETBUF(bp); + if (ts->l_ui == 0 && ts->l_uf == 0) { + strlcpy (bp, "(no time)", LIB_BUFLENGTH); + return (bp); + } + /* get & fix milliseconds */ ntps = ts->l_ui; msec = ts->l_uf / 4294967; /* fract / (2 ** 32 / 1000) */ diff --git a/contrib/ntp/libntp/ssl_init.c b/contrib/ntp/libntp/ssl_init.c index 96d9d08..9258932 100644 --- a/contrib/ntp/libntp/ssl_init.c +++ b/contrib/ntp/libntp/ssl_init.c @@ -13,16 +13,16 @@ #include <lib_strbuf.h> #ifdef OPENSSL -# include "openssl/cmac.h" -# include "openssl/crypto.h" -# include "openssl/err.h" -# include "openssl/evp.h" -# include "openssl/opensslv.h" +# include <openssl/crypto.h> +# include <openssl/err.h> +# include <openssl/evp.h> +# include <openssl/opensslv.h> # include "libssl_compat.h" - -# define CMAC_LENGTH 16 -# define CMAC "AES128CMAC" - +# ifdef HAVE_OPENSSL_CMAC_H +# include <openssl/cmac.h> +# define CMAC_LENGTH 16 +# define CMAC "AES128CMAC" +# endif /*HAVE_OPENSSL_CMAC_H*/ int ssl_init_done; #if OPENSSL_VERSION_NUMBER < 0x10100000L @@ -126,6 +126,7 @@ keytype_from_text( key_type = OBJ_sn2nid(upcased); +# ifdef ENABLE_CMAC if (!key_type && !strncmp(CMAC, upcased, strlen(CMAC) + 1)) { key_type = NID_cmac; @@ -134,6 +135,7 @@ keytype_from_text( __FILE__, __LINE__, __func__, CMAC); } } +# endif /*ENABLE_CMAC*/ #else key_type = 0; @@ -153,6 +155,7 @@ keytype_from_text( digest_len = (md) ? EVP_MD_size(md) : 0; if (!md || digest_len <= 0) { +# ifdef ENABLE_CMAC if (key_type == NID_cmac) { digest_len = CMAC_LENGTH; @@ -160,7 +163,9 @@ keytype_from_text( fprintf(stderr, "%s:%d:%s():%s:len\n", __FILE__, __LINE__, __func__, CMAC); } - } else { + } else +# endif /*ENABLE_CMAC*/ + { fprintf(stderr, "key type %s is not supported by OpenSSL\n", keytype_name(key_type)); @@ -209,6 +214,7 @@ keytype_name( INIT_SSL(); name = OBJ_nid2sn(nid); +# ifdef ENABLE_CMAC if (NID_cmac == nid) { name = CMAC; @@ -217,6 +223,7 @@ keytype_name( __FILE__, __LINE__, __func__, CMAC); } } else +# endif /*ENABLE_CMAC*/ if (NULL == name) { name = unknown_type; } diff --git a/contrib/ntp/libntp/syssignal.c b/contrib/ntp/libntp/syssignal.c index 5e496a9..cc87bff 100644 --- a/contrib/ntp/libntp/syssignal.c +++ b/contrib/ntp/libntp/syssignal.c @@ -138,12 +138,13 @@ set_ctrl_c_hook( if (NULL == c_hook) { handler = SIG_DFL; - ctrl_c_hook = NULL; + signal_no_reset(SIGINT, handler); + ctrl_c_hook = c_hook; } else { - handler = &sigint_handler; ctrl_c_hook = c_hook; + handler = &sigint_handler; + signal_no_reset(SIGINT, handler); } - signal_no_reset(SIGINT, handler); } #else /* SYS_WINNT follows */ /* diff --git a/contrib/ntp/libntp/work_fork.c b/contrib/ntp/libntp/work_fork.c index 2aa2d5c..1dd9e13 100644 --- a/contrib/ntp/libntp/work_fork.c +++ b/contrib/ntp/libntp/work_fork.c @@ -89,6 +89,10 @@ netwrite( } +#if defined(HAVE_DROPROOT) +extern int set_user_group_ids(void); +#endif + /* === functions === */ /* * exit_worker() @@ -592,6 +596,10 @@ fork_blocking_child( init_logging("ntp_intres", 0, FALSE); setup_logfile(NULL); +#ifdef HAVE_DROPROOT + (void) set_user_group_ids(); +#endif + /* * And now back to the portable code */ diff --git a/contrib/ntp/libntp/work_thread.c b/contrib/ntp/libntp/work_thread.c index 433290c..03a5647 100644 --- a/contrib/ntp/libntp/work_thread.c +++ b/contrib/ntp/libntp/work_thread.c @@ -56,6 +56,17 @@ # define THREAD_MAXSTACKSIZE THREAD_MINSTACKSIZE #endif +/* need a good integer to store a pointer... */ +#ifndef UINTPTR_T +# if defined(UINTPTR_MAX) +# define UINTPTR_T uintptr_t +# elif defined(UINT_PTR) +# define UINTPTR_T UINT_PTR +# else +# define UINTPTR_T size_t +# endif +#endif + #ifdef SYS_WINNT @@ -66,7 +77,7 @@ static BOOL same_os_sema(const sem_ref obj, void * osobj); #else -# define thread_exit(c) pthread_exit((void*)(size_t)(c)) +# define thread_exit(c) pthread_exit((void*)(UINTPTR_T)(c)) # define tickle_sem sem_post void * blocking_thread(void *); static void block_thread_signals(sigset_t *); @@ -374,7 +385,9 @@ send_blocking_resp_internal( if (empty) { # ifdef WORK_PIPE - write(c->resp_write_pipe, "", 1); + if (1 != write(c->resp_write_pipe, "", 1)) + msyslog(LOG_WARNING, "async resolver: %s", + "failed to notify main thread!"); # else tickle_sem(c->responses_pending); # endif diff --git a/contrib/ntp/libntp/xsbprintf.c b/contrib/ntp/libntp/xsbprintf.c new file mode 100644 index 0000000..4586758 --- /dev/null +++ b/contrib/ntp/libntp/xsbprintf.c @@ -0,0 +1,75 @@ +/* + * xsbprintf.c - string buffer formatting helpers + * + * Written by Juergen Perlinger (perlinger@ntp.org) for the NTP project. + * The contents of 'html/copyright.html' apply. + */ + +#include <config.h> +#include <sys/types.h> + +#include "ntp_stdlib.h" + +/* eXtended Varlist String Buffer printf + * + * Formats via 'vsnprintf' into a string buffer, with some semantic + * specialties: + * + * - The start of the buffer pointer is updated according to the number + * of characters written. + * - If the buffer is insufficient to format the number of charactes, + * the partial result will be be discarded, and zero is returned to + * indicate nothing was written to the buffer. + * - On successful formatting, the return code is the return value of + * the inner call to 'vsnprintf()'. + * - If there is any error, the state of the buffer will not be + * changed. (Bytes in the buffer might be smashed, but the buffer + * position does not change, and the NUL marker stays in place at the + * current buffer position.) + * - If '(*ppbuf - pend) <= 0' (or ppbuf is NULL), fail with EINVAL. + */ +int +xvsbprintf( + char **ppbuf, /* pointer to buffer pointer (I/O) */ + char * const pend, /* buffer end (I) */ + char const *pfmt, /* printf-like format string */ + va_list va /* formatting args for above */ + ) +{ + char *pbuf = (ppbuf) ? *ppbuf : NULL; + int rc = -1; + if (pbuf && (pend - pbuf > 0)) { + size_t blen = (size_t)(pend - pbuf); + rc = vsnprintf(pbuf, blen, pfmt, va); + if (rc > 0) { + if ((size_t)rc >= blen) + rc = 0; + pbuf += rc; + } + *pbuf = '\0'; /* fear of bad vsnprintf */ + *ppbuf = pbuf; + } else { + errno = EINVAL; + } + return rc; +} + +/* variadic wrapper around the buffer string formatter */ +int +xsbprintf( + char **ppbuf, /* pointer to buffer pointer (I/O) */ + char * const pend, /* buffer end (I) */ + char const *pfmt, /* printf-like format string */ + ... /* formatting args for above */ + ) +{ + va_list va; + int rc; + + va_start(va, pfmt); + rc = xvsbprintf(ppbuf, pend, pfmt, va); + va_end(va); + return rc; +} + +/* that's all folks! */ |