diff -u qmail-1.03/Makefile qmail-1.03-devel/Makefile --- qmail-1.03/Makefile Mon Jun 15 06:53:16 1998 +++ qmail-1.03-devel/Makefile Sun Apr 21 17:06:52 2002 @@ -783,18 +783,18 @@ ipme.o: \ compile ipme.c hassalen.h byte.h ip.h ipalloc.h ip.h gen_alloc.h \ -stralloc.h gen_alloc.h ipme.h ip.h ipalloc.h +stralloc.h gen_alloc.h ipme.h ip.h ipalloc.h readwrite.h ./compile ipme.c ipmeprint: \ -load ipmeprint.o ipme.o ip.o ipalloc.o stralloc.a alloc.a substdio.a \ +load ipmeprint.o ipme.o ip.o ipalloc.o auto_qmail.o open.a getln.a stralloc.a alloc.a substdio.a \ error.a str.a fs.a socket.lib - ./load ipmeprint ipme.o ip.o ipalloc.o stralloc.a alloc.a \ + ./load ipmeprint ipme.o ip.o ipalloc.o auto_qmail.o open.a getln.a stralloc.a alloc.a \ substdio.a error.a str.a fs.a `cat socket.lib` ipmeprint.o: \ compile ipmeprint.c subfd.h substdio.h substdio.h ip.h ipme.h ip.h \ -ipalloc.h ip.h gen_alloc.h exit.h +ipalloc.h ip.h gen_alloc.h exit.h auto_qmail.h ./compile ipmeprint.c it: \ diff -u qmail-1.03/ipme.c qmail-1.03-devel/ipme.c --- qmail-1.03/ipme.c Mon Jun 15 06:53:16 1998 +++ qmail-1.03-devel/ipme.c Sun Apr 21 17:12:37 2002 @@ -14,6 +14,8 @@ #include "ipalloc.h" #include "stralloc.h" #include "ipme.h" +#include "substdio.h" +#include "readwrite.h" static int ipmeok = 0; ipalloc ipme = {0}; @@ -31,6 +33,12 @@ static stralloc buf = {0}; +#define ipme_init_retclean(ret) { \ + if (notipme.ix) alloc_free(notipme.ix); \ + if (moreipme.ix) alloc_free(moreipme.ix); \ + if (buf.s) alloc_free(buf.s); \ + return ret; } + int ipme_init() { struct ifconf ifc; @@ -40,17 +48,31 @@ int len; int s; struct ip_mx ix; - + ipalloc notipme = {0}; + ipalloc moreipme = {0}; + int i; + if (ipmeok) return 1; - if (!ipalloc_readyplus(&ipme,0)) return 0; + if (!ipalloc_readyplus(&ipme,0)) ipme_init_retclean(0); + if (!ipalloc_readyplus(¬ipme,0)) ipme_init_retclean(0); + if (!ipalloc_readyplus(&moreipme,0)) ipme_init_retclean(0); ipme.len = 0; ix.pref = 0; - - if ((s = socket(AF_INET,SOCK_STREAM,0)) == -1) return -1; + + if (!ipme_readipfile(¬ipme, "control/notipme")) ipme_init_retclean(0); + + /* 0.0.0.0 is a special address which always refers to + * "this host, this network", according to RFC 1122, Sec. 3.2.1.3a. + */ + byte_copy(&ix.ip,4,"\0\0\0\0"); + + if (!ipme_append_unless(&ix,¬ipme)) ipme_init_retclean(0); + + if ((s = socket(AF_INET,SOCK_STREAM,0)) == -1) ipme_init_retclean(-1); len = 256; for (;;) { - if (!stralloc_ready(&buf,len)) { close(s); return 0; } + if (!stralloc_ready(&buf,len)) { close(s); ipme_init_retclean(0); } buf.len = 0; ifc.ifc_buf = buf.s; ifc.ifc_len = len; @@ -59,7 +81,7 @@ buf.len = ifc.ifc_len; break; } - if (len > 200000) { close(s); return -1; } + if (len > 200000) { close(s); ipme_init_retclean(-1); } len += 100 + (len >> 2); } x = buf.s; @@ -74,7 +96,7 @@ byte_copy(&ix.ip,4,&sin->sin_addr); if (ioctl(s,SIOCGIFFLAGS,x) == 0) if (ifr->ifr_flags & IFF_UP) - if (!ipalloc_append(&ipme,&ix)) { close(s); return 0; } + if (!ipme_append_unless(&ix,¬ipme)) { close(s); ipme_init_retclean(0); } } #else len = sizeof(*ifr); @@ -84,12 +106,55 @@ if (ifr->ifr_addr.sa_family == AF_INET) { sin = (struct sockaddr_in *) &ifr->ifr_addr; byte_copy(&ix.ip,4,&sin->sin_addr); - if (!ipalloc_append(&ipme,&ix)) { close(s); return 0; } + if (!ipme_append_unless(&ix,¬ipme)) { close(s); ipme_init_retclean(0); } } #endif x += len; } close(s); + + if (!ipme_readipfile(&moreipme, "control/moreipme")) ipme_init_retclean(0); + for(i = 0;i < moreipme.len;++i) + if (!ipme_append_unless(&moreipme.ix[i],¬ipme)) ipme_init_retclean(0); + ipmeok = 1; - return 1; + ipme_init_retclean(1); +} + + +int ipme_readipfile(ipa, fn) + ipalloc *ipa; + char *fn; +{ + int fd = -1; + char inbuf[1024]; + substdio ss; + stralloc l = {0}; + int match; + struct ip_mx ix; + int ret = 1; + + if ( (fd = open_read(fn)) != -1) { + substdio_fdbuf(&ss, read, fd, inbuf, sizeof(inbuf)); + while ( (getln(&ss,&l,&match,'\n') != -1) && (match || l.len) ) { + l.len--; + if (!stralloc_0(&l)) { ret = 0; break; } + if (!ip_scan(l.s, &ix.ip)) continue; + if (!ipalloc_append(ipa,&ix)) { ret = 0; break; } + } + if (l.s) alloc_free(l.s); + if ( (fd >= 0) && (close(fd) == -1) ) + ret = 0; + } + return ret; +} + +int ipme_append_unless(ix, notip) + struct ip_mx *ix; + struct ipalloc *notip; +{ + int i; + for (i = 0;i < notip->len;++i) + if (byte_equal(¬ip->ix[i].ip,4,&ix->ip)) return 1; + return ipalloc_append(&ipme, ix); } diff -u qmail-1.03/ipmeprint.c qmail-1.03-devel/ipmeprint.c --- qmail-1.03/ipmeprint.c Mon Jun 15 06:53:16 1998 +++ qmail-1.03-devel/ipmeprint.c Sun Apr 21 16:03:25 2002 @@ -3,12 +3,15 @@ #include "ip.h" #include "ipme.h" #include "exit.h" +#include "auto_qmail.h" char temp[IPFMT]; void main() { int j; + + chdir(auto_qmail); switch(ipme_init()) { case 0: substdio_putsflush(subfderr,"out of memory\n"); _exit(111); diff -u qmail-1.03/qmail-showctl.c qmail-1.03-devel/qmail-showctl.c --- qmail-1.03/qmail-showctl.c Mon Jun 15 06:53:16 1998 +++ qmail-1.03-devel/qmail-showctl.c Sun Apr 21 16:03:25 2002 @@ -230,6 +230,8 @@ do_str("localiphost",1,"localiphost","Local IP address becomes "); do_lst("locals","Messages for me are delivered locally.","Messages for "," are delivered locally."); do_str("me",0,"undefined! Uh-oh","My name is "); + do_lst("moreipme","No additional IP addresses are me.","IP address "," is me."); + do_lst("notipme","All of my IP addresses are me.","IP address "," is not me."); do_lst("percenthack","The percent hack is not allowed.","The percent hack is allowed for user%host@","."); do_str("plusdomain",1,"plusdomain","Plus domain name is "); do_lst("qmqpservers","No QMQP servers.","QMQP server: ","."); @@ -283,8 +285,10 @@ if (str_equal(d->d_name,"localiphost")) continue; if (str_equal(d->d_name,"locals")) continue; if (str_equal(d->d_name,"me")) continue; + if (str_equal(d->d_name,"moreipme")) continue; if (str_equal(d->d_name,"morercpthosts")) continue; if (str_equal(d->d_name,"morercpthosts.cdb")) continue; + if (str_equal(d->d_name,"notipme")) continue; if (str_equal(d->d_name,"percenthack")) continue; if (str_equal(d->d_name,"plusdomain")) continue; if (str_equal(d->d_name,"qmqpservers")) continue;