1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
22 #include "FEATURE/uwin"
24 #if !_UWIN || _lib_getpass
26 void _STUB_getpass(){}
32 #define getpass ______getpass
40 #if defined(__EXPORT__)
41 #define extern __EXPORT__
45 static void handler(int sig
)
50 extern char* getpass(const char *prompt
)
52 struct termios told
,tnew
;
54 static char *cp
, passwd
[32];
56 if(!(iop
= sfopen((Sfio_t
*)0, "/dev/tty", "r")))
58 if(tcgetattr(sffileno(iop
),&told
) < 0)
62 tnew
.c_lflag
&= ~(ECHO
|ECHOE
|ECHOK
|ECHONL
);
63 if(tcsetattr(sffileno(iop
),TCSANOW
,&tnew
) < 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');
72 signal(SIGINT
, savesig
);
74 kill(getpid(),SIGINT
);