--- nntp.1.5.12.2/server/date.c Tue Nov 1 06:08:41 1994 +++ server/date.c Fri Dec 3 23:31:31 1999 @@ -41,6 +41,9 @@ * local time, or any other kind of time, for that matter. If you * pass it a date you think is GMT, you wind up with that number of * seconds... + * + * Now regards any year < 70 as being after Y2K. Will still break due + * to time_t overflow. D. Glover, 29/11/99 * * Parameters: "date_ascii" is in the form "yymmddhhmmss". * @@ -120,7 +123,17 @@ if (hour < 0 || hour > 23) return (-1); seconds = 0; - year += 1900; + +/* We need to handle years correctly per RFC977. This fix is consistent with + * the approach in inn-2.0. Years before 1970 wouldn't work anyway, but this + * will also run out of steam after 2038... + * We seem to have Y2K as a leap year already, by accident rather than + * design. DG 29/11/99 + */ + if (year <70) + year += 2000; + else + year += 1900; for (i = 1970; i < year; i++) seconds += dysize(i); /* Leap year */ @@ -132,7 +145,6 @@ seconds = 24 * seconds + hour; seconds = 60 * seconds + mins; seconds = 60 * seconds + secs; - return (seconds); } @@ -140,11 +152,13 @@ /* * ltod -- convert long integer to date string. * + * Now returns 4-digit years. D. Glover 29/11/99 + * * Parameters: "date" is in the number of seconds * since the epoch. * * Returns: Pointer to static data in the form - * yymmddhhmmss\0. + * yyyymmddhhmmss\0. * * Side effects: None. */ @@ -158,8 +172,8 @@ tp = gmtime(&date); - (void) sprintf(timebuf, "%02d%02d%02d%02d%02d%02d", - tp->tm_year, + (void) sprintf(timebuf, "%04d%02d%02d%02d%02d%02d", + tp->tm_year +1900, /* DG 29/11/99 - return 4-digit year */ tp->tm_mon + 1, /* 0 to 11??? How silly. */ tp->tm_mday, tp->tm_hour, diff -ru nntp.1.5.12.2/server/newnews.c nntp/server/newnews.c --- nntp.1.5.12.2/server/newnews.c Tue Nov 1 06:08:58 1994 +++ server/newnews.c Sat Dec 4 12:00:20 1999 @@ -17,6 +17,10 @@ * Return the message-id's of any news articles past * a certain date and time, within the specified distributions. * + * Made RFC977/Y2K compliant via changes in dtol() - see time.c - and + * slightly simplified the comparison between incoming date and history + * file. Fixed(?) the local time offset. D. Glover 29/11/99 + * */ void @@ -92,25 +96,30 @@ argc -= 4; argv += 4; - key = datebuf; /* Unless they specify GMT */ - date = dtol(datebuf); +/* Originally the "key" for searching was obtained here and the localtime + * offset wasn't applied when doing the actual comparison... DG 29/11/99 + */ + date = dtol(datebuf); /* local time here */ if (date < 0) { printf("%d Invalid date specification.\r\n",ERR_CMDSYN); (void) fflush(stdout); return; } - if (argc > 0) { - if (!strcasecmp(*argv, "GMT")) { /* Which we handle here */ - date = gmt_to_local(date); +/* REMOVED apparently unwanted call to gmt_to_local() + * and tidied up handling of GMT/distributions DG 29/11/99 + */ + if (argc > 0 && !strcasecmp(*argv, "GMT")) { ++argv; --argc; - } } + else { /* now we convert from local to GMT since this is what history */ /* file in News 2.11 expects */ - date = local_to_gmt(date); - strcpy(datebuf,ltod(date)); + date = local_to_gmt(date); + } + strcpy(datebuf, ltod(date)); + key = datebuf; distcount = 0; if (argc > 0) { distcount = get_distlist(&distlist, *argv); @@ -241,7 +250,7 @@ * a line with date later than "akey". Get that line, and return. * * Parameters: "fp" is the active file. - * "akey" is the date, in form YYMMDDHHMMSS + * "akey" is the date, in form YYYYMMDDHHMMSS * "line" is storage for the first line we find. * * Returns: -1 on error, 0 otherwise. @@ -312,7 +321,7 @@ compare(s, t) register char *s, *t; { - for (; *s == *t; s++, t++) +for (; *s == *t; s++, t++) if (*s == 0) return(0); return (*s == 0 ? -1: @@ -333,6 +342,7 @@ { register char *cp; extern char *index(); + long qz; if (fgets(line, linesize, fp) == NULL) return (0); w[0] = '\0'; /* in case of bad format */ @@ -355,12 +365,15 @@ * The following gross hack is present because the old history file date * format is braindamaged. They like "mm/dd/yy hh:mm", which is useless * for relative comparisons of dates using something like atoi() or - * strcmp. So, this changes their format into yymmddhhmm. Sigh. + * strcmp. So, this changes their format into yyyymmddhhmm. Sigh. + * + * Modified to use 4 digit years, just in case anyone is still using B news + * but not tested here. DG 29/11/99 * * 01234567890123 ("x" for cp[x]) * mm/dd/yy hh:mm (their lousy representation) - * yymmddhhmm (our good one) - * 0123456789 ("x" for w[x]) + * yymmddhhmmss (our good one) + * 012345678901 ("x" for w[x]) */ w[0] = cp[6]; /* Years */ w[1] = cp[7]; @@ -372,15 +385,25 @@ w[7] = cp[10]; w[8] = cp[12]; /* Minutes */ w[9] = cp[13]; - w[10] = '\0'; + w[10] = '0'; /* Seconds are faked */ + w[11] = '0'; + w[12] = '\0'; + +/* We now have YYMMDDHHMMSS - use dtol() to get something sensible for the + * century and then use ltod() below to make it compatible with the way + * the search is done. Really it would be much better to compare everything + * as time_t, but this means changing seekuntil() and all the underlying stuff. + * Maybe for a subsequent release if anyone is bothered? DG 29/11/99 + */ + qz = dtol(w); } - else /* convert new format to yymmddhhmmss */ + + else /* convert new format to yyyymmddhhmmss */ { - long qz; qz =atol(w); - strcpy(w,ltod(qz)); - } - } + } + } + strcpy(w,ltod(qz)); return (1); } diff -ru nntp.1.5.12.2/server/version.c nntp/server/version.c --- nntp.1.5.12.2/server/version.c Tue Jan 9 07:28:04 1996 +++ server/version.c Sat Dec 4 12:04:57 1999 @@ -2,4 +2,4 @@ * Provide the version number of this release. */ -char nntp_version[] = "1.5.12.2 (9 Jan 1996)"; +char nntp_version[] = "1.5.12.2-DG1 (29 November 1999)"; diff -ru nntp.1.5.12.2/xfer/nntpxfer.c nntp/xfer/nntpxfer.c --- nntp.1.5.12.2/xfer/nntpxfer.c Tue Jan 9 07:28:03 1996 +++ xfer/nntpxfer.c Sun Aug 9 19:55:19 1998 @@ -185,7 +185,10 @@ } clock = time((long *)0); now = gmtime(&clock); - newdate = (now->tm_year * 10000) + + +/* DG 9/8/98 - use tm_year %100 to avoid overflow in Y2K - see man 3 ctime */ + + newdate = (now->tm_year %100 * 10000) + ((now->tm_mon + 1) * 100) + now->tm_mday; newtime = (now->tm_hour * 10000) + (now->tm_min * 100) + now->tm_sec;