mirror of
git://git.gnupg.org/gnupg.git
synced 2024-11-11 21:48:50 +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. * g10/call-agent.c (start_agent): Print an STATUS_ERROR if we can't set the pinentry mode. -- 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. Signed-off-by: Werner Koch <wk@gnupg.org>
This commit is contained in:
parent
348a6ebb63
commit
9cdff09743
@ -126,9 +126,10 @@ enum
|
||||
|
||||
STATUS_ERROR,
|
||||
STATUS_SUCCESS,
|
||||
STATUS_FAILURE,
|
||||
|
||||
STATUS_INQUIRE_MAXLEN,
|
||||
};
|
||||
STATUS_INQUIRE_MAXLEN
|
||||
};
|
||||
|
||||
|
||||
const char *get_status_string (int code);
|
||||
|
14
doc/DETAILS
14
doc/DETAILS
@ -823,9 +823,17 @@ pkd:0:1024:B665B1435F4C2 .... FF26ABB:
|
||||
numerical error code and an underscore; e.g.: "151011327_EOF".
|
||||
|
||||
*** SUCCESS [<location>]
|
||||
Postive confirimation that an operation succeeded. <location> is
|
||||
optional but if given should not contain spaces. Used only with a
|
||||
few commands.
|
||||
Postive confirmation that an operation succeeded. It is used
|
||||
similar to ISO-C's EXIT_SUCCESS. <location> is optional but if
|
||||
given should not contain spaces. Used only with a few commands.
|
||||
|
||||
*** FAILURE <location> <error_code>
|
||||
This is the counterpart to SUCCESS and used to indicate a program
|
||||
failure. It is used similar to ISO-C's EXIT_FAILURE but allows to
|
||||
convey more information, in particular an gpg-error error code.
|
||||
That numerical error code may optionally have a suffix made of an
|
||||
underscore and a string with an error symbol like "151011327_EOF".
|
||||
A dash may be used instead of <location>.
|
||||
|
||||
*** BADARMOR
|
||||
The ASCII armor is corrupted. No arguments yet.
|
||||
|
@ -318,9 +318,12 @@ start_agent (ctrl_t ctrl, int for_card)
|
||||
NULL, NULL, NULL, NULL, NULL, NULL);
|
||||
xfree (tmp);
|
||||
if (rc)
|
||||
log_error ("setting pinentry mode '%s' failed: %s\n",
|
||||
str_pinentry_mode (opt.pinentry_mode),
|
||||
gpg_strerror (rc));
|
||||
{
|
||||
log_error ("setting pinentry mode '%s' failed: %s\n",
|
||||
str_pinentry_mode (opt.pinentry_mode),
|
||||
gpg_strerror (rc));
|
||||
write_status_error ("set_pinentry_mode", rc);
|
||||
}
|
||||
}
|
||||
|
||||
check_hijacking (agent_ctx);
|
||||
|
16
g10/cpr.c
16
g10/cpr.c
@ -183,7 +183,7 @@ write_status_text (int no, const char *text)
|
||||
write_status_strings (no, text, NULL);
|
||||
}
|
||||
|
||||
/* Wrte an ERROR status line using a full gpg-error error value. */
|
||||
/* Write an ERROR status line using a full gpg-error error value. */
|
||||
void
|
||||
write_status_error (const char *where, gpg_error_t err)
|
||||
{
|
||||
@ -211,6 +211,20 @@ write_status_errcode (const char *where, int errcode)
|
||||
}
|
||||
|
||||
|
||||
/* 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. */
|
||||
|
||||
es_fprintf (statusfp, "[GNUPG:] %s %s %u\n",
|
||||
get_status_string (STATUS_FAILURE), where, err);
|
||||
if (es_fflush (statusfp) && opt.exit_on_status_write_error)
|
||||
g10_exit (0);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* Write a status line with a buffer using %XX escapes. If WRAP is >
|
||||
* 0 wrap the line after this length. If STRING is not NULL it will
|
||||
|
100
g10/gpg.c
100
g10/gpg.c
@ -3661,15 +3661,21 @@ main (int argc, char **argv)
|
||||
if( argc > 1 )
|
||||
wrong_args(_("--store [filename]"));
|
||||
if( (rc = encrypt_store(fname)) )
|
||||
{
|
||||
write_status_failure ("store", rc);
|
||||
log_error ("storing '%s' failed: %s\n",
|
||||
print_fname_stdin(fname),gpg_strerror (rc) );
|
||||
}
|
||||
break;
|
||||
case aSym: /* encrypt the given file only with the symmetric cipher */
|
||||
if( argc > 1 )
|
||||
wrong_args(_("--symmetric [filename]"));
|
||||
if( (rc = encrypt_symmetric(fname)) )
|
||||
{
|
||||
write_status_failure ("symencrypt", rc);
|
||||
log_error (_("symmetric encryption of '%s' failed: %s\n"),
|
||||
print_fname_stdin(fname),gpg_strerror (rc) );
|
||||
}
|
||||
break;
|
||||
|
||||
case aEncr: /* encrypt the given file */
|
||||
@ -3680,8 +3686,11 @@ main (int argc, char **argv)
|
||||
if( argc > 1 )
|
||||
wrong_args(_("--encrypt [filename]"));
|
||||
if( (rc = encrypt_crypt (ctrl, -1, fname, remusr, 0, NULL, -1)) )
|
||||
log_error("%s: encryption failed: %s\n",
|
||||
print_fname_stdin(fname), gpg_strerror (rc) );
|
||||
{
|
||||
write_status_failure ("encrypt", rc);
|
||||
log_error("%s: encryption failed: %s\n",
|
||||
print_fname_stdin(fname), gpg_strerror (rc) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -3701,8 +3710,11 @@ main (int argc, char **argv)
|
||||
else
|
||||
{
|
||||
if( (rc = encrypt_crypt (ctrl, -1, fname, remusr, 1, NULL, -1)) )
|
||||
log_error("%s: encryption failed: %s\n",
|
||||
print_fname_stdin(fname), gpg_strerror (rc) );
|
||||
{
|
||||
write_status_failure ("encrypt", rc);
|
||||
log_error ("%s: encryption failed: %s\n",
|
||||
print_fname_stdin(fname), gpg_strerror (rc) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -3720,8 +3732,11 @@ main (int argc, char **argv)
|
||||
strcpy(sl->d, fname);
|
||||
}
|
||||
}
|
||||
if( (rc = sign_file (ctrl, sl, detached_sig, locusr, 0, NULL, NULL)) )
|
||||
log_error("signing failed: %s\n", gpg_strerror (rc) );
|
||||
if ((rc = sign_file (ctrl, sl, detached_sig, locusr, 0, NULL, NULL)))
|
||||
{
|
||||
write_status_failure ("sign", rc);
|
||||
log_error ("signing failed: %s\n", gpg_strerror (rc) );
|
||||
}
|
||||
free_strlist(sl);
|
||||
break;
|
||||
|
||||
@ -3735,8 +3750,11 @@ main (int argc, char **argv)
|
||||
else
|
||||
sl = NULL;
|
||||
if ((rc = sign_file (ctrl, 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), gpg_strerror (rc) );
|
||||
}
|
||||
free_strlist(sl);
|
||||
break;
|
||||
|
||||
@ -3760,8 +3778,11 @@ main (int argc, char **argv)
|
||||
sl = NULL;
|
||||
if ((rc = sign_file (ctrl, sl, detached_sig, locusr,
|
||||
2, remusr, NULL)))
|
||||
log_error("%s: symmetric+sign+encrypt failed: %s\n",
|
||||
print_fname_stdin(fname), gpg_strerror (rc) );
|
||||
{
|
||||
write_status_failure ("sign-encrypt", rc);
|
||||
log_error("%s: symmetric+sign+encrypt failed: %s\n",
|
||||
print_fname_stdin(fname), gpg_strerror (rc) );
|
||||
}
|
||||
free_strlist(sl);
|
||||
}
|
||||
break;
|
||||
@ -3771,19 +3792,26 @@ 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), gpg_strerror (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), gpg_strerror (rc) );
|
||||
}
|
||||
break;
|
||||
|
||||
case aVerify:
|
||||
rc = 0;
|
||||
if (multifile)
|
||||
{
|
||||
if ((rc = verify_files (ctrl, argc, argv)))
|
||||
@ -3794,6 +3822,8 @@ main (int argc, char **argv)
|
||||
if ((rc = verify_signatures (ctrl, argc, argv)))
|
||||
log_error("verify signatures failed: %s\n", gpg_strerror (rc) );
|
||||
}
|
||||
if (rc)
|
||||
write_status_failure ("verify", rc);
|
||||
break;
|
||||
|
||||
case aDecrypt:
|
||||
@ -3804,7 +3834,10 @@ main (int argc, char **argv)
|
||||
if( argc > 1 )
|
||||
wrong_args(_("--decrypt [filename]"));
|
||||
if( (rc = decrypt_message (ctrl, fname) ))
|
||||
log_error("decrypt_message failed: %s\n", gpg_strerror (rc) );
|
||||
{
|
||||
write_status_failure ("decrypt", rc);
|
||||
log_error("decrypt_message failed: %s\n", gpg_strerror (rc) );
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
@ -3998,11 +4031,21 @@ main (int argc, char **argv)
|
||||
if(rc)
|
||||
{
|
||||
if(cmd==aSendKeys)
|
||||
log_error(_("keyserver send failed: %s\n"),gpg_strerror (rc));
|
||||
{
|
||||
write_status_failure ("send-keys", rc);
|
||||
log_error(_("keyserver send failed: %s\n"),gpg_strerror (rc));
|
||||
}
|
||||
else if(cmd==aRecvKeys)
|
||||
log_error(_("keyserver receive failed: %s\n"),gpg_strerror (rc));
|
||||
{
|
||||
write_status_failure ("recv-keys", rc);
|
||||
log_error (_("keyserver receive failed: %s\n"),
|
||||
gpg_strerror (rc));
|
||||
}
|
||||
else
|
||||
log_error(_("key export failed: %s\n"),gpg_strerror (rc));
|
||||
{
|
||||
write_status_failure ("export", rc);
|
||||
log_error (_("key export failed: %s\n"), gpg_strerror (rc));
|
||||
}
|
||||
}
|
||||
free_strlist(sl);
|
||||
break;
|
||||
@ -4013,7 +4056,10 @@ main (int argc, char **argv)
|
||||
append_to_strlist2 (&sl, *argv, utf8_strings);
|
||||
rc = keyserver_search (ctrl, sl);
|
||||
if (rc)
|
||||
log_error (_("keyserver search failed: %s\n"), gpg_strerror (rc));
|
||||
{
|
||||
write_status_failure ("search-keys", rc);
|
||||
log_error (_("keyserver search failed: %s\n"), gpg_strerror (rc));
|
||||
}
|
||||
free_strlist (sl);
|
||||
break;
|
||||
|
||||
@ -4023,7 +4069,10 @@ main (int argc, char **argv)
|
||||
append_to_strlist2( &sl, *argv, utf8_strings );
|
||||
rc = keyserver_refresh (ctrl, sl);
|
||||
if(rc)
|
||||
log_error(_("keyserver refresh failed: %s\n"),gpg_strerror (rc));
|
||||
{
|
||||
write_status_failure ("refresh-keys", rc);
|
||||
log_error (_("keyserver refresh failed: %s\n"),gpg_strerror (rc));
|
||||
}
|
||||
free_strlist(sl);
|
||||
break;
|
||||
|
||||
@ -4033,7 +4082,10 @@ main (int argc, char **argv)
|
||||
append_to_strlist2( &sl, *argv, utf8_strings );
|
||||
rc = keyserver_fetch (ctrl, sl);
|
||||
if(rc)
|
||||
log_error("key fetch failed: %s\n",gpg_strerror (rc));
|
||||
{
|
||||
write_status_failure ("fetch-keys", rc);
|
||||
log_error ("key fetch failed: %s\n",gpg_strerror (rc));
|
||||
}
|
||||
free_strlist(sl);
|
||||
break;
|
||||
|
||||
@ -4074,7 +4126,10 @@ main (int argc, char **argv)
|
||||
wrong_args("--dearmor [file]");
|
||||
rc = dearmor_file( argc? *argv: NULL );
|
||||
if( rc )
|
||||
log_error(_("dearmoring failed: %s\n"), gpg_strerror (rc));
|
||||
{
|
||||
write_status_failure ("dearmor", rc);
|
||||
log_error (_("dearmoring failed: %s\n"), gpg_strerror (rc));
|
||||
}
|
||||
break;
|
||||
|
||||
case aEnArmor:
|
||||
@ -4082,7 +4137,10 @@ main (int argc, char **argv)
|
||||
wrong_args("--enarmor [file]");
|
||||
rc = enarmor_file( argc? *argv: NULL );
|
||||
if( rc )
|
||||
log_error(_("enarmoring failed: %s\n"), gpg_strerror (rc));
|
||||
{
|
||||
write_status_failure ("enarmor", rc);
|
||||
log_error (_("enarmoring failed: %s\n"), gpg_strerror (rc));
|
||||
}
|
||||
break;
|
||||
|
||||
|
||||
@ -4274,7 +4332,7 @@ main (int argc, char **argv)
|
||||
else if (argc == 1)
|
||||
change_pin (atoi (*argv),1);
|
||||
else
|
||||
wrong_args ("--change-pin [no]");
|
||||
wrong_args ("--change-pin [no]");
|
||||
break;
|
||||
#endif /* ENABLE_CARD_SUPPORT*/
|
||||
|
||||
@ -4328,7 +4386,11 @@ main (int argc, char **argv)
|
||||
}
|
||||
rc = proc_packets (ctrl, NULL, a );
|
||||
if( rc )
|
||||
log_error("processing message failed: %s\n", gpg_strerror (rc));
|
||||
{
|
||||
write_status_failure ("-", rc);
|
||||
log_error ("processing message failed: %s\n",
|
||||
gpg_strerror (rc));
|
||||
}
|
||||
iobuf_close(a);
|
||||
}
|
||||
break;
|
||||
|
@ -180,6 +180,7 @@ int is_status_enabled ( void );
|
||||
void write_status ( int no );
|
||||
void write_status_error (const char *where, gpg_error_t err);
|
||||
void write_status_errcode (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,
|
||||
...) GPGRT_ATTR_SENTINEL(0);
|
||||
|
Loading…
Reference in New Issue
Block a user