]> git.ipfire.org Git - thirdparty/ntp.git/commitdiff
[Bug 1561] ntpq, ntpdc "passwd" prompts for MD5 password w/SHA1.
authorDave Hart <hart@ntp.org>
Mon, 24 May 2010 15:46:36 +0000 (15:46 +0000)
committerDave Hart <hart@ntp.org>
Mon, 24 May 2010 15:46:36 +0000 (15:46 +0000)
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

ChangeLog
include/ntp_stdlib.h
libntp/ssl_init.c
ntpdc/ntpdc.c
ntpq/ntpq.c
ports/winnt/ntpd/nt_clockstuff.c

index 7558d7d7c5ca3e6ec6aed1deadc0557b29041686..8de837a35d2fff8a7ee7422cbffc7675d021f0be 100644 (file)
--- 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 <stenn@ntp.org>
 
index bcceaea7ddac95c15aa423fbe54e6f5d34820c4c..0abc490722f88c7bc9aa86cf3f313d3df2247e6e 100644 (file)
@@ -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
index c7bf7e63f8b8b0c282a4aa675304fcc819ae63aa..f15de341e16f4fd627164c5c8796e0bad4fd1b46 100644 (file)
@@ -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);
+}
index 4bfb25ff2dfe6852a5973f7d540f81e985009e6d..bee7640863dbd67d4122dd01fc255bc0bde4a35a 100644 (file)
@@ -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 {
index 947ddd9d3936ae0e38436eb92b264f78e0ab45c6..6369753ef1267a866d16f194c1c851bfa1d148d0 100644 (file)
@@ -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);
index 4bd540e510f369a8d71e98c154afebfdea0101b1..d4a0676482be04207bda10983118acd433049c9f 100644 (file)
@@ -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