/* * Cleaned/adjusted for Linux (Fedora Core 19) by Dr. Peter Bieringer * * Build: * gcc -Wall -fPIC -c getpass_from_stdin.c * gcc -shared -Wl,-soname,getpass_from_stdin.so -o getpass_from_stdin.so getpass_from_stdin.o * Usage: * export LD_PRELOAD=/getpass_from_stdin.so * * based on (found at http://www.linuxmisc.com/3-linux/3e9ea6245c8db542.htm) ** $ver: getpass_from_stdin.c 1.1 (24.10.2000) ** Written by Roland.Ma...@informatik.med.uni-giessen.de ** ** Usage: ** cc -c -g -Xc getpass_from_stdin.c -ldl -o getpass_from_stdin.o ** export LD_PRELOAD= ** */ #include #include #include #include #ifndef PASS_MAX #define PASS_MAX _SC_PASS_MAX #endif #if PASS_MAX > 256 #ifdef __sun /* confusing: manpage for getpass says PASS_MAX (which is 8) * but code uses 9 (=_SC_PASS_MAX) */ #define MY_PASS_MAX (_SC_PASS_MAX) #else #define MY_PASS_MAX (PASS_MAX) #endif #else #define MY_PASS_MAX (256) #endif static char static_buffer[MY_PASS_MAX+2]; static char *getpass_from_stdin( const char *prompt, const int maxlength ) { fprintf( stdout, "%s", prompt ); fflush( stdout ); /* be nice to buggy apps. */ static_buffer[0] = '\0'; /* both getpass and getpassphrase are mt-unsafe, therefore we can use a static buffer here */ return( fgets( static_buffer, maxlength+1, stdin ) ); }; char *getpass( const char *prompt ) { char *retval; retval = getpass_from_stdin( prompt, PASS_MAX ); return( retval ); }; /* identical to getpass() except it returns up to 256 intead of PASS_MAX */ char *getpassphrase( const char *prompt ) { char *retval; retval = getpass_from_stdin( prompt, 256 ); return( retval ); };