1 /* $NetBSD: ui.c,v 1.1.1.2 2014/04/24 12:45:30 pettai Exp $ */
4 * Copyright (c) 1997 - 2000, 2005 Kungliga Tekniska Högskolan
5 * (Royal Institute of Technology, Stockholm, Sweden).
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the Institute nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE INSTITUTE AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE INSTITUTE OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
45 #include <krb5/roken.h>
52 static sig_atomic_t intr_flag
;
63 * Windows does console slightly different then then unix case.
67 read_string(const char *preprompt
, const char *prompt
,
68 char *buf
, size_t len
, int echo
)
73 void (*oldsigintr
)(int);
75 _cprintf("%s%s", preprompt
, prompt
);
77 oldsigintr
= signal(SIGINT
, intr
);
80 while(intr_flag
== 0){
81 c
= ((echo
)? _getche(): _getch());
82 if(c
== '\n' || c
== '\r')
86 of
= (p
== buf
+ len
);
96 signal(SIGINT
, oldsigintr
);
105 #else /* !HAVE_CONIO_H */
112 read_string(const char *preprompt
, const char *prompt
,
113 char *buf
, size_t len
, int echo
)
115 struct sigaction sigs
[NSIG
];
125 struct termios t_new
, t_old
;
127 memset(&oksigs
, 0, sizeof(oksigs
));
129 memset(&sa
, 0, sizeof(sa
));
130 sa
.sa_handler
= intr
;
131 sigemptyset(&sa
.sa_mask
);
133 for(i
= 1; i
< sizeof(sigs
) / sizeof(sigs
[0]); i
++)
135 if (sigaction(i
, &sa
, &sigs
[i
]) == 0)
138 if((tty
= fopen("/dev/tty", "r")) != NULL
)
139 rk_cloexec_file(tty
);
143 fprintf(stderr
, "%s%s", preprompt
, prompt
);
147 tcgetattr(fileno(tty
), &t_old
);
148 memcpy(&t_new
, &t_old
, sizeof(t_new
));
149 t_new
.c_lflag
&= ~ECHO
;
150 tcsetattr(fileno(tty
), TCSANOW
, &t_new
);
154 while(intr_flag
== 0){
165 of
= (p
== buf
+ len
);
172 fprintf(stderr
, "\n");
173 tcsetattr(fileno(tty
), TCSANOW
, &t_old
);
179 for(i
= 1; i
< sizeof(sigs
) / sizeof(sigs
[0]); i
++)
181 sigaction(i
, &sigs
[i
], NULL
);
192 #endif /* HAVE_CONIO_H */
195 UI_UTIL_read_pw_string(char *buf
, int length
, const char *prompt
, int verify
)
199 ret
= read_string("", prompt
, buf
, length
, 0);
205 buf2
= malloc(length
);
209 ret
= read_string("Verify password - ", prompt
, buf2
, length
, 0);
214 if (strcmp(buf2
, buf
) != 0)