Blame SOURCES/0018-show-which-db-we-re-checking.patch

0ac9f2
From 01b89fb7a191f4639a93c5a7c47a80752118ba95 Mon Sep 17 00:00:00 2001
0ac9f2
From: Peter Jones <pjones@redhat.com>
0ac9f2
Date: Tue, 25 Apr 2017 16:58:50 -0400
0ac9f2
Subject: [PATCH 18/29] show which db we're checking
0ac9f2
0ac9f2
---
0ac9f2
 src/certdb.c             | 35 ++++++++++++++++++++++++++++++++++-
0ac9f2
 src/pesigcheck_context.c |  2 ++
0ac9f2
 src/pesigcheck_context.h |  1 +
0ac9f2
 3 files changed, 37 insertions(+), 1 deletion(-)
0ac9f2
0ac9f2
diff --git a/src/certdb.c b/src/certdb.c
0ac9f2
index 1a4baf1..673e074 100644
0ac9f2
--- a/src/certdb.c
0ac9f2
+++ b/src/certdb.c
0ac9f2
@@ -18,6 +18,7 @@
0ac9f2
  */
0ac9f2
 
0ac9f2
 #include <fcntl.h>
0ac9f2
+#include <libgen.h>
0ac9f2
 #include <sys/mman.h>
0ac9f2
 #include <sys/types.h>
0ac9f2
 #include <sys/stat.h>
0ac9f2
@@ -42,17 +43,33 @@ add_db_file(pesigcheck_context *ctx, db_specifier which, const char *dbfile,
0ac9f2
 		return -1;
0ac9f2
 
0ac9f2
 	db->type = type;
0ac9f2
-
0ac9f2
 	db->fd = open(dbfile, O_RDONLY);
0ac9f2
 	if (db->fd < 0) {
0ac9f2
 		save_errno(free(db));
0ac9f2
 		return -1;
0ac9f2
 	}
0ac9f2
 
0ac9f2
+	char *path = strdup(dbfile);
0ac9f2
+	if (!path) {
0ac9f2
+		save_errno(close(db->fd);
0ac9f2
+			   free(db));
0ac9f2
+		return -1;
0ac9f2
+	}
0ac9f2
+
0ac9f2
+	db->path = basename(path);
0ac9f2
+	db->path = strdup(db->path);
0ac9f2
+	free(path);
0ac9f2
+	if (!db->path) {
0ac9f2
+		save_errno(close(db->fd);
0ac9f2
+			   free(db));
0ac9f2
+		return -1;
0ac9f2
+	}
0ac9f2
+
0ac9f2
 	struct stat sb;
0ac9f2
 	int rc = fstat(db->fd, &sb);
0ac9f2
 	if (rc < 0) {
0ac9f2
 		save_errno(close(db->fd);
0ac9f2
+			   free(db->path);
0ac9f2
 			   free(db));
0ac9f2
 		return -1;
0ac9f2
 	}
0ac9f2
@@ -65,6 +82,7 @@ add_db_file(pesigcheck_context *ctx, db_specifier which, const char *dbfile,
0ac9f2
 		rc = read_file(db->fd, (char **)&db->map, &sz);
0ac9f2
 		if (rc < 0) {
0ac9f2
 			save_errno(close(db->fd);
0ac9f2
+				   free(db->path);
0ac9f2
 				   free(db));
0ac9f2
 			return -1;
0ac9f2
 		}
0ac9f2
@@ -133,6 +151,7 @@ add_cert_file(pesigcheck_context *ctx, const char *filename)
0ac9f2
 #define DB_PATH "/sys/firmware/efi/efivars/db-d719b2cb-3d3a-4596-a3bc-dad00e67656f"
0ac9f2
 #define MOK_PATH "/sys/firmware/efi/efivars/MokListRT-605dab50-e046-4300-abb6-3dd810dd8b23"
0ac9f2
 #define DBX_PATH "/sys/firmware/efi/efivars/dbx-d719b2cb-3d3a-4596-a3bc-dad00e67656f"
0ac9f2
+#define MOKX_PATH "/sys/firmware/efi/efivars/MokListXRT-605dab50-e046-4300-abb6-3dd810dd8b23"
0ac9f2
 
0ac9f2
 void
0ac9f2
 init_cert_db(pesigcheck_context *ctx, int use_system_dbs)
0ac9f2
@@ -167,6 +186,18 @@ init_cert_db(pesigcheck_context *ctx, int use_system_dbs)
0ac9f2
 			"database \"%s\": %m\n", DBX_PATH);
0ac9f2
 		exit(1);
0ac9f2
 	}
