mirror of
https://github.com/omar-polo/gmid.git
synced 2024-09-29 22:12:12 +02:00
use the subject' common name as the user field in log
This commit is contained in:
parent
35579431eb
commit
ddbcd3c13f
20
ge.c
20
ge.c
@ -28,6 +28,7 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
@ -43,6 +44,7 @@ void
|
|||||||
log_request(struct client *c, int code, const char *meta)
|
log_request(struct client *c, int code, const char *meta)
|
||||||
{
|
{
|
||||||
char b[GEMINI_URL_LEN];
|
char b[GEMINI_URL_LEN];
|
||||||
|
char cntmp[64], cn[64] = "-";
|
||||||
char rfc3339[32];
|
char rfc3339[32];
|
||||||
const char *t;
|
const char *t;
|
||||||
struct tm *tm;
|
struct tm *tm;
|
||||||
@ -80,9 +82,21 @@ log_request(struct client *c, int code, const char *meta)
|
|||||||
strlcpy(b, t, sizeof(b));
|
strlcpy(b, t, sizeof(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
fprintf(stderr, "%s %s - %s %s 0 %d %s\n", rfc3339,
|
if (tls_peer_cert_provided(c->ctx)) {
|
||||||
c->rhost, *c->domain == '\0' ? c->iri.host : c->domain,
|
const char *subj;
|
||||||
b, code, meta);
|
char *n;
|
||||||
|
|
||||||
|
subj = tls_peer_cert_subject(c->ctx);
|
||||||
|
if ((n = strstr(subj, "/CN=")) != NULL) {
|
||||||
|
strlcpy(cntmp, subj + 4, sizeof(cntmp));
|
||||||
|
if ((n = strchr(cntmp, '/')) != NULL)
|
||||||
|
*n = '\0';
|
||||||
|
strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
fprintf(stderr, "%s %s %s %s %s 0 %d %s\n", rfc3339, c->rhost, cn,
|
||||||
|
*c->domain == '\0' ? c->iri.host : c->domain, b, code, meta);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
|
36
gmid.c
36
gmid.c
@ -29,6 +29,7 @@
|
|||||||
#include <signal.h>
|
#include <signal.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <syslog.h>
|
#include <syslog.h>
|
||||||
|
#include <vis.h>
|
||||||
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
#include "proc.h"
|
#include "proc.h"
|
||||||
@ -85,6 +86,7 @@ log_request(struct client *c, int code, const char *meta)
|
|||||||
{
|
{
|
||||||
struct conf *conf = c->conf;
|
struct conf *conf = c->conf;
|
||||||
char tstamp[64], rfc3339[32];
|
char tstamp[64], rfc3339[32];
|
||||||
|
char cntmp[64], cn[64] = "-";
|
||||||
char b[GEMINI_URL_LEN];
|
char b[GEMINI_URL_LEN];
|
||||||
char *fmted;
|
char *fmted;
|
||||||
const char *t;
|
const char *t;
|
||||||
@ -126,6 +128,19 @@ log_request(struct client *c, int code, const char *meta)
|
|||||||
strlcpy(b, t, sizeof(b));
|
strlcpy(b, t, sizeof(b));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (tls_peer_cert_provided(c->ctx)) {
|
||||||
|
const char *subj;
|
||||||
|
char *n;
|
||||||
|
|
||||||
|
subj = tls_peer_cert_subject(c->ctx);
|
||||||
|
if ((n = strstr(subj, "/CN=")) != NULL) {
|
||||||
|
strlcpy(cntmp, subj + 4, sizeof(cntmp));
|
||||||
|
if ((n = strchr(cntmp, '/')) != NULL)
|
||||||
|
*n = '\0';
|
||||||
|
strnvis(cn, cntmp, sizeof(cn), VIS_WHITE|VIS_DQ);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
switch (conf->log_format) {
|
switch (conf->log_format) {
|
||||||
case LOG_FORMAT_LEGACY:
|
case LOG_FORMAT_LEGACY:
|
||||||
ec = asprintf(&fmted, "%s:%s GET %s %d %s", c->rhost,
|
ec = asprintf(&fmted, "%s:%s GET %s %d %s", c->rhost,
|
||||||
@ -134,14 +149,11 @@ log_request(struct client *c, int code, const char *meta)
|
|||||||
|
|
||||||
case LOG_FORMAT_CONDENSED:
|
case LOG_FORMAT_CONDENSED:
|
||||||
/*
|
/*
|
||||||
* XXX the first '-' is the remote user name, we
|
|
||||||
* could use the client cert for it.
|
|
||||||
*
|
|
||||||
* XXX it should log the size of the request and
|
* XXX it should log the size of the request and
|
||||||
* response.
|
* response.
|
||||||
*/
|
*/
|
||||||
ec = asprintf(&fmted, "%s %s - %s %s 0 0 %d %s", rfc3339,
|
ec = asprintf(&fmted, "%s %s %s %s %s 0 0 %d %s", rfc3339,
|
||||||
c->rhost, *c->domain == '\0' ? c->iri.host : c->domain,
|
c->rhost, cn, *c->domain == '\0' ? c->iri.host : c->domain,
|
||||||
b, code, meta);
|
b, code, meta);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
@ -152,14 +164,11 @@ log_request(struct client *c, int code, const char *meta)
|
|||||||
*/
|
*/
|
||||||
case LOG_FORMAT_COMMON:
|
case LOG_FORMAT_COMMON:
|
||||||
/*
|
/*
|
||||||
* XXX the second '-' is the remote user name, we
|
|
||||||
* could use the client cert for it.
|
|
||||||
*
|
|
||||||
* XXX it should log the size of the response.
|
* XXX it should log the size of the response.
|
||||||
*/
|
*/
|
||||||
ec = asprintf(&fmted, "%s %s - - %s \"%s\" %d 0",
|
ec = asprintf(&fmted, "%s %s - %s %s \"%s\" %d 0",
|
||||||
*c->domain == '\0' ? c->iri.host : c->domain,
|
*c->domain == '\0' ? c->iri.host : c->domain,
|
||||||
c->rhost, tstamp, b, code);
|
c->rhost, cn, tstamp, b, code);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
/*
|
/*
|
||||||
@ -170,13 +179,10 @@ log_request(struct client *c, int code, const char *meta)
|
|||||||
case LOG_FORMAT_COMBINED:
|
case LOG_FORMAT_COMBINED:
|
||||||
default:
|
default:
|
||||||
/*
|
/*
|
||||||
* XXX the second '-' is the remote user name, we
|
|
||||||
* could use the client cert for it.
|
|
||||||
*
|
|
||||||
* XXX it should log the size of the response.
|
* XXX it should log the size of the response.
|
||||||
*/
|
*/
|
||||||
ec = asprintf(&fmted, "%s - - [%s] \"%s\" %d 0 \"-\" \"\"",
|
ec = asprintf(&fmted, "%s - %s [%s] \"%s\" %d 0 \"-\" \"\"",
|
||||||
c->rhost, tstamp, b, code);
|
c->rhost, cn, tstamp, b, code);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user