diff --git a/ChangeLog b/ChangeLog index 57b7a59..2fbab93 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,7 @@ +2021-02-22 Omar Polo + + * log.c (log_request): add `log on/off' to enable/disable logs per-server or per-location + 2021-02-09 Omar Polo * parse.y (locopt): add `require client ca' rule to require client certs signed by a specified CA diff --git a/gmid.h b/gmid.h index 2a5b6be..454ddd3 100644 --- a/gmid.h +++ b/gmid.h @@ -66,6 +66,7 @@ struct location { const char *block_fmt; int strip; X509_STORE *reqca; + int disable_log; }; struct vhost { @@ -234,6 +235,7 @@ int vhost_auto_index(struct vhost*, const char*); int vhost_block_return(struct vhost*, const char*, int*, const char**); int vhost_strip(struct vhost*, const char*); X509_STORE *vhost_require_ca(struct vhost*, const char*); +int vhost_disable_log(struct vhost*, const char*); void mark_nonblock(int); void loop(struct tls*, int, int); diff --git a/lex.l b/lex.l index 41fab03..d61b994 100644 --- a/lex.l +++ b/lex.l @@ -65,6 +65,7 @@ ipv6 return TIPV6; key return TKEY; lang return TLANG; location return TLOCATION; +log return TLOG; mime return TMIME; port return TPORT; prefork return TPREFORK; diff --git a/log.c b/log.c index 6bb84f1..b47444b 100644 --- a/log.c +++ b/log.c @@ -188,6 +188,9 @@ log_request(struct client *c, char *meta, size_t l) size_t len; int ec; + if (vhost_disable_log(c->host, c->iri.path)) + return; + len = sizeof(c->addr); ec = getnameinfo((struct sockaddr*)&c->addr, len, hbuf, sizeof(hbuf), diff --git a/parse.y b/parse.y index 968670d..06fdf25 100644 --- a/parse.y +++ b/parse.y @@ -58,7 +58,7 @@ void advance_loc(void); %token TIPV6 TPORT TPROTOCOLS TMIME TDEFAULT TTYPE %token TCHROOT TUSER TSERVER TPREFORK -%token TLOCATION TCERT TKEY TROOT TCGI TLANG TINDEX TAUTO +%token TLOCATION TCERT TKEY TROOT TCGI TLANG TLOG TINDEX TAUTO %token TSTRIP TBLOCK TRETURN TENTRYPOINT TREQUIRE TCLIENT TCA %token TERR @@ -190,6 +190,7 @@ locopt : TAUTO TINDEX TBOOL { loc->auto_index = $3 ? 1 : -1; } yyerror("`lang' specified more than once"); loc->lang = $2; } + | TLOG TBOOL { loc->disable_log = !$2; } | TREQUIRE TCLIENT TCA TSTRING { if (loc->reqca != NULL) yyerror("`require client ca' specified more than once"); diff --git a/server.c b/server.c index 13e0830..ec0762d 100644 --- a/server.c +++ b/server.c @@ -224,6 +224,22 @@ vhost_require_ca(struct vhost *v, const char *path) return v->locations[0].reqca; } +int +vhost_disable_log(struct vhost *v, const char *path) +{ + struct location *loc; + + if (v == NULL || path == NULL) + return 0; + + for (loc = &v->locations[1]; loc->match != NULL; ++loc) { + if (loc->disable_log && matches(loc->match, path)) + return 1; + } + + return v->locations[0].disable_log; +} + static int check_path(struct client *c, const char *path, int *fd) {