From: Mark Wooding Date: Sun, 21 Oct 2012 21:30:26 +0000 (+0100) Subject: policy.c, yaid.c: Silently ignore missing user policy files. X-Git-Tag: 1.0.0~1 X-Git-Url: https://git.distorted.org.uk/~mdw/yaid/commitdiff_plain/17272ab8669aa3061b08de9862ea1e9086b8b540 policy.c, yaid.c: Silently ignore missing user policy files. --- diff --git a/policy.c b/policy.c index 32a4550..57ce979 100644 --- a/policy.c +++ b/policy.c @@ -443,13 +443,15 @@ fail: * formatting error messages for the log. */ int open_policy_file(struct policy_file *pf, const char *name, - const char *what, const struct query *q) + const char *what, const struct query *q, unsigned f) { struct stat st; if ((pf->fp = fopen(name, "r")) == 0) { - logmsg(q, LOG_ERR, "failed to open %s `%s': %s", - what, name, strerror(errno)); + if (errno != ENOENT || !(f & OPF_NOENTOK)) { + logmsg(q, LOG_ERR, "failed to open %s `%s': %s", + what, name, strerror(errno)); + } goto err_0; } @@ -529,7 +531,7 @@ int load_policy_file(const char *file, policy_v *pv) struct policy_file pf; policy_v v = DA_INIT; - if (open_policy_file(&pf, file, "policy file", 0)) + if (open_policy_file(&pf, file, "policy file", 0, 0)) return (-1); while (!read_policy_file(&pf)) { DA_PUSH(&v, pf.p); diff --git a/yaid.c b/yaid.c index a99604f..1dfa947 100644 --- a/yaid.c +++ b/yaid.c @@ -705,7 +705,7 @@ static void client_line(char *line, size_t len, void *p) */ DRESET(&d); dstr_putf(&d, "%s/.yaid.policy", pw->pw_dir); - if (open_policy_file(&pf, d.buf, "user policy file", &c->q)) + if (open_policy_file(&pf, d.buf, "user policy file", &c->q, OPF_NOENTOK)) continue; while (!read_policy_file(&pf)) { diff --git a/yaid.h b/yaid.h index 4011787..18c17ec 100644 --- a/yaid.h +++ b/yaid.h @@ -349,7 +349,9 @@ struct policy_file { * formatting error messages for the log. */ extern int open_policy_file(struct policy_file */*pf*/, const char */*name*/, - const char */*what*/, const struct query */*q*/); + const char */*what*/, const struct query */*q*/, + unsigned /*f*/); +#define OPF_NOENTOK 1u /* Don't complain if file missing */ /* Read a policy rule from the file, storing it in PF->p. Return one of the * T_* codes.