Sfoglia il codice sorgente

Merge branch 'nagios-plugins:master' into check_dig-641

kraken-jim 3 anni fa
parent
commit
06ace73d11

+ 15 - 0
NEWS

@@ -1,5 +1,20 @@
 This file documents the major additions and syntax changes between releases.
 
+2.4.2 2022-11-08
+	FIXES
+	check_ntp/check_ntp_time: Fix calculation bug introduced in 2.4.1 (#677)
+
+2.4.1 2022-10-25
+	FIXES
+	check_ntp_time: Ensure -W/-C (stratum warning/critical thresholds) are available as short options (#661)
+	check_icmp: Fix "Invalid Argument" errors on FreeBSD 13.1 (#659)
+	check_icmp: Fix address binding in ipv6 (#666)
+	check_ntp/check_ntp_time: Fixed errors when compiling with strict aliasing (#665)
+	check_ifstatus: Fixed issue where OID 1.3.6.1.4.1.9.2.2.1.1.28 was queried on systems that didn't support it (#650)
+	check_smtp: Fix regression when using STARTTLS (#649, #648, #651)
+	check_log.sh: Use temporary files to fix diffing for high-throughput logs (#566)
+	Fixed several compile errors for upcoming clang-16 (#670)
+
 2.4.0 2021-11-18
 	ENHANCEMENTS
 	check_http: Add -o option (Append page body as performance data) (#615) (Tobias Leich)

+ 1 - 1
NP-VERSION-GEN

@@ -6,7 +6,7 @@
 SRC_ROOT=`dirname $0`
 
 NPVF=NP-VERSION-FILE
-DEF_VER=2.4.0.git
+DEF_VER=2.4.2.git
 
 LF='
 '

+ 3 - 0
THANKS.in

@@ -3,6 +3,7 @@ Abid Rasheed
 Adrian Murphy
 Adrian Wieczorek
 Alain Richard
+Alan Hicks
 Alen Salamun
 Alessandro Ren
 Alex Bradley
@@ -28,6 +29,7 @@ Anton Lofgren
 Antony Simmonds
 Aravind Gottipati
 Ari Pollak
+Arjen Zonneveld
 Arkadiusz Miśkiewicz (arekm)
 Arnaud Quette
 Arnold Cavazos
@@ -112,6 +114,7 @@ Eric Chen
 Eric J. Mislivec
 Erik Wasser
 Erik Welch
+eriksejr
 Ernst-Dieter Martin
 Erwan Ben Souiden
 Evgeni Golov

+ 1 - 1
configure.ac

@@ -1,6 +1,6 @@
 dnl Process this file with autoconf to produce a configure script.
 AC_PREREQ(2.59)
-AC_INIT(nagios-plugins,2.4.0)
+AC_INIT(nagios-plugins,2.4.2)
 AC_CONFIG_SRCDIR(NPTest.pm)
 AC_CONFIG_FILES([gl/Makefile
 	nagios-plugins.spec])

+ 2 - 2
lib/utils_base.h

@@ -103,12 +103,12 @@ char *np_extract_value(const char*, const char*, char);
 
 
 void np_enable_state(char *, int);
-state_data *np_state_read();
+state_data *np_state_read(void);
 void np_state_write_string(time_t, char *);
 
 void np_init(char *, int argc, char **argv);
 void np_set_args(int argc, char **argv);
-void np_cleanup();
+void np_cleanup(void);
 
 /* np_suid() returns true if the real and effective uids differs, such as when
  * running a suid plugin */

+ 25 - 8
plugins-root/check_icmp.c

@@ -242,7 +242,7 @@ extern char **environ;
 /* global variables */
 static struct rta_host **table, *cursor, *list;
 static threshold crit = {80, 500000}, warn = {40, 200000};
-static int mode, protocols, sockets, debug = 0, timeout = 10, perfdata_num=-1;
+static int mode, protocols, sockets, debug = 0, timeout = 10, perfdata_num=-1, ttl = 0;
 static char *perfdata_sep = NULL;
 static unsigned short icmp_data_size = DEFAULT_PING_DATA_SIZE;
 static unsigned short icmp_pkt_size = DEFAULT_PING_DATA_SIZE + ICMP_MINLEN;
@@ -257,7 +257,6 @@ static pid_t pid;
 static struct timezone tz;
 static struct timeval prog_start;
 static unsigned long long max_completion_time = 0;
-static unsigned char ttl = 0; /* outgoing ttl */
 static unsigned int warn_down = 1,
                     crit_down = 1; /* host down threshold values */
 static int min_hosts_alive = -1;
@@ -647,7 +646,7 @@ int main(int argc, char **argv) {
         break;
 
       case 'l':
-        ttl = (unsigned char)strtoul(optarg, NULL, 0);
+        ttl = (int)strtoul(optarg, NULL, 0);
         break;
 
       case 'm':
@@ -1162,6 +1161,7 @@ static int send_icmp_ping(int sock, struct rta_host *host) {
   struct msghdr hdr;
   struct iovec iov;
   struct timeval tv;
+  size_t addrlen;
   void *buf = NULL;
 
   if (sock == -1) {
@@ -1191,6 +1191,7 @@ static int send_icmp_ping(int sock, struct rta_host *host) {
 
   if (address_family == AF_INET) {
     struct icmp *icp = (struct icmp *)buf;
+    addrlen = sizeof(struct sockaddr_in);
     memcpy(&icp->icmp_data, &data, sizeof(data));
     icp->icmp_type = ICMP_ECHO;
     icp->icmp_code = 0;
@@ -1206,6 +1207,7 @@ static int send_icmp_ping(int sock, struct rta_host *host) {
     }
   } else if (address_family == AF_INET6) {
     struct icmp6_hdr *icp6 = (struct icmp6_hdr *)buf;
+    addrlen = sizeof(struct sockaddr_in6);
     memcpy(&icp6->icmp6_dataun.icmp6_un_data8[4], &data, sizeof(data));
     icp6->icmp6_type = ICMP6_ECHO_REQUEST;
     icp6->icmp6_code = 0;
@@ -1226,7 +1228,7 @@ static int send_icmp_ping(int sock, struct rta_host *host) {
   iov.iov_len = icmp_pkt_size;
   memset(&hdr, 0, sizeof(hdr));
   hdr.msg_name = (struct sockaddr *)&host->saddr_in;
-  hdr.msg_namelen = sizeof(struct sockaddr_storage);
+  hdr.msg_namelen = addrlen;
   hdr.msg_iov = &iov;
   hdr.msg_iovlen = 1;
 
@@ -1845,12 +1847,27 @@ static int add_target(char *arg) {
 }
 
 static void set_source_ip(char *arg) {
-  struct sockaddr_in src;
+  struct sockaddr_storage src;
+  int result;
+  void *address_offset;
 
   memset(&src, 0, sizeof(src));
-  src.sin_family = address_family;
-  if ((src.sin_addr.s_addr = inet_addr(arg)) == INADDR_NONE) {
-    src.sin_addr.s_addr = get_ip_address(arg);
+  src.ss_family = address_family;
+
+  if (address_family == AF_INET) {
+    struct sockaddr_in *src_ipv4 = (struct sockaddr_in *) &src;
+    address_offset = (void *) &src_ipv4->sin_addr.s_addr;
+  }
+  else if (address_family == AF_INET6) {
+    struct sockaddr_in6 *src_ipv6 = (struct sockaddr_in6 *) &src;
+    /* Note: s6_addr is already an array, unlike s_addr */
+    address_offset = (void *) src_ipv6->sin6_addr.s6_addr;
+  }
+
+  result = inet_pton(address_family, arg, address_offset);
+  if (result != 1) {
+    struct sockaddr_in *src_ipv4 = (struct sockaddr_in *) &src;
+    src_ipv4->sin_addr.s_addr = get_ip_address(arg);
   }
   if (bind(icmp_sock, (struct sockaddr *)&src, sizeof(src)) == -1) {
     crash("Cannot bind to IP address %s", arg);

+ 1 - 1
plugins-scripts/check_ifstatus.pl

@@ -136,11 +136,11 @@ if (!defined($session)) {
 }
 
 
-push(@snmpoids,$snmpLocIfDescr);
 push(@snmpoids,$snmpIfOperStatus);
 push(@snmpoids,$snmpIfAdminStatus);
 push(@snmpoids,$snmpIfDescr);
 push(@snmpoids,$snmpIfType);
+push(@snmpoids,$snmpLocIfDescr) if ( defined $ifXTable);
 push(@snmpoids,$snmpIfName) if ( defined $ifXTable);
 push(@snmpoids,$snmpIfAlias) if ( defined $ifXTable);
 

+ 26 - 3
plugins-scripts/check_log.sh

@@ -18,7 +18,7 @@
 # On the first run of the plugin, it will return an OK state with a message
 # of "Log check data initialized".  On successive runs, it will return an OK
 # state if *no* pattern matches have been found in the *difference* between the
-# log file and the older copy of the log file.  If the plugin detects any 
+# log file and the older copy of the log file.  If the plugin detects any
 # pattern matches in the log diff, it will return a CRITICAL state and print
 # out a message is the following format: "(x) last_match", where "x" is the
 # total number of pattern matches found in the file and "last_match" is the
@@ -162,6 +162,10 @@ while test -n "$1"; do
             exitstatus=$2
             shift
             ;;
+		-t)
+			TMPDIR=$2
+			shift
+			;;
         *)
             echo "Unknown argument: $1"
             print_usage
@@ -191,6 +195,25 @@ elif [ ! -r "$logfile" ] ; then
     exit "$STATE_UNKNOWN"
 fi
 
+# Only use /tmp as a fallback if $TMPDIR doesn't exist
+if [ ! -d "$TMPDIR" ];then
+	TMPDIR="/tmp"
+fi
+echo "$TMPDIR"
+
+# Copy the logfile to a temporary file, to prevent diff from
+# never finishing when $logfile continues to be written to
+# during the diff
+templog="${TMPDIR}/temp_check_log.tmp"
+if [ -x /bin/mktemp ]; then
+    templog=$(/bin/mktemp "${TMPDIR}/temp_check_log.XXXXXXXXXX")
+else
+    templog=$(/bin/date '+%H%M%S')
+    templog="${TMPDIR}/temp_check_log.${templog}"
+fi
+cp "$logfile" "$templog"
+logfile=$templog
+
 # If the old log file doesn't exist, this must be the first time
 # we're running this test, so copy the original log file over to
 # the old diff file and exit
@@ -206,10 +229,10 @@ fi
 # The temporary file that the script should use while
 # processing the log file.
 if [ -x /bin/mktemp ]; then
-    tempdiff=$(/bin/mktemp /tmp/check_log.XXXXXXXXXX)
+    tempdiff=$(/bin/mktemp "${TMPDIR}/check_log.XXXXXXXXXX")
 else
     tempdiff=$(/bin/date '+%H%M%S')
-    tempdiff="/tmp/check_log.${tempdiff}"
+    tempdiff="${TMPDIR}/check_log.${tempdiff}"
     touch "$tempdiff"
     chmod 600 "$tempdiff"
 fi

+ 1 - 1
plugins/check_load.c

@@ -53,7 +53,7 @@ static int process_arguments (int argc, char **argv);
 static int validate_arguments (void);
 void print_help (void);
 void print_usage (void);
-static int print_top_consuming_processes();
+static int print_top_consuming_processes(void);
 
 static int n_procs_to_show = 0;
 

+ 87 - 30
plugins/check_ntp.c

@@ -68,13 +68,31 @@ typedef struct {
 	uint8_t stratum;     /* clock stratum */
 	int8_t poll;         /* polling interval */
 	int8_t precision;    /* precision of the local clock */
-	int32_t rtdelay;     /* total rt delay, as a fixed point num. see macros */
-	uint32_t rtdisp;     /* like above, but for max err to primary src */
+	union {
+		int32_t rtdelay;     /* total rt delay, as a fixed point num. see macros */
+		struct {
+			uint16_t rtdelay_l16;
+			uint16_t rtdelay_r16;
+		};
+	};
+	union {
+		uint32_t rtdisp;     /* like above, but for max err to primary src */
+		struct {
+			uint16_t rtdisp_l16;
+			uint16_t rtdisp_r16;
+		};
+	};
 	uint32_t refid;      /* ref clock identifier */
 	uint64_t refts;      /* reference timestamp.  local time local clock */
 	uint64_t origts;     /* time at which request departed client */
 	uint64_t rxts;       /* time at which request arrived at server */
-	uint64_t txts;       /* time at which request departed server */
+	union {
+		uint64_t txts;       /* time at which request departed server */
+		struct {
+			uint32_t txts_l32;
+			uint32_t txts_r32;
+		};
+	};
 } ntp_message;
 
 /* this structure holds data about results from querying offset from a peer */
@@ -167,35 +185,68 @@ static int allow_zero_stratum = 0;
 /* ntp wants seconds since 1/1/00, epoch is 1/1/70.  this is the difference */
 #define EPOCHDIFF 0x83aa7e80UL
 
+/* extract double from 32-bit ntp fixed point number, without violating strict aliasing rules */
+double ntp32_to_double(uint32_t n) {
+	double result = 0;
+	if (n) {
+		uint16_t l16 = ntohs((uint16_t) (n & ((1<<16) - 1)));
+		uint16_t r16 = ntohs((uint16_t) (n >> 16));
+		result = l16 + ((double) r16/65536.0);
+	}
+	return result;
+}
 /* extract a 32-bit ntp fixed point number into a double */
-#define NTP32asDOUBLE(x) (ntohs(L16(x)) + (double)ntohs(R16(x))/65536.0)
+/* #define NTP32asDOUBLE(x) (ntohs(L16(x)) + (double)ntohs(R16(x))/65536.0)*/
+
+/* extract double from 64-bit ntp fixed point number, without violating strict aliasing rules */
+double ntp64_to_double(uint64_t n) {
+	double result = 0;
+	if (n) {
+		uint32_t l32 = ntohl((uint32_t) (n & ((1ul<<32) - 1)));
+		uint32_t r32 = ntohl((uint32_t) (n >> 32));
+		result = (l32 - EPOCHDIFF)
+		       + (.00000001*(0.5+(double)(r32/42.94967296)));
+	}
+	return result;
+}
 
 /* likewise for a 64-bit ntp fp number */
-#define NTP64asDOUBLE(n) (double)(((uint64_t)n)?\
-                         (ntohl(L32(n))-EPOCHDIFF) + \
-                         (.00000001*(0.5+(double)(ntohl(R32(n))/42.94967296))):\
-                         0)
+/* #define NTP64asDOUBLE(n) (double)(((uint64_t)n)?\
+                          (ntohl(L32(n))-EPOCHDIFF) + \
+                          (.00000001*(0.5+(double)(ntohl(R32(n))/42.94967296))):\
+                          0)*/
 
 /* convert a struct timeval to a double */
 #define TVasDOUBLE(x) (double)(x.tv_sec+(0.000001*x.tv_usec))
 
+struct timeval ntp64_to_tv(uint64_t n) {
+	struct timeval result = {};
+	if (n) {
+		uint32_t l32 = ntohl((uint32_t) (n & ((1ul<<32) - 1)));
+		uint32_t r32 = ntohl((uint32_t) (n >> 32));
+		result.tv_sec = l32 - EPOCHDIFF;
+		result.tv_usec = (int)(0.5+(double)(r32/4294.967296));
+	}
+	return result;
+}
+
 /* convert an ntp 64-bit fp number to a struct timeval */
-#define NTP64toTV(n,t) \
+/* #define NTP64toTV(n,t) \
 	do{ if(!n) t.tv_sec = t.tv_usec = 0; \
 	    else { \
 			t.tv_sec=ntohl(L32(n))-EPOCHDIFF; \
 			t.tv_usec=(int)(0.5+(double)(ntohl(R32(n))/4294.967296)); \
 		} \
-	}while(0)
+	}while(0) */
 
 /* convert a struct timeval to an ntp 64-bit fp number */
-#define TVtoNTP64(t,n) \
+/* #define TVtoNTP64(t,n) \
 	do{ if(!t.tv_usec && !t.tv_sec) n=0x0UL; \
 		else { \
 			L32(n)=htonl(t.tv_sec + EPOCHDIFF); \
 			R32(n)=htonl((uint64_t)((4294.967296*t.tv_usec)+.5)); \
 		} \
-	} while(0)
+	} while(0) */
 
 /* NTP control message header is 12 bytes, plus any data in the data
  * field, plus null padding to the nearest 32-bit boundary per rfc.
@@ -212,9 +263,9 @@ static int allow_zero_stratum = 0;
 /* calculate the offset of the local clock */
 static inline double calc_offset(const ntp_message *m, const struct timeval *t){
 	double client_tx, peer_rx, peer_tx, client_rx;
-	client_tx = NTP64asDOUBLE(m->origts);
-	peer_rx = NTP64asDOUBLE(m->rxts);
-	peer_tx = NTP64asDOUBLE(m->txts);
+	client_tx = ntp64_to_double(m->origts);
+	peer_rx = ntp64_to_double(m->rxts);
+	peer_tx = ntp64_to_double(m->txts);
 	client_rx=TVasDOUBLE((*t));
 	return (.5*((peer_tx-client_rx)+(peer_rx-client_tx)));
 }
@@ -223,10 +274,10 @@ static inline double calc_offset(const ntp_message *m, const struct timeval *t){
 void print_ntp_message(const ntp_message *p){
 	struct timeval ref, orig, rx, tx;
 
-	NTP64toTV(p->refts,ref);
-	NTP64toTV(p->origts,orig);
-	NTP64toTV(p->rxts,rx);
-	NTP64toTV(p->txts,tx);
+	ref = ntp64_to_tv(p->refts);
+	orig = ntp64_to_tv(p->origts);
+	rx = ntp64_to_tv(p->rxts);
+	tx = ntp64_to_tv(p->txts);
 
 	printf("packet contents:\n");
 	printf("\tflags: 0x%.2x\n", p->flags);
@@ -236,13 +287,13 @@ void print_ntp_message(const ntp_message *p){
 	printf("\tstratum = %d\n", p->stratum);
 	printf("\tpoll = %g\n", pow(2, p->poll));
 	printf("\tprecision = %g\n", pow(2, p->precision));
-	printf("\trtdelay = %-.16g\n", NTP32asDOUBLE(p->rtdelay));
-	printf("\trtdisp = %-.16g\n", NTP32asDOUBLE(p->rtdisp));
+	printf("\trtdelay = %-.16g\n", ntp32_to_double(p->rtdelay));
+	printf("\trtdisp = %-.16g\n", ntp32_to_double(p->rtdisp));
 	printf("\trefid = %x\n", p->refid);
-	printf("\trefts = %-.16g\n", NTP64asDOUBLE(p->refts));
-	printf("\torigts = %-.16g\n", NTP64asDOUBLE(p->origts));
-	printf("\trxts = %-.16g\n", NTP64asDOUBLE(p->rxts));
-	printf("\ttxts = %-.16g\n", NTP64asDOUBLE(p->txts));
+	printf("\trefts = %-.16g\n", ntp64_to_double(p->refts));
+	printf("\torigts = %-.16g\n", ntp64_to_double(p->origts));
+	printf("\trxts = %-.16g\n", ntp64_to_double(p->rxts));
+	printf("\ttxts = %-.16g\n", ntp64_to_double(p->txts));
 }
 
 void print_ntp_control_message(const ntp_control_message *p){
@@ -290,11 +341,17 @@ void setup_request(ntp_message *p){
 	MODE_SET(p->flags, MODE_CLIENT);
 	p->poll=4;
 	p->precision=(int8_t)0xfa;
-	L16(p->rtdelay)=htons(1);
-	L16(p->rtdisp)=htons(1);
+	p->rtdelay_l16=htons(1);
+	p->rtdisp_l16=htons(1);
 
 	gettimeofday(&t, NULL);
-	TVtoNTP64(t,p->txts);
+
+	/* This used to use TVtoNTP64 but we ran into issues with strict aliasing/type punning.
+	 * We only used the macro in one place, so it's inlined now */
+	if (t.tv_usec || t.tv_sec) {
+		p->txts_l32 = htonl(t.tv_sec + EPOCHDIFF);
+		p->txts_r32 = htonl((uint64_t) ((4294.967296*t.tv_usec)+.5));
+	}
 }
 
 /* select the "best" server from a list of servers, and return its index.
@@ -464,8 +521,8 @@ double offset_request(const char *host, int *status){
 					printf("offset %.10g\n", servers[i].offset[respnum]);
 				}
 				servers[i].stratum=req[i].stratum;
-				servers[i].rtdisp=NTP32asDOUBLE(req[i].rtdisp);
-				servers[i].rtdelay=NTP32asDOUBLE(req[i].rtdelay);
+				servers[i].rtdisp=ntp32_to_double(req[i].rtdisp);
+				servers[i].rtdelay=ntp32_to_double(req[i].rtdelay);
 				servers[i].waiting--;
 				servers[i].flags=req[i].flags;
 				servers_readable--;

+ 89 - 32
plugins/check_ntp_time.c

@@ -73,13 +73,31 @@ typedef struct {
 	uint8_t stratum;     /* clock stratum */
 	int8_t poll;         /* polling interval */
 	int8_t precision;    /* precision of the local clock */
-	int32_t rtdelay;     /* total rt delay, as a fixed point num. see macros */
-	uint32_t rtdisp;     /* like above, but for max err to primary src */
+	union {
+		int32_t rtdelay;     /* total rt delay, as a fixed point num. see macros */
+		struct {
+			uint16_t rtdelay_l16;
+			uint16_t rtdelay_r16;
+		};
+	};
+	union {
+		uint32_t rtdisp;     /* like above, but for max err to primary src */
+		struct {
+			uint16_t rtdisp_l16;
+			uint16_t rtdisp_r16;
+		};
+	};
 	uint32_t refid;      /* ref clock identifier */
 	uint64_t refts;      /* reference timestamp.  local time local clock */
 	uint64_t origts;     /* time at which request departed client */
 	uint64_t rxts;       /* time at which request arrived at server */
-	uint64_t txts;       /* time at which request departed server */
+	union {
+		uint64_t txts;       /* time at which request departed server */
+		struct {
+			uint32_t txts_l32;
+			uint32_t txts_r32;
+		};
+	};
 } ntp_message;
 
 /* this structure holds data about results from querying offset from a peer */
@@ -155,35 +173,68 @@ ntp_server_results *servers=NULL;
 /* ntp wants seconds since 1/1/00, epoch is 1/1/70.  this is the difference */
 #define EPOCHDIFF 0x83aa7e80UL
 
+/* extract double from 32-bit ntp fixed point number, without violating strict aliasing rules */
+double ntp32_to_double(uint32_t n) {
+	double result = 0;
+	if (n) {
+		uint16_t l16 = ntohs((uint16_t) (n & ((1<<16) - 1)));
+		uint16_t r16 = ntohs((uint16_t) (n >> 16));
+		result = l16 + ((double) r16/65536.0);
+	}
+	return result;
+}
 /* extract a 32-bit ntp fixed point number into a double */
-#define NTP32asDOUBLE(x) (ntohs(L16(x)) + (double)ntohs(R16(x))/65536.0)
+/* #define NTP32asDOUBLE(x) (ntohs(L16(x)) + (double)ntohs(R16(x))/65536.0)*/
+
+/* extract double from 64-bit ntp fixed point number, without violating strict aliasing rules */
+double ntp64_to_double(uint64_t n) {
+	double result = 0;
+	if (n) {
+		uint32_t l32 = ntohl((uint32_t) (n & ((1ul<<32) - 1)));
+		uint32_t r32 = ntohl((uint32_t) (n >> 32));
+		result = (l32 - EPOCHDIFF)
+		       + (.00000001*(0.5+(double)(r32/42.94967296)));
+	}
+	return result;
+}
 
 /* likewise for a 64-bit ntp fp number */
-#define NTP64asDOUBLE(n) (double)(((uint64_t)n)?\
-                         (ntohl(L32(n))-EPOCHDIFF) + \
-                         (.00000001*(0.5+(double)(ntohl(R32(n))/42.94967296))):\
-                         0)
+/* #define NTP64asDOUBLE(n) (double)(((uint64_t)n)?\
+                          (ntohl(L32(n))-EPOCHDIFF) + \
+                          (.00000001*(0.5+(double)(ntohl(R32(n))/42.94967296))):\
+                          0)*/
 
 /* convert a struct timeval to a double */
 #define TVasDOUBLE(x) (double)(x.tv_sec+(0.000001*x.tv_usec))
 
+struct timeval ntp64_to_tv(uint64_t n) {
+	struct timeval result = {};
+	if (n) {
+		uint32_t l32 = ntohl((uint32_t) (n & ((1ul<<32) - 1)));
+		uint32_t r32 = ntohl((uint32_t) (n >> 32));
+		result.tv_sec = l32 - EPOCHDIFF;
+		result.tv_usec = (int)(0.5+(double)(r32/4294.967296));
+	}
+	return result;
+}
+
 /* convert an ntp 64-bit fp number to a struct timeval */
-#define NTP64toTV(n,t) \
+/* #define NTP64toTV(n,t) \
 	do{ if(!n) t.tv_sec = t.tv_usec = 0; \
 	    else { \
 			t.tv_sec=ntohl(L32(n))-EPOCHDIFF; \
 			t.tv_usec=(int)(0.5+(double)(ntohl(R32(n))/4294.967296)); \
 		} \
-	}while(0)
+	}while(0) */
 
 /* convert a struct timeval to an ntp 64-bit fp number */
-#define TVtoNTP64(t,n) \
+/* #define TVtoNTP64(t,n) \
 	do{ if(!t.tv_usec && !t.tv_sec) n=0x0UL; \
 		else { \
 			L32(n)=htonl(t.tv_sec + EPOCHDIFF); \
 			R32(n)=htonl((uint64_t)((4294.967296*t.tv_usec)+.5)); \
 		} \
-	} while(0)
+	} while(0) */
 
 /* NTP control message header is 12 bytes, plus any data in the data
  * field, plus null padding to the nearest 32-bit boundary per rfc.
@@ -200,9 +251,9 @@ ntp_server_results *servers=NULL;
 /* calculate the offset of the local clock */
 static inline double calc_offset(const ntp_message *m, const struct timeval *t){
 	double client_tx, peer_rx, peer_tx, client_rx;
-	client_tx = NTP64asDOUBLE(m->origts);
-	peer_rx = NTP64asDOUBLE(m->rxts);
-	peer_tx = NTP64asDOUBLE(m->txts);
+	client_tx = ntp64_to_double(m->origts);
+	peer_rx = ntp64_to_double(m->rxts);
+	peer_tx = ntp64_to_double(m->txts);
 	client_rx=TVasDOUBLE((*t));
 	return (.5*((peer_tx-client_rx)+(peer_rx-client_tx)));
 }
@@ -211,10 +262,10 @@ static inline double calc_offset(const ntp_message *m, const struct timeval *t){
 void print_ntp_message(const ntp_message *p){
 	struct timeval ref, orig, rx, tx;
 
-	NTP64toTV(p->refts,ref);
-	NTP64toTV(p->origts,orig);
-	NTP64toTV(p->rxts,rx);
-	NTP64toTV(p->txts,tx);
+	ref = ntp64_to_tv(p->refts);
+	orig = ntp64_to_tv(p->origts);
+	rx = ntp64_to_tv(p->rxts);
+	tx = ntp64_to_tv(p->txts);
 
 	printf("packet contents:\n");
 	printf("\tflags: 0x%.2x\n", p->flags);
@@ -224,13 +275,13 @@ void print_ntp_message(const ntp_message *p){
 	printf("\tstratum = %d\n", p->stratum);
 	printf("\tpoll = %g\n", pow(2, p->poll));
 	printf("\tprecision = %g\n", pow(2, p->precision));
-	printf("\trtdelay = %-.16g\n", NTP32asDOUBLE(p->rtdelay));
-	printf("\trtdisp = %-.16g\n", NTP32asDOUBLE(p->rtdisp));
+	printf("\trtdelay = %-.16g\n", ntp32_to_double(p->rtdelay));
+	printf("\trtdisp = %-.16g\n", ntp32_to_double(p->rtdisp));
 	printf("\trefid = %x\n", p->refid);
-	printf("\trefts = %-.16g\n", NTP64asDOUBLE(p->refts));
-	printf("\torigts = %-.16g\n", NTP64asDOUBLE(p->origts));
-	printf("\trxts = %-.16g\n", NTP64asDOUBLE(p->rxts));
-	printf("\ttxts = %-.16g\n", NTP64asDOUBLE(p->txts));
+	printf("\trefts = %-.16g\n", ntp64_to_double(p->refts));
+	printf("\torigts = %-.16g\n", ntp64_to_double(p->origts));
+	printf("\trxts = %-.16g\n", ntp64_to_double(p->rxts));
+	printf("\ttxts = %-.16g\n", ntp64_to_double(p->txts));
 }
 
 void setup_request(ntp_message *p){
@@ -242,11 +293,17 @@ void setup_request(ntp_message *p){
 	MODE_SET(p->flags, MODE_CLIENT);
 	p->poll=4;
 	p->precision=(int8_t)0xfa;
-	L16(p->rtdelay)=htons(1);
-	L16(p->rtdisp)=htons(1);
+	p->rtdelay_l16=htons(1);
+	p->rtdisp_l16=htons(1);
 
 	gettimeofday(&t, NULL);
-	TVtoNTP64(t,p->txts);
+
+	/* This used to use TVtoNTP64 but we ran into issues with strict aliasing/type punning.
+	 * We only used the macro in one place, so it's inlined now */
+	if (t.tv_usec || t.tv_sec) {
+		p->txts_l32 = htonl(t.tv_sec + EPOCHDIFF);
+		p->txts_r32 = htonl((uint64_t) ((4294.967296*t.tv_usec)+.5));
+	}
 }
 
 /* select the "best" server from a list of servers, and return its index.
@@ -420,8 +477,8 @@ double offset_request(const char *host, int *status){
 					printf("offset %.10g\n", servers[i].offset[respnum]);
 				}
 				servers[i].stratum=req[i].stratum;
-				servers[i].rtdisp=NTP32asDOUBLE(req[i].rtdisp);
-				servers[i].rtdelay=NTP32asDOUBLE(req[i].rtdelay);
+				servers[i].rtdisp=ntp32_to_double(req[i].rtdisp);
+				servers[i].rtdelay=ntp32_to_double(req[i].rtdelay);
 				servers[i].waiting--;
 				servers[i].flags=req[i].flags;
 				servers_readable--;
@@ -490,7 +547,7 @@ int process_arguments(int argc, char **argv){
 		usage ("\n");
 
 	while (1) {
-		c = getopt_long (argc, argv, "Vhv46qw:c:t:H:p:o:d:", longopts, &option);
+		c = getopt_long (argc, argv, "Vhv46qw:c:t:H:p:o:d:C:W:", longopts, &option);
 		if (c == -1 || c == EOF || c == 1)
 			break;
 
@@ -722,6 +779,6 @@ void
 print_usage(void)
 {
 	printf ("%s\n", _("Usage:"));
-	printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose] [-o <time offset>] [-d <delay>]\n", progname);
+	printf(" %s -H <host> [-4|-6] [-w <warn>] [-c <crit>] [-v verbose] [-o <time offset>] [-d <delay>] [-W <stratum warn>] [-C <stratum crit>]\n", progname);
 }
 

+ 7 - 5
plugins/check_smtp.c

@@ -311,16 +311,17 @@ main (int argc, char **argv)
 			printf("%s", buffer);
 		}
 
-#  ifdef USE_OPENSSL
-		  if ( check_cert ) {
+		}
+#endif
+
+#ifdef USE_OPENSSL
+		if ( (use_ssl || use_starttls) && check_cert ) {
                     result = np_net_ssl_check_cert(days_till_exp_warn, days_till_exp_crit);
 		    smtp_quit();
 		    my_close();
 		    return result;
 		  }
-#  endif /* USE_OPENSSL */
-		}
-#endif
+#endif /* USE_OPENSSL */
 
 		if (send_mail_from) {
 		  my_send(cmd_str, strlen(cmd_str));
@@ -648,6 +649,7 @@ process_arguments (int argc, char **argv)
 #else
 			usage (_("SSL support not available - install OpenSSL and recompile"));
 #endif
+			break;
 		case 's':
 		/* ssl */
 			use_ssl = TRUE;

+ 1 - 1
plugins/netutils.h

@@ -108,7 +108,7 @@ int np_net_ssl_init(int sd);
 int np_net_ssl_init_with_hostname(int sd, char *host_name);
 int np_net_ssl_init_with_hostname_and_version(int sd, char *host_name, int version);
 int np_net_ssl_init_with_hostname_version_and_cert(int sd, char *host_name, int version, char *cert, char *privkey);
-void np_net_ssl_cleanup();
+void np_net_ssl_cleanup(void);
 int np_net_ssl_write(const void *buf, int num);
 int np_net_ssl_read(void *buf, int num);
 int np_net_ssl_check_cert(int days_till_exp_warn, int days_till_exp_crit);

+ 2 - 0
plugins/utils.h

@@ -79,6 +79,8 @@ char *strpcat (char *, const char *, const char *);
 int xvasprintf (char **strp, const char *fmt, va_list ap);
 int xasprintf (char **strp, const char *fmt, ...);
 
+
+int min_state (int a, int b);
 int max_state (int a, int b);
 int max_state_alt (int a, int b);
 

File diff suppressed because it is too large
+ 213 - 209
po/de.po


File diff suppressed because it is too large
+ 215 - 211
po/fr.po


File diff suppressed because it is too large
+ 213 - 209
po/nagios-plugins.pot


Some files were not shown because too many files changed in this diff