🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: news.software.nntp
Article #86948

Patch to munge posting-host

#86948
From: Steve Crook
Date: Sun, 06 Sep 2015 10:50
86 lines
4036 bytes
Hi all,

I constructed the following patch to munge the client details in the
Posting-Host and Path headers.  Previously I've done this via the Perl
hook but using this approach means I can drop "with-perl" from my INN
config.

It's probably not a mainstream thing to do but I thought a few people
might find it useful.  After applying, remember to change the
SHA_PH_SALT in nnrpd/post.c to something unique.


--- post.c.old	2015-09-06 11:25:11.923062898 +0100
+++ post.c	2015-09-06 11:24:02.592241184 +0100
@@ -9,6 +9,7 @@
 #include "nnrpd.h"
 #include "inn/ov.h"
 #include "post.h"
+#include <openssl/sha.h>
 
 #define FLUSH_ERROR(F)		(fflush((F)) == EOF || ferror((F)))
 #define HEADER_DELTA		20
@@ -23,6 +24,8 @@
 static const char * const BadDistribs[] = {
     BAD_DISTRIBS
 };
+// Salt the SHA1 Hash used in posting-host
+static const char* SHA_PH_SALT = "Insert Salt here";
 
 /*
 **  Do not modify the table without also looking at post.h for potential
@@ -488,11 +491,10 @@
         free(newpath);
     if (PERMaccessconf->addinjectionpostinghost) {
         if (addvirtual) {
-            newpath = concat(VirtualPath, ".POSTED.", Client.host, "!",
-                             HDR(HDR__PATH), (char *) 0);
-        } else {
-            newpath = concat(".POSTED.", Client.host, "!", HDR(HDR__PATH),
+            newpath = concat(VirtualPath, ".POSTED!", HDR(HDR__PATH),
                              (char *) 0);
+        } else {
+            newpath = concat(".POSTED!", HDR(HDR__PATH), (char *) 0);
         }
     } else {
         if (addvirtual) {
@@ -562,17 +564,26 @@
      * (we already saw the case of "localhost:" without IP),
      * when getpeername fails. */
     if ((strlen(Client.host) > 0) || (strlen(Client.ip) > 0)) {
+        unsigned char digest[SHA_DIGEST_LENGTH];
+        SHA_CTX ctx;
+        SHA1_Init(&ctx);
         if ((strcmp(Client.host, Client.ip) == 0)
            || (strlen(Client.host) == 0)) {
-            snprintf(postinghostbuff, sizeof(postinghostbuff),
-                     "; posting-host=\"%s\"", Client.ip);
+            SHA1_Update(&ctx, Client.ip, strlen(Client.ip));
         } else if (strlen(Client.ip) == 0) {
-            snprintf(postinghostbuff, sizeof(postinghostbuff),
-                     "; posting-host=\"%s\"", Client.host);
+            SHA1_Update(&ctx, Client.host, strlen(Client.host));
         } else {
-            snprintf(postinghostbuff, sizeof(postinghostbuff),
-                     "; posting-host=\"%s:%s\"", Client.host, Client.ip);
+            SHA1_Update(&ctx, Client.host, strlen(Client.host));
+            SHA1_Update(&ctx, Client.ip, strlen(Client.ip));
         }
+        SHA1_Update(&ctx, SHA_PH_SALT, strlen(SHA_PH_SALT));
+        SHA1_Final(digest, &ctx);
+        char mdString[SHA_DIGEST_LENGTH*2+1];
+        int i;
+        for (i = 0; i < SHA_DIGEST_LENGTH; i++)
+            sprintf(&mdString[i*2], "%02x", (unsigned int)digest[i]);
+        snprintf(postinghostbuff, sizeof(postinghostbuff),
+                 "; posting-host=\"%s\"", mdString);
     }
 
     /* Set the logging-data attribute. */

-- 
What shall we use 
To fill the empty spaces 
Where we used to talk?

Technical Details
Message-ID: <slrnmuo6jn.ilk.steve@snorky.mixmin.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.(19219).mbox.7z!not-for-mail

Show Full Headers
Complete Article Headers
Message-ID: <slrnmuo6jn.ilk.steve@snorky.mixmin.net>
Subject: Patch to munge posting-host
Date: Sun, 06 Sep 2015 10:50:31 +0000
From: Steve Crook <steve@mixmin.net>
Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.(19219).mbox.7z!not-for-mail
Newsgroups: news.software.nntp
Organization: Mixmin
Injection-Date: Sun, 6 Sep 2015 10:50:31 +0000 (UTC)
Injection-Info: news.mixmin.net; posting-host="b3d35a7ea93243cd2837e0450058617a56b6aceb";
 logging-data="12468"; mail-complaints-to="abuse@mixmin.net"
User-Agent: slrn/pre1.0.3-4 (Linux)
X-Received-Body-CRC: 2482591464
X-Received-Bytes: 3894