[pacman-dev] [PATCH 2/2] Provide more information for database signature failures

Allan McRae allan at archlinux.org
Sun Jul 21 05:25:47 EDT 2013


Distinguish between database that failed to verify and that are missing.

Signed-off-by: Allan McRae <allan at archlinux.org>
---
 lib/libalpm/alpm.h    |  1 +
 lib/libalpm/be_sync.c | 14 ++++++++++++--
 lib/libalpm/db.h      |  1 +
 lib/libalpm/error.c   |  2 ++
 src/pacman/conf.c     |  2 +-
 5 files changed, 17 insertions(+), 3 deletions(-)

diff --git a/lib/libalpm/alpm.h b/lib/libalpm/alpm.h
index 28608bd..b8aab76 100644
--- a/lib/libalpm/alpm.h
+++ b/lib/libalpm/alpm.h
@@ -1246,6 +1246,7 @@ typedef enum _alpm_errno_t {
 	ALPM_ERR_DB_NOT_FOUND,
 	ALPM_ERR_DB_INVALID,
 	ALPM_ERR_DB_INVALID_SIG,
+	ALPM_ERR_DB_MISSING_SIG,
 	ALPM_ERR_DB_VERSION,
 	ALPM_ERR_DB_WRITE,
 	ALPM_ERR_DB_REMOVE,
diff --git a/lib/libalpm/be_sync.c b/lib/libalpm/be_sync.c
index 65d2331..72589ef 100644
--- a/lib/libalpm/be_sync.c
+++ b/lib/libalpm/be_sync.c
@@ -76,8 +76,13 @@ static int sync_db_validate(alpm_db_t *db)
 	if(db->status & DB_STATUS_VALID || db->status & DB_STATUS_MISSING) {
 		return 0;
 	}
+
 	if(db->status & DB_STATUS_INVALID) {
-		db->handle->pm_errno = ALPM_ERR_DB_INVALID_SIG;
+		if(db->status & DB_STATUS_MISSING_SIG) {
+			db->handle->pm_errno = ALPM_ERR_DB_MISSING_SIG;
+		} else {
+			db->handle->pm_errno = ALPM_ERR_DB_INVALID_SIG;
+		}
 		return -1;
 	}
 
@@ -121,7 +126,12 @@ static int sync_db_validate(alpm_db_t *db)
 		if(ret) {
 			db->status &= ~DB_STATUS_VALID;
 			db->status |= DB_STATUS_INVALID;
-			db->handle->pm_errno = ALPM_ERR_DB_INVALID_SIG;
+			if(db->handle->pm_errno == ALPM_ERR_SIG_MISSING) {
+				db->status |= DB_STATUS_MISSING_SIG;
+				db->handle->pm_errno = ALPM_ERR_DB_MISSING_SIG;
+			} else {
+				db->handle->pm_errno = ALPM_ERR_DB_INVALID_SIG;
+			}
 			return 1;
 		}
 	}
diff --git a/lib/libalpm/db.h b/lib/libalpm/db.h
index e4d9f71..909c66f 100644
--- a/lib/libalpm/db.h
+++ b/lib/libalpm/db.h
@@ -48,6 +48,7 @@ enum _alpm_dbstatus_t {
 	DB_STATUS_INVALID = (1 << 1),
 	DB_STATUS_EXISTS = (1 << 2),
 	DB_STATUS_MISSING = (1 << 3),
+	DB_STATUS_MISSING_SIG = (1 << 4),
 
 	DB_STATUS_LOCAL = (1 << 10),
 	DB_STATUS_PKGCACHE = (1 << 11),
diff --git a/lib/libalpm/error.c b/lib/libalpm/error.c
index 8622180..bf085e4 100644
--- a/lib/libalpm/error.c
+++ b/lib/libalpm/error.c
@@ -72,6 +72,8 @@ const char SYMEXPORT *alpm_strerror(alpm_errno_t err)
 			return _("invalid or corrupted database");
 		case ALPM_ERR_DB_INVALID_SIG:
 			return _("invalid or corrupted database (PGP signature)");
+		case ALPM_ERR_DB_MISSING_SIG:
+			return _("database missing required signature");
 		case ALPM_ERR_DB_VERSION:
 			return _("database is incorrect version");
 		case ALPM_ERR_DB_WRITE:
diff --git a/src/pacman/conf.c b/src/pacman/conf.c
index aa27559..42b59bd 100644
--- a/src/pacman/conf.c
+++ b/src/pacman/conf.c
@@ -774,7 +774,7 @@ static int finish_section(struct section_t *section, int parse_options)
 	}
 
 	/* if we are not looking at options sections only, register a db */
-	db = alpm_register_syncdb(config->handle, section->name, section->siglevel, config->op_s_upgrade);
+	db = alpm_register_syncdb(config->handle, section->name, section->siglevel, config->op_s_sync);
 	if(db == NULL) {
 		pm_printf(ALPM_LOG_ERROR, _("could not register '%s' database (%s)\n"),
 				section->name, alpm_strerror(alpm_errno(config->handle)));
-- 
1.8.3.3



More information about the pacman-dev mailing list