summaryrefslogtreecommitdiff
path: root/lib/libalpm/signing.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-03-28 12:48:37 -0500
committerDan McGee <dan@archlinux.org>2011-04-20 20:10:27 -0500
commit3c5661ec3cd5cdf2f1c3101d90789c83786a6897 (patch)
tree7f23826062a221b5a8d773ee3f47207a6de37339 /lib/libalpm/signing.c
parent791928dc48bcd94ef5cb57b4da36fb5e398e30da (diff)
downloadpacman-3c5661ec3cd5cdf2f1c3101d90789c83786a6897.tar.xz
Form the signature file location in one place
Since we do this for all cases anyway. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/signing.c')
-rw-r--r--lib/libalpm/signing.c24
1 files changed, 14 insertions, 10 deletions
diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index 42e8c677..51c4f4ce 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -210,19 +210,22 @@ error:
*
* @return 0 on success, 1 on file not found, -1 on error
*/
-int _alpm_load_signature(const char *sigfile, pmpgpsig_t *pgpsig) {
+int _alpm_load_signature(const char *file, pmpgpsig_t *pgpsig) {
struct stat st;
+ char *sigfile;
+ int ret = -1;
+
+ /* look around for a PGP signature file; load if available */
+ MALLOC(sigfile, strlen(file) + 5, RET_ERR(PM_ERR_MEMORY, -1));
+ sprintf(sigfile, "%s.sig", file);
if(access(sigfile, R_OK) == 0 && stat(sigfile, &st) == 0) {
FILE *f;
size_t bytes_read;
- if(st.st_size > 4096) {
- return -1;
- }
-
- if((f = fopen(sigfile, "rb")) == NULL) {
- return -1;
+ if(st.st_size > 4096 || (f = fopen(sigfile, "rb")) == NULL) {
+ free(sigfile);
+ return ret;
}
CALLOC(pgpsig->rawdata, st.st_size, sizeof(unsigned char),
RET_ERR(PM_ERR_MEMORY, -1));
@@ -231,21 +234,22 @@ int _alpm_load_signature(const char *sigfile, pmpgpsig_t *pgpsig) {
pgpsig->rawlen = bytes_read;
_alpm_log(PM_LOG_DEBUG, "loaded gpg signature file, location %s\n",
sigfile);
+ ret = 0;
} else {
_alpm_log(PM_LOG_WARNING, _("Failed reading PGP signature file %s"),
sigfile);
FREE(pgpsig->rawdata);
- return -1;
}
fclose(f);
} else {
_alpm_log(PM_LOG_DEBUG, "signature file %s not found\n", sigfile);
/* not fatal...we return a different error code here */
- return 1;
+ ret = 1;
}
- return 0;
+ free(sigfile);
+ return ret;
}
/**