X-Git-Url: https://www.chiark.greenend.org.uk/ucgi/~mdw/git/yaid/blobdiff_plain/223e3e2be7a30ab58804b9b741c9438b123a16fd..152ca59daf3abc63081bc5da9748d86cbb75c1af:/yaid.c?ds=inline diff --git a/yaid.c b/yaid.c index a99604f..cc3bb47 100644 --- a/yaid.c +++ b/yaid.c @@ -298,7 +298,8 @@ static void done_client_write(int err, void *p) /* Format the message FMT and queue it to be sent to the client. Client * input will be disabled until the write completes. */ -static void write_to_client(struct client *c, const char *fmt, ...) +static void PRINTF_LIKE(2, 3) + write_to_client(struct client *c, const char *fmt, ...) { va_list ap; char buf[WRBUFSZ]; @@ -364,8 +365,8 @@ static void cancel_proxy(struct proxy *px) selbuf_destroy(&px->b); free_writebuf(&px->wb); } - selbuf_enable(&px->c->b); px->c->px = 0; + selbuf_enable(&px->c->b); xfree(px); } @@ -629,9 +630,10 @@ static void client_line(char *line, size_t len, void *p) struct policy upol = POLICY_INIT(A_LIMIT); struct policy_file pf; char buf[16]; - int i; + int i, t; /* If the connection has closed, then tidy stuff away. */ + c->q.s[R].addr = c->raddr; c->q.s[L].port = c->q.s[R].port = 0; if (!line) { disconnect_client(c); @@ -657,7 +659,6 @@ static void client_line(char *line, size_t len, void *p) skipws(&q); if (*q) goto bad; /* Identify the connection. Act on the result. */ - c->q.s[R].addr = c->raddr; identify(&c->q); switch (c->q.resp) { @@ -705,13 +706,13 @@ 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)) { + while ((t = read_policy_file(&pf)) < T_ERROR) { - /* Give up after 100 lines. If the user's policy is that complicated, - * something's gone very wrong. Or there's too much commentary or - * something. + /* Give up after 100 lines or if there's an error. If the user's + * policy is that complicated, something's gone very wrong. Or there's + * too much commentary or something. */ if (pf.lno > 100) { logmsg(&c->q, LOG_ERR, "%s:%d: user policy file too long", @@ -719,6 +720,9 @@ static void client_line(char *line, size_t len, void *p) break; } + /* If this was a blank line, just go around again. */ + if (t != T_OK) continue; + /* If this isn't a match, go around for the next rule. */ if (!match_policy(&pf.p, &c->q)) continue; @@ -906,7 +910,7 @@ static int make_listening_socket(const struct addrops *ao, int port) } /* Quit because of a fatal signal. */ -static void quit(int sig, void *p) +static void NORETURN quit(int sig, void *p) { const char *signame = p;