1
0
mirror of git://git.gnupg.org/gnupg.git synced 2024-12-22 10:19:57 +01:00

gpg: Print a new FAILURE status after most commands.

* common/status.h (STATUS_FAILURE): New.
* g10/cpr.c (write_status_failure): New.
* g10/gpg.c (main): Call write_status_failure for all commands which
print an error message here.
--

This status line can be used similar to the error code returned by
commands send over the Assuan interface in gpgsm.  We don't emit them
in gpgsm because there we already have that Assuan interface to return
proper error code.  This change helps GPGME to return better error
codes.

(backported from master 9cdff09743c473a12359bfdb914578ede0e4e3e2)

Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
Werner Koch 2015-09-08 15:29:59 +02:00
parent 0b01bb7f25
commit 77f2964b96
No known key found for this signature in database
GPG Key ID: E3FDFF218E45B72B
4 changed files with 94 additions and 19 deletions

View File

@ -126,6 +126,7 @@ enum
STATUS_TRUNCATED,
STATUS_ERROR,
STATUS_FAILURE,
STATUS_SUCCESS
};

View File

@ -303,6 +303,20 @@ write_status_begin_signing (gcry_md_hd_t md)
}
/* Write a FAILURE status line. */
void
write_status_failure (const char *where, gpg_error_t err)
{
if (!statusfp || !status_currently_allowed (STATUS_FAILURE))
return; /* Not enabled or allowed. */
fprintf (statusfp, "[GNUPG:] %s %s %u\n",
get_status_string (STATUS_FAILURE), where, err);
if (fflush (statusfp) && opt.exit_on_status_write_error)
g10_exit (0);
}
static int
myread(int fd, void *buf, size_t count)
{

View File

@ -3504,15 +3504,21 @@ main (int argc, char **argv)
if( argc > 1 )
wrong_args(_("--store [filename]"));
if( (rc = encode_store(fname)) )
{
write_status_failure ("store", rc);
log_error ("storing `%s' failed: %s\n",
print_fname_stdin(fname),g10_errstr(rc) );
}
break;
case aSym: /* encrypt the given file only with the symmetric cipher */
if( argc > 1 )
wrong_args(_("--symmetric [filename]"));
if( (rc = encode_symmetric(fname)) )
{
write_status_failure ("symencrypt", rc);
log_error (_("symmetric encryption of `%s' failed: %s\n"),
print_fname_stdin(fname),g10_errstr(rc) );
}
break;
case aEncr: /* encrypt the given file */
@ -3523,9 +3529,12 @@ main (int argc, char **argv)
if( argc > 1 )
wrong_args(_("--encrypt [filename]"));
if( (rc = encode_crypt(fname,remusr,0)) )
{
write_status_failure ("encrypt", rc);
log_error("%s: encryption failed: %s\n",
print_fname_stdin(fname), g10_errstr(rc) );
}
}
break;
case aEncrSym:
@ -3544,9 +3553,12 @@ main (int argc, char **argv)
else
{
if( (rc = encode_crypt(fname,remusr,1)) )
{
write_status_failure ("encrypt", rc);
log_error("%s: encryption failed: %s\n",
print_fname_stdin(fname), g10_errstr(rc) );
}
}
break;
case aSign: /* sign the given file */
@ -3564,7 +3576,10 @@ main (int argc, char **argv)
}
}
if( (rc = sign_file( sl, detached_sig, locusr, 0, NULL, NULL)) )
{
write_status_failure ("sign", rc);
log_error("signing failed: %s\n", g10_errstr(rc) );
}
free_strlist(sl);
break;
@ -3578,8 +3593,11 @@ main (int argc, char **argv)
else
sl = NULL;
if( (rc = sign_file(sl, detached_sig, locusr, 1, remusr, NULL)) )
{
write_status_failure ("sign-encrypt", rc);
log_error("%s: sign+encrypt failed: %s\n",
print_fname_stdin(fname), g10_errstr(rc) );
}
free_strlist(sl);
break;
@ -3602,8 +3620,11 @@ main (int argc, char **argv)
else
sl = NULL;
if( (rc = sign_file(sl, detached_sig, locusr, 2, remusr, NULL)) )
{
write_status_failure ("sign-encrypt", rc);
log_error("%s: symmetric+sign+encrypt failed: %s\n",
print_fname_stdin(fname), g10_errstr(rc) );
}
free_strlist(sl);
}
break;
@ -3613,16 +3634,22 @@ main (int argc, char **argv)
wrong_args(_("--sign --symmetric [filename]"));
rc = sign_symencrypt_file (fname, locusr);
if (rc)
{
write_status_failure ("sign-symencrypt", rc);
log_error("%s: sign+symmetric failed: %s\n",
print_fname_stdin(fname), g10_errstr(rc) );
}
break;
case aClearsign: /* make a clearsig */
if( argc > 1 )
wrong_args(_("--clearsign [filename]"));
if( (rc = clearsign_file(fname, locusr, NULL)) )
{
write_status_failure ("sign", rc);
log_error("%s: clearsign failed: %s\n",
print_fname_stdin(fname), g10_errstr(rc) );
}
break;
case aVerify:
@ -3636,6 +3663,8 @@ main (int argc, char **argv)
if( (rc = verify_signatures( argc, argv ) ))
log_error("verify signatures failed: %s\n", g10_errstr(rc) );
}
if (rc)
write_status_failure ("verify", rc);
break;
case aDecrypt:
@ -3646,7 +3675,10 @@ main (int argc, char **argv)
if( argc > 1 )
wrong_args(_("--decrypt [filename]"));
if( (rc = decrypt_message( fname ) ))
log_error("decrypt_message failed: %s\n", g10_errstr(rc) );
{
write_status_failure ("decrypt", rc);
log_error("decrypt_message failed: %s\n", g10_errstr(rc));
}
}
break;
@ -3780,12 +3812,21 @@ main (int argc, char **argv)
if(rc)
{
if(cmd==aSendKeys)
{
write_status_failure ("send-keys", rc);
log_error(_("keyserver send failed: %s\n"),g10_errstr(rc));
}
else if(cmd==aRecvKeys)
{
write_status_failure ("recv-keys", rc);
log_error(_("keyserver receive failed: %s\n"),g10_errstr(rc));
}
else
{
write_status_failure ("export", rc);
log_error(_("key export failed: %s\n"),g10_errstr(rc));
}
}
free_strlist(sl);
break;
@ -3795,7 +3836,10 @@ main (int argc, char **argv)
append_to_strlist2( &sl, *argv, utf8_strings );
rc=keyserver_search( sl );
if(rc)
log_error(_("keyserver search failed: %s\n"),g10_errstr(rc));
{
write_status_failure ("search-keys", rc);
log_error(_("keyserver search failed: %s\n"), g10_errstr(rc));
}
free_strlist(sl);
break;
@ -3805,7 +3849,10 @@ main (int argc, char **argv)
append_to_strlist2( &sl, *argv, utf8_strings );
rc=keyserver_refresh(sl);
if(rc)
{
write_status_failure ("refresh-keys", rc);
log_error(_("keyserver refresh failed: %s\n"),g10_errstr(rc));
}
free_strlist(sl);
break;
@ -3815,7 +3862,10 @@ main (int argc, char **argv)
append_to_strlist2( &sl, *argv, utf8_strings );
rc=keyserver_fetch(sl);
if(rc)
{
write_status_failure ("fetch-keys", rc);
log_error("key fetch failed: %s\n",g10_errstr(rc));
}
free_strlist(sl);
break;
@ -3856,7 +3906,10 @@ main (int argc, char **argv)
wrong_args("--dearmor [file]");
rc = dearmor_file( argc? *argv: NULL );
if( rc )
{
write_status_failure ("dearmor", rc);
log_error(_("dearmoring failed: %s\n"), g10_errstr(rc));
}
break;
case aEnArmor:
@ -3864,7 +3917,10 @@ main (int argc, char **argv)
wrong_args("--enarmor [file]");
rc = enarmor_file( argc? *argv: NULL );
if( rc )
{
write_status_failure ("enarmor", rc);
log_error(_("enarmoring failed: %s\n"), g10_errstr(rc));
}
break;
@ -4105,7 +4161,10 @@ main (int argc, char **argv)
}
rc = proc_packets(NULL, a );
if( rc )
{
write_status_failure ("-", rc);
log_error("processing message failed: %s\n", g10_errstr(rc) );
}
iobuf_close(a);
}
break;

View File

@ -163,6 +163,7 @@ void set_status_fd ( int fd );
int is_status_enabled ( void );
void write_status ( int no );
void write_status_error (const char *where, int errcode);
void write_status_failure (const char *where, gpg_error_t err);
void write_status_text ( int no, const char *text );
void write_status_strings (int no, const char *text,
...) GNUPG_GCC_A_SENTINEL(0);