Article View: news.software.nntp
Article #18428Re: "NNTP-Posting-Date", etc. headers
From: Sven Paulus
Date: Thu, 12 Jun 1997 00:00
Date: Thu, 12 Jun 1997 00:00
237 lines
7533 bytes
7533 bytes
James Brister <brister@vix.com> wrote:
JB> The next version of INN is most likely going to be adding new header in
JB> nnrpd:
JB> X-Trace: time pid indent-info ip-addr
JB> e.g.
JB> X-Trace: 865982250 666 brister@vix.com 192.5.5.1
JB> or
JB> X-Trace: 865982250 666 (none) 192.5.5.1
JB> for sites where ident is not used (or useful).
Here is a quick little patch based on Luke Mewburns <lm@rmit.edu.au>
NNTP-Posting-User patch implementing this new line. It's against a plain
1.5.1 nnrpd.
diff -uNr nnrpd-orig/Makefile nnrpd/Makefile
--- nnrpd-orig/Makefile Thu Jun 12 01:22:22 1997
+++ nnrpd/Makefile Thu Jun 12 14:28:16 1997
@@ -39,11 +39,11 @@
SOURCES = \
article.c group.c commands.c misc.c newnews.c nnrpd.c \
- perl.c post.c loadave.c
+ perl.c post.c loadave.c ident_client.c
OBJECTS = \
article.o group.o commands.o misc.o newnews.o nnrpd.o \
- perl.o post.o loadave.o
+ perl.o post.o loadave.o ident_client.o
ALL = nnrpd
diff -uNr nnrpd-orig/ident_client.c nnrpd/ident_client.c
--- nnrpd-orig/ident_client.c Thu Jan 1 01:00:00 1970
+++ nnrpd/ident_client.c Thu Jun 12 02:14:18 1997
@@ -0,0 +1,100 @@
+/*
+ * ident_client.c
+ *
+ * Identifies the remote user of a given connection.
+ *
+ * Written 940112 by Luke Mewburn <lm@rmit.edu.au>
+ *
+ * Copyright (C) 1994 by Luke Mewburn.
+ * This code may be used freely by anyone as long as this copyright remains.
+ *
+ */
+
+#include <stdio.h>
+#include <string.h>
+#include <sys/types.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netdb.h>
+
+#include <syslog.h>
+
+#define IDENT_PORT 113
+
+/*
+ * ident_client
+ * - user interface to identd
+ *
+ * Args:
+ * peeraddr sockaddr_in struct of peer end, from getpeername(...)
+ * ouraddr sockaddr_in struct of local end, from getsockname(...)
+ *
+ * Returns:
+ * NULL on failure to identify (for whatever reason), or pointer to
+ * static character string with the identity.
+ */
+
+char *
+ident_client(peeraddr, ouraddr)
+ struct sockaddr_in peeraddr, ouraddr;
+{
+ struct sockaddr_in authcon;
+ int authfd, authlen;
+ struct servent *identserv;
+ int identport;
+
+ FILE *authfpin, *authfpout;
+ char buffer[8192]; /* XXX: argh! magic numbers */
+ char reply_type[81];
+ char opsys_or_err[81];
+ int rport, lport;
+
+ static char identifier[1024];
+
+ authfd = socket(AF_INET, SOCK_STREAM, 0);
+ if (authfd == -1)
+ return NULL;
+
+ identserv = getservbyname("ident", "tcp");
+ if (identserv)
+ identport = identserv->s_port;
+ else
+ identport = ntohs(IDENT_PORT);
+
+ memset(&authcon, 0, sizeof(authcon));
+ authcon.sin_family = AF_INET;
+ authcon.sin_addr.s_addr = peeraddr.sin_addr.s_addr;
+ authcon.sin_port = identport;
+
+ authlen = sizeof(authcon);
+ if (connect(authfd, (struct sockaddr *)&authcon, authlen) < 0) {
+ return NULL;
+ }
+
+ authfpin = fdopen(authfd, "r");
+ authfpout = fdopen(authfd, "w");
+ if (!authfpin || !authfpout)
+ return NULL;
+
+ fprintf(authfpout, "%d , %d\n", ntohs(peeraddr.sin_port), ntohs(ouraddr.sin_port));
+ fflush(authfpout);
+
+ if (fgets(buffer, sizeof(buffer)-1, authfpin) == NULL)
+ return NULL;
+
+ shutdown(authfd, 1);
+
+ authlen = sscanf(buffer, "%d , %d : %[^ \t\n\r:] : %[^ \t\n\r:] : %[^\n\r]",
+ &lport, &rport, reply_type, opsys_or_err, identifier);
+ if (authlen < 3)
+ return NULL;
+
+#if 0 /* XXX: for if we ever handle the ERROR class */
+ if (! strcasecmp(reply_type, "ERROR"))
+ return NULL;
+#endif
+ if (strcasecmp(reply_type, "USERID"))
+ return NULL;
+
+ return identifier;
+} /* ident_client */
diff -uNr nnrpd-orig/nnrpd.c nnrpd/nnrpd.c
--- nnrpd-orig/nnrpd.c Thu Jun 12 01:22:24 1997
+++ nnrpd/nnrpd.c Thu Jun 12 22:04:30 1997
@@ -382,7 +382,7 @@
StartConnection(accesslist)
char *accesslist;
{
- struct sockaddr_in sin;
+ struct sockaddr_in sin, ourad;
int length;
char buff[SMBUF];
char *ClientAddr;
@@ -447,6 +447,28 @@
Printf("%d You are not in my access file. Goodbye.\r\n",
NNTP_ACCESS_VAL);
ExitWithStats(1);
+ }
+
+ /* lm, 940112 */
+ ClientUser[0] = '\0';
+ strcpy(LocalAddr, "(none)");
+ if (!isatty(STDIN)) {
+ length = sizeof(ourad);
+ if (getsockname(STDIN, (struct sockaddr *)&ourad, &length) >= 0) {
+ char *ident_client();
+ char *them;
+
+ strcpy(LocalAddr, inet_ntoa(ourad.sin_addr));
+
+ them = ident_client(sin, ourad);
+ if (them) {
+ (void)strncpy(ClientUser, them, sizeof(ClientUser) - 1);
+ ClientUser[sizeof(ClientUser) - 1] = '\0';
+ syslog(L_NOTICE, "%s remote user is '%s'", ClientHost, ClientUser);
+ } else
+ syslog(L_NOTICE, "remote user is unknown!");
+ } else
+ syslog(L_NOTICE, "could not get sockname");
}
}
diff -uNr nnrpd-orig/nnrpd.h nnrpd/nnrpd.h
--- nnrpd-orig/nnrpd.h Thu Jun 12 01:22:24 1997
+++ nnrpd/nnrpd.h Thu Jun 12 21:57:05 1997
@@ -93,6 +93,8 @@
EXTERN STRING MyHostName;
extern char ACTIVE[];
EXTERN char ClientHost[SMBUF];
+EXTERN char LocalAddr[SMBUF];
+EXTERN char ClientUser[SMBUF];
EXTERN char LogName[256] ;
extern char ACTIVETIMES[];
extern char HISTORY[];
diff -uNr nnrpd-orig/post.c nnrpd/post.c
--- nnrpd-orig/post.c Thu Jun 12 01:22:24 1997
+++ nnrpd/post.c Thu Jun 12 21:54:36 1997
@@ -71,6 +71,8 @@
#define _contenttype 19
{ "Content-Transfer-Encoding", TRUE, HTstd },
#define _contenttransferencoding 20
+ { "X-Trace", FALSE, HTstd }, /* lm, 931203 */
+#define _xtrace 21
{ "Xref", FALSE, HTstd },
{ "Summary", TRUE, HTstd },
{ "Keywords", TRUE, HTstd },
@@ -262,6 +264,7 @@
static char mimeversion[SMBUF];
static char mimetype[SMBUF];
static char mimeencoding[SMBUF];
+ static char xtracebuf[1024];
register HEADER *hp;
register char *p;
time_t t;
@@ -428,6 +431,17 @@
/* NNTP-Posting host; set. */
HDR(_nntpposthost) = ClientHost;
+
+ /* X-Trace; set. */
+ sprintf(xtracebuf, "%ld %d %s%s%s %s",
+ (unsigned long) time(NULL),
+ getpid(),
+ *ClientUser ? ClientUser : "(none)",
+ *ClientUser ? "@" : "",
+ *ClientUser ? ClientHost : "",
+ LocalAddr);
+ HDR(_xtrace) = xtracebuf;
+
/* Now make sure everything is there. */
for (hp = Table; hp < ENDOF(Table); hp++)
Sven
--
--Sven-Paulus----------28-48-32--3-----ub6v@rz.uni-karlsruhe.de------
--Karlstr.-55----------30--2-50-29-----sven@oops.sub.de-----3C9A6091-
--D-76133-Karlsruhe----44-49-10--8-----T#-49-721-9375094---------irc-
--Fido-2:2476/530-------9-12-19-71-----F#-49-721-9375095-----svennie-
Technical Details
Message-ID:
<5npm8i$gc1$1@imperator.oops.sub.de>Path:
mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mailReferences:
<5mtl3h$2fo@tor-nn1-hb0.netcom.ca> <5mu0e0$1gf@nntp02.primenet.com> <5mukrn$q3n@tor-nn1-hb0.netcom.ca> <yy3bu5evzmk.fsf@velo.pp.vix.com>Show Full Headers
Complete Article Headers
Message-ID: <5npm8i$gc1$1@imperator.oops.sub.de> Subject: Re: "NNTP-Posting-Date", etc. headers Date: Thu, 12 Jun 1997 00:00:00 +0000 From: Sven Paulus <sven@oops.sub.de> References: <5mtl3h$2fo@tor-nn1-hb0.netcom.ca> <5mu0e0$1gf@nntp02.primenet.com> <5mukrn$q3n@tor-nn1-hb0.netcom.ca> <yy3bu5evzmk.fsf@velo.pp.vix.com> Path: mbox-mo1.pugleaf.net!archive.usenet.blueworldhosting.com!illumos!news.pugleaf.net!.TX!archive.pugleaf.net!archive.newsdeef.eu!mbox2nntp-news.software.nntp.mbox.zip!not-for-mail X-Deja-AN: 247958944 Sender: Sven Paulus <sven@imperator.oops.sub.de> X-Trace: 866147410 16769 sven@imperator.oops.sub.de 192.101.75.81 Organization: clueless in Karlsruhe, Germany Newsgroups: news.software.nntp