25 #if defined(LIBC_SCCS) && !defined(lint)
26 static const char rcsid[] =
"$OpenBSD: readpassphrase.c,v 1.16 2003/06/17 21:56:23 millert Exp $";
31 #ifndef HAVE_READPASSPHRASE
58 #ifdef HAVE_SYS_TYPES_H
59 #include <sys/types.h>
62 #ifdef HAVE_SYS_STAT_H
74 #if !defined(_WIN32) && !defined(_WIN64)
78 # define _PATH_TTY "/dev/tty"
82 # define _T_FLUSH (TCSAFLUSH|TCSASOFT)
84 # define _T_FLUSH (TCSAFLUSH)
88 #if !defined(_POSIX_VDISABLE) && defined(VDISABLE)
89 # define _POSIX_VDISABLE VDISABLE
92 static volatile sig_atomic_t
signo;
102 struct termios term, oterm;
103 struct sigaction sa, savealrm, saveint, savehup, savequit, saveterm;
104 struct sigaction savetstp, savettin, savettou, savepipe;
133 sigemptyset(&sa.sa_mask);
136 (void)sigaction(SIGALRM, &sa, &savealrm);
137 (void)sigaction(SIGHUP, &sa, &savehup);
138 (void)sigaction(SIGINT, &sa, &saveint);
139 (void)sigaction(SIGPIPE, &sa, &savepipe);
140 (void)sigaction(SIGQUIT, &sa, &savequit);
141 (void)sigaction(SIGTERM, &sa, &saveterm);
142 (void)sigaction(SIGTSTP, &sa, &savetstp);
143 (void)sigaction(SIGTTIN, &sa, &savettin);
144 (void)sigaction(SIGTTOU, &sa, &savettou);
148 memcpy(&term, &oterm,
sizeof(term));
150 term.c_lflag &= ~(
ECHO | ECHONL);
152 if (term.c_cc[VSTATUS] != _POSIX_VDISABLE)
153 term.c_cc[VSTATUS] = _POSIX_VDISABLE;
157 memset(&term, 0,
sizeof(term));
158 term.c_lflag |=
ECHO;
159 memset(&oterm, 0,
sizeof(oterm));
160 oterm.c_lflag |=
ECHO;
164 (void)write(
output, prompt, strlen(prompt));
165 end =
buf + bufsiz - 1;
166 for (p =
buf; (nr = read(
input, &ch, 1)) == 1 && ch !=
'\n' && ch !=
'\r';) {
170 if (
isalpha((
unsigned char) ch)) {
172 ch =
tolower((
unsigned char) ch);
174 ch =
toupper((
unsigned char) ch);
181 if (!(term.c_lflag &
ECHO))
182 (
void)write(
output,
"\n", 1);
185 if (memcmp(&term, &oterm,
sizeof(term)) != 0)
187 (void)sigaction(SIGALRM, &savealrm,
NULL);
188 (void)sigaction(SIGHUP, &savehup,
NULL);
189 (void)sigaction(SIGINT, &saveint,
NULL);
190 (void)sigaction(SIGQUIT, &savequit,
NULL);
191 (void)sigaction(SIGPIPE, &savepipe,
NULL);
192 (void)sigaction(SIGTERM, &saveterm,
NULL);
193 (void)sigaction(SIGTSTP, &savetstp,
NULL);
194 (void)sigaction(SIGTTIN, &savettin,
NULL);
203 kill(getpid(),
signo);
218 getpass(
const char *prompt)
220 static char buf[_PASSWORD_LEN + 1];
246 printf(
"%s", prompt);
249 for (p =
buf; (ch = getchar()) != EOF && ch !=
'\n' && ch !=
'\r';) {
267 return (ch == EOF ?
NULL :
buf);
constexpr auto end(const ct_const_array< T, N > &in) noexcept
static SQLCHAR output[256]
char * tds_readpassphrase(const char *prompt, char *buf, size_t bufsiz, int flags)
static volatile sig_atomic_t signo
static char const rcsid[]