| 1 | Print a warning when a configuration file cannot not be opened due to read
|
| 2 | access.
|
| 3 |
|
| 4 | Upstream-status: Forwarded to the author of Pounce via email.
|
| 5 |
|
| 6 | diff --git a/local.c b/local.c
|
| 7 | index fcd670a..d4603c4 100644
|
| 8 | |
| 9 | |
| 10 | @@ -43,6 +43,15 @@
|
| 11 |
|
| 12 | static struct tls *server;
|
| 13 |
|
| 14 | +void checkReadable(const char* file) {
|
| 15 | + FILE* f = fopen(file, "r");
|
| 16 | + if (f == NULL) {
|
| 17 | + if (errno == EACCES) warnx("failed to read file '%s'", file);
|
| 18 | + } else {
|
| 19 | + fclose(f);
|
| 20 | + }
|
| 21 | +}
|
| 22 | +
|
| 23 | int localConfig(
|
| 24 | const char *cert, const char *priv, const char *ca, bool require
|
| 25 | ) {
|
| 26 | @@ -55,12 +64,14 @@ int localConfig(
|
| 27 | int error;
|
| 28 | char buf[PATH_MAX];
|
| 29 | for (int i = 0; configPath(buf, sizeof(buf), cert, i); ++i) {
|
| 30 | + checkReadable(buf);
|
| 31 | error = tls_config_set_cert_file(config, buf);
|
| 32 | if (!error) break;
|
| 33 | }
|
| 34 | if (error) goto fail;
|
| 35 |
|
| 36 | for (int i = 0; configPath(buf, sizeof(buf), priv, i); ++i) {
|
| 37 | + checkReadable(buf);
|
| 38 | error = tls_config_set_key_file(config, buf);
|
| 39 | if (!error) break;
|
| 40 | }
|
| 41 | @@ -68,6 +79,7 @@ int localConfig(
|
| 42 |
|
| 43 | if (ca) {
|
| 44 | for (int i = 0; configPath(buf, sizeof(buf), ca, i); ++i) {
|
| 45 | + checkReadable(buf);
|
| 46 | error = tls_config_set_ca_file(config, buf);
|
| 47 | if (!error) break;
|
| 48 | }
|