diff options
Diffstat (limited to 'src/policy.c')
| -rw-r--r-- | src/policy.c | 17 |
1 files changed, 12 insertions, 5 deletions
diff --git a/src/policy.c b/src/policy.c index b2d4348..db00c78 100644 --- a/src/policy.c +++ b/src/policy.c @@ -86,13 +86,18 @@ static void perr(policy_t *p, int line, const char *fmt, ...) { va_list ap; + // A person pushing has no use for a line number in a file they cannot read, + // so the hook loads its policy with the log switched off. + p->errors++; - fprintf(stderr, "%s:%d: error: ", + if (p->log == NULL) + return; + fprintf(p->log, "%s:%d: error: ", p->path != NULL ? p->path : "authz.conf", line); va_start(ap, fmt); - vfprintf(stderr, fmt, ap); + vfprintf(p->log, fmt, ap); va_end(ap); - fputc('\n', stderr); + fputc('\n', p->log); } int authz_user_pattern_ok(const char *s) @@ -290,6 +295,7 @@ void policy_init(policy_t *p, const char *path) { memset(p, 0, sizeof(*p)); p->path = xstrdup(path); + p->log = stderr; // whoever reads the file hears what is wrong } void policy_free(policy_t *p) @@ -324,8 +330,9 @@ int policy_load(policy_t *p) rc = authz_read_lines(p->path, &lines); if (rc != 0) { p->unreadable = 1; - fprintf(stderr, "%s: cannot read the policy: %s\n", p->path, - strerror(errno)); + if (p->log != NULL) + fprintf(p->log, "%s: cannot read the policy: %s\n", p->path, + strerror(errno)); lines_free(&lines); return -2; } |
