+* [Bug 1169] quiet compiler warnings
+* Re-enable gcc -Wstrict-prototypes when not building with OpenSSL
+* Enable gcc -Wstrict-overflow
+* ntpq/ntpdc emit newline after accepting password on Windows
(4.2.5p166) 2009/04/25 Released by Harlan Stenn <stenn@ntp.org>
* [Bug 1165] Clean up small memory leaks in the config file parser
* Correct logconfig keyword declaration to MULTIPLE_ARG
CFLAGS="$CFLAGS -Wmissing-prototypes"
CFLAGS="$CFLAGS -Wpointer-arith"
CFLAGS="$CFLAGS -Wshadow"
- #
- # OpenSSL has a number of callback prototypes
- # inside other function prototypes which trigger
- # warnings with -Wstrict-prototypes, such as:
- #
- # int i2d_RSA_NET(const RSA *a, unsigned char **pp,
- # int (*cb)(), int sgckey);
- # ^^^^^^^^^^^
- #
- CFLAGS="$CFLAGS -Wno-strict-prototypes"
# CFLAGS="$CFLAGS -Wtraditional"
# CFLAGS="$CFLAGS -Wwrite-strings"
CFLAGS="$CFLAGS -Winit-self"
case "$ac_cv_gcc_Wstrict_overflow" in
yes)
- #not yet: CFLAGS="$CFLAGS -Wstrict-overflow"
+ CFLAGS="$CFLAGS -Wstrict-overflow"
esac
- ;;
+ # if building with OpenSSL, -Wno-strict-prototypes is added later
esac
case "$host" in
esac
AC_MSG_RESULT([$ans])
+AC_MSG_CHECKING([if we will use crypto])
AC_ARG_WITH(crypto,
AC_HELP_STRING([--with-crypto], [+ =openssl]),
[ans=$withval], [ans=yes])
case "$ans" in
- no) ;;
+ no)
+ ;;
yes|openssl)
if test -z "$OPENSSL_LIB" -o -z "$OPENSSL_INC"
then
ans=no
else
- # We have OpenSSL inc/lib - use them.
- ans=openssl
- CPPFLAGS="$CPPFLAGS -I$OPENSSL_INC"
- LDFLAGS="$LDFLAGS -L$OPENSSL_LIB"
- case "$need_dash_r" in
- 1) LDFLAGS="$LDFLAGS -R$OPENSSL_LIB"
- ;;
- esac
- AC_SUBST(LCRYPTO, [-lcrypto])
- AC_DEFINE(OPENSSL, , [Use OpenSSL?])
- AC_CHECK_FUNCS(EVP_md2 EVP_mdc2)
+ ans=yes
fi
- ;;
esac
-AC_MSG_CHECKING(for the level of crypto support)
+ntp_openssl=$ans
AC_MSG_RESULT([$ans])
+case "$ntp_openssl" in
+ yes)
+ # We have OpenSSL inc/lib - use them.
+ CPPFLAGS="$CPPFLAGS -I$OPENSSL_INC"
+ LDFLAGS="$LDFLAGS -L$OPENSSL_LIB"
+ case "$need_dash_r" in
+ 1) LDFLAGS="$LDFLAGS -R$OPENSSL_LIB"
+ esac
+ AC_SUBST(LCRYPTO, [-lcrypto])
+ AC_DEFINE(OPENSSL, , [Use OpenSSL?])
+ AC_CHECK_FUNCS([EVP_md2 EVP_mdc2])
+esac
+
+#
+# OpenSSL has a number of callback prototypes inside other function
+# prototypes which trigger copious warnings with -Wstrict-prototypes,
+# (which is included in -Wall).
+#
+# An example:
+#
+# int i2d_RSA_NET(const RSA *a, unsigned char **pp,
+# int (*cb)(), int sgckey);
+# ^^^^^^^^^^^
+#
+# The OpenSSL headers probably haven't been fixed in this regard
+# due to the hoops you have to jump through to stay compatible with
+# K&R C compilers.
+#
+case "$GCC$ntp_openssl" in
+ yesyes)
+ CFLAGS="$CFLAGS -Wno-strict-prototypes"
+esac
+
AC_MSG_CHECKING([if we want to compile with ElectricFence])
AC_ARG_WITH(electricfence,
AC_HELP_STRING([--with-electricfence], [- compile with ElectricFence malloc debugger]),
*/
int
auth_init (
- char *keyfile,
+ const char *keyfile,
struct key **keys
)
{
struct key *prev = NULL;
register int a, line_limit;
- int scan_cnt, line_cnt = 0, key_cnt = 0;
+ int scan_cnt, line_cnt = 0;
char kbuf[96];
if(keyf == NULL) {
for(a=0; a<strlen(kbuf) && a < 96; a++) {
if(kbuf[a] == '#') {
line_limit = a;
- a = 96;
+ break;
}
}
};
int auth_md5(char *pkt_data, int mac_size, struct key *cmp_key);
-int auth_init(char *keyfile, struct key **keys);
+int auth_init(const char *keyfile, struct key **keys);
void get_key(int key_id, struct key **d_key);
#define DEBUG
int kod_init = 0, entryc = 0;
-char *kod_db_file;
+const char *kod_db_file;
struct kod_entry *kod_db;
FILE *db_s;
void
kod_init_kod_db (
- char *db_file
+ const char *db_file
)
{
if(kod_init)
void add_entry (char *hostname, char *type);
void delete_entry (char *hostname, char *type);
-void kod_init_kod_db (char *db_file);
+void kod_init_kod_db (const char *db_file);
void write_kod_db (void);
void kod_atexit (void);
}
}
-void init_log(char *logfile) {
+void init_log(const char *logfile) {
log_file = fopen(logfile, "a");
if(log_file == NULL) {
void log_msg(char *message, char type);
void debug_msg(char *message);
-void init_log(char *logfile);
+void init_log(const char *logfile);
void cleanup_log(void);
#endif
#include <isc/result.h>
+#include <isc/net.h>
#include <l_stdlib.h>
#include <ntp_fp.h>
#include <ntp.h>
/* Initialize logging system */
if(HAVE_OPT(FILELOG)) {
- init_log((char *)OPT_ARG(FILELOG));
+ init_log(OPT_ARG(FILELOG));
}
/* If there's a specified KOD file init KOD system.
* If not and system may save to HD use default file.
*/
if(HAVE_OPT(KOD)) {
- kod_init_kod_db((char *)OPT_ARG(KOD));
+ kod_init_kod_db(OPT_ARG(KOD));
}
if(HAVE_OPT(KEYFILE)) {
- auth_init((char *)OPT_ARG(KEYFILE), &keys);
+ auth_init(OPT_ARG(KEYFILE), &keys);
}
{
struct timeval timeout_tv;
fd_set bcst_fd;
-
+ char *buf;
int btrue = 1;
int recv_bytes = 0;
setsockopt(rsock, SOL_SOCKET, SO_REUSEADDR, &btrue, sizeof(btrue));
if(sas->ss_family == AF_INET) {
- struct sockaddr_in sin;
struct ip_mreq mdevadr;
- sin.sin_family = AF_INET;
- sin.sin_addr.s_addr = htonl(INADDR_ANY);
- sin.sin_port = htons(123);
-
if(bind(rsock, (struct sockaddr *) sas, SOCKLEN(sas)) < 0) {}
if(setsockopt(rsock, IPPROTO_IP, IP_MULTICAST_LOOP, &btrue, sizeof(btrue)) < 0) {
/* some error message regarding setting up multicast loop */
return BROADCAST_FAILED;
- }
+ }
- char *buf = ss_to_str(sas);
+ buf = ss_to_str(sas);
mdevadr.imr_multiaddr.s_addr = inet_addr(buf);
mdevadr.imr_interface.s_addr = htonl(INADDR_ANY);
if (setsockopt(rsock, IPPROTO_IP, IP_ADD_MEMBERSHIP, &mdevadr, sizeof(mdevadr)) < 0) {
if(ENABLED_OPT(NORMALVERBOSE)) {
- char *buf = ss_to_str(sas);
+ buf = ss_to_str(sas);
printf("sntp recv_bcst_data: Couldn't add IP membership for %s\n", buf);
}
}
else if(sas->ss_family == AF_INET6) {
- struct sockaddr_in6 sin6;
struct ipv6_mreq mdevadr;
- sin6.sin6_family = AF_INET6;
- sin6.sin6_addr = in6addr_any;
- sin6.sin6_port = htons(123);
-
if(bind(rsock, (struct sockaddr *) sas, sizeof(sas)) < 0) {
if(ENABLED_OPT(NORMALVERBOSE))
printf("sntp recv_bcst_data: Couldn't bind() address.\n");
if(!IN6_IS_ADDR_MULTICAST((struct in6_addr *) &mdevadr.ipv6mr_multiaddr)) {
if(ENABLED_OPT(NORMALVERBOSE)) {
- char *buf = ss_to_str(sas);
+ buf = ss_to_str(sas);
printf("sntp recv_bcst_data: %s is not a broad-/multicast address, aborting...\n", buf);
if (setsockopt(rsock, IPPROTO_IPV6, IPV6_JOIN_GROUP, &mdevadr, sizeof(mdevadr)) < 0) {
if(ENABLED_OPT(NORMALVERBOSE)) {
- char *buf = ss_to_str(sas);
+ buf = ss_to_str(sas);
printf("sntp recv_bcst_data: Couldn't join group for %s\n", buf);
case 0:
if(ENABLED_OPT(NORMALVERBOSE))
- printf("sntp recv_bcst_data: select() reached timeout (%i sec), aborting.\n", timeout_tv.tv_sec);
+ printf("sntp recv_bcst_data: select() reached timeout (%li sec), aborting.\n", timeout_tv.tv_sec);
return BROADCAST_FAILED;
break;
ISC_LANG_BEGINDECLS
isc_result_t
-isc_file_settime(const char *file, isc_time_t *time);
+isc_file_settime(const char *file, isc_time_t *mtime);
isc_result_t
-isc_file_getmodtime(const char *file, isc_time_t *time);
+isc_file_getmodtime(const char *file, isc_time_t *mtime);
/*!<
* \brief Get the time of last modication of a file.
*
+/*
+ * short-circuited NTP-local imitation of isc/mem.h
+ */
+
/*
* Copyright (C) 1997-2001 Internet Software Consortium.
*
#ifndef ISC_MEM_H
#define ISC_MEM_H 1
+#include <stdlib.h>
#include <stdio.h>
-#include <isc/types.h>
-void *
-isc_mem_get(isc_mem_t *, size_t);
-void
-isc_mem_put(isc_mem_t *, void *, size_t);
+
+#define isc_mem_get(c, cnt) malloc((cnt) ? (cnt) : 1)
+#define isc_mem_put(c, mem, cnt) free(mem)
+#define isc_mem_free(c, mem) free(mem)
+#define isc_mem_strdup(c, str) strdup(str)
#endif /* ISC_MEM_H */
struct peer_node *create_peer_node(int hmode, struct address_node *addr, queue *options);
struct unpeer_node *create_unpeer_node(struct address_node *addr);
struct address_node *create_address_node(char *addr, int type);
+void destroy_address_node(struct address_node *my_node);
queue *enqueue_in_new_queue(void *my_node);
struct attr_val *create_attr_dval(int attr, double value);
struct attr_val *create_attr_ival(int attr, int value);
extern char * mfptoa (u_long, u_long, short);
extern char * mfptoms (u_long, u_long, short);
extern const char * modetoa (int);
-extern const char * eventstr (int);
-extern const char * ceventstr (int);
+extern const char * eventstr (int);
+extern const char * ceventstr (int);
extern char * statustoa (int, int);
extern const char * sysstatstr (int);
extern const char * peerstatstr (int);
extern struct sockaddr_storage* netof (struct sockaddr_storage*);
extern char * numtoa (u_int32);
extern char * numtohost (u_int32);
-extern char * socktoa (struct sockaddr_storage *);
-extern char * socktohost (struct sockaddr_storage *);
+extern char * socktoa (struct sockaddr_storage *);
+extern char * socktohost (struct sockaddr_storage *);
extern int octtoint (const char *, u_long *);
extern u_long ranp2 (int);
extern char * refnumtoa (struct sockaddr_storage *);
extern int decodenetnum (const char *, struct sockaddr_storage *);
-extern const char * FindConfig (const char *);
+extern const char * FindConfig (const char *);
extern void signal_no_reset (int, RETSIGTYPE (*func)(int));
/* Function Prototypes */
+int ntpsim (int argc, char *argv[]);
Event *event (double t, funcTkn f);
void sim_event_timer (Event *e);
int simulate_server (struct sockaddr_storage *serv_addr,
#include <config.h>
+#ifdef ISC_PLATFORM_NEEDNTOP
+
#include <errno.h>
#include <stdio.h>
#include <string.h>
return (dst);
}
#endif /* AF_INET6 */
+
+#else
+int inet_ntop_c_not_empty;
+#endif /* ISC_PLATFORM_NEEDNTOP */
#include <config.h>
+#ifdef ISC_PLATFORM_NEEDPTON
+
#include <errno.h>
#include <string.h>
memcpy(dst, tmp, NS_IN6ADDRSZ);
return (1);
}
+
+#else
+int inet_pton_c_not_empty;
+#endif /* ISC_PLATFORM_NEEDPTON */
+/*
+ * this file is leaving the NTP build in favor of
+ * inline macros in isc/mem.h for now
+ */
+
/*
* Copyright (C) 1997-2002 Internet Software Consortium.
*
uglydate.c uinttoa.c ymd2yd.c \
$(srcdir)/../libisc/assertions.c $(srcdir)/../libisc/error.c \
$(srcdir)/../libisc/interfaceiter.c $(srcdir)/../libisc/lib.c \
- $(srcdir)/../libisc/log.c $(srcdir)/../libisc/md5.c \
- $(srcdir)/../libisc/mem.c $(srcdir)/../libisc/msgcat.c \
+ $(srcdir)/../libisc/md5.c $(srcdir)/../libisc/msgcat.c \
$(srcdir)/../libisc/net.c $(srcdir)/../libisc/isc_strerror.c \
- $(srcdir)/../libisc/inet_ntop.c \
- $(srcdir)/../libisc/inet_pton.c \
+ $(srcdir)/../libisc/inet_ntop.c $(srcdir)/../libisc/inet_pton.c \
$(srcdir)/../libisc/netaddr.c $(srcdir)/../libisc/sockaddr.c \
$(srcdir)/../libisc/netscope.c
libntp_a_SOURCES = systime.c $(libntp_a_SRCS)
}
password[i] = '\0';
+ fputc('\n', stderr);
+ fflush(stderr);
+
return password;
}
#endif /* SYS_WINNT */
/*
* numtoa - return asciized network numbers store in local array space
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if HAVE_NETINET_IN_H
+#include <netinet/in.h> /* ntohl */
+#endif
+
#include <stdio.h>
#include "ntp_fp.h"
* numtohost - convert network number to host name.
*/
+#ifdef HAVE_CONFIG_H
+#include <config.h>
+#endif
+
+#if HAVE_NETINET_IN_H
+#include <netinet/in.h> /* ntohl */
+#endif
+
#include "ntp_fp.h"
#include "ntp_stdlib.h"
#include "lib_strbuf.h"
#include "ntp_stdlib.h"
#include "ntp_assert.h"
+static char *common_prettydate(l_fp *, int);
+
const char *months[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
}
-char *
+static char *
common_prettydate(
l_fp *ts,
int local
{ -1, "clk" }
};
+
+#ifdef FLASH_CODES_UNUSED
/*
- * Flash bits
+ * Flash bits -- see ntpq.c tstflags & tstflagnames
*/
static
struct codestring flash_codes[] = {
{ TEST13, "peer_unreach" },
{ -1, "flash" }
};
+#endif
+
/*
* System events (sys)
static void
pprintf(
int lev,
- const char *form,
+ char *form,
...
)
{
va_start(ap, form);
if (lev & parsedebug)
- vcmn_err(CE_CONT, (char *)form, ap);
+ vcmn_err(CE_CONT, form, ap);
va_end(ap);
}
register parsestream_t * parse = (parsestream_t *)q->q_ptr;
register mblk_t *nmp;
register unsigned long ch;
- timestamp_t ctime;
+ timestamp_t c_time;
timespec_t hres_time;
/*
* get time on packet delivery
*/
gethrestime(&hres_time);
- ctime.tv.tv_sec = hres_time.tv_sec;
- ctime.tv.tv_usec = hres_time.tv_nsec / 1000;
+ c_time.tv.tv_sec = hres_time.tv_sec;
+ c_time.tv.tv_usec = hres_time.tv_nsec / 1000;
if (!(parse->parse_status & PARSE_ENABLE))
{
while (mp != (mblk_t *)NULL)
{
ch = rdchar(&mp);
- if (ch != ~0 && parse_ioread(&parse->parse_io, (unsigned int)ch, &ctime))
+ if (ch != ~0 && parse_ioread(&parse->parse_io, (unsigned int)ch, &c_time))
{
/*
* up up and away (hopefully ...)
}
else
{
- if (parse_ioread(&parse->parse_io, (unsigned int)0, &ctime))
+ if (parse_ioread(&parse->parse_io, (unsigned int)0, &c_time))
{
/*
* up up and away (hopefully ...)
case M_UNHANGUP:
{
register parsestream_t * parse = (parsestream_t *)q->q_ptr;
- timestamp_t ctime;
+ timestamp_t c_time;
timespec_t hres_time;
register mblk_t *nmp;
register int status = cd_invert ^ (type == M_UNHANGUP);
gethrestime(&hres_time);
- ctime.tv.tv_sec = hres_time.tv_sec;
- ctime.tv.tv_usec = hres_time.tv_nsec / 1000;
+ c_time.tv.tv_sec = hres_time.tv_sec;
+ c_time.tv.tv_usec = hres_time.tv_nsec / 1000;
pprintf(DD_RPUT, "parse: parserput - M_%sHANGUP\n", (type == M_HANGUP) ? "" : "UN");
if ((parse->parse_status & PARSE_ENABLE) &&
- parse_iopps(&parse->parse_io, status ? SYNC_ONE : SYNC_ZERO, &ctime))
+ parse_iopps(&parse->parse_io, status ? SYNC_ONE : SYNC_ZERO, &c_time))
{
nmp = (mblk_t *)NULL;
if (canputnext(parse->parse_queue) && (nmp = allocb(sizeof(parsetime_t), BPRI_MED)))
if (status)
{
- parse->parse_ppsclockev.tv = ctime.tv;
+ parse->parse_ppsclockev.tv = c_time.tv;
++(parse->parse_ppsclockev.serial);
}
}
#endif
double *create_dval(double val);
void destroy_restrict_node(struct restrict_node *my_node);
+#if !defined(SIM)
static struct sockaddr_storage *get_next_address(struct address_node *addr);
+#endif
static void config_other_modes(void);
static void config_auth(void);
free_syntax_tree(void)
{
DESTROY_QUEUE(my_config.peers);
+ DESTROY_QUEUE(my_config.unpeers);
DESTROY_QUEUE(my_config.orphan_cmds);
DESTROY_QUEUE(my_config.manycastserver);
}
+#if !defined(SIM)
+
#define ADDR_LENGTH 16 + 1
static struct sockaddr_storage *
freeaddrinfo(ptr);
return final_addr;
}
+#endif /* !SIM */
server_info *
/* end stuff to be filled in */
-static RETSIGTYPE bong (int);
static void checkparent (void);
static void removeentry (struct conf_entry *);
static void addentry (char *, int, int, int, int, u_int,
}
;
unpeer_keyword
- : T_Unconfig { $$ = T_Unconfig }
- | T_Unpeer { $$ = T_Unpeer }
+ : T_Unconfig { $$ = T_Unconfig; }
+ | T_Unpeer { $$ = T_Unpeer; }
;
struct refclock_atom *ap /* atom structure pointer */
)
{
- if (ap->handle == NULL) {
+ if (!ap->handle) {
if (time_pps_create(fddev, &ap->handle) < 0) {
msyslog(LOG_ERR,
"refclock_atom: time_pps_create failed: %m");
* most recent PPS timestamp.
*/
pp = peer->procptr;
- if (ap->handle == NULL)
+ if (!ap->handle)
return (0);
if (ap->pps_params.mode == 0 && sys_leap != LEAP_NOTINSYNC) {
static int leap_file(FILE *);
static void record_sys_stats(void);
+/*
+ * Prototypes
+ */
+#ifdef DEBUG
+void uninit_util(void);
+#endif
+
/*
* uninit_util - free memory allocated by init_util
/* Main Simulator Code */
-int ntpsim(int argc, char *argv[]);
int ntpsim(int argc, char *argv[])
{
char time_mark_valid, time_sync, op_mode;
int sentence_type, valid;
int year, day_of_year, month, day_of_month;
- int hour, minute, second, leapsec;
+ int hour, minute, second, leapsec_warn;
int oscillator_offset, time_mark_error, time_bias;
pp = peer->procptr;
up = (struct mx4200unit *)pp->unitptr;
- leapsec = 0; /* Not all receivers output leap second warnings (!) */
+ leapsec_warn = 0; /* Not all receivers output leap second warnings (!) */
sscanf(pp->a_lastcode,
"$PMVXG,%d,%c,%d,%d,%d,%d:%d:%d,%c,%c,%d,%d,%d,%d",
&sentence_type, &time_mark_valid, &year, &month, &day_of_month,
&hour, &minute, &second, &time_sync, &op_mode,
- &oscillator_offset, &time_mark_error, &time_bias, &leapsec);
+ &oscillator_offset, &time_mark_error, &time_bias, &leapsec_warn);
if (sentence_type != PMVXG_D_TRECOVOUT)
return ("wrong rec-type");
mx4200_debug(peer,
"mx4200_parse_t: bad time %02d:%02d:%02d",
hour, minute, second);
- if (leapsec != 0)
- mx4200_debug(peer, " (leap %+d\n)", leapsec);
+ if (leapsec_warn != 0)
+ mx4200_debug(peer, " (leap %+d\n)", leapsec_warn);
mx4200_debug(peer, "\n");
refclock_report(peer, CEVNT_BADTIME);
return ("bad time");
/*
* Setup leap second indicator
*/
- switch (leapsec) {
+ switch (leapsec_warn) {
case 0:
pp->leap = LEAP_NOWARNING;
break;
/*
* Any change to the leap second warning status?
*/
- if (leapsec != up->last_leap ) {
+ if (leapsec_warn != up->last_leap ) {
msyslog(LOG_DEBUG,
"mx4200: leap second warning: %d to %d (%d)",
- up->last_leap, leapsec, pp->leap);
+ up->last_leap, leapsec_warn, pp->leap);
}
- up->last_leap = leapsec;
+ up->last_leap = leapsec_warn;
/*
* Copy time data for billboard monitoring.
if (time_pps_fetch(up->pps_h, PPS_TSFMT_TSPEC, &(up->pps_i),
&timeout) < 0) {
mx4200_debug(peer,
- "mx4200_pps: time_pps_fetch: serial=%ul, %s\n",
+ "mx4200_pps: time_pps_fetch: serial=%lu, %s\n",
(unsigned long)up->pps_i.assert_sequence, strerror(errno));
refclock_report(peer, CEVNT_FAULT);
return(1);
}
if (temp_serial == up->pps_i.assert_sequence) {
mx4200_debug(peer,
- "mx4200_pps: assert_sequence serial not incrementing: %ul\n",
+ "mx4200_pps: assert_sequence serial not incrementing: %lu\n",
(unsigned long)up->pps_i.assert_sequence);
refclock_report(peer, CEVNT_FAULT);
return(1);
if (up->pps_i.assert_sequence == up->lastserial) {
mx4200_debug(peer, "mx4200_pps: no new pps event\n");
} else {
- mx4200_debug(peer, "mx4200_pps: missed %ul pps events\n",
+ mx4200_debug(peer, "mx4200_pps: missed %lu pps events\n",
up->pps_i.assert_sequence - up->lastserial - 1UL);
}
refclock_report(peer, CEVNT_FAULT);
* They are taken from Markus Prosch
*/
+#ifdef UNUSED
/*
* sendcmd - Build data packet for sending
*/
int c
)
{
- buffer->data[0] = DLE;
- buffer->data[1] = (unsigned char)c;
- buffer->size = 2;
+ buffer->data[0] = DLE;
+ buffer->data[1] = (unsigned char)c;
+ buffer->size = 2;
}
+#endif
/*
* sendsupercmd - Build super data packet for sending
long getlong (u_char *);
/* Thunderbolt specific function prototypes */
+#ifdef UNUSED
static void sendcmd (struct packettx *buffer, int c);
+#endif
static void sendsupercmd (struct packettx *buffer, int c1, int c2);
static void sendbyte (struct packettx *buffer, int b);
static void sendint (struct packettx *buffer, int a);
static int getresponse (int, int, u_short *, int *, char **, int);
static int sendrequest (int, int, int, int, char *);
static char * tstflags (u_long);
+#ifndef BUILD_AS_LIB
static void getcmds (void);
+#ifndef SYS_WINNT
static RETSIGTYPE abortcmd (int);
+#endif /* SYS_WINNT */
static void docmd (const char *);
static void tokenize (const char *, char **, int *);
-static int findcmd (char *, struct xcmd *, struct xcmd *, struct xcmd **);
static int getarg (char *, int, arg_v *);
+#endif /* BUILD_AS_LIB */
+static int findcmd (char *, struct xcmd *, struct xcmd *, struct xcmd **);
static int rtdatetolfp (char *, l_fp *);
static int decodearr (char *, int *, l_fp *);
static void help (struct parse *, FILE *);
#define MAXVARLEN 256 /* maximum length of a variable name */
#define MAXVALLEN 400 /* maximum length of a variable value */
#define MAXOUTLINE 72 /* maximum length of an output line */
-#define SCREENWIDTH 76 /* nominal screen width in columns */
+#define SCREENWIDTH 76 /* nominal screen width in columns */
/*
* Some variables used and manipulated locally
#ifdef NO_MAIN_ALLOWED
#ifndef BUILD_AS_LIB
CALL(ntpq,"ntpq",ntpqmain);
-#endif
void clear_globals(void)
{
- extern int ntp_optind;
- showhostnames = 0; /* don'tshow host names by default */
- ntp_optind = 0;
- server_entry = NULL; /* server entry for ntp */
- havehost = 0; /* set to 1 when host open */
- numassoc = 0; /* number of cached associations */
- numcmds = 0;
- numhosts = 0;
+ extern int ntp_optind;
+ showhostnames = 0; /* don'tshow host names by default */
+ ntp_optind = 0;
+ server_entry = NULL; /* server entry for ntp */
+ havehost = 0; /* set to 1 when host open */
+ numassoc = 0; /* number of cached associations */
+ numcmds = 0;
+ numhosts = 0;
}
-#endif
+#endif /* !BUILD_AS_LIB */
+#endif /* NO_MAIN_ALLOWED */
/*
* main - parse arguments and handle options
ADDHOST(DEFHOST);
} else {
for (; ntp_optind < argc; ntp_optind++)
- ADDHOST(argv[ntp_optind]);
+ ADDHOST(argv[ntp_optind]);
}
if (numcmds == 0 && interactive == 0
for (ihost = 0; ihost < numhosts; ihost++) {
if (openhost(chosts[ihost]))
- for (icmd = 0; icmd < numcmds; icmd++)
- docmd(ccmds[icmd]);
+ for (icmd = 0; icmd < numcmds; icmd++)
+ docmd(ccmds[icmd]);
}
}
#ifdef SYS_WINNT
#endif /* SYS_WINNT */
return 0;
}
-#endif // build as lib
+#endif /* !BUILD_AS_LIB */
/*
* openhost - open a socket to a host
}
if (ai->ai_canonname == NULL) {
- strncpy(temphost, stoa((struct sockaddr_storage *)ai->ai_addr),
- LENHOSTNAME);
- temphost[LENHOSTNAME-1] = '\0';
+ strncpy(temphost,
+ stoa((struct sockaddr_storage *)ai->ai_addr),
+ LENHOSTNAME);
} else {
strncpy(temphost, ai->ai_canonname, LENHOSTNAME);
- temphost[LENHOSTNAME-1] = '\0';
}
+ temphost[LENHOSTNAME-1] = '\0';
if (debug > 2)
- printf("Opening host %s\n", temphost);
+ printf("Opening host %s\n", temphost);
if (havehost == 1) {
if (debug > 2)
- printf("Closing old host %s\n", currenthost);
+ printf("Closing old host %s\n", currenthost);
(void) closesocket(sockfd);
havehost = 0;
}
int optionValue = SO_SYNCHRONOUS_NONALERT;
int err;
- err = setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE, (char *)&optionValue, sizeof(optionValue));
- if (err != NO_ERROR) {
- (void) fprintf(stderr, "cannot open nonoverlapped sockets\n");
+ err = setsockopt(INVALID_SOCKET, SOL_SOCKET, SO_OPENTYPE,
+ (char *)&optionValue, sizeof(optionValue));
+ if (err) {
+ err = WSAGetLastError();
+ fprintf(stderr,
+ "setsockopt(SO_SYNCHRONOUS_NONALERT) "
+ "error: %s\n", strerror(err));
exit(1);
}
}
}
+#ifndef BUILD_AS_LIB
/*
* getcmds - read commands from the standard input and execute them
*/
getcmds(void)
{
#if defined(HAVE_LIBREADLINE)
- char *line;
-
- for (;;) {
- if ((line = readline(interactive?prompt:"")) == NULL) return;
- if (*line) add_history(line);
- docmd(line);
- free(line);
- }
+ char *line;
+
+ for (;;) {
+ if ((line = readline(interactive?prompt:"")) == NULL) return;
+ if (*line) add_history(line);
+ docmd(line);
+ free(line);
+ }
#else /* not (HAVE_LIBREADLINE) */
- char line[MAXLINE];
+ char line[MAXLINE];
- for (;;) {
- if (interactive) {
-#ifdef VMS /* work around a problem with mixing stdout & stderr */
- fputs("",stdout);
+ for (;;) {
+ if (interactive) {
+#ifdef VMS /* work around a problem with mixing stdout & stderr */
+ fputs("",stdout);
#endif
- (void) fputs(prompt, stderr);
- (void) fflush(stderr);
- }
+ (void) fputs(prompt, stderr);
+ (void) fflush(stderr);
+ }
- if (fgets(line, sizeof line, stdin) == NULL)
- return;
+ if (fgets(line, sizeof line, stdin) == NULL)
+ return;
- docmd(line);
- }
+ docmd(line);
+ }
#endif /* not (HAVE_LIBREADLINE || HAVE_LIBEDIT) */
}
+#endif /* !BUILD_AS_LIB */
-#ifndef SYS_WINNT /* Under NT cannot handle SIGINT, WIN32 spawns a handler */
+#if !defined(SYS_WINNT) && !defined(BUILD_AS_LIB)
/*
* abortcmd - catch interrupts and abort the current command
*/
(void) fflush(stderr);
if (jump) longjmp(interrupt_buf, 1);
}
-#endif /* SYS_WINNT */
+#endif /* !SYS_WINNT && !BUILD_AS_LIB */
+
+#ifndef BUILD_AS_LIB
/*
* docmd - decode the command line and execute a command
*/
break;
}
if ((xcmd->arg[i] & OPT) && (*tokens[i+1] == '>'))
- break;
+ break;
if (!getarg(tokens[i+1], (int)xcmd->arg[i], &pcmd.argval[i]))
- return;
+ return;
pcmd.nargs++;
}
char *fname;
if (*(tokens[i]+1) != '\0')
- fname = tokens[i]+1;
+ fname = tokens[i]+1;
else if ((i+1) < ntok)
- fname = tokens[i+1];
+ fname = tokens[i+1];
else {
(void) fprintf(stderr, "***No file for redirect\n");
return;
* If yes, continue reading till the next double quote
*/
else if (*cp == '\"') {
- ++cp;
- do {
- *sp++ = *cp++;
- } while ((*cp != '\"') && !ISEOL(*cp));
- /* HMS: a missing closing " should be an error */
- }
- else {
- do {
- *sp++ = *cp++;
- } while ((*cp != '\"') && !ISSPACE(*cp) && !ISEOL(*cp));
- /* HMS: Why check for a " in the previous line? */
- }
-
- *sp++ = '\0';
- }
-}
-
-
-/*
- * findcmd - find a command in a command description table
- */
-static int
-findcmd(
- register char *str,
- struct xcmd *clist1,
- struct xcmd *clist2,
- struct xcmd **cmd
- )
-{
- register struct xcmd *cl;
- register int clen;
- int nmatch;
- struct xcmd *nearmatch = NULL;
- struct xcmd *clist;
-
- clen = strlen(str);
- nmatch = 0;
- if (clist1 != 0)
- clist = clist1;
- else if (clist2 != 0)
- clist = clist2;
- else
- return 0;
-
- again:
- for (cl = clist; cl->keyword != 0; cl++) {
- /* do a first character check, for efficiency */
- if (*str != *(cl->keyword))
- continue;
- if (strncmp(str, cl->keyword, (unsigned)clen) == 0) {
- /*
- * Could be extact match, could be approximate.
- * Is exact if the length of the keyword is the
- * same as the str.
- */
- if (*((cl->keyword) + clen) == '\0') {
- *cmd = cl;
- return 1;
- }
- nmatch++;
- nearmatch = cl;
+ ++cp;
+ do {
+ *sp++ = *cp++;
+ } while ((*cp != '\"') && !ISEOL(*cp));
+ /* HMS: a missing closing " should be an error */
+ }
+ else {
+ do {
+ *sp++ = *cp++;
+ } while ((*cp != '\"') && !ISSPACE(*cp) && !ISEOL(*cp));
+ /* HMS: Why check for a " in the previous line? */
}
- }
-
- /*
- * See if there is more to do. If so, go again. Sorry about the
- * goto, too much looking at BSD sources...
- */
- if (clist == clist1 && clist2 != 0) {
- clist = clist2;
- goto again;
- }
- /*
- * If we got extactly 1 near match, use it, else return number
- * of matches.
- */
- if (nmatch == 1) {
- *cmd = nearmatch;
- return 1;
+ *sp++ = '\0';
}
- return nmatch;
}
return 1;
}
+#endif /* !BUILD_AS_LIB */
+
+
+/*
+ * findcmd - find a command in a command description table
+ */
+static int
+findcmd(
+ register char *str,
+ struct xcmd *clist1,
+ struct xcmd *clist2,
+ struct xcmd **cmd
+ )
+{
+ register struct xcmd *cl;
+ register int clen;
+ int nmatch;
+ struct xcmd *nearmatch = NULL;
+ struct xcmd *clist;
+
+ clen = strlen(str);
+ nmatch = 0;
+ if (clist1 != 0)
+ clist = clist1;
+ else if (clist2 != 0)
+ clist = clist2;
+ else
+ return 0;
+
+ again:
+ for (cl = clist; cl->keyword != 0; cl++) {
+ /* do a first character check, for efficiency */
+ if (*str != *(cl->keyword))
+ continue;
+ if (strncmp(str, cl->keyword, (unsigned)clen) == 0) {
+ /*
+ * Could be extact match, could be approximate.
+ * Is exact if the length of the keyword is the
+ * same as the str.
+ */
+ if (*((cl->keyword) + clen) == '\0') {
+ *cmd = cl;
+ return 1;
+ }
+ nmatch++;
+ nearmatch = cl;
+ }
+ }
+
+ /*
+ * See if there is more to do. If so, go again. Sorry about the
+ * goto, too much looking at BSD sources...
+ */
+ if (clist == clist1 && clist2 != 0) {
+ clist = clist2;
+ goto again;
+ }
+
+ /*
+ * If we got extactly 1 near match, use it, else return number
+ * of matches.
+ */
+ if (nmatch == 1) {
+ *cmd = nearmatch;
+ return 1;
+ }
+ return nmatch;
+}
/*
)
{
if (!showhostnames)
- return stoa(netnum);
- if ((netnum->ss_family == AF_INET) && ISREFCLOCKADR(netnum))
- return refnumtoa(netnum);
- return socktohost(netnum);
+ return stoa(netnum);
+ else if ((netnum->ss_family == AF_INET) && ISREFCLOCKADR(netnum))
+ return refnumtoa(netnum);
+ else
+ return socktohost(netnum);
}
* If it starts with a 0x, decode as hex.
*/
if (*str == '0' && (*(str+1) == 'x' || *(str+1) == 'X'))
- return hextolfp(str+2, lfp);
+ return hextolfp(str+2, lfp);
/*
* If it starts with a '"', try it as an RT-11 date.
bp = buf;
while (*cp != '"' && *cp != '\0' && bp < &buf[29])
- *bp++ = *cp++;
+ *bp++ = *cp++;
*bp = '\0';
return rtdatetolfp(buf, lfp);
}
* about heuristics!
*/
if ((*str >= 'A' && *str <= 'F') || (*str >= 'a' && *str <= 'f'))
- return hextolfp(str, lfp);
+ return hextolfp(str, lfp);
/*
* Try it as a decimal. If this fails, try as an unquoted
* RT-11 date. This code should go away eventually.
*/
if (atolfp(str, lfp))
- return 1;
+ return 1;
+
return rtdatetolfp(str, lfp);
}
FILE *fp
)
{
- struct xcmd *xcp;
+ struct xcmd *xcp = NULL; /* quiet warning */
char *cmd;
const char *list[100];
- int word, words;
- int row, rows;
- int col, cols;
+ int word, words;
+ int row, rows;
+ int col, cols;
if (pcmd->nargs == 0) {
words = 0;
for (xcp = builtins; xcp->keyword != 0; xcp++) {
if (*(xcp->keyword) != '?')
- list[words++] = xcp->keyword;
+ list[words++] = xcp->keyword;
}
for (xcp = opcmds; xcp->keyword != 0; xcp++)
- list[words++] = xcp->keyword;
+ list[words++] = xcp->keyword;
qsort(
#ifdef QSORT_USES_VOID_P
for (word = 0; word < words; word++) {
int length = strlen(list[word]);
if (col < length) {
- col = length;
- }
+ col = length;
+ }
}
cols = SCREENWIDTH / ++col;
- rows = (words + cols - 1) / cols;
+ rows = (words + cols - 1) / cols;
(void) fprintf(fp, "ntpq commands:\n");
for (row = 0; row < rows; row++) {
- for (word = row; word < words; word += rows) {
- (void) fprintf(fp, "%-*.*s", col, col-1, list[word]);
- }
- (void) fprintf(fp, "\n");
- }
+ for (word = row; word < words; word += rows) {
+ (void) fprintf(fp, "%-*.*s", col,
+ col-1, list[word]);
+ }
+ (void) fprintf(fp, "\n");
+ }
} else {
cmd = pcmd->argval[0].string;
words = findcmd(cmd, builtins, opcmds, &xcp);
if (pcmd->nargs == 0) {
if (havehost)
- (void) fprintf(fp, "current host is %s\n", currenthost);
+ (void) fprintf(fp, "current host is %s\n",
+ currenthost);
else
- (void) fprintf(fp, "no current host\n");
+ (void) fprintf(fp, "no current host\n");
return;
}
else {
if (havehost)
(void) fprintf(fp,
- "current host remains %s\n", currenthost);
+ "current host remains %s\n",
+ currenthost);
else
(void) fprintf(fp, "still no current host\n");
return;
numassoc = 0;
} else {
if (havehost)
- (void) fprintf(fp,
- "current host remains %s\n", currenthost);
+ (void) fprintf(fp,
+ "current host remains %s\n",
+ currenthost);
else
- (void) fprintf(fp, "still no current host\n");
+ (void) fprintf(fp, "still no current host\n");
}
}
}
pass = getpass("MD5 Password: ");
if (*pass == '\0')
- (void) fprintf(fp, "Password unchanged\n");
+ (void) fprintf(fp, "Password unchanged\n");
else {
- authusekey(info_auth_keyid, info_auth_keytype, (u_char *)pass);
- authtrust(info_auth_keyid, 1);
+ authusekey(info_auth_keyid, info_auth_keytype, (u_char *)pass);
+ authtrust(info_auth_keyid, 1);
}
}
const struct association *ass2 = (const struct association *)t2;
if (ass1->assid < ass2->assid)
- return -1;
+ return -1;
if (ass1->assid > ass2->assid)
- return 1;
+ return 1;
return 0;
}
#else
#define R_SHIFT(_X_, _Y_) (((_X_) < 0) ? -(-(_X_) >> (_Y_)) : ((_X_) >> (_Y_)))
-static struct timeval max_adj_offset = { 0, 128000 };
+static long max_adj_offset_usec = 128000;
static long clock_adjust = 0; /* current adjustment value (usec * 2^USECSCALE) */
static long accum_drift = 0; /* accumulated drift value (usec / ADJINTERVAL) */
/*
* DCF77 state flags
*/
-#define DCFB_ANNOUNCE 0x0001 /* switch time zone warning (DST switch) */
-#define DCFB_DST 0x0002 /* DST in effect */
+#define DCFB_ANNOUNCE 0x0001 /* switch time zone warning (DST switch) */
+#define DCFB_DST 0x0002 /* DST in effect */
#define DCFB_LEAP 0x0004 /* LEAP warning (1 hour prior to occurrence) */
#define DCFB_ALTERNATE 0x0008 /* alternate antenna used */
toffset = *offset;
toffset.tv_sec = l_abs(toffset.tv_sec);
toffset.tv_usec = l_abs(toffset.tv_usec);
- if (timercmp(&toffset, &max_adj_offset, >))
+ if (toffset.tvsec ||
+ (!toffset.tv_sec && toffset.tv_usec > max_adj_offset_usec))
{
/*
* hopeless - set the clock - and clear the timing
RelativePath="..\..\..\libisc\md5.c"
>
</File>
- <File
- RelativePath="..\..\..\libisc\mem.c"
- >
- <FileConfiguration
- Name="Debug|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories=""
- PreprocessorDefinitions=""
- />
- </FileConfiguration>
- <FileConfiguration
- Name="Release|Win32"
- >
- <Tool
- Name="VCCLCompilerTool"
- AdditionalIncludeDirectories=""
- PreprocessorDefinitions=""
- />
- </FileConfiguration>
- </File>
<File
RelativePath="..\..\..\libntp\memmove.c"
>
RelativePath="..\..\..\include\ntpd.h"
>
</File>
+ <File
+ RelativePath="..\..\..\include\ntpsim.h"
+ >
+ </File>
<File
RelativePath="..\include\ntservice.h"
>
SetConsoleTitle(ConsoleTitle);
}
- #ifdef _DEBUG
+ #if defined(_MSC_VER) && defined(_DEBUG)
/* ask the runtime to dump memory leaks at exit */
_CrtSetDbgFlag(_CRTDBG_ALLOC_MEM_DF | _CRTDBG_LEAK_CHECK_DF);
#ifdef WANT_LEAK_CHECK_ON_STDERR_TOO
/* the file being stderr */
_CrtSetReportFile(_CRT_ERROR, _CRTDBG_FILE_STDERR);
#endif
- #endif /* _DEBUG */
+ #endif /* _MSC_VER && _DEBUG */
atexit( ntservice_exit );
}
msyslog(LOG_INFO, "ntservice: The Network Time Protocol Service is stopping.");
-#ifdef _DEBUG
+#ifdef DEBUG
FormatErrorFreeMem();
#endif
case SERVICE_CONTROL_PAUSE:
case SERVICE_CONTROL_CONTINUE:
case SERVICE_CONTROL_INTERROGATE:
- default:
+ default:
break;
}
UpdateSCM(SERVICE_RUNNING);
}
/* we've handled it, no more handlers should be called */
- return TRUE;;
+ return TRUE;
}
#ifdef OPENSSL
passwd1 = hostbuf;
if (HAVE_OPT( PVT_PASSWD ))
- passwd1 = OPT_ARG( PVT_PASSWD );
+ passwd1 = strdup(OPT_ARG( PVT_PASSWD ));
if (HAVE_OPT( GET_PVT_PASSWD ))
- passwd2 = OPT_ARG( GET_PVT_PASSWD );
+ passwd2 = strdup(OPT_ARG( GET_PVT_PASSWD ));
if (HAVE_OPT( HOST_KEY ))
hostkey++;
if (HAVE_OPT( SIGN_KEY ))
- sign = OPT_ARG( SIGN_KEY );
+ sign = strdup(OPT_ARG( SIGN_KEY ));
if (HAVE_OPT( GQ_PARAMS ))
gqkey++;
scheme = OPT_ARG( CERTIFICATE );
if (HAVE_OPT( SUBJECT_NAME ))
- hostname = OPT_ARG( SUBJECT_NAME );
+ hostname = strdup(OPT_ARG( SUBJECT_NAME ));
if (HAVE_OPT( ISSUER_NAME ))
- groupname = OPT_ARG( ISSUER_NAME );
+ groupname = strdup(OPT_ARG( ISSUER_NAME ));
if (HAVE_OPT( PVT_CERT ))
exten = EXT_KEY_PRIVATE;
int i, j;
str = fheader("MD5key", id, groupname);
- ntp_srandom(epoch);
+ ntp_srandom((u_long)epoch);
for (i = 1; i <= MD5KEYS; i++) {
for (j = 0; j < 16; j++) {
int temp;
cert = X509_new();
X509_set_version(cert, 2L);
serial = ASN1_INTEGER_new();
- ASN1_INTEGER_set(serial, epoch + JAN_1970);
+ ASN1_INTEGER_set(serial, (long)epoch + JAN_1970);
X509_set_serialNumber(cert, serial);
ASN1_INTEGER_free(serial);
X509_time_adj(X509_get_notBefore(cert), 0L, &epoch);