From ca67902311b832f8dfe1cabb5bf358890a1d3821 Mon Sep 17 00:00:00 2001 From: Marcus Brinkmann Date: Mon, 26 Oct 2009 17:38:39 +0000 Subject: [PATCH] 2009-10-26 Marcus Brinkmann * debug.h (DEBUG_GLOBAL): New debug level. * conversion.c (gnupg_errors, _gpgme_map_gnupg_error): Removed. * data-user.c (gpgme_data_new_from_cbs): Add debug output. * data-fd.c (gpgme_data_new_from_fd): Likewise. * data-stream.c (gpgme_data_new_from_stream): Likewise. * decrypt.c (gpgme_op_decrypt_result, gpgme_op_decrypt_start) (gpgme_op_decrypt): Likewise. * delete.c (gpgme_op_delete_start, gpgme_op_delete): Likewise. * decrypt-verify.c (gpgme_op_decrypt_verify_start) (gpgme_op_decrypt_verify): Likewise. * sign.c (gpgme_op_sign_result): Fix debug message. * data-mem.c (gpgme_data_new): Improve debug output. * verify.c (parse_trust): Use atoi instead of _gpgme_map_gnupg_error. * decrypt.c (_gpgme_decrypt_status_handler): Likewise. --- src/ChangeLog | 18 +++++++ src/conversion.c | 116 ------------------------------------------- src/data-fd.c | 14 ++++-- src/data-mem.c | 2 +- src/data-stream.c | 15 ++++-- src/data-user.c | 16 +++--- src/debug.h | 11 ++-- src/decrypt-verify.c | 13 +++-- src/decrypt.c | 55 +++++++++++++++++--- src/delete.c | 15 +++++- src/sign.c | 2 +- src/verify.c | 4 +- 12 files changed, 127 insertions(+), 154 deletions(-) diff --git a/src/ChangeLog b/src/ChangeLog index 4214023..024c771 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,21 @@ +2009-10-26 Marcus Brinkmann + + * debug.h (DEBUG_GLOBAL): New debug level. + * conversion.c (gnupg_errors, _gpgme_map_gnupg_error): Removed. + * data-user.c (gpgme_data_new_from_cbs): Add debug output. + * data-fd.c (gpgme_data_new_from_fd): Likewise. + * data-stream.c (gpgme_data_new_from_stream): Likewise. + * decrypt.c (gpgme_op_decrypt_result, gpgme_op_decrypt_start) + (gpgme_op_decrypt): Likewise. + * delete.c (gpgme_op_delete_start, gpgme_op_delete): Likewise. + * decrypt-verify.c (gpgme_op_decrypt_verify_start) + (gpgme_op_decrypt_verify): Likewise. + * sign.c (gpgme_op_sign_result): Fix debug message. + * data-mem.c (gpgme_data_new): Improve debug output. + * verify.c (parse_trust): Use atoi instead of + _gpgme_map_gnupg_error. + * decrypt.c (_gpgme_decrypt_status_handler): Likewise. + 2009-10-22 Marcus Brinkmann * Makefile.am: Remove @NETLIBS@ from LIBADDs. diff --git a/src/conversion.c b/src/conversion.c index 8b3b715..45513f6 100644 --- a/src/conversion.c +++ b/src/conversion.c @@ -371,119 +371,3 @@ _gpgme_parse_timestamp (const char *timestamp, char **endp) else return (time_t)strtoul (timestamp, endp, 10); } - - - - -static struct -{ - char *name; - gpgme_error_t err; -} gnupg_errors[] = - { - { "EOF", GPG_ERR_EOF }, - { "No_Error", GPG_ERR_NO_ERROR }, - { "General_Error", GPG_ERR_GENERAL }, - { "Out_Of_Core", GPG_ERR_ENOMEM }, - { "Invalid_Value", GPG_ERR_INV_VALUE }, - { "IO_Error", GPG_ERR_GENERAL }, - { "Resource_Limit", GPG_ERR_RESOURCE_LIMIT }, - { "Internal_Error", GPG_ERR_INTERNAL }, - { "Bad_Certificate", GPG_ERR_BAD_CERT }, - { "Bad_Certificate_Chain", GPG_ERR_BAD_CERT_CHAIN}, - { "Missing_Certificate", GPG_ERR_MISSING_CERT }, - { "No_Data", GPG_ERR_NO_DATA }, - { "Bad_Signature", GPG_ERR_BAD_SIGNATURE }, - { "Not_Implemented", GPG_ERR_NOT_IMPLEMENTED }, - { "Conflict", GPG_ERR_CONFLICT }, - { "Bug", GPG_ERR_BUG }, - { "Read_Error", GPG_ERR_GENERAL }, - { "Write_Error", GPG_ERR_GENERAL }, - { "Invalid_Line", GPG_ERR_GENERAL }, - { "Incomplete_Line", GPG_ERR_INCOMPLETE_LINE }, - { "Invalid_Response", GPG_ERR_INV_RESPONSE }, - { "Agent_Error", GPG_ERR_AGENT }, - { "No_Public_Key", GPG_ERR_NO_PUBKEY }, - { "No_Secret_Key", GPG_ERR_NO_SECKEY }, - { "File_Open_Error", GPG_ERR_GENERAL }, - { "File_Create_Error", GPG_ERR_GENERAL }, - { "File_Error", GPG_ERR_GENERAL }, - { "Not_Supported", GPG_ERR_NOT_SUPPORTED }, - { "Invalid_Data", GPG_ERR_INV_DATA }, - { "Assuan_Server_Fault", GPG_ERR_ASSUAN_SERVER_FAULT }, - { "Assuan_Error", GPG_ERR_ASSUAN }, - { "Invalid_Session_Key", GPG_ERR_INV_SESSION_KEY }, - { "Invalid_Sexp", GPG_ERR_INV_SEXP }, - { "Unsupported_Algorithm", GPG_ERR_UNSUPPORTED_ALGORITHM }, - { "No_PIN_Entry", GPG_ERR_NO_PIN_ENTRY }, - { "PIN_Entry_Error", GPG_ERR_NO_PIN_ENTRY }, - { "Bad_PIN", GPG_ERR_BAD_PIN }, - { "Bad_Passphrase", GPG_ERR_BAD_PASSPHRASE }, - { "Invalid_Name", GPG_ERR_INV_NAME }, - { "Bad_Public_Key", GPG_ERR_BAD_PUBKEY }, - { "Bad_Secret_Key", GPG_ERR_BAD_SECKEY }, - { "Bad_Data", GPG_ERR_BAD_DATA }, - { "Invalid_Parameter", GPG_ERR_INV_PARAMETER }, - { "Tribute_to_D_A", GPG_ERR_TRIBUTE_TO_D_A }, - { "No_Dirmngr", GPG_ERR_NO_DIRMNGR }, - { "Dirmngr_Error", GPG_ERR_DIRMNGR }, - { "Certificate_Revoked", GPG_ERR_CERT_REVOKED }, - { "No_CRL_Known", GPG_ERR_NO_CRL_KNOWN }, - { "CRL_Too_Old", GPG_ERR_CRL_TOO_OLD }, - { "Line_Too_Long", GPG_ERR_LINE_TOO_LONG }, - { "Not_Trusted", GPG_ERR_NOT_TRUSTED }, - { "Canceled", GPG_ERR_CANCELED }, - { "Bad_CA_Certificate", GPG_ERR_BAD_CA_CERT }, - { "Certificate_Expired", GPG_ERR_CERT_EXPIRED }, - { "Certificate_Too_Young", GPG_ERR_CERT_TOO_YOUNG }, - { "Unsupported_Certificate", GPG_ERR_UNSUPPORTED_CERT }, - { "Unknown_Sexp", GPG_ERR_UNKNOWN_SEXP }, - { "Unsupported_Protection", GPG_ERR_UNSUPPORTED_PROTECTION }, - { "Corrupted_Protection", GPG_ERR_CORRUPTED_PROTECTION }, - { "Ambiguous_Name", GPG_ERR_AMBIGUOUS_NAME }, - { "Card_Error", GPG_ERR_CARD }, - { "Card_Reset", GPG_ERR_CARD_RESET }, - { "Card_Removed", GPG_ERR_CARD_REMOVED }, - { "Invalid_Card", GPG_ERR_INV_CARD }, - { "Card_Not_Present", GPG_ERR_CARD_NOT_PRESENT }, - { "No_PKCS15_App", GPG_ERR_NO_PKCS15_APP }, - { "Not_Confirmed", GPG_ERR_NOT_CONFIRMED }, - { "Configuration_Error", GPG_ERR_CONFIGURATION }, - { "No_Policy_Match", GPG_ERR_NO_POLICY_MATCH }, - { "Invalid_Index", GPG_ERR_INV_INDEX }, - { "Invalid_Id", GPG_ERR_INV_ID }, - { "No_Scdaemon", GPG_ERR_NO_SCDAEMON }, - { "Scdaemon_Error", GPG_ERR_SCDAEMON }, - { "Unsupported_Protocol", GPG_ERR_UNSUPPORTED_PROTOCOL }, - { "Bad_PIN_Method", GPG_ERR_BAD_PIN_METHOD }, - { "Card_Not_Initialized", GPG_ERR_CARD_NOT_INITIALIZED }, - { "Unsupported_Operation", GPG_ERR_UNSUPPORTED_OPERATION }, - { "Wrong_Key_Usage", GPG_ERR_WRONG_KEY_USAGE } - }; - - -gpgme_error_t -_gpgme_map_gnupg_error (char *errstr) -{ - unsigned int i; - gpgme_error_t err = gpg_err_make (GPG_ERR_SOURCE_GPG, GPG_ERR_GENERAL); - - /* Future version of GnuPG might return the error code directly, so - we first test for a a numerical value and use that verbatim. - Note that this numerical value might be followed by an - underschore and the textual representation of the error code. */ - if (*errstr >= '0' && *errstr <= '9') - return strtoul (errstr, NULL, 10); - - /* Well, this is a token, use the mapping table to get the error. - The drawback is that we won't receive an error source and have to - use GPG as source. */ - for (i = 0; i < DIM (gnupg_errors); i++) - if (!strcmp (gnupg_errors[i].name, errstr)) - err = gpg_err_make (GPG_ERR_SOURCE_GPG, gnupg_errors[i].err); - - TRACE3 (DEBUG_CTX, "_gpgme_map_gnupg_error", 0, - "mapped %s to %s <%s>", errstr, gpgme_strerror (err), - gpgme_strsource (err)); - return err; -} diff --git a/src/data-fd.c b/src/data-fd.c index 2c65be1..47a0d99 100644 --- a/src/data-fd.c +++ b/src/data-fd.c @@ -25,6 +25,7 @@ #include #include +#include "debug.h" #include "data.h" @@ -67,12 +68,15 @@ static struct _gpgme_data_cbs fd_cbs = gpgme_error_t -gpgme_data_new_from_fd (gpgme_data_t *dh, int fd) +gpgme_data_new_from_fd (gpgme_data_t *r_dh, int fd) { - gpgme_error_t err = _gpgme_data_new (dh, &fd_cbs); + gpgme_error_t err; + TRACE_BEG1 (DEBUG_DATA, "gpgme_data_new_from_fd", r_dh, "fd=0x%x", fd); + + err = _gpgme_data_new (r_dh, &fd_cbs); if (err) - return err; + return TRACE_ERR (err); - (*dh)->data.fd = fd; - return 0; + (*r_dh)->data.fd = fd; + return TRACE_SUC1 ("dh=%p", *r_dh); } diff --git a/src/data-mem.c b/src/data-mem.c index b58a3c0..5dca89a 100644 --- a/src/data-mem.c +++ b/src/data-mem.c @@ -175,7 +175,7 @@ gpgme_data_new (gpgme_data_t *r_dh) if (err) return TRACE_ERR (err); - return TRACE_SUC1 ("r_dh=%p", *r_dh); + return TRACE_SUC1 ("dh=%p", *r_dh); } diff --git a/src/data-stream.c b/src/data-stream.c index 629fb36..34a18d4 100644 --- a/src/data-stream.c +++ b/src/data-stream.c @@ -25,6 +25,7 @@ #include #include +#include "debug.h" #include "data.h" @@ -90,12 +91,16 @@ static struct _gpgme_data_cbs stream_cbs = gpgme_error_t -gpgme_data_new_from_stream (gpgme_data_t *dh, FILE *stream) +gpgme_data_new_from_stream (gpgme_data_t *r_dh, FILE *stream) { - gpgme_error_t err = _gpgme_data_new (dh, &stream_cbs); + gpgme_error_t err; + TRACE_BEG1 (DEBUG_DATA, "gpgme_data_new_from_stream", r_dh, "stream=%p", + stream); + + err = _gpgme_data_new (r_dh, &stream_cbs); if (err) - return err; + return TRACE_ERR (err); - (*dh)->data.stream = stream; - return 0; + (*r_dh)->data.stream = stream; + return TRACE_SUC1 ("dh=%p", *r_dh); } diff --git a/src/data-user.c b/src/data-user.c index ca9e9b1..de81c7b 100644 --- a/src/data-user.c +++ b/src/data-user.c @@ -25,6 +25,7 @@ #include #include +#include "debug.h" #include "data.h" @@ -86,13 +87,16 @@ static struct _gpgme_data_cbs user_cbs = gpgme_error_t -gpgme_data_new_from_cbs (gpgme_data_t *dh, gpgme_data_cbs_t cbs, void *handle) +gpgme_data_new_from_cbs (gpgme_data_t *r_dh, gpgme_data_cbs_t cbs, void *handle) { - gpgme_error_t err = _gpgme_data_new (dh, &user_cbs); + gpgme_error_t err; + TRACE_BEG1 (DEBUG_DATA, "gpgme_data_new_from_cbs", r_dh, "handle=%p", handle); + + err = _gpgme_data_new (r_dh, &user_cbs); if (err) - return err; + return TRACE_ERR (err); - (*dh)->data.user.cbs = cbs; - (*dh)->data.user.handle = handle; - return 0; + (*r_dh)->data.user.cbs = cbs; + (*r_dh)->data.user.handle = handle; + return TRACE_SUC1 ("dh=%p", *r_dh); } diff --git a/src/debug.h b/src/debug.h index 766c03f..d46c34d 100644 --- a/src/debug.h +++ b/src/debug.h @@ -34,11 +34,12 @@ /* The debug levels. */ #define DEBUG_INIT 1 -#define DEBUG_CTX 2 -#define DEBUG_ENGINE 3 -#define DEBUG_DATA 4 -#define DEBUG_ASSUAN 5 -#define DEBUG_SYSIO 6 +#define DEBUG_GLOBAL 2 +#define DEBUG_CTX 3 +#define DEBUG_ENGINE 4 +#define DEBUG_DATA 5 +#define DEBUG_ASSUAN 6 +#define DEBUG_SYSIO 7 /* Remove path components from filenames (i.e. __FILE__) for cleaner diff --git a/src/decrypt-verify.c b/src/decrypt-verify.c index 2fa3bb2..77b725f 100644 --- a/src/decrypt-verify.c +++ b/src/decrypt-verify.c @@ -23,6 +23,7 @@ #include #endif +#include "debug.h" #include "gpgme.h" #include "ops.h" @@ -86,7 +87,9 @@ gpgme_error_t gpgme_op_decrypt_verify_start (gpgme_ctx_t ctx, gpgme_data_t cipher, gpgme_data_t plain) { - return decrypt_verify_start (ctx, 0, cipher, plain); + TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_verify_start", ctx, + "cipher=%p, plain=%p", cipher, plain); + return TRACE_ERR (decrypt_verify_start (ctx, 0, cipher, plain)); } @@ -96,8 +99,12 @@ gpgme_error_t gpgme_op_decrypt_verify (gpgme_ctx_t ctx, gpgme_data_t cipher, gpgme_data_t plain) { - gpgme_error_t err = decrypt_verify_start (ctx, 1, cipher, plain); + gpgme_error_t err; + + TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_verify", ctx, + "cipher=%p, plain=%p", cipher, plain); + err = decrypt_verify_start (ctx, 1, cipher, plain); if (!err) err = _gpgme_wait_one (ctx); - return err; + return TRACE_ERR (err); } diff --git a/src/decrypt.c b/src/decrypt.c index 2569f97..c48e1a9 100644 --- a/src/decrypt.c +++ b/src/decrypt.c @@ -26,6 +26,7 @@ #include #include +#include "debug.h" #include "gpgme.h" #include "util.h" #include "context.h" @@ -74,11 +75,45 @@ gpgme_op_decrypt_result (gpgme_ctx_t ctx) op_data_t opd; gpgme_error_t err; + TRACE_BEG (DEBUG_CTX, "gpgme_op_decrypt_result", ctx); + err = _gpgme_op_data_lookup (ctx, OPDATA_DECRYPT, &hook, -1, NULL); opd = hook; if (err || !opd) - return NULL; + { + TRACE_SUC0 ("result=(null)"); + return NULL; + } + + if (_gpgme_debug_trace ()) + { + gpgme_recipient_t rcp; + int signatures = 0; + + if (opd->result.unsupported_algorithm) + { + TRACE_LOG1 ("result: unsupported_algorithm: %s", + opd->result.unsupported_algorithm); + } + if (opd->result.wrong_key_usage) + { + TRACE_LOG ("result: wrong key usage"); + } + rcp = opd->result.recipients; + while (rcp) + { + TRACE_LOG3 ("result: recipient: keyid=%s, pubkey_algo=%i, " + "status=%s", rcp->keyid, rcp->pubkey_algo, + gpg_strerror (rcp->status)); + rcp = rcp->next; + } + if (opd->result.file_name) + { + TRACE_LOG1 ("result: original file name: %s", opd->result.file_name); + } + } + TRACE_SUC1 ("result=%p", &opd->result); return &opd->result; } @@ -188,8 +223,7 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code, while (*args == ' ') args++; - if (gpg_err_code (_gpgme_map_gnupg_error (args)) - == GPG_ERR_UNSUPPORTED_ALGORITHM) + if (gpg_err_code (atoi (args)) == GPG_ERR_UNSUPPORTED_ALGORITHM) { char *end; @@ -216,8 +250,7 @@ _gpgme_decrypt_status_handler (void *priv, gpgme_status_code_t code, while (*args == ' ') args++; - err = _gpgme_map_gnupg_error (args); - if (gpg_err_code (err) == GPG_ERR_WRONG_KEY_USAGE) + if (gpg_err_code (atoi (args)) == GPG_ERR_WRONG_KEY_USAGE) opd->result.wrong_key_usage = 1; } } @@ -333,7 +366,9 @@ gpgme_error_t gpgme_op_decrypt_start (gpgme_ctx_t ctx, gpgme_data_t cipher, gpgme_data_t plain) { - return decrypt_start (ctx, 0, cipher, plain); + TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_start", ctx, + "cipher=%p, plain=%p", cipher, plain); + return TRACE_ERR (decrypt_start (ctx, 0, cipher, plain)); } @@ -342,8 +377,12 @@ gpgme_op_decrypt_start (gpgme_ctx_t ctx, gpgme_data_t cipher, gpgme_error_t gpgme_op_decrypt (gpgme_ctx_t ctx, gpgme_data_t cipher, gpgme_data_t plain) { - gpgme_error_t err = decrypt_start (ctx, 1, cipher, plain); + gpgme_error_t err; + + TRACE_BEG2 (DEBUG_CTX, "gpgme_op_decrypt_start", ctx, + "cipher=%p, plain=%p", cipher, plain); + err = decrypt_start (ctx, 1, cipher, plain); if (!err) err = _gpgme_wait_one (ctx); - return err; + return TRACE_ERR (err); } diff --git a/src/delete.c b/src/delete.c index 38f2fdd..1fd5bd8 100644 --- a/src/delete.c +++ b/src/delete.c @@ -24,6 +24,7 @@ #include #include +#include "debug.h" #include "gpgme.h" #include "context.h" #include "ops.h" @@ -93,7 +94,11 @@ gpgme_error_t gpgme_op_delete_start (gpgme_ctx_t ctx, const gpgme_key_t key, int allow_secret) { - return delete_start (ctx, 0, key, allow_secret); + TRACE_BEG3 (DEBUG_CTX, "gpgme_op_delete", ctx, + "key=%p (%s), allow_secret=%i", key, + (key->subkeys && !key->subkeys->fpr) ? + key->subkeys->fpr : "invalid", allow_secret); + return TRACE_ERR (delete_start (ctx, 0, key, allow_secret)); } @@ -102,7 +107,13 @@ gpgme_op_delete_start (gpgme_ctx_t ctx, const gpgme_key_t key, gpgme_error_t gpgme_op_delete (gpgme_ctx_t ctx, const gpgme_key_t key, int allow_secret) { - gpgme_error_t err = delete_start (ctx, 1, key, allow_secret); + gpgme_error_t err; + + TRACE_BEG3 (DEBUG_CTX, "gpgme_op_delete", ctx, + "key=%p (%s), allow_secret=%i", key, + (key->subkeys && !key->subkeys->fpr) ? + key->subkeys->fpr : "invalid", allow_secret); + err = delete_start (ctx, 1, key, allow_secret); if (!err) err = _gpgme_wait_one (ctx); return err; diff --git a/src/sign.c b/src/sign.c index 8dfccf0..0c85d0a 100644 --- a/src/sign.c +++ b/src/sign.c @@ -399,7 +399,7 @@ gpgme_op_sign (gpgme_ctx_t ctx, gpgme_data_t plain, gpgme_data_t sig, { gpgme_error_t err; - TRACE_BEG3 (DEBUG_CTX, "gpgme_op_sign_start", ctx, + TRACE_BEG3 (DEBUG_CTX, "gpgme_op_sign", ctx, "plain=%p, sig=%p, mode=%i", plain, sig, mode); err = sign_start (ctx, 1, plain, sig, mode); if (!err) diff --git a/src/verify.c b/src/verify.c index ef1ccd6..bf73a8c 100644 --- a/src/verify.c +++ b/src/verify.c @@ -545,7 +545,7 @@ parse_trust (gpgme_signature_t sig, gpgme_status_code_t code, char *args) sig->chain_model = 0; if (*args) { - sig->validity_reason = _gpgme_map_gnupg_error (args); + sig->validity_reason = atoi (args); while (*args && *args != ' ') args++; if (*args) @@ -585,7 +585,7 @@ parse_error (gpgme_signature_t sig, char *args, int set_status) else return gpg_error (GPG_ERR_INV_ENGINE); - err = _gpgme_map_gnupg_error (which); + err = atoi (which); if (!strcmp (where, "proc_pkt.plaintext") && gpg_err_code (err) == GPG_ERR_BAD_DATA) -- 2.26.2