1
0
mirror of https://github.com/moparisthebest/pacman synced 2024-08-13 17:03:46 -04:00

Reduce duplicate signing debug code and fix logic condition

We had a lot of similar looking code that we can collapse down into a
function. This also fixes errors seen when turning on some gcc warnings
and implicitly casting away the const-ness of the string. Free the list
when we are done with it as well.

Also, fix a logic error where we should be checking with &&, not ||.

Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
Dan McGee 2011-05-04 15:42:50 -05:00
parent 4758cfe33f
commit c03faa32f3

View File

@ -60,6 +60,15 @@ static const char *gpgme_string_validity(gpgme_validity_t validity)
return "???"; return "???";
} }
static alpm_list_t *sigsum_test_bit(gpgme_sigsum_t sigsum, alpm_list_t *summary,
gpgme_sigsum_t bit, const char *value)
{
if(sigsum & bit) {
summary = alpm_list_add(summary, (void *)value);
}
return summary;
}
static alpm_list_t *gpgme_list_sigsum(gpgme_sigsum_t sigsum) static alpm_list_t *gpgme_list_sigsum(gpgme_sigsum_t sigsum)
{ {
alpm_list_t *summary = NULL; alpm_list_t *summary = NULL;
@ -67,52 +76,30 @@ static alpm_list_t *gpgme_list_sigsum(gpgme_sigsum_t sigsum)
* for it anyway and show all possible flags in the returned string. */ * for it anyway and show all possible flags in the returned string. */
/* The signature is fully valid. */ /* The signature is fully valid. */
if(sigsum & GPGME_SIGSUM_VALID) { summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_VALID, "valid");
summary = alpm_list_add(summary, "valid");
}
/* The signature is good. */ /* The signature is good. */
if(sigsum & GPGME_SIGSUM_GREEN) { summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_GREEN, "green");
summary = alpm_list_add(summary, "green");
}
/* The signature is bad. */ /* The signature is bad. */
if(sigsum & GPGME_SIGSUM_RED) { summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_RED, "red");
summary = alpm_list_add(summary, "red");
}
/* One key has been revoked. */ /* One key has been revoked. */
if(sigsum & GPGME_SIGSUM_KEY_REVOKED) { summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_KEY_REVOKED, "key revoked");
summary = alpm_list_add(summary, "key revoked");
}
/* One key has expired. */ /* One key has expired. */
if(sigsum & GPGME_SIGSUM_KEY_EXPIRED) { summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_KEY_EXPIRED, "key expired");
summary = alpm_list_add(summary, "key expired");
}
/* The signature has expired. */ /* The signature has expired. */
if(sigsum & GPGME_SIGSUM_SIG_EXPIRED) { summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_SIG_EXPIRED, "sig expired");
summary = alpm_list_add(summary, "sig expired");
}
/* Can't verify: key missing. */ /* Can't verify: key missing. */
if(sigsum & GPGME_SIGSUM_KEY_MISSING) { summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_KEY_MISSING, "key missing");
summary = alpm_list_add(summary, "key missing");
}
/* CRL not available. */ /* CRL not available. */
if(sigsum & GPGME_SIGSUM_CRL_MISSING) { summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_CRL_MISSING, "crl missing");
summary = alpm_list_add(summary, "crl missing");
}
/* Available CRL is too old. */ /* Available CRL is too old. */
if(sigsum & GPGME_SIGSUM_CRL_TOO_OLD) { summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_CRL_TOO_OLD, "crl too old");
summary = alpm_list_add(summary, "crl too old");
}
/* A policy was not met. */ /* A policy was not met. */
if(sigsum & GPGME_SIGSUM_BAD_POLICY) { summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_BAD_POLICY, "bad policy");
summary = alpm_list_add(summary, "bad policy");
}
/* A system error occured. */ /* A system error occured. */
if(sigsum & GPGME_SIGSUM_SYS_ERROR) { summary = sigsum_test_bit(sigsum, summary, GPGME_SIGSUM_SYS_ERROR, "sys error");
summary = alpm_list_add(summary, "sys error");
}
/* Fallback case */ /* Fallback case */
if(!sigsum) { if(!sigsum) {
summary = alpm_list_add(summary, "(empty)"); summary = alpm_list_add(summary, (void *)"(empty)");
} }
return summary; return summary;
} }
@ -189,7 +176,7 @@ static int decode_signature(const char *base64_data,
int ret, destlen = 0; int ret, destlen = 0;
/* get the necessary size for the buffer by passing 0 */ /* get the necessary size for the buffer by passing 0 */
ret = base64_decode(NULL, &destlen, usline, len); ret = base64_decode(NULL, &destlen, usline, len);
if(ret != 0 || ret != POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) { if(ret != 0 && ret != POLARSSL_ERR_BASE64_BUFFER_TOO_SMALL) {
goto error; goto error;
} }
/* alloc our memory and repeat the call to decode */ /* alloc our memory and repeat the call to decode */
@ -316,6 +303,7 @@ int _alpm_gpgme_checksig(const char *path, const char *base64_sig)
for(summary = summary_list; summary; summary = summary->next) { for(summary = summary_list; summary; summary = summary->next) {
_alpm_log(PM_LOG_DEBUG, "summary: %s\n", (const char *)summary->data); _alpm_log(PM_LOG_DEBUG, "summary: %s\n", (const char *)summary->data);
} }
alpm_list_free(summary_list);
_alpm_log(PM_LOG_DEBUG, "status: %s\n", gpgme_strerror(gpgsig->status)); _alpm_log(PM_LOG_DEBUG, "status: %s\n", gpgme_strerror(gpgsig->status));
_alpm_log(PM_LOG_DEBUG, "timestamp: %lu\n", gpgsig->timestamp); _alpm_log(PM_LOG_DEBUG, "timestamp: %lu\n", gpgsig->timestamp);
_alpm_log(PM_LOG_DEBUG, "exp_timestamp: %lu\n", gpgsig->exp_timestamp); _alpm_log(PM_LOG_DEBUG, "exp_timestamp: %lu\n", gpgsig->exp_timestamp);