4
* Copyright (c) 1996-1997 by Alexander V. Lukyanov (lav@yars.free.net)
6
* This program is free software; you can redistribute it and/or modify
7
* it under the terms of the GNU General Public License as published by
8
* the Free Software Foundation; either version 2 of the License, or
9
* (at your option) any later version.
11
* This program is distributed in the hope that it will be useful,
12
* but WITHOUT ANY WARRANTY; without even the implied warranty of
13
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
* GNU General Public License for more details.
16
* You should have received a copy of the GNU General Public License
17
* along with this program; if not, write to the Free Software
18
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
29
#include "CharReader.h"
30
#include "SignalHook.h"
32
char *GetPass(const char *prompt)
34
static char *oldpass=0;
47
tty_fd=open("/dev/tty",O_RDONLY);
49
fcntl(tty_fd,F_SETFD,FD_CLOEXEC);
60
write(tty_fd,prompt,strlen(prompt));
64
tcgetattr(tty_fd,&tc);
65
tcflag_t old_lflag=tc.c_lflag;
67
tcsetattr(tty_fd,TCSANOW,&tc);
69
oldpass=readline_from_file(f);
72
tcsetattr(tty_fd,TCSANOW,&tc);
74
write(tty_fd,"\r\n",2);
79
char *readline_from_file(FILE *f)
82
char *line=(char*)xmalloc(size);
88
CharReader r(fileno(f));
97
if(SignalHook::GetCount(SIGINT)>0)
103
if(c==r.EOFCHAR && ptr==line)
108
if(c==r.EOFCHAR || c=='\n')
116
line=(char*)xrealloc(line,size);