[pmg-devel] [PATCH pmg-log-filter v2 3/8] fix csum calculation and update checksums

Dominik Csapak d.csapak at proxmox.com
Thu Feb 21 09:42:02 CET 2019


it was intended to be a rol instead of a simple left shift which changes the
checksums for the various programs (like 'proxprox', 'postfix/postscreen',
etc.) so we update those and use defines instead of the hardcoded hex values.
this makes it much more readable and less error prone

Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
---
changes from v1:
* remove unnecessary comments
* improve commit message
 pmg-log-tracker.c | 39 ++++++++++++++++++++++++++-------------
 1 file changed, 26 insertions(+), 13 deletions(-)

diff --git a/pmg-log-tracker.c b/pmg-log-tracker.c
index 21145fa..39ed965 100644
--- a/pmg-log-tracker.c
+++ b/pmg-log-tracker.c
@@ -34,6 +34,7 @@
 #include <time.h>
 #include <unistd.h>
 #include <sys/types.h>
+#include <stdint.h>
 #include <zlib.h>
 #include <fnmatch.h>
 
@@ -290,6 +291,18 @@ void      parser_free (LParser *parser);
 
 // Implementations
 
+// Checksum Macros
+#define PROXPROX		0xE0E4DEF0
+#define PMG_SMTP_FILTER		0x0A85A6B7
+#define POSTFIX_POSTSCREEN	0xD17E2019
+#define POSTFIX_QMGR		0x48465316
+#define POSTFIX_SMTP		0x4A466014
+#define POSTFIX_LMTP		0x43466014
+#define POSTFIX_LOCAL		0x484F05AF
+#define POSTFIX_ERROR		0x4B5E13AE
+#define POSTFIX_SMTPD		0x466014AE
+#define POSTFIX_CLEANUP		0x05A8BAC1
+
 //#define LOGPATH "./log/"
 #define LOGPATH "/var/log/"
 //#define LOGPATH "/root/testlog/"
@@ -1773,7 +1786,7 @@ main (int argc, char * const argv[])
   const char *idx2;
   const char *cpos;
   int found = 0;
-  int csum_prog;
+  uint32_t csum_prog;
   unsigned long lines = 0;
   unsigned long rel_line_nr = 0;
   char qidbuf[30];
@@ -2037,7 +2050,7 @@ main (int argc, char * const argv[])
 
       csum_prog = 0;
       found = 0; while (*cpos && (*cpos != ':') && (*cpos != '[')) { 
-	csum_prog = (csum_prog <<8) + *cpos;
+	csum_prog = ((csum_prog << 8)|(csum_prog >> 24)) + *cpos;
 	cpos++; 
 	found++; 
       }
@@ -2081,8 +2094,8 @@ main (int argc, char * const argv[])
 	strmatch = 1;
       }
 
-      if ((csum_prog == 0x70726F78) ||// proxprox
-	  (csum_prog == 0x6C746572)) { // pmg-smtp-filter
+      if ((csum_prog == PROXPROX) ||
+	  (csum_prog == PMG_SMTP_FILTER)) {
 
 	if ((idx1 = parse_qid (&cpos, qidbuf, ':', 25))) {
 
@@ -2171,7 +2184,7 @@ main (int argc, char * const argv[])
 
 	}
 
-      } else if (csum_prog == 0x7265656E) { // postfix/postscreen
+      } else if (csum_prog == POSTFIX_POSTSCREEN) {
 
 	      SEntry *se;
 
@@ -2228,7 +2241,7 @@ main (int argc, char * const argv[])
 		      sentry_free (parser, se);
 	      }
 	      
-      } else if (csum_prog == 0x716D6772) { // postfix/qmgr
+      } else if (csum_prog == POSTFIX_QMGR) {
 
 	if ((idx2 = text) && (idx1 = parse_qid (&idx2, qidbuf, ':', 15))) {
 
@@ -2275,12 +2288,12 @@ main (int argc, char * const argv[])
 	  }
 	}
 
-      } else if ((csum_prog == 0x736D7470) || //postfix/smtp
-		 (csum_prog == 0x6C6D7470) || //postfix/lmtp
-		 (csum_prog == 0x6F63616C) || //postfix/local
-		 (csum_prog == 0x72726F72)) { //postfix/error
+      } else if ((csum_prog == POSTFIX_SMTP) ||
+		 (csum_prog == POSTFIX_LMTP) ||
+		 (csum_prog == POSTFIX_LOCAL) ||
+		 (csum_prog == POSTFIX_ERROR)) {
 
-	int lmtp = (csum_prog == 0x6C6D7470);
+	int lmtp = (csum_prog == POSTFIX_LMTP);
 
 	if ((cpos = text) && (idx1 = parse_qid (&cpos, qidbuf, ':', 15))) {
 
@@ -2362,7 +2375,7 @@ main (int argc, char * const argv[])
 	  }
 	}
 
-      } else if (csum_prog == 0x6D747064) { // postfix/smtpd
+      } else if (csum_prog == POSTFIX_SMTPD) {
 	SEntry *se;
 
 	if (!pid) {
@@ -2469,7 +2482,7 @@ main (int argc, char * const argv[])
 
 	}
  
-      } else if (csum_prog == 0x616E7570) { // postfix/cleanup
+      } else if (csum_prog == POSTFIX_CLEANUP) {
 
 	QEntry *qe;
 
-- 
2.11.0




More information about the pmg-devel mailing list