[patch] cfservd gets confused by config files from the future

Iain Patterson <[email protected]> Fri, 14 May 2010 17:41:23 +0100
Newsgroups gmane.comp.sysutils.cfengine.bugs
Message-ID <[email protected]>
This is a multi-part message in MIME format.
--------------060503090307080704070404
Content-Type: text/plain; charset=ISO-8859-1; format=flowed
Content-Transfer-Encoding: 7bit

   If for whatever reason cfservd.conf has a timestamp from the 
future, cfservd will keep rereading it over and over again because it 
stat()s the file and considers it changed if the mtime is later than 
the daemon start time.

   With this patch we look at the mtime, inode number and filesize and 
iff one or more of them change we checksum the file and see if it is 
actually different before rereading.

--------------060503090307080704070404
Content-Type: text/x-patch;
 name="cfengine-2.2.10-cfservdconf.diff"
Content-Transfer-Encoding: 7bit
Content-Disposition: attachment;
 filename="cfengine-2.2.10-cfservdconf.diff"

--- cfengine-2.2.10/src/cfservd.c
+++ cfengine-2.2.10/src/cfservd.c
@@ -68,6 +68,9 @@ struct option CFDOPTIONS[] =
 
 struct Item *CONNECTIONLIST = NULL;
 
+struct stat confstat;
+unsigned char confdigest[EVP_MAX_MD_SIZE+1];
+
 
 /*******************************************************************/
 /* Functions internal to cfservd.c                                 */
@@ -985,6 +988,7 @@ void CheckFileChanges(int argc,char **argv,int sd)
 
 { struct stat newstat;
   char filename[CF_BUFSIZE],*sp;
+  unsigned char newdigest[EVP_MAX_MD_SIZE+1];
   
 memset(&newstat,0,sizeof(struct stat));
 memset(filename,0,CF_BUFSIZE);
@@ -1017,9 +1021,22 @@ if (stat(filename,&newstat) == -1)
    return;
    }
 
-Debug("Checking file updates on %s (%x/%x)\n",filename, newstat.st_mtime, CFDSTARTTIME);
+if (!confstat.st_mtime) /* First run */
+   {
+   memmove(&confstat,&newstat,sizeof(struct stat));
+   ChecksumFile(filename,confdigest,'m');
+   }
+
+Debug("Checking file updates on %s ({%x/%x)\n",filename, newstat.st_mtime, confstat.st_mtime);
+
+if (newstat.st_mtime == confstat.st_mtime && newstat.st_ino == confstat.st_ino && newstat.st_size == confstat.st_size)
+   {
+   return;
+   }
+
+ChecksumFile(filename,newdigest,'m');
 
-if (CFDSTARTTIME < newstat.st_mtime)
+if (memcmp(newdigest,confdigest,EVP_MAX_MD_SIZE))
    {
    snprintf(OUTPUT,CF_BUFSIZE*2,"Rereading config files %s..\n",filename);
    CfLog(cfinform,OUTPUT,"");
@@ -1061,6 +1078,9 @@ if (CFDSTARTTIME < newstat.st_mtime)
    CheckVariables();
    SummarizeParsing();
    }
+
+memmove(&confstat,&newstat,sizeof(struct stat));
+memmove(&confdigest,&newdigest,EVP_MAX_MD_SIZE+1);
 }
 
 /*********************************************************************/

--------------060503090307080704070404
Content-Type: text/plain; charset="us-ascii"
MIME-Version: 1.0
Content-Transfer-Encoding: 7bit
Content-Disposition: inline

_______________________________________________
Bug-cfengine mailing list
[email protected]
https://cfengine.org/mailman/listinfo/bug-cfengine

--------------060503090307080704070404--