"Fossies" - the Fresh Open Source Software Archive

Member "leafnode-1.12.0/fetchnews_check_date.c" (28 Dec 2021, 2382 Bytes) of package /linux/misc/leafnode-1.12.0.tar.xz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "fetchnews_check_date.c" see the Fossies "Dox" file reference documentation and the latest Fossies "Diffs" side-by-side code changes report: 1.11.12_vs_1.12.0.

    1 /* (C) Copyright 2003 - 2010 Matthias Andree. See COPYING for license. */
    2 
    3 #include "leafnode.h"
    4 
    5 #include <string.h>
    6 
    7 #include "fetchnews.h"
    8 #include "system.h"
    9 #include "ln_log.h"
   10 
   11 /* send DATE command to upstream server and complain if the clocks are
   12  * more than 15 minutes apart.
   13  */
   14 void
   15 check_date(const struct server *current_server)
   16 {
   17     int reply;
   18     struct tm tm;
   19     time_t t, to;
   20     const int tolerate = 10;
   21     const char *lastline;
   22 
   23     strcpy(lineout, "DATE\r\n");
   24     putaline();
   25     reply = nntpreply(current_server);
   26     if (reply != 111) {
   27     /* upstream does not support the DATE command, so ignore */
   28     if (debugmode) {
   29         syslog(LOG_DEBUG, "check_date: %s: does not support DATE, "
   30             "reply %d, expected 111", current_server->name, reply);
   31     }
   32     return;
   33     }
   34 
   35     lastline = lastreply();
   36     if (lastline == NULL) {
   37     ln_log(LNLOG_SWARNING, LNLOG_CTOP,
   38         "%s: warning: server disconnect or timeout in response to DATE command",
   39         current_server->name);
   40     return;
   41     }
   42 
   43     /* upstream supports the DATE command */
   44     if (sscanf(lastline, "%*d %4d%2d%2d%2d%2d%2d",
   45         &tm.tm_year, &tm.tm_mon, &tm.tm_mday,
   46         &tm.tm_hour, &tm.tm_min, &tm.tm_sec) < 6) {
   47     /* too few fields */
   48     ln_log(LNLOG_SINFO, LNLOG_CSERVER, "%s: check_date: too few fields in successful DATE reply "
   49         "\"%s\"", current_server->name, lastline);
   50     return;
   51     }
   52 
   53     /* we can match 6 fields, parse date */
   54     tm.tm_year -= 1900;
   55     tm.tm_mon -= 1;
   56     tm.tm_isdst = -1; /* let libc figure time zone offset */
   57     t = timegm(&tm);
   58     if (t == (time_t) -1) {
   59     /* error, ignore */
   60     ln_log(LNLOG_SINFO, LNLOG_CSERVER, "%s: check_date: upstream sent unparsable reply "
   61         "to DATE, mktime failed. \"%s\"", current_server->name, lastline);
   62     return;
   63     }
   64 
   65     if (labs((long)(t - time(&to))) > tolerate * 60
   66 #if SIZEOF_TIME_T >= SIZEOF_LONG
   67             || t - to > LONG_MAX || to - t > LONG_MAX
   68 #endif
   69             ) {
   70     syslog(LOG_WARNING, "check_date: %s: clocks of upstream and this computer are more than %d minutes apart. Check your system clock.", current_server->name, tolerate);
   71     printf("check_date: %s: clocks of upstream and this computer are more than\n%d minutes apart. Check your system clock.\n", current_server->name, tolerate);
   72     } else {
   73     if (debugmode) {
   74         syslog(LOG_DEBUG, "check_date: %s: server time %ld, our time %ld",
   75             current_server->name, (long)t, (long)to);
   76     }
   77     }
   78 }