Blame SOURCES/fapolicyd-hash.patch

d51d46
From f5bca29fb408fce7297656c5bb01f70cd452a9d7 Mon Sep 17 00:00:00 2001
d51d46
From: Steve Grubb <sgrubb@redhat.com>
d51d46
Date: Thu, 20 Jun 2019 14:46:36 -0400
d51d46
Subject: [PATCH] Convert hashes to lowercase like sha256sum outputs
d51d46
d51d46
---
d51d46
 ChangeLog             | 1 +
d51d46
 doc/fapolicyd.rules.5 | 2 +-
d51d46
 src/file.c            | 5 +++--
d51d46
 3 files changed, 5 insertions(+), 3 deletions(-)
d51d46
d51d46
diff --git a/doc/fapolicyd.rules.5 b/doc/fapolicyd.rules.5
d51d46
index 6b12f03..887bdf7 100644
d51d46
--- a/doc/fapolicyd.rules.5
d51d46
+++ b/doc/fapolicyd.rules.5
d51d46
@@ -115,7 +115,7 @@ This option will match against the device that the file being accessed resides o
d51d46
 This option matches against the mime type of the file being accessed. See \fBexe_type\fP for more information on determining the mime type.
d51d46
 .TP
d51d46
 .B sha256hash
d51d46
-This option matches against the sha256 hash of the file being accessed.
d51d46
+This option matches against the sha256 hash of the file being accessed. The hash in the rules should be all lowercase letters and do NOT start with 0x. Lowercase is the default output of sha256sum.
d51d46
 .RE
d51d46
 
d51d46
 .SH EXAMPLES
d51d46
diff --git a/src/file.c b/src/file.c
d51d46
index 39d3a58..68e6bf5 100644
d51d46
--- a/src/file.c
d51d46
+++ b/src/file.c
d51d46
@@ -1,6 +1,6 @@
d51d46
 /*
d51d46
  * file.c - functions for accessing attributes of files
d51d46
- * Copyright (c) 2016,2018 Red Hat Inc., Durham, North Carolina.
d51d46
+ * Copyright (c) 2016,2018-19 Red Hat Inc., Durham, North Carolina.
d51d46
  * All Rights Reserved.
d51d46
  *
d51d46
  * This software may be freely redistributed and/or modified under the
d51d46
@@ -272,7 +272,7 @@ static char *bytes2hex(char *final, const char *buf, unsigned int size)
d51d46
 {
d51d46
 	unsigned int i;
d51d46
 	char *ptr = final;
d51d46
-	const char *hex = "0123456789ABCDEF";
d51d46
+	const char *hex = "0123456789abcdef";
d51d46
 
d51d46
 	for (i=0; i
d51d46
 		*ptr++ = hex[(buf[i] & 0xF0)>>4]; /* Upper nibble */
d51d46
@@ -307,6 +307,7 @@ char *get_hash_from_fd(int fd)
d51d46
 		return NULL;
d51d46
 
d51d46
 	// read in a buffer at a time and hand to gcrypt
d51d46
+	lseek(fd, 0, SEEK_SET);
d51d46
 	while ((len = safe_read(fd, fbuf, 4096)) > 0) {
d51d46
 		gcry_md_write(ctx, fbuf, len);
d51d46
 		if (len != 4096)