#include #include #include #include #include #include #if defined (linux) #define LOCAL_MAJOR 4 #endif #if defined(__FreeBSD__) || defined(__OpenBSD__) || defined(__NetBSD__) #define LOCAL_MAJOR 12 #endif #define EXECNAME "/usr/bin/ssh" #define MAXUSERNAME 20 int main() { char user[MAXUSERNAME+2]; char* p; char *login; struct stat tty_stat; extern int errno; if( fstat( 0, &tty_stat ) < 0 ) { perror( "fstat()" ); return 1; }; if( ( tty_stat.st_mode & S_IFCHR ) == 0 ) { fprintf (stderr, "Running not from a character device!\n"); return 1; }; if((255 & (tty_stat.st_rdev >> 8)) != LOCAL_MAJOR ) { fprintf( stderr, "Only local forwarding allowed\n" ); return 1; }; if ((login=getlogin())==NULL) { fprintf(stderr, "getlogin() failed, bailing out\n"); return 1; }; printf( "login @ %s: ", login ); fflush( stdout ); if( fgets( user, sizeof user, stdin ) == NULL ) return 1; if( ( p = strchr( user, '\n' ) ) == NULL ) { fprintf( stderr, "Name too long\n" ); return 1; } *p = 0; fflush( NULL ); (void) execlp(EXECNAME,EXECNAME,"-C","-cblowfish","-enone","-l", user,login,(char *) 0); perror("execlp()"); _exit( 1 ); }