1/*********************************************************************** 2* * 3* This software is part of the ast package * 4* Copyright (c) 1985-2011 AT&T Intellectual Property * 5* and is licensed under the * 6* Eclipse Public License, Version 1.0 * 7* by AT&T Intellectual Property * 8* * 9* A copy of the License is available at * 10* http://www.eclipse.org/org/documents/epl-v10.html * 11* (with md5 checksum b35adb5213ca9657e911e9befb180842) * 12* * 13* Information and Software Systems Research * 14* AT&T Research * 15* Florham Park NJ * 16* * 17* Glenn Fowler <gsf@research.att.com> * 18* David Korn <dgk@research.att.com> * 19* Phong Vo <kpv@research.att.com> * 20* * 21***********************************************************************/ 22#include "FEATURE/uwin" 23 24#if !_UWIN || _lib_getpass 25 26void _STUB_getpass(){} 27 28#else 29 30#pragma prototyped 31 32#define getpass ______getpass 33 34#include <ast.h> 35#include <termios.h> 36#include <signal.h> 37 38#undef getpass 39 40#if defined(__EXPORT__) 41#define extern __EXPORT__ 42#endif 43 44static int interrupt; 45static void handler(int sig) 46{ 47 interrupt++; 48} 49 50extern char* getpass(const char *prompt) 51{ 52 struct termios told,tnew; 53 Sfio_t *iop; 54 static char *cp, passwd[32]; 55 void (*savesig)(int); 56 if(!(iop = sfopen((Sfio_t*)0, "/dev/tty", "r"))) 57 return(0); 58 if(tcgetattr(sffileno(iop),&told) < 0) 59 return(0); 60 interrupt = 0; 61 tnew = told; 62 tnew.c_lflag &= ~(ECHO|ECHOE|ECHOK|ECHONL); 63 if(tcsetattr(sffileno(iop),TCSANOW,&tnew) < 0) 64 return(0); 65 savesig = signal(SIGINT, handler); 66 sfputr(sfstderr,prompt,-1); 67 if(cp = sfgetr(iop,'\n',1)) 68 strncpy(passwd,cp,sizeof(passwd)-1); 69 tcsetattr(sffileno(iop),TCSANOW,&told); 70 sfputc(sfstderr,'\n'); 71 sfclose(iop); 72 signal(SIGINT, savesig); 73 if(interrupt) 74 kill(getpid(),SIGINT); 75 return(cp?passwd:0); 76} 77 78 79#endif 80