| 1 |
This contains part of the BOFH patch by Andrew Gierth and my backport |
| 2 |
of the INN 2.x code to modify headers. |
| 3 |
|
| 4 |
|
| 5 |
--- inn-1.7.2.orig/nnrpd/post.c |
| 6 |
+++ inn-1.7.2/nnrpd/post.c |
| 7 |
@@ -20,8 +20,8 @@ |
| 8 |
STATIC char *tmpPtr ; |
| 9 |
STATIC char Error[SMBUF]; |
| 10 |
STATIC char NGSEPS[] = NG_SEPARATOR; |
| 11 |
-STATIC char **OtherHeaders; |
| 12 |
-STATIC int OtherCount; |
| 13 |
+char **OtherHeaders; |
| 14 |
+int OtherCount; |
| 15 |
STATIC int OtherSize; |
| 16 |
STATIC BOOL WasMailed; |
| 17 |
STATIC STRING BadDistribs[] = { |
| 18 |
@@ -886,8 +893,13 @@ |
| 19 |
|
| 20 |
#if defined(DO_PERL) |
| 21 |
/* Calls the Perl subroutine for headers management */ |
| 22 |
- if ((p = (char *)HandleHeaders()) != NULL) |
| 23 |
+ if ((p = (char *)HandleHeaders(article)) != NULL) { |
| 24 |
+ if (strncmp(p, "DROP", 4) == 0) { |
| 25 |
+ syslog(L_NOTICE, "%s post %s", ClientHost, p); |
| 26 |
+ return NULL; |
| 27 |
+ } |
| 28 |
return p; |
| 29 |
+ } |
| 30 |
#endif /* defined(DO_PERL) */ |
| 31 |
|
| 32 |
/* Open a local connection to the server. */ |
| 33 |
--- inn-1.7.2.orig/nnrpd/perl.c |
| 34 |
+++ inn-1.7.2/nnrpd/perl.c |
| 35 |
@@ -23,25 +23,40 @@ |
| 36 |
#include "paths.h" |
| 37 |
#include "post.h" |
| 38 |
#include "logging.h" |
| 39 |
+#include "macros.h" |
| 40 |
|
| 41 |
#if defined(DO_PERL) |
| 42 |
|
| 43 |
#include <EXTERN.h> |
| 44 |
#include <perl.h> |
| 45 |
+#define my_perl PerlCode |
| 46 |
+extern PerlInterpreter *PerlCode; |
| 47 |
|
| 48 |
extern BOOL PerlFilterActive; |
| 49 |
extern HEADER Table[], *EndOfTable; |
| 50 |
extern char LogName[]; |
| 51 |
+extern char PERMuser[]; |
| 52 |
+ |
| 53 |
+extern char **OtherHeaders; |
| 54 |
+extern int OtherCount; |
| 55 |
+static int HeaderLen; |
| 56 |
|
| 57 |
char * |
| 58 |
-HandleHeaders() |
| 59 |
+HandleHeaders(artBody) |
| 60 |
+char *artBody; |
| 61 |
{ |
| 62 |
dSP; |
| 63 |
HEADER *hp; |
| 64 |
HV *hdr; |
| 65 |
+ SV *body; |
| 66 |
int rc; |
| 67 |
char *p; |
| 68 |
static char buf[256]; |
| 69 |
+ register int i; |
| 70 |
+ register char *s,*t; |
| 71 |
+ HE *scan; |
| 72 |
+ SV *modswitch; |
| 73 |
+ int OtherSize; |
| 74 |
|
| 75 |
if (!PerlFilterActive) |
| 76 |
return NULL; /* not really necessary */ |
| 77 |
@@ -56,17 +71,81 @@ |
| 78 |
hv_store(hdr, (char *) hp->Name, strlen(hp->Name), newSVpv(hp->Value, 0), 0); |
| 79 |
} |
| 80 |
|
| 81 |
+ /* Also store other headers */ |
| 82 |
+ OtherSize = OtherCount; |
| 83 |
+ for (i = 0; i < OtherCount; i++) { |
| 84 |
+ p = OtherHeaders[i]; |
| 85 |
+ if (p == NULL) { |
| 86 |
+ syslog (L_ERROR,"Null header number %d copying headers for Perl",i); |
| 87 |
+ continue; |
| 88 |
+ } |
| 89 |
+ s = strchr(p,':'); |
| 90 |
+ if (s == NULL) { |
| 91 |
+ syslog (L_ERROR,"Bad header copying headers for Perl: '%s'",p); |
| 92 |
+ continue; |
| 93 |
+ } |
| 94 |
+ s++; |
| 95 |
+ t = (*s == ' ' ? s + 1 : s); |
| 96 |
+ hv_store(hdr, p, (s - p) - 1, newSVpv(t, 0), 0); |
| 97 |
+ } |
| 98 |
+ /* Store user */ |
| 99 |
+ sv_setpv(perl_get_sv("user",TRUE), PERMuser); |
| 100 |
+ |
| 101 |
+ /* Store body */ |
| 102 |
+ body = perl_get_sv("body", TRUE); |
| 103 |
+ sv_setpv(body, artBody); |
| 104 |
+ |
| 105 |
+ /* Call the filtering function */ |
| 106 |
rc = perl_call_argv("filter_post", G_EVAL|G_SCALAR, NULL); |
| 107 |
|
| 108 |
SPAGAIN; |
| 109 |
|
| 110 |
+ /* Restore headers */ |
| 111 |
+ modswitch = perl_get_sv("modify_headers",FALSE); |
| 112 |
+ if (SvTRUE(modswitch)) { |
| 113 |
+ HeaderLen = 0; |
| 114 |
+ i = 0; |
| 115 |
+ |
| 116 |
+ hv_iterinit(hdr); |
| 117 |
+ while ((scan = hv_iternext(hdr)) != NULL) { |
| 118 |
+ register int x; |
| 119 |
+ |
| 120 |
+ /* Get the values */ |
| 121 |
+ p = HePV(scan, PL_na); |
| 122 |
+ s = SvPV(HeVAL(scan), PL_na); |
| 123 |
+ |
| 124 |
+ /* See if it's a table header */ |
| 125 |
+ for (hp = Table; hp < EndOfTable; hp++) { |
| 126 |
+ if (caseEQn(p, hp->Name, hp->Size)) { |
| 127 |
+ hp->Value = COPY(s); |
| 128 |
+ HeaderLen += strlen(s) + hp->Size + 3; |
| 129 |
+ break; |
| 130 |
+ } |
| 131 |
+ } |
| 132 |
+ if (hp != EndOfTable) continue; |
| 133 |
+ |
| 134 |
+ /* Add to other headers */ |
| 135 |
+ if (i >= OtherSize - 1) { |
| 136 |
+ OtherSize += 20; |
| 137 |
+ RENEW(OtherHeaders, char*, OtherSize); |
| 138 |
+ } |
| 139 |
+ x = strlen(p) + strlen(s) + 3; |
| 140 |
+ t = NEW(char, x); |
| 141 |
+ sprintf(t,"%s: %s",p,s); |
| 142 |
+ OtherHeaders[i++] = t; |
| 143 |
+ HeaderLen += x; |
| 144 |
+ } |
| 145 |
+ OtherCount = i; |
| 146 |
+ } |
| 147 |
+ |
| 148 |
hv_undef (hdr); |
| 149 |
+ sv_setsv (body, &PL_sv_undef); |
| 150 |
|
| 151 |
buf [0] = '\0' ; |
| 152 |
|
| 153 |
- if (SvTRUE(GvSV(errgv))) /* check $@ */ { |
| 154 |
+ if (SvTRUE(ERRSV)) /* check $@ */ { |
| 155 |
syslog (L_ERROR,"Perl function filter_post died: %s", |
| 156 |
- SvPV(GvSV(errgv), na)) ; |
| 157 |
+ SvPV(ERRSV, PL_na)) ; |
| 158 |
POPs ; |
| 159 |
PerlFilter (FALSE) ; |
| 160 |
} else if (rc == 1) { |