policy.c, yaid.c: Silently ignore missing user policy files.
authorMark Wooding <mdw@distorted.org.uk>
Sun, 21 Oct 2012 21:30:26 +0000 (22:30 +0100)
committerMark Wooding <mdw@distorted.org.uk>
Fri, 26 Oct 2012 23:16:38 +0000 (00:16 +0100)
policy.c
yaid.c
yaid.h

index 32a4550..57ce979 100644 (file)
--- 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 (file)
--- 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 (file)
--- 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.