From: Dave Hart Date: Thu, 23 Dec 2010 07:03:00 +0000 (+0000) Subject: Allow ntpq &1 associd use without preceding association-fetching. X-Git-Tag: NTP_4_2_7P102~2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=5475e636a1b428a45a77cb89508d6b9105560354;p=thirdparty%2Fntp.git Allow ntpq &1 associd use without preceding association-fetching. bk: 4d12f424HDwR4arGrbtQU4uTLrkRTQ --- diff --git a/ChangeLog b/ChangeLog index 29e036a92..1936fffbf 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,4 @@ +* Allow ntpq &1 associd use without preceding association-fetching. (4.2.7p101) 2010/12/22 Released by Harlan Stenn * from 4.2.6p3-RC12: Upgrade to libopts 34.0.9 from AutoGen 5.11.6pre7. * from 4.2.6p3-RC12: Relax minimum Automake version to 1.10 with updated diff --git a/include/ntp_calendar.h b/include/ntp_calendar.h index 532ff9346..8e227387f 100644 --- a/include/ntp_calendar.h +++ b/include/ntp_calendar.h @@ -92,6 +92,8 @@ typedef struct { + ((val)<<4) + ((val)<<2) + (val)) /* *big* hack */ +extern const char *months[12]; +extern const char *daynames[7]; extern void caljulian (u_int32, struct calendar *); extern u_int32 caltontp (const struct calendar *); diff --git a/libntp/ntp_calendar.c b/libntp/ntp_calendar.c index 81110ac80..2821ff312 100644 --- a/libntp/ntp_calendar.c +++ b/libntp/ntp_calendar.c @@ -863,14 +863,14 @@ ntpcal_days_in_months( int32 ntpcal_edate_to_eradays( int32 years , - int32 months , + int32 mons , int32 mdays ) { ntpcal_split tmp; int32 res; - if (months) { - tmp = ntpcal_days_in_months(months); + if (mons) { + tmp = ntpcal_days_in_months(mons); res = ntpcal_days_in_years(years + tmp.hi) + tmp.lo; } else res = ntpcal_days_in_years(years); @@ -891,16 +891,16 @@ ntpcal_edate_to_eradays( int32 ntpcal_edate_to_yeardays( int32 years , - int32 months, + int32 mons, int32 mdays ) { ntpcal_split tmp; - if (0 <= months && months < 12) { + if (0 <= mons && mons < 12) { years += 1; - mdays += real_month_table[is_leapyear(years)][months]; + mdays += real_month_table[is_leapyear(years)][mons]; } else { - tmp = ntpcal_days_in_months(months); + tmp = ntpcal_days_in_months(mons); mdays += tmp.lo + ntpcal_days_in_years(years + tmp.hi) - ntpcal_days_in_years(years); diff --git a/libntp/prettydate.c b/libntp/prettydate.c index c48ab8eb3..cdac5840b 100644 --- a/libntp/prettydate.c +++ b/libntp/prettydate.c @@ -17,12 +17,12 @@ static char *common_prettydate(l_fp *, int); -const char *months[] = { +const char * months[12] = { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" }; -static const char *days[] = { +const char * daynames[7] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" }; @@ -188,13 +188,13 @@ common_prettydate( ntpcal_time_to_date(&jd, &sec); snprintf(bp, LIB_BUFLENGTH, pfmt[local != 0], (u_long)ts->l_ui, (u_long)ts->l_uf, - days[jd.weekday], months[jd.month-1], + daynames[jd.weekday], months[jd.month-1], jd.monthday, jd.year, jd.hour, jd.minute, jd.second, msec); } else snprintf(bp, LIB_BUFLENGTH, pfmt[0], (u_long)ts->l_ui, (u_long)ts->l_uf, - days[tm->tm_wday], months[tm->tm_mon], + daynames[tm->tm_wday], months[tm->tm_mon], tm->tm_mday, 1900 + tm->tm_year, tm->tm_hour, tm->tm_min, tm->tm_sec, msec); return bp; diff --git a/ntpd/refclock_oncore.c b/ntpd/refclock_oncore.c index 5fdb67b67..d6da0c3ee 100644 --- a/ntpd/refclock_oncore.c +++ b/ntpd/refclock_oncore.c @@ -161,6 +161,7 @@ #include "ntp_io.h" #include "ntp_unixtime.h" #include "ntp_refclock.h" +#include "ntp_calendar.h" #include "ntp_stdlib.h" #include @@ -553,9 +554,6 @@ static u_char oncore_cmd_Ia[] = { 'I', 'a' }; /* 12 Self Test */ * Gj in UT as of 3.0, 1999 , Bj as of 1.3 */ -static char *Month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jly", - "Aug", "Sep", "Oct", "Nov", "Dec" }; - #define DEVICE1 "/dev/oncore.serial.%d" /* name of serial device */ #define DEVICE2 "/dev/oncore.pps.%d" /* name of pps device */ @@ -599,7 +597,9 @@ oncore_start( struct refclockproc *pp; int fd1, fd2; char device1[STRING_LEN], device2[STRING_LEN], Msg[160]; +#ifndef SYS_WINNT struct stat stat1, stat2; +#endif /* create instance structure for this unit */ @@ -3203,7 +3203,7 @@ oncore_msg_Gb( snprintf(Msg, sizeof(Msg), "Date/Time set to: %d%s%d %2d:%02d:%02d GMT (GMT offset is %s%02d:%02d)", - d, Month[mo-1], y, h, m, s, gmts, gmth, gmtm); + d, months[mo-1], y, h, m, s, gmts, gmth, gmtm); oncore_log(instance, LOG_NOTICE, Msg); } @@ -3257,7 +3257,7 @@ oncore_msg_Gj( if (dt) { snprintf(Msg, sizeof(Msg), "Leap second (%d) scheduled for %d%s%d at %d:%d:%d", - dt, buf[9], Month[buf[8] - 1], + dt, buf[9], months[buf[8] - 1], 256 * buf[6] + buf[7], buf[15], buf[16], buf[17]); oncore_log(instance, LOG_NOTICE, Msg); diff --git a/ntpdc/ntpdc.c b/ntpdc/ntpdc.c index a3e061a9f..b5369e459 100644 --- a/ntpdc/ntpdc.c +++ b/ntpdc/ntpdc.c @@ -278,7 +278,6 @@ ntpdcmain( char *argv[] ) { - extern int ntp_optind; delay_time.l_ui = 0; delay_time.l_uf = DEFDELAY; @@ -353,62 +352,6 @@ ntpdcmain( interactive = 1; } -#if 0 - ai_fam_templ = ai_fam_default; - while ((c = ntp_getopt(argc, argv, "46c:dilnps")) != EOF) - switch (c) { - case '4': - ai_fam_templ = AF_INET; - break; - case '6': - ai_fam_templ = AF_INET6; - break; - case 'c': - ADDCMD(ntp_optarg); - break; - case 'd': - ++debug; - break; - case 'i': - interactive = 1; - break; - case 'l': - ADDCMD("listpeers"); - break; - case 'n': - showhostnames = 0; - break; - case 'p': - ADDCMD("peers"); - break; - case 's': - ADDCMD("dmpeers"); - break; - default: - errflg++; - break; - } - - if (errflg) { - (void) fprintf(stderr, - "usage: %s [-46dilnps] [-c cmd] host ...\n", - progname); - exit(2); - } - - if (ntp_optind == argc) { - ADDHOST(DEFHOST); - } else { - for (; ntp_optind < argc; ntp_optind++) - ADDHOST(argv[ntp_optind]); - } - - if (numcmds == 0 && interactive == 0 - && isatty(fileno(stdin)) && isatty(fileno(stderr))) { - interactive = 1; - } -#endif - #ifndef SYS_WINNT /* Under NT cannot handle SIGINT, WIN32 spawns a handler */ if (interactive) (void) signal_no_reset(SIGINT, abortcmd); diff --git a/ntpq/libntpq_subs.c b/ntpq/libntpq_subs.c index 09b99bd48..e53b4193c 100644 --- a/ntpq/libntpq_subs.c +++ b/ntpq/libntpq_subs.c @@ -17,21 +17,19 @@ #include "libntpq.h" -/* the following functions are required internally by a number of libntpq functions - * and since they are defined as static in ntpq-subs.c, they need to be exported here - */ - int ntpq_dogetassoc(void) { - if ( dogetassoc(NULL)) - { + if (dogetassoc(NULL)) return numassoc; - } else { - return 0; - } + else + return 0; } +/* the following functions are required internally by a number of libntpq functions + * and since they are defined as static in ntpq-subs.c, they need to be exported here + */ + char ntpq_decodeaddrtype(sockaddr_u *sock) { return decodeaddrtype(sock); diff --git a/ntpq/ntpq-subs.c b/ntpq/ntpq-subs.c index 0e622c8d8..b0f55796f 100644 --- a/ntpq/ntpq-subs.c +++ b/ntpq/ntpq-subs.c @@ -12,7 +12,6 @@ extern char * chosts[]; extern char currenthost[]; -extern int numhosts; int maxhostlen; /* @@ -42,7 +41,6 @@ static void clockvar (struct parse *, FILE *); static int findassidrange (u_int32, u_int32, int *, int *); static void mreadlist (struct parse *, FILE *); static void mreadvar (struct parse *, FILE *); -static int dogetassoc (FILE *); static void printassoc (int, FILE *); static void associations (struct parse *, FILE *); static void lassociations (struct parse *, FILE *); @@ -257,7 +255,6 @@ extern int showhostnames; extern int rawmode; extern struct servent *server_entry; extern struct association assoc_cache[]; -extern int numassoc; extern u_char pktversion; extern struct ctl_var peer_var[]; @@ -902,7 +899,7 @@ findassidrange( { associd_t assids[2]; int ind[COUNTOF(assids)]; - int i; + u_int i; size_t a; assids[0] = checkassocid(assid1); @@ -1010,7 +1007,7 @@ mreadvar( /* * dogetassoc - query the host for its list of associations */ -static int +int dogetassoc( FILE *fp ) @@ -1029,8 +1026,8 @@ dogetassoc( if (dsize == 0) { if (numhosts > 1) - (void) fprintf(fp, "server=%s ", currenthost); - (void) fprintf(fp, "No association ID's returned\n"); + fprintf(fp, "server=%s ", currenthost); + fprintf(fp, "No association ID's returned\n"); return 0; } @@ -1075,7 +1072,7 @@ printassoc( ) { register char *bp; - int i; + u_int i; u_char statval; int event; u_long event_count; @@ -1884,7 +1881,7 @@ dopeers( int af ) { - register int i; + u_int i; char fullname[LENHOSTNAME]; sockaddr_u netnum; @@ -2064,7 +2061,7 @@ config ( FILE *fp ) { - char *cfgcmd; + const char *cfgcmd; u_short rstatus; int rsize; const char *rdata; @@ -2879,7 +2876,7 @@ mrulist( char parms_buf[128]; char buf[24]; char *parms; - char *arg; + const char *arg; size_t cb; mru **sorted; mru **ppentry; diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 972dc6e2d..fedc47072 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -253,7 +253,7 @@ static int openhost (const char *); static int sendpkt (void *, size_t); static int getresponse (int, int, u_short *, int *, const char **, int); -static int sendrequest (int, associd_t, int, int, char *); +static int sendrequest (int, associd_t, int, int, const char *); static char * tstflags (u_long); #ifndef BUILD_AS_LIB static void getcmds (void); @@ -262,9 +262,10 @@ static RETSIGTYPE abortcmd (int); #endif /* SYS_WINNT */ static void docmd (const char *); static void tokenize (const char *, char **, int *); -static int getarg (char *, int, arg_v *); +static int getarg (const char *, int, arg_v *); #endif /* BUILD_AS_LIB */ -static int findcmd (char *, struct xcmd *, struct xcmd *, struct xcmd **); +static int findcmd (const 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 *); @@ -424,7 +425,7 @@ long pktdata[DATASIZE/sizeof(long)]; * Holds association data for use with the &n operator. */ struct association assoc_cache[MAXASSOC]; -int numassoc = 0; /* number of cached associations */ +u_int numassoc = 0; /* number of cached associations */ /* * For commands typed on the command line (with the -c option) @@ -436,7 +437,7 @@ const char *ccmds[MAXCMDS]; /* * When multiple hosts are specified. */ -int numhosts = 0; +u_int numhosts; const char *chosts[MAXHOSTS]; #define ADDHOST(cp) if (numhosts < MAXHOSTS) chosts[numhosts++] = (cp) @@ -504,7 +505,9 @@ ntpqmain( char *argv[] ) { - extern int ntp_optind; + u_int ihost; + int icmd; + #ifdef SYS_VXWORKS clear_globals(); @@ -551,47 +554,11 @@ ntpqmain( old_rv = HAVE_OPT(OLD_RV); -#if 0 - while ((c = ntp_getopt(argc, argv, "46c:dinp")) != EOF) - switch (c) { - case '4': - ai_fam_templ = AF_INET; - break; - case '6': - ai_fam_templ = AF_INET6; - break; - case 'c': - ADDCMD(ntp_optarg); - break; - case 'd': - ++debug; - break; - case 'i': - interactive = 1; - break; - case 'n': - showhostnames = 0; - break; - case 'p': - ADDCMD("peers"); - break; - default: - errflg++; - break; - } - if (errflg) { - (void) fprintf(stderr, - "usage: %s [-46dinp] [-c cmd] host ...\n", - progname); - exit(2); - } -#endif - NTP_INSIST(ntp_optind <= argc); - if (ntp_optind == argc) { + if (0 == argc) { ADDHOST(DEFHOST); } else { - for (; ntp_optind < argc; ntp_optind++) - ADDHOST(argv[ntp_optind]); + for (ihost = 0; ihost < (u_int)argc; ihost++) + ADDHOST(argv[ihost]); } if (numcmds == 0 && interactive == 0 @@ -608,9 +575,6 @@ ntpqmain( (void) openhost(chosts[0]); getcmds(); } else { - int ihost; - int icmd; - for (ihost = 0; ihost < numhosts; ihost++) { if (openhost(chosts[ihost])) for (icmd = 0; icmd < numcmds; icmd++) @@ -1207,7 +1171,7 @@ sendrequest( associd_t associd, int auth, int qsize, - char *qdata + const char *qdata ) { struct ntp_control qpkt; @@ -1391,7 +1355,7 @@ doquery( associd_t associd, int auth, int qsize, - char *qdata, + const char *qdata, u_short *rstatus, int *rsize, const char **rdata @@ -1412,7 +1376,7 @@ doqueryex( associd_t associd, int auth, int qsize, - char *qdata, + const char *qdata, u_short *rstatus, int *rsize, const char **rdata, @@ -1673,84 +1637,64 @@ tokenize( */ static int getarg( - char *str, + const char *str, int code, arg_v *argp ) { - int isneg; - char *cp, *np; - static const char *digits = "0123456789"; + u_long ul; switch (code & ~OPT) { - case NTP_STR: + case NTP_STR: argp->string = str; break; - case NTP_ADD: - if (!getnetnum(str, &(argp->netnum), (char *)0, 0)) { + + case NTP_ADD: + if (!getnetnum(str, &argp->netnum, NULL, 0)) return 0; - } break; - case NTP_INT: - case NTP_UINT: - isneg = 0; - np = str; - if (*np == '&') { - np++; - isneg = atoi(np); - if (isneg <= 0) { - (void) fprintf(stderr, - "***Association value `%s' invalid/undecodable\n", str); + + case NTP_UINT: + if ('&' == str[0]) { + if (!atouint(&str[1], &ul)) { + fprintf(stderr, + "***Association value `%s' invalid/undecodable\n", + str); return 0; } - if (isneg > numassoc) { - if (numassoc == 0) { - (void) fprintf(stderr, - "***Association for `%s' unknown (max &%d)\n", - str, numassoc); - return 0; - } else { - isneg = numassoc; - } + if (0 == numassoc) + dogetassoc(stdout); + if (ul > numassoc) { + fprintf(stderr, + "***Association for `%s' unknown (max &%d)\n", + str, numassoc); + return 0; } - argp->uval = assoc_cache[isneg-1].assid; + argp->uval = assoc_cache[ul - 1].assid; break; } - - if (*np == '-') { - np++; - isneg = 1; + if (!atouint(str, &argp->uval)) { + fprintf(stderr, "***Illegal unsigned value %s\n", + str); + return 0; } + break; - argp->uval = 0; - do { - cp = strchr(digits, *np); - if (cp == NULL) { - (void) fprintf(stderr, - "***Illegal integer value %s\n", str); - return 0; - } - argp->uval *= 10; - argp->uval += (cp - digits); - } while (*(++np) != '\0'); - - if (isneg) { - if ((code & ~OPT) == NTP_UINT) { - (void) fprintf(stderr, - "***Value %s should be unsigned\n", str); - return 0; - } - argp->ival = -argp->ival; + case NTP_INT: + if (!atoint(str, &argp->ival)) { + fprintf(stderr, "***Illegal integer value %s\n", + str); + return 0; } break; - case IP_VERSION: - if (!strcmp("-6", str)) - argp->ival = 6 ; - else if (!strcmp("-4", str)) - argp->ival = 4 ; - else { - (void) fprintf(stderr, - "***Version must be either 4 or 6\n"); + + case IP_VERSION: + if (!strcmp("-6", str)) { + argp->ival = 6; + } else if (!strcmp("-4", str)) { + argp->ival = 4; + } else { + fprintf(stderr, "***Version must be either 4 or 6\n"); return 0; } break; @@ -1766,14 +1710,14 @@ getarg( */ static int findcmd( - register char *str, - struct xcmd *clist1, - struct xcmd *clist2, - struct xcmd **cmd + const char * str, + struct xcmd * clist1, + struct xcmd * clist2, + struct xcmd ** cmd ) { - register struct xcmd *cl; - register int clen; + struct xcmd *cl; + int clen; int nmatch; struct xcmd *nearmatch = NULL; struct xcmd *clist; @@ -1907,10 +1851,6 @@ rtdatetolfp( register int i; struct calendar cal; char buf[4]; - static const char *months[12] = { - "Jan", "Feb", "Mar", "Apr", "May", "Jun", - "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" - }; cal.yearday = 0; @@ -2172,7 +2112,7 @@ help( ) { struct xcmd *xcp = NULL; /* quiet warning */ - char *cmd; + const char *cmd; const char *list[100]; size_t word, words; size_t row, rows; @@ -2457,7 +2397,7 @@ passwd( FILE *fp ) { - char *pass; + const char *pass; if (info_auth_keyid == 0) { info_auth_keyid = getkeyid("Keyid: "); @@ -2475,7 +2415,8 @@ passwd( return; } } - authusekey(info_auth_keyid, info_auth_keytype, (u_char *)pass); + authusekey(info_auth_keyid, info_auth_keytype, + (const u_char *)pass); authtrust(info_auth_keyid, 1); } diff --git a/ntpq/ntpq.h b/ntpq/ntpq.h index 1d2ddabc1..f3afecac5 100644 --- a/ntpq/ntpq.h +++ b/ntpq/ntpq.h @@ -62,7 +62,7 @@ * Arguments are returned in a union */ typedef union { - char *string; + const char *string; long ival; u_long uval; sockaddr_u netnum; @@ -112,14 +112,17 @@ struct ctl_var { extern int interactive; /* are we prompting? */ extern int old_rv; /* use old rv behavior? --old-rv */ +extern u_int numhosts; +extern u_int numassoc; extern void asciize (int, char *, FILE *); extern int getnetnum (const char *, sockaddr_u *, char *, int); extern void sortassoc (void); extern void show_error_msg (int, associd_t); -extern int doquery (int, associd_t, int, int, char *, +extern int dogetassoc (FILE *); +extern int doquery (int, associd_t, int, int, const char *, u_short *, int *, const char **); -extern int doqueryex (int, associd_t, int, int, char *, +extern int doqueryex (int, associd_t, int, int, const char *, u_short *, int *, const char **, int); extern char * nntohost (sockaddr_u *); extern int decodets (char *, l_fp *);