// Copyright 2003 Data Helper, Inc. // This program is realeased under the // GNU GENERAL PUBLIC LICENSE Version 2. // See COPYING.GPL for information. // Mark Willcox // Run this before qmail-smtpd. If the IP address has been // vetted by postpop, we'll set RELAYCLIENT. // If anything is wrong, just go on without setting RELAYCLIENT. #include "postpop.h" #include #include #include #include #include #include #include #include int main(int argc, char **argv) { if (argc < 2) _exit( 2 ); checkAuth(); execvp(argv[1],argv + 1); _exit(111); return 0; } int checkAuth() { int dot; char ip[16]; char *lastDot; char fn[PATH_MAX]; struct stat finfo; if (! getenv( "TCPREMOTEIP")) return; if (strlen( getenv( "TCPREMOTEIP")) > 15) return; strncpy( ip, getenv( "TCPREMOTEIP" ), 16 ); if (strlen( ip ) < 7) return; strcpy( fn, IP_DIR ); for (dot = 0; dot < DIR_DEPTH; ++dot) { lastDot = strrchr( ip, '.' ); if (! lastDot) return; *lastDot++ = '\0'; strcat( fn, lastDot ); strcat( fn, "/" ); } strcat( fn, ip ); if (stat( fn, &finfo ) == -1 ) return; if ((time( NULL ) - finfo.st_mtime) > AUTH_LIFE ) return; putenv( "RELAYCLIENT=" ); }