Browse Source

[core] server.syslog-facility (fixes #2800)

server.syslog-facility = "daemon"

x-ref:
  "lighttpd needs config option for syslog facility"
  https://redmine.lighttpd.net/issues/2800
personal/stbuehler/mod-csrf
Glenn Strauss 5 years ago
parent
commit
a8561450a5
  1. 1
      src/base.h
  2. 2
      src/configfile.c
  3. 65
      src/log.c
  4. 2
      src/server.c

1
src/base.h

@ -519,6 +519,7 @@ typedef struct {
unsigned short high_precision_timestamps;
time_t loadts;
double loadavg[3];
buffer *syslog_facility;
} server_config;
typedef struct server_socket {

2
src/configfile.c

@ -163,6 +163,7 @@ static int config_insert(server *srv) {
{ "server.stream-response-body", NULL, T_CONFIG_SHORT, T_CONFIG_SCOPE_CONNECTION }, /* 77 */
{ "server.max-request-field-size", NULL, T_CONFIG_INT, T_CONFIG_SCOPE_SERVER }, /* 78 */
{ "server.error-intercept", NULL, T_CONFIG_BOOLEAN, T_CONFIG_SCOPE_CONNECTION }, /* 79 */
{ "server.syslog-facility", NULL, T_CONFIG_STRING, T_CONFIG_SCOPE_SERVER }, /* 80 */
{ NULL, NULL, T_CONFIG_UNSET, T_CONFIG_SCOPE_UNSET }
};
@ -202,6 +203,7 @@ static int config_insert(server *srv) {
cv[73].destination = &(srv->srvconf.http_host_strict);
cv[74].destination = &(srv->srvconf.http_host_normalize);
cv[78].destination = &(srv->srvconf.max_request_field_size);
cv[80].destination = srv->srvconf.syslog_facility;
srv->config_storage = calloc(1, srv->config_context->used * sizeof(specific_config *));

65
src/log.c

@ -197,7 +197,70 @@ int open_logfile_or_pipe(server *srv, const char* logfile) {
int log_error_open(server *srv) {
#ifdef HAVE_SYSLOG_H
/* perhaps someone wants to use syslog() */
openlog("lighttpd", LOG_CONS | LOG_PID, LOG_DAEMON);
int facility = 0;
if (!buffer_string_is_empty(srv->srvconf.syslog_facility)) {
static const struct facility_name_st {
const char *name;
int val;
} facility_names[] = {
{ "auth", LOG_AUTH }
#ifdef LOG_AUTHPRIV
,{ "authpriv", LOG_AUTHPRIV }
#endif
#ifdef LOG_CRON
,{ "cron", LOG_CRON }
#endif
,{ "daemon", LOG_DAEMON }
#ifdef LOG_FTP
,{ "ftp", LOG_FTP }
#endif
#ifdef LOG_KERN
,{ "kern", LOG_KERN }
#endif
#ifdef LOG_LPR
,{ "lpr", LOG_LPR }
#endif
#ifdef LOG_MAIL
,{ "mail", LOG_MAIL }
#endif
#ifdef LOG_NEWS
,{ "news", LOG_NEWS }
#endif
,{ "security", LOG_AUTH } /* DEPRECATED */
#ifdef LOG_SYSLOG
,{ "syslog", LOG_SYSLOG }
#endif
#ifdef LOG_USER
,{ "user", LOG_USER }
#endif
#ifdef LOG_UUCP
,{ "uucp", LOG_UUCP }
#endif
,{ "local0", LOG_LOCAL0 }
,{ "local1", LOG_LOCAL1 }
,{ "local2", LOG_LOCAL2 }
,{ "local3", LOG_LOCAL3 }
,{ "local4", LOG_LOCAL4 }
,{ "local5", LOG_LOCAL5 }
,{ "local6", LOG_LOCAL6 }
,{ "local7", LOG_LOCAL7 }
};
unsigned int i;
for (i = 0; i < sizeof(facility_names)/sizeof(facility_names[0]); ++i) {
const struct facility_name_st *f = facility_names+i;
if (0 == strcmp(srv->srvconf.syslog_facility->ptr, f->name)) {
facility = f->val;
break;
}
}
if (0 == facility) {
log_error_write(srv, __FILE__, __LINE__, "SBS",
"unrecognized server.syslog-facility: \"",
srv->srvconf.syslog_facility,
"\"; defaulting to \"daemon\" facility");
}
}
openlog("lighttpd", LOG_CONS | LOG_PID, facility ? facility : LOG_DAEMON);
#endif
srv->errorlog_mode = ERRORLOG_FD;

2
src/server.c

@ -246,6 +246,7 @@ static server *server_init(void) {
CLEAN(srvconf.bindhost);
CLEAN(srvconf.event_handler);
CLEAN(srvconf.pid_file);
CLEAN(srvconf.syslog_facility);
CLEAN(tmp_chunk_len);
#undef CLEAN
@ -337,6 +338,7 @@ static void server_free(server *srv) {
CLEAN(srvconf.modules_dir);
CLEAN(srvconf.network_backend);
CLEAN(srvconf.xattr_name);
CLEAN(srvconf.syslog_facility);
CLEAN(tmp_chunk_len);
#undef CLEAN

Loading…
Cancel
Save