mirror of
https://github.com/moparisthebest/pacman
synced 2025-01-10 21:38:19 -05:00
Form the signature file location in one place
Since we do this for all cases anyway. Signed-off-by: Dan McGee <dan@archlinux.org>
This commit is contained in:
parent
791928dc48
commit
3c5661ec3c
@ -243,7 +243,6 @@ static pmpkg_t *pkg_load(const char *pkgfile, int full)
|
|||||||
|
|
||||||
/* attempt to stat the package file, ensure it exists */
|
/* attempt to stat the package file, ensure it exists */
|
||||||
if(stat(pkgfile, &st) == 0) {
|
if(stat(pkgfile, &st) == 0) {
|
||||||
char *pgpfile;
|
|
||||||
int sig_ret;
|
int sig_ret;
|
||||||
|
|
||||||
newpkg = _alpm_pkg_new();
|
newpkg = _alpm_pkg_new();
|
||||||
@ -253,13 +252,9 @@ static pmpkg_t *pkg_load(const char *pkgfile, int full)
|
|||||||
newpkg->filename = strdup(pkgfile);
|
newpkg->filename = strdup(pkgfile);
|
||||||
newpkg->size = st.st_size;
|
newpkg->size = st.st_size;
|
||||||
|
|
||||||
/* look around for a PGP signature file; load if available */
|
|
||||||
MALLOC(pgpfile, strlen(pkgfile) + 5, RET_ERR(PM_ERR_MEMORY, NULL));
|
|
||||||
sprintf(pgpfile, "%s.sig", pkgfile);
|
|
||||||
/* TODO: do something with ret value */
|
/* TODO: do something with ret value */
|
||||||
sig_ret = _alpm_load_signature(pgpfile, &(newpkg->pgpsig));
|
sig_ret = _alpm_load_signature(pkgfile, &(newpkg->pgpsig));
|
||||||
(void)sig_ret;
|
(void)sig_ret;
|
||||||
FREE(pgpfile);
|
|
||||||
} else {
|
} else {
|
||||||
/* couldn't stat the pkgfile, return an error */
|
/* couldn't stat the pkgfile, return an error */
|
||||||
RET_ERR(PM_ERR_PKG_OPEN, NULL);
|
RET_ERR(PM_ERR_PKG_OPEN, NULL);
|
||||||
|
@ -322,21 +322,14 @@ const pmpgpsig_t *_alpm_db_pgpsig(pmdb_t *db)
|
|||||||
ASSERT(db != NULL, return(NULL));
|
ASSERT(db != NULL, return(NULL));
|
||||||
|
|
||||||
if(db->pgpsig.rawdata == NULL) {
|
if(db->pgpsig.rawdata == NULL) {
|
||||||
size_t len;
|
|
||||||
const char *dbfile;
|
const char *dbfile;
|
||||||
char *sigfile;
|
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
dbfile = _alpm_db_path(db);
|
dbfile = _alpm_db_path(db);
|
||||||
len = strlen(dbfile) + 5;
|
|
||||||
MALLOC(sigfile, len, RET_ERR(PM_ERR_MEMORY, NULL));
|
|
||||||
sprintf(sigfile, "%s.sig", dbfile);
|
|
||||||
|
|
||||||
/* TODO: do something with ret value */
|
/* TODO: do something with ret value */
|
||||||
ret = _alpm_load_signature(sigfile, &(db->pgpsig));
|
ret = _alpm_load_signature(dbfile, &(db->pgpsig));
|
||||||
(void)ret;
|
(void)ret;
|
||||||
|
|
||||||
FREE(sigfile);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return &(db->pgpsig);
|
return &(db->pgpsig);
|
||||||
|
@ -210,19 +210,22 @@ error:
|
|||||||
*
|
*
|
||||||
* @return 0 on success, 1 on file not found, -1 on 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;
|
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) {
|
if(access(sigfile, R_OK) == 0 && stat(sigfile, &st) == 0) {
|
||||||
FILE *f;
|
FILE *f;
|
||||||
size_t bytes_read;
|
size_t bytes_read;
|
||||||
|
|
||||||
if(st.st_size > 4096) {
|
if(st.st_size > 4096 || (f = fopen(sigfile, "rb")) == NULL) {
|
||||||
return -1;
|
free(sigfile);
|
||||||
}
|
return ret;
|
||||||
|
|
||||||
if((f = fopen(sigfile, "rb")) == NULL) {
|
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
CALLOC(pgpsig->rawdata, st.st_size, sizeof(unsigned char),
|
CALLOC(pgpsig->rawdata, st.st_size, sizeof(unsigned char),
|
||||||
RET_ERR(PM_ERR_MEMORY, -1));
|
RET_ERR(PM_ERR_MEMORY, -1));
|
||||||
@ -231,21 +234,22 @@ int _alpm_load_signature(const char *sigfile, pmpgpsig_t *pgpsig) {
|
|||||||
pgpsig->rawlen = bytes_read;
|
pgpsig->rawlen = bytes_read;
|
||||||
_alpm_log(PM_LOG_DEBUG, "loaded gpg signature file, location %s\n",
|
_alpm_log(PM_LOG_DEBUG, "loaded gpg signature file, location %s\n",
|
||||||
sigfile);
|
sigfile);
|
||||||
|
ret = 0;
|
||||||
} else {
|
} else {
|
||||||
_alpm_log(PM_LOG_WARNING, _("Failed reading PGP signature file %s"),
|
_alpm_log(PM_LOG_WARNING, _("Failed reading PGP signature file %s"),
|
||||||
sigfile);
|
sigfile);
|
||||||
FREE(pgpsig->rawdata);
|
FREE(pgpsig->rawdata);
|
||||||
return -1;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fclose(f);
|
fclose(f);
|
||||||
} else {
|
} else {
|
||||||
_alpm_log(PM_LOG_DEBUG, "signature file %s not found\n", sigfile);
|
_alpm_log(PM_LOG_DEBUG, "signature file %s not found\n", sigfile);
|
||||||
/* not fatal...we return a different error code here */
|
/* not fatal...we return a different error code here */
|
||||||
return 1;
|
ret = 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
return 0;
|
free(sigfile);
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
Loading…
Reference in New Issue
Block a user