INN, ident i IPv6, c.d.
Jacek Konieczny
jajcus w bnet.pl
Czw, 27 Wrz 2001, 20:32:04 CEST
Witam,
Bo ciężkich bojach ze żródłami inn z naszego pakietu udało mi się
doprowadzić to do działania na moim serwerze.
Odpowiednie patche w załączniku. Trzba im się jeszcze przyjrzeć (i
wyrzucić trochę "debuging code"), ale ja już nie mam siły.
Prosiłbym kogoś zajmującego się inn, a w szczególności IPv6 w tymże o
przyjżeniu się temu.
Pozdrowienia,
Jacek
PS. Ten mail został napisany dłuuugo po poprzednim, ale że namieszałem w
swojej konfiguracji poczty, to tamto zdążyło się kilka razy odbić :-)
-------------- następna część ---------
--- inn-2.3.2/authprogs/ident.c.orig Thu May 3 22:27:32 2001
+++ inn-2.3.2/authprogs/ident.c Thu Sep 27 18:40:52 2001
@@ -10,6 +10,7 @@
#include <netdb.h>
#include <syslog.h>
#include <sys/socket.h>
+#include <sys/types.h>
#include "libinn.h"
#include "macros.h"
@@ -18,7 +19,7 @@
{
struct servent *s;
char buf[2048];
- struct sockaddr_in sin, loc, cli;
+ struct sockaddr sa, loc, cli;
int sock;
int opt;
extern char *optarg;
@@ -26,34 +27,18 @@
int got;
char *endstr;
int gotcliaddr, gotcliport, gotlocaddr, gotlocport;
+ char *service="auth";
+ char *localip,*localport,*remoteip,*remoteport;
+ int ret;
+ struct addrinfo hints,*ai;
+ int i;
- memset(&sin, '\0', sizeof(sin));
- sin.sin_family = AF_INET;
-
-#define IDENT_PORT 113
-
- s = getservbyname("ident", "tcp");
- if (!s)
- sin.sin_port = htons(IDENT_PORT);
- else
- sin.sin_port = s->s_port;
-
+ memset(&hints,0,sizeof(hints));
+ hints.ai_socktype=SOCK_STREAM;
while ((opt = getopt(argc, argv, "p:")) != -1) {
switch (opt) {
case 'p':
- for (iter = optarg; *iter; iter++)
- if (*iter < '0' || *iter > '9')
- break;
- if (*iter) {
- /* not entirely numeric */
- if ((s = getservbyname(optarg, "tcp")) == (struct servent *) 0) {
- fprintf(stderr, "ident: can't getservbyname(%s/tcp)\n", optarg);
- exit(1);
- }
- sin.sin_port = s->s_port;
- } else
- sin.sin_port = atoi(optarg);
- sin.sin_port = htons(sin.sin_port);
+ service=optarg;
break;
}
}
@@ -63,27 +48,29 @@
#define PORTNAME "ClientPort: "
#define LOCIP "LocalIP: "
#define LOCPORT "LocalPort: "
- memset(&cli, '\0', sizeof(cli));
- cli.sin_family = AF_INET;
- memset(&loc, '\0', sizeof(loc));
- loc.sin_family = AF_INET;
gotcliaddr = gotcliport = gotlocaddr = gotlocport = 0;
while(fgets(buf, sizeof(buf), stdin) != (char*) 0) {
/* strip '\n' */
- buf[strlen(buf)-1] = '\0';
+ for(i=strlen(buf)-1;i>0;i--)
+ if (buf[i]==' '||buf[i]=='\r'||buf[i]=='\n') buf[strlen(buf)-1] = '\0';
+ else break;
if (!strncmp(buf, IPNAME, strlen(IPNAME))) {
- cli.sin_addr.s_addr = inet_addr(buf+strlen(IPNAME));
+ remoteip=strdup(buf+strlen(IPNAME));
+ fprintf(stderr,"Remote IP: %s\n",remoteip);
gotcliaddr = 1;
} else if (!strncmp(buf, PORTNAME, strlen(PORTNAME))) {
- cli.sin_port = htons(atoi(buf+strlen(PORTNAME)));
+ remoteport = strdup(buf+strlen(PORTNAME));
+ fprintf(stderr,"Remote port: %s\n",remoteport);
gotcliport = 1;
} else if (!strncmp(buf, LOCIP, strlen(LOCIP))) {
- loc.sin_addr.s_addr = inet_addr(buf+strlen(LOCIP));
+ localip = strdup(buf+strlen(LOCIP));
+ fprintf(stderr,"Local IP: %s\n",localip);
gotlocaddr = 1;
} else if (!strncmp(buf, LOCPORT, strlen(LOCPORT))) {
- loc.sin_port = htons(atoi(buf+strlen(LOCPORT)));
+ localport = strdup(buf+strlen(LOCPORT));
+ fprintf(stderr,"Local port: %s\n",localport);
gotlocport = 1;
}
}
@@ -97,24 +84,35 @@
fprintf(stderr, "ident: couldn't create socket: %s\n", strerror(errno));
exit(1);
}
- opt = loc.sin_port;
- loc.sin_port = 0;
- if (bind(sock, (struct sockaddr*) &loc, sizeof(loc)) < 0) {
+ ret=getaddrinfo(localip,NULL,&hints,&ai);
+ if (ret){
+ fprintf(stderr, "ident: getaddrinfo(\"%s\",NULL,&hints,&ai) failed\n",localip);
+ exit(1);
+ }
+ memcpy(&loc,ai->ai_addr,ai->ai_addrlen);
+ if (bind(sock, &loc, sizeof(loc)) < 0) {
fprintf(stderr, "ident: couldn't bind socket: %s\n", strerror(errno));
exit(1);
}
- loc.sin_port = opt;
- sin.sin_addr.s_addr = cli.sin_addr.s_addr;
- if (connect(sock, (struct sockaddr*) &sin, sizeof(sin)) < 0) {
+ ret=getaddrinfo(remoteip,service,&hints,&ai);
+ if (ret){
+ fprintf(stderr, "ident: getaddrinfo(\"%s\",\"%s\",&hints,&ai) failed\n",remoteip,service);
+ exit(1);
+ }
+ memcpy(&sa,ai->ai_addr,ai->ai_addrlen);
+ if (connect(sock, &sa, sizeof(sa)) < 0) {
if (errno != ECONNREFUSED) {
- fprintf(stderr, "ident: couldn't connect to %s:%d: %s\n",
- inet_ntoa(sin.sin_addr), ntohs(sin.sin_port), strerror(errno));
+ fprintf(stderr, "ident: couldn't connect to %s:%s: %s\n",
+ remoteip, service, strerror(errno));
}
exit(1);
}
+ fprintf(stderr, "ident: connected to: %s:%s\n", remoteip, service);
+
/* send the request out */
- sprintf(buf, "%d , %d\r\n", ntohs(cli.sin_port), ntohs(loc.sin_port));
+ sprintf(buf, "%s , %s\r\n", remoteport, localport);
+ fprintf(stderr, "ident: query: %s\n",buf);
got = 0;
while (got != strlen(buf)) {
opt = write(sock, buf+got, strlen(buf)-got);
@@ -140,6 +138,8 @@
buf[got] = '\0';
if (buf[got-1] == '\r')
buf[got-1] = '\0';
+
+ fprintf(stderr, "ident: answer: %s\n",buf);
/* buf now contains the entire ident response. */
if (!(iter = strchr(buf, ':')))
-------------- następna część ---------
--- inn-2.3.2/nnrpd/perm.c.orig Thu Sep 27 18:53:30 2001
+++ inn-2.3.2/nnrpd/perm.c Thu Sep 27 20:13:35 2001
@@ -7,6 +7,8 @@
#include "clibrary.h"
#include <netinet/in.h>
#include <arpa/inet.h>
+#include <sys/types.h>
+#include <sys/socket.h>
#include <netdb.h>
#include <signal.h>
@@ -1688,24 +1690,43 @@
static void GetConnInfo(METHOD *method, char *buf)
{
- struct sockaddr_in cli, loc;
+ struct sockaddr_in6 cli, loc;
int gotsin;
int i;
+ int cliport,locport;
+ char locaddr[80];
ARGTYPE j;
- j = sizeof(cli);
- gotsin = (getpeername(0, (struct sockaddr*)&cli, &j) == 0);
+ j = sizeof(struct sockaddr_in6);
+ gotsin = (getpeername(0, (struct sockaddr *)&cli, &j) == 0);
if (gotsin)
- getsockname(0, (struct sockaddr*)&loc, &j);
+ getsockname(0, (struct sockaddr *)&loc, &j);
+
+ if (gotsin){
+ if (((struct sockaddr*)&cli)->sa_family==AF_INET6)
+ cliport=ntohs(((struct sockaddr_in6 *)&cli)->sin6_port);
+ else
+ cliport=ntohs(((struct sockaddr_in *)&cli)->sin_port);
+
+ if (((struct sockaddr*)&loc)->sa_family==AF_INET6){
+ locport=ntohs(((struct sockaddr_in6 *)&loc)->sin6_port);
+ inet_ntop(AF_INET6,&((struct sockaddr_in6 *)&loc)->sin6_addr,locaddr,80);
+ }
+ else{
+ locport=ntohs(((struct sockaddr_in *)&loc)->sin_port);
+ inet_ntop(AF_INET,&((struct sockaddr_in *)&loc)->sin_addr,locaddr,80);
+ }
+ }
+
buf[0] = '\0';
if (*ClientHost)
sprintf(buf, "ClientHost: %s\r\n", ClientHost);
if (*ClientIp)
sprintf(buf+strlen(buf), "ClientIP: %s\r\n", ClientIp);
if (gotsin) {
- sprintf(buf+strlen(buf), "ClientPort: %d\r\n", ntohs(cli.sin_port));
- sprintf(buf+strlen(buf), "LocalIP: %s\r\n", inet_ntoa(loc.sin_addr));
- sprintf(buf+strlen(buf), "LocalPort: %d\r\n", ntohs(loc.sin_port));
+ sprintf(buf+strlen(buf), "ClientPort: %d\r\n", cliport);
+ sprintf(buf+strlen(buf), "LocalIP: %s\r\n", locaddr);
+ sprintf(buf+strlen(buf), "LocalPort: %d\r\n", locport);
}
/* handle this here, since we only get here when we're about to exec
* something. */
Więcej informacji o liście dyskusyjnej pld-devel-pl