1 /* password.c get passwords from user
2 * Copyright (C) 2002, 2003 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi 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 * Shishi 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 Shishi; if not, write to the Free Software
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 /* XXX? zeroize password */
25 #ifdef WITH_STRINGPREP
26 #include <stringprep.h>
27 #include <stringprep_kerberos5.h>
30 #if defined (HAVE_TERMIOS_H)
35 tty_set_echo (int echo
)
37 struct termios termios_p
;
38 int fd
= fileno (stdin
);
40 if (tcgetattr (fd
, &termios_p
) != 0)
41 return SHISHI_TTY_ERROR
;
44 termios_p
.c_lflag
|= ECHO
;
46 termios_p
.c_lflag
&= ~ECHO
;
48 if (tcsetattr (fd
, TCSANOW
, &termios_p
) != 0)
49 return SHISHI_TTY_ERROR
;
56 mail simon @ josefsson
.org
and tell what system
this is
65 tty_noecho (int signum
)
71 shishi_read_password (FILE * fh
, char *s
, int size
)
75 rc
= tty_set_echo (0);
80 signal (SIGQUIT
, tty_echo
);
81 signal (SIGCONT
, tty_noecho
);
85 s
[strlen (s
) - 1] = '\0';
88 signal (SIGQUIT
, SIG_DFL
);
89 signal (SIGCONT
, SIG_DFL
);
92 rc
= tty_set_echo (1);
100 shishi_prompt_password_raw (FILE * in
, char *s
, int size
,
101 FILE * out
, char *format
, ...)
106 va_start (ap
, format
);
107 vfprintf (out
, format
, ap
);
111 rc
= shishi_read_password (in
, s
, size
);
119 shishi_prompt_password (Shishi
* handle
,
120 FILE * in
, char *s
, int size
,
121 FILE * out
, char *format
, ...)
127 #ifdef WITH_STRINGPREP
128 if (VERBOSE (handle
))
130 printf ("Libstringprep thinks your locale is `%s'.\n",
131 stringprep_locale_charset ());
135 va_start (ap
, format
);
136 vfprintf (out
, format
, ap
);
140 rc
= shishi_read_password (in
, s
, size
);
147 if (VERBOSE (handle
))
150 printf ("Read password (length %d): ", strlen (s
));
151 for (i
= 0; i
< strlen (s
); i
++)
152 printf ("%02x ", s
[i
] & 0xFF);
156 if (handle
->stringprocess
157 && strcasecmp (handle
->stringprocess
, "none") != 0)
158 #ifdef WITH_STRINGPREP
160 if (strcasecmp (handle
->stringprocess
, "stringprep") == 0)
161 p
= stringprep_locale_to_utf8 (s
);
163 p
= stringprep_convert (s
, handle
->stringprocess
,
164 stringprep_locale_charset ());
168 strncpy (s
, p
, size
);
173 if (VERBOSE (handle
))
176 printf ("Password converted to %s (length %d): ",
177 strcasecmp (handle
->stringprocess
, "stringprep") == 0 ?
178 "UTF-8" : handle
->stringprocess
, strlen (s
));
179 for (i
= 0; i
< strlen (s
); i
++)
180 printf ("%02x ", s
[i
] & 0xFF);
184 if (strcasecmp (handle
->stringprocess
, "stringprep") == 0)
186 rc
= stringprep_kerberos5 (s
, size
);
190 if (VERBOSE (handle
))
193 printf ("Stringprep'ed password (length %d): ", strlen (s
));
194 for (i
= 0; i
< strlen (s
); i
++)
195 printf ("%02x ", s
[i
] & 0xFF);
202 shishi_warn (handle
, "Password string processing (%s) disabled",
203 handle
->stringprocess
);