// 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 after the POP connection is authenticated. #include #include #include #include #include #include #include // The following are defined at compile time: // PASSWD The file containing the required password, if any. // IP_DIR The directory were the IP address files go. // DIR_DEPTH Number of nodes to use as subdirectores. int main( int argc, char **argv ) { int fp; int dot; char ip[16]; char *lastDot; int havePwd; char fn[PATH_MAX]; char passwd[65]; FILE *pwf; // Are we expecting a password? havePwd = ( strlen( PASSWD ) > 0 ); // Do we have enough arguments? Optional password, next program. if (argc < (havePwd ? 3 : 2)) _exit( 2 ); // If we expect a password, check it. If we don't get it, assume // someone is messing with us. if( havePwd ) { pwf = fopen( PASSWD, "r" ); if( ! pwf ) _exit( 2 ); fgets( passwd, 64, pwf ); fclose( pwf ); if( strncmp( argv[1], passwd, strlen( passwd ) - 1 ) != 0 ) { puts( passwd); puts( "Security Violation: The postal police have been notified." ); _exit( 2 ); } } // Is the IP address there? (If not, you need to run tcp-env first!) if (! getenv( "TCPREMOTEIP")) _exit( 2 ); // Sanity check on the IP address. if (strlen( getenv( "TCPREMOTEIP")) > 15) _exit( 2 ); // Grab the IP and make sure it's at LEAST the length of "0.0.0.0". strncpy( ip, getenv( "TCPREMOTEIP" ), 16 ); if (strlen( ip ) < 7) _exit( 2 ); // Base path. The place where the IP addres files go. strcpy( fn, IP_DIR ); // If we're breaking the addresses out into subdirectories, take // the requested number of nodes and add them. for (dot = 0; dot < DIR_DEPTH; ++dot) { lastDot = strrchr( ip, '.' ); if (! lastDot) _exit( 2 ); *lastDot++ = '\0'; strcat( fn, lastDot ); // Make sure there's a directory at each level. mkdir( fn, 0755 ); strcat( fn, "/" ); } // Add the IP address at the end. strcat( fn, ip ); // Touch the file. fp = creat( fn, S_IRWXU | S_IRGRP | S_IROTH ); close( fp ); // Run the next thing. if( havePwd ) execvp(argv[2],argv + 2); else execvp(argv[1],argv + 1); _exit(111); return 0; }