1 #pragma ident "%Z%%M% %I% %E% SMI"
3 * promptusr.c --- prompt user for input/output
18 typedef struct _krb5_uio
{
23 struct _krb5_uio
*next
;
26 #define KRB5_UIO_GETRESPONSE 0x0001
27 #define KRB5_UIO_ECHORESPONSE 0x0002
28 #define KRB5_UIO_FREE_PROMPT 0x0004
30 static jmp_buf pwd_jump
;
34 intr_routine(int signo
)
42 krb5_os_get_tty_uio(krb5_context context
, krb5_uio uio
)
44 volatile krb5_error_code retval
;
45 krb5_sigtype (*volatile ointrfunc
)();
47 struct termios echo_control
, save_control
;
49 char read_string
[BUFSIZ
];
53 /* get the file descriptor associated with stdin */
56 if (tcgetattr(fd
, &echo_control
) == -1)
59 save_control
= echo_control
;
60 echo_control
.c_lflag
&= ~(ECHO
|ECHONL
);
62 if (setjmp(pwd_jump
)) {
63 retval
= KRB5_LIBOS_PWDINTR
; /* we were interrupted... */
67 ointrfunc
= signal(SIGINT
, intr_routine
);
69 for (p
= uio
; p
; p
= p
->next
) {
71 fputs(p
->prompt
, stdout
);
74 if ((p
->flags
& KRB5_UIO_GETRESPONSE
) == 0)
77 if ((p
->flags
& KRB5_UIO_ECHORESPONSE
) == 0)
78 if (tcsetattr(fd
, TCSANOW
, &echo_control
) == -1)
81 if (fgets(read_string
, sizeof(read_string
), stdin
) == NULL
) {
83 retval
= KRB5_LIBOS_CANTREADPWD
;
87 /* replace newline with null */
88 if ((cp
= strchr(read_string
, '\n')))
90 else /* flush rest of input line */
93 } while (ch
!= EOF
&& ch
!= '\n');
94 read_string
[sizeof(read_string
)-1] = 0;
96 if ((p
->response
= malloc(strlen(read_string
)+1)) == NULL
) {
100 strcpy(p
->response
, read_string
);
102 if ((p
->flags
& KRB5_UIO_ECHORESPONSE
) == 0) {
103 (void) putchar('\n');
104 if (tcsetattr(fd
, TCSANOW
, &save_control
) == -1) {
113 (void) signal(SIGINT
, ointrfunc
);
115 for (p
= uio
; p
; p
= p
->next
) {
117 memset(p
->response
, 0, strlen(p
->response
));
123 memset(read_string
, 0, sizeof(read_string
));
124 tcsetattr(fd
, TCSANOW
, &save_control
);
130 krb5_free_uio(krb5_context context
, krb5_uio uio
)
134 for (p
= uio
; p
; p
= next
) {
136 if (p
->prompt
&& (p
->flags
& KRB5_UIO_FREE_PROMPT
))
146 struct _krb5_uio uio_a
= { 0, KRB5_UIO_GETRESPONSE
, "Password 1: " };
147 struct _krb5_uio uio_b
= { 0, KRB5_UIO_GETRESPONSE
|
148 KRB5_UIO_ECHORESPONSE
, "Password 2: " };
149 struct _krb5_uio uio_c
= { 0, KRB5_UIO_GETRESPONSE
, "Password 3: " };
153 main(int argc
, char **argv
)
158 krb5_os_get_tty_uio(0, &uio_a
);