aboutsummaryrefslogtreecommitdiff
path: root/gnu/packages/patches/pounce-readable-checks.patch
blob: 3b47b0012033a3a78536e8f367df453f949e4e9b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
Print a warning when a configuration file cannot not be opened due to read
access.

Upstream-status: Forwarded to the author of Pounce via email.

diff --git a/local.c b/local.c
index fcd670a..d4603c4 100644
--- a/local.c
+++ b/local.c
@@ -43,6 +43,15 @@
 
 static struct tls *server;
 
+void checkReadable(const char* file) {
+	FILE* f = fopen(file, "r");
+	if (f == NULL) {
+		if (errno == EACCES) warnx("failed to read file '%s'", file);
+	} else {
+		fclose(f);
+	}
+}
+
 int localConfig(
 	const char *cert, const char *priv, const char *ca, bool require
 ) {
@@ -55,12 +64,14 @@ int localConfig(
 	int error;
 	char buf[PATH_MAX];
 	for (int i = 0; configPath(buf, sizeof(buf), cert, i); ++i) {
+		checkReadable(buf);
 		error = tls_config_set_cert_file(config, buf);
 		if (!error) break;
 	}
 	if (error) goto fail;
 
 	for (int i = 0; configPath(buf, sizeof(buf), priv, i); ++i) {
+		checkReadable(buf);
 		error = tls_config_set_key_file(config, buf);
 		if (!error) break;
 	}
@@ -68,6 +79,7 @@ int localConfig(
 
 	if (ca) {
 		for (int i = 0; configPath(buf, sizeof(buf), ca, i); ++i) {
+			checkReadable(buf);
 			error = tls_config_set_ca_file(config, buf);
 			if (!error) break;
 		}