add `log on/off' to enable/disable logs per-location

This commit is contained in:
Omar Polo 2021-02-22 08:53:14 +00:00
parent fd9a486925
commit 793835cb26
No known key found for this signature in database
GPG Key ID: 35F98C96A1786F0D
6 changed files with 28 additions and 1 deletions

View File

@ -1,3 +1,7 @@
2021-02-22 Omar Polo <op@omarpolo.com>
* log.c (log_request): add `log on/off' to enable/disable logs per-server or per-location
2021-02-09 Omar Polo <op@omarpolo.com>
* parse.y (locopt): add `require client ca' rule to require client certs signed by a specified CA

2
gmid.h
View File

@ -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);

1
lex.l
View File

@ -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;

3
log.c
View File

@ -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),

View File

@ -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");

View File

@ -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)
{