mirror of
git://git.gnupg.org/gnupg.git
synced 2025-04-17 15:44:34 +02:00
With --quiet do not print reading passphrase from fd message.
Fix for bug#1403. * g10/passphrase.c (read_passphrase_from_fd): Act on --quiet.
This commit is contained in:
parent
509fe4ce5d
commit
7a852fba6c
106
g10/passphrase.c
106
g10/passphrase.c
@ -127,8 +127,8 @@ read_passphrase_from_fd( int fd )
|
|||||||
{
|
{
|
||||||
int i, len;
|
int i, len;
|
||||||
char *pw;
|
char *pw;
|
||||||
|
|
||||||
if ( opt.use_agent )
|
if ( opt.use_agent )
|
||||||
{ /* Not used but we have to do a dummy read, so that it won't end
|
{ /* Not used but we have to do a dummy read, so that it won't end
|
||||||
up at the begin of the message if the quite usual trick to
|
up at the begin of the message if the quite usual trick to
|
||||||
prepend the passphtrase to the message is used. */
|
prepend the passphtrase to the message is used. */
|
||||||
@ -137,14 +137,14 @@ read_passphrase_from_fd( int fd )
|
|||||||
while (!(read (fd, buf, 1) != 1 || *buf == '\n' ))
|
while (!(read (fd, buf, 1) != 1 || *buf == '\n' ))
|
||||||
;
|
;
|
||||||
*buf = 0;
|
*buf = 0;
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!opt.batch )
|
if (!opt.batch && !opt.quiet)
|
||||||
tty_printf("Reading passphrase from file descriptor %d ...", fd );
|
tty_printf("Reading passphrase from file descriptor %d ...", fd );
|
||||||
for (pw = NULL, i = len = 100; ; i++ )
|
for (pw = NULL, i = len = 100; ; i++ )
|
||||||
{
|
{
|
||||||
if (i >= len-1 )
|
if (i >= len-1 )
|
||||||
{
|
{
|
||||||
char *pw2 = pw;
|
char *pw2 = pw;
|
||||||
len += 100;
|
len += 100;
|
||||||
@ -176,8 +176,8 @@ static int
|
|||||||
agent_send_option (assuan_context_t ctx, const char *name, const char *value)
|
agent_send_option (assuan_context_t ctx, const char *name, const char *value)
|
||||||
{
|
{
|
||||||
char *line;
|
char *line;
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
if (!value || !*value)
|
if (!value || !*value)
|
||||||
return 0; /* Avoid sending empty option values. */
|
return 0; /* Avoid sending empty option values. */
|
||||||
|
|
||||||
@ -189,7 +189,7 @@ agent_send_option (assuan_context_t ctx, const char *name, const char *value)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Send all required options to the gpg-agent. */
|
/* Send all required options to the gpg-agent. */
|
||||||
static int
|
static int
|
||||||
agent_send_all_options (assuan_context_t ctx)
|
agent_send_all_options (assuan_context_t ctx)
|
||||||
{
|
{
|
||||||
char *dft_display = NULL;
|
char *dft_display = NULL;
|
||||||
@ -299,7 +299,7 @@ agent_open (int try, const char *orig_codeset)
|
|||||||
else
|
else
|
||||||
{
|
{
|
||||||
infostr = getenv ( "GPG_AGENT_INFO" );
|
infostr = getenv ( "GPG_AGENT_INFO" );
|
||||||
if (!infostr || !*infostr)
|
if (!infostr || !*infostr)
|
||||||
{
|
{
|
||||||
if (!try)
|
if (!try)
|
||||||
{
|
{
|
||||||
@ -314,7 +314,7 @@ agent_open (int try, const char *orig_codeset)
|
|||||||
}
|
}
|
||||||
infostr = xstrdup ( infostr );
|
infostr = xstrdup ( infostr );
|
||||||
}
|
}
|
||||||
|
|
||||||
if ( !(p = strchr (infostr, PATHSEP_C)) || p == infostr)
|
if ( !(p = strchr (infostr, PATHSEP_C)) || p == infostr)
|
||||||
{
|
{
|
||||||
if (!try)
|
if (!try)
|
||||||
@ -349,7 +349,7 @@ agent_open (int try, const char *orig_codeset)
|
|||||||
xfree (infostr);
|
xfree (infostr);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
rc = assuan_socket_connect (&ctx, infostr, pid);
|
rc = assuan_socket_connect (&ctx, infostr, pid);
|
||||||
if (rc)
|
if (rc)
|
||||||
{
|
{
|
||||||
@ -359,7 +359,7 @@ agent_open (int try, const char *orig_codeset)
|
|||||||
if (orig_codeset)
|
if (orig_codeset)
|
||||||
bind_textdomain_codeset (PACKAGE, orig_codeset);
|
bind_textdomain_codeset (PACKAGE, orig_codeset);
|
||||||
#endif /*ENABLE_NLS*/
|
#endif /*ENABLE_NLS*/
|
||||||
log_info ( _("can't connect to `%s': %s\n"),
|
log_info ( _("can't connect to `%s': %s\n"),
|
||||||
infostr, assuan_strerror (rc));
|
infostr, assuan_strerror (rc));
|
||||||
opt.use_agent = 0;
|
opt.use_agent = 0;
|
||||||
}
|
}
|
||||||
@ -436,7 +436,7 @@ struct agent_okay_cb_s {
|
|||||||
status line without leading white spaces. */
|
status line without leading white spaces. */
|
||||||
static assuan_error_t
|
static assuan_error_t
|
||||||
agent_okay_cb (void *opaque, const char *line)
|
agent_okay_cb (void *opaque, const char *line)
|
||||||
{
|
{
|
||||||
struct agent_okay_cb_s *parm = opaque;
|
struct agent_okay_cb_s *parm = opaque;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
@ -446,10 +446,10 @@ agent_okay_cb (void *opaque, const char *line)
|
|||||||
memory function code to allow wiping arbitrary stuff on memory
|
memory function code to allow wiping arbitrary stuff on memory
|
||||||
failure. */
|
failure. */
|
||||||
parm->pw = xmalloc_secure (strlen (line)/2+2);
|
parm->pw = xmalloc_secure (strlen (line)/2+2);
|
||||||
|
|
||||||
for (i=0; hexdigitp (line) && hexdigitp (line+1); line += 2)
|
for (i=0; hexdigitp (line) && hexdigitp (line+1); line += 2)
|
||||||
parm->pw[i++] = xtoi_2 (line);
|
parm->pw[i++] = xtoi_2 (line);
|
||||||
parm->pw[i] = 0;
|
parm->pw[i] = 0;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
#endif /*ENABLE_AGENT_SUPPORT*/
|
#endif /*ENABLE_AGENT_SUPPORT*/
|
||||||
@ -494,10 +494,10 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *cacheid,
|
|||||||
if( keyid && get_pubkey( pk, keyid ) )
|
if( keyid && get_pubkey( pk, keyid ) )
|
||||||
{
|
{
|
||||||
if (pk)
|
if (pk)
|
||||||
free_public_key( pk );
|
free_public_key( pk );
|
||||||
pk = NULL; /* oops: no key for some reason */
|
pk = NULL; /* oops: no key for some reason */
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
/* The Assuan agent protocol requires us to transmit utf-8 strings */
|
/* The Assuan agent protocol requires us to transmit utf-8 strings */
|
||||||
orig_codeset = bind_textdomain_codeset (PACKAGE, NULL);
|
orig_codeset = bind_textdomain_codeset (PACKAGE, NULL);
|
||||||
@ -509,36 +509,36 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *cacheid,
|
|||||||
{ /* We only switch when we are able to restore the codeset later. */
|
{ /* We only switch when we are able to restore the codeset later. */
|
||||||
orig_codeset = xstrdup (orig_codeset);
|
orig_codeset = xstrdup (orig_codeset);
|
||||||
if (!bind_textdomain_codeset (PACKAGE, "utf-8"))
|
if (!bind_textdomain_codeset (PACKAGE, "utf-8"))
|
||||||
orig_codeset = NULL;
|
orig_codeset = NULL;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if ( !(ctx = agent_open (0, orig_codeset)) )
|
if ( !(ctx = agent_open (0, orig_codeset)) )
|
||||||
goto failure;
|
goto failure;
|
||||||
|
|
||||||
if (custom_description)
|
if (custom_description)
|
||||||
atext = native_to_utf8 (custom_description);
|
atext = native_to_utf8 (custom_description);
|
||||||
else if ( !mode && pk && keyid )
|
else if ( !mode && pk && keyid )
|
||||||
{
|
{
|
||||||
char *uid;
|
char *uid;
|
||||||
size_t uidlen;
|
size_t uidlen;
|
||||||
const char *algo_name = pubkey_algo_to_string ( pk->pubkey_algo );
|
const char *algo_name = pubkey_algo_to_string ( pk->pubkey_algo );
|
||||||
const char *timestr;
|
const char *timestr;
|
||||||
char *maink;
|
char *maink;
|
||||||
|
|
||||||
if ( !algo_name )
|
if ( !algo_name )
|
||||||
algo_name = "?";
|
algo_name = "?";
|
||||||
|
|
||||||
#define KEYIDSTRING _(" (main key ID %s)")
|
#define KEYIDSTRING _(" (main key ID %s)")
|
||||||
|
|
||||||
maink = xmalloc ( strlen (KEYIDSTRING) + keystrlen() + 20 );
|
maink = xmalloc ( strlen (KEYIDSTRING) + keystrlen() + 20 );
|
||||||
if( keyid[2] && keyid[3] && keyid[0] != keyid[2]
|
if( keyid[2] && keyid[3] && keyid[0] != keyid[2]
|
||||||
&& keyid[1] != keyid[3] )
|
&& keyid[1] != keyid[3] )
|
||||||
sprintf( maink, KEYIDSTRING, keystr(&keyid[2]) );
|
sprintf( maink, KEYIDSTRING, keystr(&keyid[2]) );
|
||||||
else
|
else
|
||||||
*maink = 0;
|
*maink = 0;
|
||||||
|
|
||||||
uid = get_user_id ( keyid, &uidlen );
|
uid = get_user_id ( keyid, &uidlen );
|
||||||
timestr = strtimestamp (pk->timestamp);
|
timestr = strtimestamp (pk->timestamp);
|
||||||
|
|
||||||
#undef KEYIDSTRING
|
#undef KEYIDSTRING
|
||||||
@ -548,7 +548,7 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *cacheid,
|
|||||||
"\"%.*s\"\n" \
|
"\"%.*s\"\n" \
|
||||||
"%u-bit %s key, ID %s, created %s%s\n" )
|
"%u-bit %s key, ID %s, created %s%s\n" )
|
||||||
|
|
||||||
atext = xmalloc ( 100 + strlen (PROMPTSTRING)
|
atext = xmalloc ( 100 + strlen (PROMPTSTRING)
|
||||||
+ uidlen + 15 + strlen(algo_name) + keystrlen()
|
+ uidlen + 15 + strlen(algo_name) + keystrlen()
|
||||||
+ strlen (timestr) + strlen (maink) );
|
+ strlen (timestr) + strlen (maink) );
|
||||||
sprintf (atext, PROMPTSTRING,
|
sprintf (atext, PROMPTSTRING,
|
||||||
@ -560,21 +560,21 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *cacheid,
|
|||||||
|
|
||||||
#undef PROMPTSTRING
|
#undef PROMPTSTRING
|
||||||
|
|
||||||
{
|
{
|
||||||
size_t dummy;
|
size_t dummy;
|
||||||
fingerprint_from_pk( pk, fpr, &dummy );
|
fingerprint_from_pk( pk, fpr, &dummy );
|
||||||
have_fpr = 1;
|
have_fpr = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
else if (mode == 2 )
|
else if (mode == 2 )
|
||||||
atext = xstrdup ( _("Repeat passphrase\n") );
|
atext = xstrdup ( _("Repeat passphrase\n") );
|
||||||
else
|
else
|
||||||
atext = xstrdup ( _("Enter passphrase\n") );
|
atext = xstrdup ( _("Enter passphrase\n") );
|
||||||
|
|
||||||
{
|
{
|
||||||
char *line, *p;
|
char *line, *p;
|
||||||
int i, rc;
|
int i, rc;
|
||||||
struct agent_okay_cb_s okay_cb_parm;
|
struct agent_okay_cb_s okay_cb_parm;
|
||||||
|
|
||||||
if (!tryagain_text)
|
if (!tryagain_text)
|
||||||
@ -584,7 +584,7 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *cacheid,
|
|||||||
|
|
||||||
/* We allocate 23 times the needed space for thye texts so that
|
/* We allocate 23 times the needed space for thye texts so that
|
||||||
there is enough space for escaping. */
|
there is enough space for escaping. */
|
||||||
line = xmalloc (15 + 46
|
line = xmalloc (15 + 46
|
||||||
+ 3*strlen (atext)
|
+ 3*strlen (atext)
|
||||||
+ 3*strlen (custom_prompt? custom_prompt:"")
|
+ 3*strlen (custom_prompt? custom_prompt:"")
|
||||||
+ (cacheid? (3*strlen (cacheid)): 0)
|
+ (cacheid? (3*strlen (cacheid)): 0)
|
||||||
@ -650,14 +650,14 @@ agent_get_passphrase ( u32 *keyid, int mode, const char *cacheid,
|
|||||||
if (canceled)
|
if (canceled)
|
||||||
*canceled = 1;
|
*canceled = 1;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
log_error (_("problem with the agent - disabling agent use\n"));
|
log_error (_("problem with the agent - disabling agent use\n"));
|
||||||
opt.use_agent = 0;
|
opt.use_agent = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
failure:
|
failure:
|
||||||
#ifdef ENABLE_NLS
|
#ifdef ENABLE_NLS
|
||||||
if (orig_codeset)
|
if (orig_codeset)
|
||||||
@ -689,14 +689,14 @@ passphrase_clear_cache ( u32 *keyid, const char *cacheid, int algo )
|
|||||||
assuan_context_t ctx = NULL;
|
assuan_context_t ctx = NULL;
|
||||||
PKT_public_key *pk;
|
PKT_public_key *pk;
|
||||||
byte fpr[MAX_FINGERPRINT_LEN];
|
byte fpr[MAX_FINGERPRINT_LEN];
|
||||||
|
|
||||||
#if MAX_FINGERPRINT_LEN < 20
|
#if MAX_FINGERPRINT_LEN < 20
|
||||||
#error agent needs a 20 byte fingerprint
|
#error agent needs a 20 byte fingerprint
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
if (!opt.use_agent)
|
if (!opt.use_agent)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
if (!cacheid)
|
if (!cacheid)
|
||||||
{
|
{
|
||||||
pk = xcalloc (1, sizeof *pk);
|
pk = xcalloc (1, sizeof *pk);
|
||||||
@ -705,7 +705,7 @@ passphrase_clear_cache ( u32 *keyid, const char *cacheid, int algo )
|
|||||||
{
|
{
|
||||||
goto failure; /* oops: no key for some reason */
|
goto failure; /* oops: no key for some reason */
|
||||||
}
|
}
|
||||||
|
|
||||||
{
|
{
|
||||||
size_t dummy;
|
size_t dummy;
|
||||||
fingerprint_from_pk( pk, fpr, &dummy );
|
fingerprint_from_pk( pk, fpr, &dummy );
|
||||||
@ -713,13 +713,13 @@ passphrase_clear_cache ( u32 *keyid, const char *cacheid, int algo )
|
|||||||
}
|
}
|
||||||
else
|
else
|
||||||
pk = NULL;
|
pk = NULL;
|
||||||
|
|
||||||
if ( !(ctx = agent_open (0, NULL)) )
|
if ( !(ctx = agent_open (0, NULL)) )
|
||||||
goto failure;
|
goto failure;
|
||||||
|
|
||||||
{
|
{
|
||||||
char *line, *p;
|
char *line, *p;
|
||||||
int i, rc;
|
int i, rc;
|
||||||
|
|
||||||
if (cacheid)
|
if (cacheid)
|
||||||
{
|
{
|
||||||
@ -746,7 +746,7 @@ passphrase_clear_cache ( u32 *keyid, const char *cacheid, int algo )
|
|||||||
opt.use_agent = 0;
|
opt.use_agent = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
failure:
|
failure:
|
||||||
agent_close (ctx);
|
agent_close (ctx);
|
||||||
if (pk)
|
if (pk)
|
||||||
@ -766,7 +766,7 @@ ask_passphrase (const char *description,
|
|||||||
const char *cacheid, int *canceled)
|
const char *cacheid, int *canceled)
|
||||||
{
|
{
|
||||||
char *pw = NULL;
|
char *pw = NULL;
|
||||||
|
|
||||||
if (canceled)
|
if (canceled)
|
||||||
*canceled = 0;
|
*canceled = 0;
|
||||||
|
|
||||||
@ -781,9 +781,9 @@ ask_passphrase (const char *description,
|
|||||||
else
|
else
|
||||||
tty_printf ("\n%s\n",description);
|
tty_printf ("\n%s\n",description);
|
||||||
}
|
}
|
||||||
|
|
||||||
agent_died:
|
agent_died:
|
||||||
if ( opt.use_agent )
|
if ( opt.use_agent )
|
||||||
{
|
{
|
||||||
pw = agent_get_passphrase (NULL, 0, cacheid,
|
pw = agent_get_passphrase (NULL, 0, cacheid,
|
||||||
tryagain_text, description, prompt,
|
tryagain_text, description, prompt,
|
||||||
@ -795,7 +795,7 @@ ask_passphrase (const char *description,
|
|||||||
pw = NULL;
|
pw = NULL;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (fd_passwd)
|
else if (fd_passwd)
|
||||||
{
|
{
|
||||||
pw = xmalloc_secure (strlen(fd_passwd)+1);
|
pw = xmalloc_secure (strlen(fd_passwd)+1);
|
||||||
strcpy (pw, fd_passwd);
|
strcpy (pw, fd_passwd);
|
||||||
@ -824,7 +824,7 @@ ask_passphrase (const char *description,
|
|||||||
* KEYID and PUBKEY_ALGO to prompt the user.
|
* KEYID and PUBKEY_ALGO to prompt the user.
|
||||||
|
|
||||||
MODE 0: Allow cached passphrase
|
MODE 0: Allow cached passphrase
|
||||||
1: Ignore cached passphrase
|
1: Ignore cached passphrase
|
||||||
2: Ditto, but change the text to "repeat entry"
|
2: Ditto, but change the text to "repeat entry"
|
||||||
*/
|
*/
|
||||||
DEK *
|
DEK *
|
||||||
@ -840,7 +840,7 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo,
|
|||||||
*canceled = 0;
|
*canceled = 0;
|
||||||
|
|
||||||
if( !s2k ) {
|
if( !s2k ) {
|
||||||
/* This is used for the old rfc1991 mode
|
/* This is used for the old rfc1991 mode
|
||||||
* Note: This must match the code in encode.c with opt.rfc1991 set */
|
* Note: This must match the code in encode.c with opt.rfc1991 set */
|
||||||
s2k = &help_s2k;
|
s2k = &help_s2k;
|
||||||
s2k->mode = 0;
|
s2k->mode = 0;
|
||||||
@ -851,7 +851,7 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo,
|
|||||||
information are request, we print them now. */
|
information are request, we print them now. */
|
||||||
if( !next_pw && is_status_enabled() ) {
|
if( !next_pw && is_status_enabled() ) {
|
||||||
char buf[50];
|
char buf[50];
|
||||||
|
|
||||||
if( keyid ) {
|
if( keyid ) {
|
||||||
u32 used_kid[2];
|
u32 used_kid[2];
|
||||||
char *us;
|
char *us;
|
||||||
@ -873,7 +873,7 @@ passphrase_to_dek( u32 *keyid, int pubkey_algo,
|
|||||||
(ulong)keyid[0], (ulong)keyid[1],
|
(ulong)keyid[0], (ulong)keyid[1],
|
||||||
(ulong)used_kid[0], (ulong)used_kid[1],
|
(ulong)used_kid[0], (ulong)used_kid[1],
|
||||||
pubkey_algo );
|
pubkey_algo );
|
||||||
|
|
||||||
write_status_text( STATUS_NEED_PASSPHRASE, buf );
|
write_status_text( STATUS_NEED_PASSPHRASE, buf );
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user