From: Dave Hart Date: Mon, 24 May 2010 15:46:36 +0000 (+0000) Subject: [Bug 1561] ntpq, ntpdc "passwd" prompts for MD5 password w/SHA1. X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=d32f2fc892b98c39c807ae6849130c849eed584d;p=thirdparty%2Fntp.git [Bug 1561] ntpq, ntpdc "passwd" prompts for MD5 password w/SHA1. Windows port: do not exit in ntp_timestamp_from_counter() without first logging the reason. Support "passwd blah" syntax in ntpq. bk: 4bfa9f5c_mAgDpGsrKG-YEeV85HUsg --- diff --git a/ChangeLog b/ChangeLog index 7558d7d7c5..8de837a35d 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,10 @@ +--- + +* [Bug 1561] ntpq, ntpdc "passwd" prompts for MD5 password w/SHA1. +* Windows port: do not exit in ntp_timestamp_from_counter() without + first logging the reason. +* Support "passwd blah" syntax in ntpq. + --- (4.2.6p2-RC4) 2010/05/19 Released by Harlan Stenn diff --git a/include/ntp_stdlib.h b/include/ntp_stdlib.h index bcceaea7dd..0abc490722 100644 --- a/include/ntp_stdlib.h +++ b/include/ntp_stdlib.h @@ -175,6 +175,7 @@ extern int ssl_init_done; #endif extern int keytype_from_text (const char *, size_t *); extern const char *keytype_name (int); +extern char * getpass_keytype (int); /* lib/isc/win32/strerror.c diff --git a/libntp/ssl_init.c b/libntp/ssl_init.c index c7bf7e63f8..f15de341e1 100644 --- a/libntp/ssl_init.c +++ b/libntp/ssl_init.c @@ -143,3 +143,28 @@ keytype_name( return name; } + +/* + * Use getpassphrase() if configure.ac detected it, as Suns that + * have it truncate the password in getpass() to 8 characters. + */ +#ifdef HAVE_GETPASSPHRASE +# define getpass(str) getpassphrase(str) +#endif + +/* + * getpass_keytype() -- shared between ntpq and ntpdc, only vaguely + * related to the rest of ssl_init.c. + */ +char * +getpass_keytype( + int keytype + ) +{ + char pass_prompt[64 + 11 + 1]; /* 11 for " Password: " */ + + snprintf(pass_prompt, sizeof(pass_prompt), + "%.64s Password: ", keytype_name(keytype)); + + return getpass(pass_prompt); +} diff --git a/ntpdc/ntpdc.c b/ntpdc/ntpdc.c index 4bfb25ff2d..bee7640863 100644 --- a/ntpdc/ntpdc.c +++ b/ntpdc/ntpdc.c @@ -59,14 +59,6 @@ u_long current_time; /* needed by authkeys; not used */ */ s_char sys_precision; /* local clock precision (log2 s) */ -/* - * Use getpassphrase() if configure.ac detected it, as Suns that - * have it truncate the password in getpass() to 8 characters. - */ -#ifdef HAVE_GETPASSPHRASE -# define getpass(str) getpassphrase(str) -#endif - int ntpdcmain (int, char **); /* * Built in command handler declarations @@ -920,7 +912,6 @@ sendrequest( l_fp ts; l_fp * ptstamp; int maclen; - char pass_prompt[32]; char * pass; memset(&qpkt, 0, sizeof(qpkt)); @@ -953,10 +944,7 @@ sendrequest( info_auth_keyid = key_id; } if (!authistrusted(info_auth_keyid)) { - snprintf(pass_prompt, sizeof(pass_prompt), - "%s Password: ", - keytype_name(info_auth_keytype)); - pass = getpass(pass_prompt); + pass = getpass_keytype(info_auth_keytype); if ('\0' == pass[0]) { fprintf(stderr, "Invalid password\n"); return 1; @@ -1854,7 +1842,7 @@ passwd( (u_char *)pcmd->argval[0].string); authtrust(info_auth_keyid, 1); } else { - pass = getpass("MD5 Password: "); + pass = getpass_keytype(info_auth_keytype); if (*pass == '\0') (void) fprintf(fp, "Password unchanged\n"); else { diff --git a/ntpq/ntpq.c b/ntpq/ntpq.c index 947ddd9d39..6369753ef1 100644 --- a/ntpq/ntpq.c +++ b/ntpq/ntpq.c @@ -237,14 +237,6 @@ static const char *tstflagnames[] = { }; -/* - * Use getpassphrase() if configure.ac detected it, as Suns that - * have it truncate the password in getpass() to 8 characters. - */ -#ifdef HAVE_GETPASSPHRASE -# define getpass(str) getpassphrase(str) -#endif - int ntpqmain (int, char **); /* * Built in command handler declarations @@ -1220,7 +1212,6 @@ sendrequest( struct ntp_control qpkt; int pktsize; u_long key_id; - char pass_prompt[32]; char * pass; int maclen; @@ -1289,10 +1280,7 @@ sendrequest( info_auth_keyid = key_id; } if (!authistrusted(info_auth_keyid)) { - snprintf(pass_prompt, sizeof(pass_prompt), - "%s Password: ", - keytype_name(info_auth_keytype)); - pass = getpass(pass_prompt); + pass = getpass_keytype(info_auth_keytype); if ('\0' == pass[0]) { fprintf(stderr, "Invalid password\n"); return 1; @@ -2437,13 +2425,17 @@ passwd( } info_auth_keyid = u_keyid; } - pass = getpass("MD5 Password: "); - if (*pass == '\0') - (void) fprintf(fp, "Password unchanged\n"); + if (pcmd->nargs >= 1) + pass = pcmd->argval[0].string; else { - authusekey(info_auth_keyid, info_auth_keytype, (u_char *)pass); - authtrust(info_auth_keyid, 1); + pass = getpass_keytype(info_auth_keytype); + if ('\0' == pass[0]) { + fprintf(fp, "Password unchanged\n"); + return; + } } + authusekey(info_auth_keyid, info_auth_keytype, (u_char *)pass); + authtrust(info_auth_keyid, 1); } @@ -2751,10 +2743,13 @@ makeascii( FILE *fp ) { - register u_char *cp; - register int c; + const u_char *data_u_char; + const u_char *cp; + int c; + + data_u_char = (const u_char *)data; - for (cp = (u_char *)data; cp < (u_char *)data + length; cp++) { + for (cp = data_u_char; cp < data_u_char + length; cp++) { c = (int)*cp; if (c & 0x80) { putc('M', fp); diff --git a/ports/winnt/ntpd/nt_clockstuff.c b/ports/winnt/ntpd/nt_clockstuff.c index 4bd540e510..d4a0676482 100644 --- a/ports/winnt/ntpd/nt_clockstuff.c +++ b/ports/winnt/ntpd/nt_clockstuff.c @@ -1205,14 +1205,17 @@ ntp_timestamp_from_counter( /* sanity check timestamp is within 1 minute of now */ GetSystemTimeAsFileTime(&Now.ft); Now.ll -= InterpTimestamp; - if (Now.ll > 60 * HECTONANOSECONDS || + if (debug && + Now.ll > 60 * HECTONANOSECONDS || Now.ll < -60 * (LONGLONG) HECTONANOSECONDS) { - DPRINTF(1, ("ntp_timestamp_from_counter interpolated " - "time %.6fs from current\n", + DPRINTF(1, ("ntp_timestamp_from_counter interpolated time %.6fs from current\n", Now.ll / (double)LL_HNS)); DPRINTF(1, ("interpol time %llx from %llx\n", InterpTimestamp, Counterstamp)); + msyslog(LOG_ERR, + "ntp_timestamp_from_counter interpolated time %.6fs from current\n", + Now.ll / (double)LL_HNS); exit(-1); } #endif