Send patches - preferably formatted by git format-patch - to patches at archlinux32 dot org.
summaryrefslogtreecommitdiff
path: root/lib/libalpm/signing.c
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2011-03-23 22:56:54 -0500
committerDan McGee <dan@archlinux.org>2011-03-23 22:56:54 -0500
commit9a3325a56db87cc8c6336225162daefcd190208f (patch)
treeb0c4b0b25aeb98719050fda363e4a96f9819d7d1 /lib/libalpm/signing.c
parented6fda2f98bdcde56a67e43a6bcf644c549892a2 (diff)
Refactor signature loading code into common function
We can use this for both standalone package signatures as well as standalone database signatures. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'lib/libalpm/signing.c')
-rw-r--r--lib/libalpm/signing.c49
1 files changed, 47 insertions, 2 deletions
diff --git a/lib/libalpm/signing.c b/lib/libalpm/signing.c
index ecb81c9c..0434d996 100644
--- a/lib/libalpm/signing.c
+++ b/lib/libalpm/signing.c
@@ -204,6 +204,51 @@ error:
}
/**
+ * Load the signature from the given path into the provided struct.
+ * @param sigfile the signature to attempt to load
+ * @param pgpsig the struct to place the data in
+ *
+ * @return 0 on success, 1 on file not found, -1 on error
+ */
+int _alpm_load_signature(const char *sigfile, pmpgpsig_t *pgpsig) {
+ struct stat st;
+
+ 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;
+ }
+ CALLOC(pgpsig->rawdata, st.st_size, sizeof(unsigned char),
+ RET_ERR(PM_ERR_MEMORY, -1));
+ bytes_read = fread(pgpsig->rawdata, sizeof(char), st.st_size, f);
+ if(bytes_read == (size_t)st.st_size) {
+ pgpsig->rawlen = bytes_read;
+ _alpm_log(PM_LOG_DEBUG, "loaded gpg signature file, location %s\n",
+ sigfile);
+ } 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;
+ }
+
+ return 0;
+}
+
+/**
* Check the PGP package signature for the given package file.
* @param pkg the package to check
* @return a int value : 0 (valid), 1 (invalid), -1 (an error occured)
@@ -227,8 +272,8 @@ int SYMEXPORT alpm_db_check_pgp_signature(pmdb_t *db)
ALPM_LOG_FUNC;
ASSERT(db != NULL, return(0));
- return(_alpm_gpgme_checksig(_alpm_db_path(db),
- _alpm_db_pgpsig(db)));
+ return _alpm_gpgme_checksig(_alpm_db_path(db),
+ _alpm_db_pgpsig(db));
}