0ac9f2
+
0ac9f2
+	rc = add_db_file(ctx, DBX, MOKX_PATH, DB_EFIVAR);
0ac9f2
+	if (rc < 0 && errno != ENOENT) {
0ac9f2
+		fprintf(stderr, "pesigcheck: Could not add key database "
0ac9f2
+			"\"%s\": %m\n", MOKX_PATH);
0ac9f2
+		exit(1);
0ac9f2
+	}
0ac9f2
+
0ac9f2
+	if (ctx->dbx == NULL) {
0ac9f2
+		fprintf(stderr, "pesigcheck: warning: "
0ac9f2
+			"No key recovation database available\n");
0ac9f2
+	}
0ac9f2
 }
0ac9f2
 
0ac9f2
 typedef db_status (*checkfn)(pesigcheck_context *ctx, SECItem *sig,
0ac9f2
@@ -187,6 +218,8 @@ check_db(db_specifier which, pesigcheck_context *ctx, checkfn check,
0ac9f2
 	sig.type = siBuffer;
0ac9f2
 
0ac9f2
 	while (dbl) {
0ac9f2
+		printf("Searching %s %s\n", which == DB ? "db" : "dbx",
0ac9f2
+		       dbl->path);
0ac9f2
 		EFI_SIGNATURE_LIST *certlist;
0ac9f2
 		EFI_SIGNATURE_DATA *cert;
0ac9f2
 		size_t dbsize = dbl->datalen;
0ac9f2
diff --git a/src/pesigcheck_context.c b/src/pesigcheck_context.c
0ac9f2
index b934cbe..5a355b1 100644
0ac9f2
--- a/src/pesigcheck_context.c
0ac9f2
+++ b/src/pesigcheck_context.c
0ac9f2
@@ -87,6 +87,7 @@ pesigcheck_context_fini(pesigcheck_context *ctx)
0ac9f2
 		munmap(db->map, db->size);
0ac9f2
 		close(db->fd);
0ac9f2
 		ctx->db = db->next;
0ac9f2
+		free(db->path);
0ac9f2
 		free(db);
0ac9f2
 	}
0ac9f2
 	while (ctx->dbx) {
0ac9f2
@@ -95,6 +96,7 @@ pesigcheck_context_fini(pesigcheck_context *ctx)
0ac9f2
 		if (db->type == DB_CERT)
0ac9f2
 			free(db->data);
0ac9f2
 		munmap(db->map, db->size);
0ac9f2
+		free(db->path);
0ac9f2
 		close(db->fd);
0ac9f2
 		ctx->dbx = db->next;
0ac9f2
 		free(db);
0ac9f2
diff --git a/src/pesigcheck_context.h b/src/pesigcheck_context.h
0ac9f2
index 1b916e3..7b5cc89 100644
0ac9f2
--- a/src/pesigcheck_context.h
0ac9f2
+++ b/src/pesigcheck_context.h
0ac9f2
@@ -34,6 +34,7 @@ typedef enum {
0ac9f2
 
0ac9f2
 struct dblist {
0ac9f2
 	db_f_type type;
0ac9f2
+	char *path;
0ac9f2
 	int fd;
0ac9f2
 	struct dblist *next;
0ac9f2
 	size_t size;
0ac9f2
-- 
0ac9f2
2.13.4
0ac9f2