@@ -3086,6 +3086,7 @@ static void usage(const char *argv0, const char *cmd)
3086
3086
printf ("%1s [ -askpass ]" , "" );
3087
3087
#endif /* PROVIDE_ASKPASS */
3088
3088
printf ("%1s[ -readpass <file> ]\n" , "" );
3089
+ printf ("%12s(use \"-\" with readpass to read from stdin)\n" , "" );
3089
3090
printf ("%12s[ -ac <crosscertfile> ]\n" , "" );
3090
3091
printf ("%12s[ -h {md5,sha1,sha2(56),sha384,sha512} ]\n" , "" );
3091
3092
printf ("%12s[ -n <desc> ] [ -i <url> ] [ -jp <level> ] [ -comm ]\n" , "" );
@@ -3425,39 +3426,43 @@ static char *getpassword(const char *prompt)
3425
3426
*/
3426
3427
static int read_password (GLOBAL_OPTIONS * options )
3427
3428
{
3428
- char passbuf [4096 ];
3429
+ char passbuf [4096 ] = { 0 } ;
3429
3430
int passlen ;
3430
3431
const u_char utf8_bom [] = {0xef , 0xbb , 0xbf };
3431
3432
3432
3433
if (options -> readpass ) {
3434
+ if (!strcmp (options -> readpass , "-" )) {
3435
+ passlen = read (fileno (stdin ), passbuf , sizeof (passbuf )- 1 );
3436
+ } else {
3433
3437
#ifdef WIN32
3434
- HANDLE fhandle , fmap ;
3435
- LPVOID faddress ;
3436
- fhandle = CreateFile (options -> readpass , GENERIC_READ , FILE_SHARE_READ , NULL , OPEN_EXISTING , 0 , NULL );
3437
- if (fhandle == INVALID_HANDLE_VALUE ) {
3438
- return 0 ; /* FAILED */
3439
- }
3440
- fmap = CreateFileMapping (fhandle , NULL , PAGE_READONLY , 0 , 0 , NULL );
3441
- if (fmap == NULL ) {
3442
- return 0 ; /* FAILED */
3443
- }
3444
- faddress = MapViewOfFile (fmap , FILE_MAP_READ , 0 , 0 , 0 );
3445
- CloseHandle (fmap );
3446
- if (faddress == NULL ) {
3447
- return 0 ; /* FAILED */
3448
- }
3449
- passlen = (int )GetFileSize (fhandle , NULL );
3450
- memcpy (passbuf , faddress , passlen );
3451
- UnmapViewOfFile (faddress );
3452
- CloseHandle (fhandle );
3438
+ HANDLE fhandle , fmap ;
3439
+ LPVOID faddress ;
3440
+ fhandle = CreateFile (options -> readpass , GENERIC_READ , FILE_SHARE_READ , NULL , OPEN_EXISTING , 0 , NULL );
3441
+ if (fhandle == INVALID_HANDLE_VALUE ) {
3442
+ return 0 ; /* FAILED */
3443
+ }
3444
+ fmap = CreateFileMapping (fhandle , NULL , PAGE_READONLY , 0 , 0 , NULL );
3445
+ if (fmap == NULL ) {
3446
+ return 0 ; /* FAILED */
3447
+ }
3448
+ faddress = MapViewOfFile (fmap , FILE_MAP_READ , 0 , 0 , 0 );
3449
+ CloseHandle (fmap );
3450
+ if (faddress == NULL ) {
3451
+ return 0 ; /* FAILED */
3452
+ }
3453
+ passlen = (int )GetFileSize (fhandle , NULL );
3454
+ memcpy (passbuf , faddress , passlen );
3455
+ UnmapViewOfFile (faddress );
3456
+ CloseHandle (fhandle );
3453
3457
#else /* WIN32 */
3454
- int passfd = open (options -> readpass , O_RDONLY );
3455
- if (passfd < 0 ) {
3456
- return 0 ; /* FAILED */
3457
- }
3458
- passlen = (int )read (passfd , passbuf , sizeof passbuf - 1 );
3459
- close (passfd );
3458
+ int passfd = open (options -> readpass , O_RDONLY );
3459
+ if (passfd < 0 ) {
3460
+ return 0 ; /* FAILED */
3461
+ }
3462
+ passlen = (int )read (passfd , passbuf , sizeof passbuf - 1 );
3463
+ close (passfd );
3460
3464
#endif /* WIN32 */
3465
+ }
3461
3466
if (passlen <= 0 ) {
3462
3467
return 0 ; /* FAILED */
3463
3468
}
0 commit comments