Skip to content
This repository has been archived by the owner on May 24, 2022. It is now read-only.

Logging: make syslog facility configurable. #83

Merged
merged 1 commit into from
Mar 15, 2012
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.md
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ Detail about the entire set of options can be found by invoking `stud -h`:
LOGGING: LOGGING:
-q --quiet Be quiet; emit only error messages -q --quiet Be quiet; emit only error messages
-s --syslog Send log message to syslog in addition to stderr/stdout -s --syslog Send log message to syslog in addition to stderr/stdout
--syslog-facility=FACILITY Syslog facility to use (Default: "daemon")


OTHER OPTIONS: OTHER OPTIONS:
--daemon Fork into background and become a daemon (Default: off) --daemon Fork into background and become a daemon (Default: off)
Expand Down
98 changes: 98 additions & 0 deletions configuration.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
#include <pwd.h> #include <pwd.h>
#include <grp.h> #include <grp.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <syslog.h>


#include "configuration.h" #include "configuration.h"
#include "version.h" #include "version.h"
Expand All @@ -39,6 +40,8 @@
#define CFG_GROUP "group" #define CFG_GROUP "group"
#define CFG_QUIET "quiet" #define CFG_QUIET "quiet"
#define CFG_SYSLOG "syslog" #define CFG_SYSLOG "syslog"
#define CFG_SYSLOG_FACILITY "syslog-facility"
#define CFG_PARAM_SYSLOG_FACILITY 11015
#define CFG_DAEMON "daemon" #define CFG_DAEMON "daemon"
#define CFG_WRITE_IP "write-ip" #define CFG_WRITE_IP "write-ip"
#define CFG_WRITE_PROXY "write-proxy" #define CFG_WRITE_PROXY "write-proxy"
Expand Down Expand Up @@ -137,6 +140,7 @@ stud_config * config_new (void) {


r->QUIET = 0; r->QUIET = 0;
r->SYSLOG = 0; r->SYSLOG = 0;
r->SYSLOG_FACILITY = LOG_DAEMON;
r->TCP_KEEPALIVE_TIME = 3600; r->TCP_KEEPALIVE_TIME = 3600;
r->DAEMONIZE = 0; r->DAEMONIZE = 0;
r->PREFER_SERVER_CIPHERS = 0; r->PREFER_SERVER_CIPHERS = 0;
Expand Down Expand Up @@ -620,6 +624,47 @@ void config_param_validate (char *k, char *v, stud_config *cfg, char *file, int
else if (strcmp(k, CFG_SYSLOG) == 0) { else if (strcmp(k, CFG_SYSLOG) == 0) {
r = config_param_val_bool(v, &cfg->SYSLOG); r = config_param_val_bool(v, &cfg->SYSLOG);
} }
else if (strcmp(k, CFG_SYSLOG_FACILITY) == 0) {
r = 1;
if (!strcmp(v, "auth") || !strcmp(v, "authpriv"))
cfg->SYSLOG_FACILITY = LOG_AUTHPRIV;
else if (!strcmp(v, "cron"))
cfg->SYSLOG_FACILITY = LOG_CRON;
else if (!strcmp(v, "daemon"))
cfg->SYSLOG_FACILITY = LOG_DAEMON;
else if (!strcmp(v, "ftp"))
cfg->SYSLOG_FACILITY = LOG_FTP;
else if (!strcmp(v, "local0"))
cfg->SYSLOG_FACILITY = LOG_LOCAL0;
else if (!strcmp(v, "local1"))
cfg->SYSLOG_FACILITY = LOG_LOCAL1;
else if (!strcmp(v, "local2"))
cfg->SYSLOG_FACILITY = LOG_LOCAL2;
else if (!strcmp(v, "local3"))
cfg->SYSLOG_FACILITY = LOG_LOCAL3;
else if (!strcmp(v, "local4"))
cfg->SYSLOG_FACILITY = LOG_LOCAL4;
else if (!strcmp(v, "local5"))
cfg->SYSLOG_FACILITY = LOG_LOCAL5;
else if (!strcmp(v, "local6"))
cfg->SYSLOG_FACILITY = LOG_LOCAL6;
else if (!strcmp(v, "local7"))
cfg->SYSLOG_FACILITY = LOG_LOCAL7;
else if (!strcmp(v, "lpr"))
cfg->SYSLOG_FACILITY = LOG_LPR;
else if (!strcmp(v, "mail"))
cfg->SYSLOG_FACILITY = LOG_MAIL;
else if (!strcmp(v, "news"))
cfg->SYSLOG_FACILITY = LOG_NEWS;
else if (!strcmp(v, "user"))
cfg->SYSLOG_FACILITY = LOG_USER;
else if (!strcmp(v, "uucp"))
cfg->SYSLOG_FACILITY = LOG_UUCP;
else {
config_error_set("Invalid facility '%s'.", v);
r = 0;
}
}
else if (strcmp(k, CFG_DAEMON) == 0) { else if (strcmp(k, CFG_DAEMON) == 0) {
r = config_param_val_bool(v, &cfg->DAEMONIZE); r = config_param_val_bool(v, &cfg->DAEMONIZE);
} }
Expand Down Expand Up @@ -748,6 +793,48 @@ char * config_disp_hostport (char *host, char *port) {
return tmp_buf; return tmp_buf;
} }


const char * config_disp_log_facility (int facility) {
switch (facility)
{
case LOG_AUTHPRIV:
return "authpriv";
case LOG_CRON:
return "cron";
case LOG_DAEMON:
return "daemon";
case LOG_FTP:
return "ftp";
case LOG_LOCAL0:
return "local0";
case LOG_LOCAL1:
return "local1";
case LOG_LOCAL2:
return "local2";
case LOG_LOCAL3:
return "local3";
case LOG_LOCAL4:
return "local4";
case LOG_LOCAL5:
return "local5";
case LOG_LOCAL6:
return "local6";
case LOG_LOCAL7:
return "local7";
case LOG_LPR:
return "lpr";
case LOG_MAIL:
return "mail";
case LOG_NEWS:
return "news";
case LOG_USER:
return "user";
case LOG_UUCP:
return "uucp";
default:
return "UNKNOWN";
}
}

void config_print_usage_fd (char *prog, stud_config *cfg, FILE *out) { void config_print_usage_fd (char *prog, stud_config *cfg, FILE *out) {
if (out == NULL) out = stderr; if (out == NULL) out = stderr;
fprintf(out, "Usage: %s [OPTIONS] PEM\n\n", basename(prog)); fprintf(out, "Usage: %s [OPTIONS] PEM\n\n", basename(prog));
Expand Down Expand Up @@ -806,6 +893,7 @@ void config_print_usage_fd (char *prog, stud_config *cfg, FILE *out) {
fprintf(out, "LOGGING:\n"); fprintf(out, "LOGGING:\n");
fprintf(out, " -q --quiet Be quiet; emit only error messages\n"); fprintf(out, " -q --quiet Be quiet; emit only error messages\n");
fprintf(out, " -s --syslog Send log message to syslog in addition to stderr/stdout\n"); fprintf(out, " -s --syslog Send log message to syslog in addition to stderr/stdout\n");
fprintf(out, " --syslog-facility=FACILITY Syslog facility to use (Default: \"%s\")\n", config_disp_log_facility(cfg->SYSLOG_FACILITY));
fprintf(out, "\n"); fprintf(out, "\n");
fprintf(out, "OTHER OPTIONS:\n"); fprintf(out, "OTHER OPTIONS:\n");
fprintf(out, " --daemon Fork into background and become a daemon (Default: %s)\n", config_disp_bool(cfg->DAEMONIZE)); fprintf(out, " --daemon Fork into background and become a daemon (Default: %s)\n", config_disp_bool(cfg->DAEMONIZE));
Expand Down Expand Up @@ -968,6 +1056,12 @@ void config_print_default (FILE *fd, stud_config *cfg) {
fprintf(fd, FMT_STR, CFG_SYSLOG, config_disp_bool(cfg->SYSLOG)); fprintf(fd, FMT_STR, CFG_SYSLOG, config_disp_bool(cfg->SYSLOG));
fprintf(fd, "\n"); fprintf(fd, "\n");


fprintf(fd, "# Syslog facility to use\n");
fprintf(fd, "#\n");
fprintf(fd, "# type: string\n");
fprintf(fd, FMT_QSTR, CFG_SYSLOG_FACILITY, config_disp_log_facility(cfg->SYSLOG_FACILITY));
fprintf(fd, "\n");

fprintf(fd, "# Run as daemon\n"); fprintf(fd, "# Run as daemon\n");
fprintf(fd, "#\n"); fprintf(fd, "#\n");
fprintf(fd, "# type: boolean\n"); fprintf(fd, "# type: boolean\n");
Expand Down Expand Up @@ -1032,6 +1126,7 @@ void config_parse_cli(int argc, char **argv, stud_config *cfg) {
{ CFG_GROUP, 1, NULL, 'g' }, { CFG_GROUP, 1, NULL, 'g' },
{ CFG_QUIET, 0, NULL, 'q' }, { CFG_QUIET, 0, NULL, 'q' },
{ CFG_SYSLOG, 0, NULL, 's' }, { CFG_SYSLOG, 0, NULL, 's' },
{ CFG_SYSLOG_FACILITY, 1, NULL, CFG_PARAM_SYSLOG_FACILITY },
{ CFG_DAEMON, 0, &cfg->DAEMONIZE, 1 }, { CFG_DAEMON, 0, &cfg->DAEMONIZE, 1 },
{ CFG_WRITE_IP, 0, &cfg->WRITE_IP_OCTET, 1 }, { CFG_WRITE_IP, 0, &cfg->WRITE_IP_OCTET, 1 },
{ CFG_WRITE_PROXY, 0, &cfg->WRITE_PROXY_LINE, 1 }, { CFG_WRITE_PROXY, 0, &cfg->WRITE_PROXY_LINE, 1 },
Expand Down Expand Up @@ -1066,6 +1161,9 @@ void config_parse_cli(int argc, char **argv, stud_config *cfg) {
exit(0); exit(0);
break; break;
#endif #endif
case CFG_PARAM_SYSLOG_FACILITY:
config_param_validate(CFG_SYSLOG_FACILITY, optarg, cfg, NULL, 0);
break;
case 'c': case 'c':
config_param_validate(CFG_CIPHERS, optarg, cfg, NULL, 0); config_param_validate(CFG_CIPHERS, optarg, cfg, NULL, 0);
break; break;
Expand Down
1 change: 1 addition & 0 deletions configuration.h
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ struct __stud_config {
#endif #endif
int QUIET; int QUIET;
int SYSLOG; int SYSLOG;
int SYSLOG_FACILITY;
int TCP_KEEPALIVE_TIME; int TCP_KEEPALIVE_TIME;
int DAEMONIZE; int DAEMONIZE;
int PREFER_SERVER_CIPHERS; int PREFER_SERVER_CIPHERS;
Expand Down
3 changes: 3 additions & 0 deletions stud.8
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -107,6 +107,9 @@ Send messages to syslog in addition to
.Em stderr .Em stderr
and and
.Em stdout . .Em stdout .
.It Fl -syslog-facility Ar facility
Syslog facility to use. Default is
.Ar daemon .
.It Fl -write-ip .It Fl -write-ip
Write 1 octet with the IP family followed by the IP address in 4 Write 1 octet with the IP family followed by the IP address in 4
(IPv4) or 16 (IPv6) octets little-endian to backend before the actual (IPv4) or 16 (IPv6) octets little-endian to backend before the actual
Expand Down
2 changes: 1 addition & 1 deletion stud.c
Original file line number Original file line Diff line number Diff line change
Expand Up @@ -1262,7 +1262,7 @@ void init_globals() {
fail("calloc"); fail("calloc");


if (CONFIG->SYSLOG) if (CONFIG->SYSLOG)
openlog("stud", LOG_CONS | LOG_PID | LOG_NDELAY, LOG_DAEMON); openlog("stud", LOG_CONS | LOG_PID | LOG_NDELAY, CONFIG->SYSLOG_FACILITY);
} }


/* Forks COUNT children starting with START_INDEX. /* Forks COUNT children starting with START_INDEX.
Expand Down