Read the password from stdin if desired

Use the common convention: "-" means to use stdin

Signed-off-by: Steve McIntyre <steve.mcintyre@pexip.com>
This commit is contained in:
Steve McIntyre 2024-03-21 14:24:50 +00:00 committed by Michał Trojnara
parent 4776f43f04
commit 6ad2679f17

View File

@ -3086,6 +3086,7 @@ static void usage(const char *argv0, const char *cmd)
printf("%1s [ -askpass ]", "");
#endif /* PROVIDE_ASKPASS */
printf("%1s[ -readpass <file> ]\n", "");
printf("%12s(use \"-\" with readpass to read from stdin)\n", "");
printf("%12s[ -ac <crosscertfile> ]\n", "");
printf("%12s[ -h {md5,sha1,sha2(56),sha384,sha512} ]\n", "");
printf("%12s[ -n <desc> ] [ -i <url> ] [ -jp <level> ] [ -comm ]\n", "");
@ -3425,11 +3426,14 @@ static char *getpassword(const char *prompt)
*/
static int read_password(GLOBAL_OPTIONS *options)
{
char passbuf[4096];
char passbuf[4096] = {0};
int passlen;
const u_char utf8_bom[] = {0xef, 0xbb, 0xbf};
if (options->readpass) {
if (!strcmp(options->readpass, "-")) {
passlen = read(fileno(stdin), passbuf, sizeof(passbuf)-1);
} else {
#ifdef WIN32
HANDLE fhandle, fmap;
LPVOID faddress;
@ -3458,6 +3462,7 @@ static int read_password(GLOBAL_OPTIONS *options)
passlen = (int)read(passfd, passbuf, sizeof passbuf - 1);
close(passfd);
#endif /* WIN32 */
}
if (passlen <= 0) {
return 0; /* FAILED */
}