1 /* password.c --- Get passwords from user.
2 * Copyright (C) 2002, 2003, 2004, 2005, 2007 Simon Josefsson
4 * This file is part of Shishi.
6 * Shishi is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
11 * Shishi is distributed in the hope that it will be useful, but
12 * 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, see http://www.gnu.org/licenses or write
18 * to the Free Software Foundation, Inc., 51 Franklin Street, Fifth
19 * Floor, Boston, MA 02110-1301, USA
23 /* XXX? zeroize password */
30 # include <stringprep.h>
34 * shishi_prompt_password:
35 * @handle: shishi handle as allocated by shishi_init().
36 * @s: pointer to newly allocated output string with read password.
37 * @format: printf(3) style format string.
38 * @...: printf(3) style arguments.
40 * Format and print a prompt, and read a password from user. The
41 * password is possibly converted (e.g., converted from Latin-1 to
42 * UTF-8, or processed using Stringprep profile) following any
43 * 'stringprocess' keywords in configuration files.
45 * Return value: Returns SHISHI_OK iff successful.
48 shishi_prompt_password (Shishi
* handle
, char **s
, const char *format
, ...)
56 printf ("Libstringprep thinks your locale is `%s'.\n",
57 stringprep_locale_charset ());
61 va_start (ap
, format
);
72 if (VERBOSENOISE (handle
))
75 printf ("Read password (length %d): ", strlen (*s
));
76 for (i
= 0; i
< strlen (*s
); i
++)
77 printf ("%02x ", (*s
)[i
] & 0xFF);
81 if (handle
->stringprocess
82 && strcasecmp (handle
->stringprocess
, "none") != 0)
85 if (strcasecmp (handle
->stringprocess
, "stringprep") == 0)
86 p
= stringprep_locale_to_utf8 (*s
);
88 p
= stringprep_convert (*s
, handle
->stringprocess
,
89 stringprep_locale_charset ());
97 shishi_warn (handle
, "Charset conversion of password failed");
99 if (VERBOSENOISE (handle
))
102 printf ("Password converted to %s (length %d): ",
103 strcasecmp (handle
->stringprocess
, "stringprep") == 0 ?
104 "UTF-8" : handle
->stringprocess
, strlen (*s
));
105 for (i
= 0; i
< strlen (*s
); i
++)
106 printf ("%02x ", (*s
)[i
] & 0xFF);
110 if (strcasecmp (handle
->stringprocess
, "stringprep") == 0)
114 rc
= stringprep_profile (*s
, &p
, "SASLprep", 0);
121 shishi_warn (handle
, "Stringprep conversion of password failed");
123 if (VERBOSENOISE (handle
))
126 printf ("Stringprep'ed password (length %d): ", strlen (*s
));
127 for (i
= 0; i
< strlen (*s
); i
++)
128 printf ("%02x ", (*s
)[i
] & 0xFF);
135 shishi_warn (handle
, "Password string processing (%s) disabled",
136 handle
->stringprocess
);