head 1.35; access; symbols L2_0_9_13:1.35 FSL_1_7_0:1.35 L2_0_9_12:1.35 LMTP2NNTP_1_4_1:1.35 LMTP2NNTP_1_4_0:1.35 FSL_1_6_1:1.35 L2_0_9_11:1.35 FSL_1_6_0:1.34 FSL_1_6b2:1.34 L2_0_9_10:1.34 FSL_1_6b1:1.34 L2_0_9_9:1.34 LMTP2NNTP_1_3_0:1.33 LMTP2NNTP_1_3b2:1.33 LMTP2NNTP_1_3b1:1.33 LMTP2NNTP_1_3a3:1.33 FSL_1_5_0:1.33 LMTP2NNTP_1_3a2:1.33 FSL_1_5a3:1.33 LMTP2NNTP_1_3a1:1.33 FSL_1_5a2:1.33 L2_0_9_8:1.33 FSL_1_5a1:1.33 L2_0_9_7:1.33 L2_0_9_6:1.33 FSL_1_4_0:1.33 FSL_1_4b1:1.33 L2_0_9_5:1.33 FSL_1_4a1:1.33 FSL_1_3_0:1.33 FSL_1_3b1:1.33 L2_0_9_4:1.33 FSL_1_2_1:1.33 L2_0_9_3:1.33 FSL_1_2_0:1.33 L2_0_9_2:1.33 FSL_1_1_0:1.33 FSL_1_1b1:1.33 WORKOFF:1.33.0.2 WORKOFF_BP:1.33 FSL_1_0_8:1.33 LMTP2NNTP_1_2_0:1.33 LMTP2NNTP_1_2b4:1.33 LMTP2NNTP_1_2b3:1.33 LMTP2NNTP_1_2b2:1.33 LMTP2NNTP_1_2b1:1.33 LMTP2NNTP_1_2a8:1.33 LMTP2NNTP_1_2a7:1.33 FSL_1_0_7:1.33 FSL_1_0_6:1.32 FSL_1_0_5:1.31 FSL_1_0_4:1.31 L2_0_9_1:1.31 FSL_1_0_3:1.31 LMTP2NNTP_1_2a6:1.31 FSL_1_0_2:1.31 FSL_1_0_1:1.31 FSL_1_0_0:1.31 FSL_0_9_0:1.31 L2_0_9_0:1.31 FSL_0_1_12:1.30 FSL_0_1_11:1.30 FSL_0_1_10:1.30 FSL_0_1_9:1.30 FSL_0_1_8:1.30 FSL_0_1_7:1.30 FSL_0_1_6:1.30 FSL_0_1_5:1.29 FSL_0_1_1:1.29 LMTP2NNTP_1_2a5:1.29 LMTP2NNTP_1_2a4:1.29 LMTP2NNTP_1_2a3:1.29 LMTP2NNTP_1_2a1:1.28 LMTP2NNTP_1_1_1:1.25 LMTP2NNTP_1_1_0:1.25 LMTP2NNTP_1_1b4:1.25 LMTP2NNTP_1_1b3:1.25 L2_CHANNEL_ONLY_REVAMPING_BEFORE:1.25 LMTP2NNTP_1_1b2:1.25 LMTP2NNTP_1_1b1:1.25 L2_0_1_0:1.20 L2NGATE:1.8.0.2 START_MICHAEL:1.6 L2_INITIAL:1.1.1.1 OSSP:1.1.1; locks; strict; comment @ * @; 1.35 date 2005.10.03.08.08.11; author rse; state Exp; branches; next 1.34; 1.34 date 2005.01.24.15.03.17; author rse; state Exp; branches; next 1.33; 1.33 date 2003.01.06.11.41.51; author rse; state Exp; branches; next 1.32; 1.32 date 2002.11.09.14.44.31; author rse; state Exp; branches; next 1.31; 1.31 date 2002.07.30.19.08.25; author rse; state Exp; branches; next 1.30; 1.30 date 2002.07.25.13.33.00; author thl; state Exp; branches; next 1.29; 1.29 date 2002.01.02.17.07.38; author rse; state Exp; branches; next 1.28; 1.28 date 2001.11.08.09.02.35; author rse; state Exp; branches; next 1.27; 1.27 date 2001.11.07.13.05.20; author rse; state Exp; branches; next 1.26; 1.26 date 2001.11.07.11.37.18; author rse; state Exp; branches; next 1.25; 1.25 date 2001.10.12.13.51.41; author rse; state Exp; branches; next 1.24; 1.24 date 2001.10.10.15.58.27; author rse; state Exp; branches; next 1.23; 1.23 date 2001.10.06.14.35.57; author rse; state Exp; branches; next 1.22; 1.22 date 2001.10.06.14.33.09; author rse; state Exp; branches; next 1.21; 1.21 date 2001.09.14.19.11.00; author rse; state Exp; branches; next 1.20; 1.20 date 2001.09.12.09.42.34; author ms; state Exp; branches; next 1.19; 1.19 date 2001.09.10.14.33.24; author ms; state Exp; branches; next 1.18; 1.18 date 2001.09.10.06.42.00; author thl; state Exp; branches; next 1.17; 1.17 date 2001.09.06.16.10.05; author rse; state Exp; branches; next 1.16; 1.16 date 2001.09.06.14.43.25; author rse; state Exp; branches; next 1.15; 1.15 date 2001.09.06.14.37.53; author rse; state Exp; branches; next 1.14; 1.14 date 2001.09.05.07.47.12; author rse; state Exp; branches; next 1.13; 1.13 date 2001.09.04.19.35.20; author ms; state Exp; branches; next 1.12; 1.12 date 2001.09.04.19.18.49; author rse; state Exp; branches; next 1.11; 1.11 date 2001.09.04.15.44.48; author rse; state Exp; branches; next 1.10; 1.10 date 2001.09.04.15.41.17; author rse; state Exp; branches; next 1.9; 1.9 date 2001.09.04.13.52.59; author rse; state Exp; branches; next 1.8; 1.8 date 2001.08.26.13.05.41; author ms; state Exp; branches; next 1.7; 1.7 date 2001.08.25.18.27.48; author ms; state Exp; branches; next 1.6; 1.6 date 2001.08.15.10.36.03; author rse; state Exp; branches; next 1.5; 1.5 date 2001.05.26.08.04.12; author rse; state Exp; branches; next 1.4; 1.4 date 2001.05.26.08.02.55; author rse; state Exp; branches; next 1.3; 1.3 date 2001.05.17.14.42.00; author simons; state Exp; branches; next 1.2; 1.2 date 2001.05.11.17.07.52; author rse; state Exp; branches; next 1.1; 1.1 date 2001.05.10.19.46.01; author rse; state Exp; branches 1.1.1.1; next ; 1.1.1.1 date 2001.05.10.19.46.01; author rse; state Exp; branches; next ; desc @@ 1.35 log @Adjust copyright messages for new year 2005. @ text @/* ** OSSP l2 - Flexible Logging ** Copyright (c) 2001-2005 Cable & Wireless ** Copyright (c) 2001-2005 The OSSP Project ** Copyright (c) 2001-2005 Ralf S. Engelschall ** ** This file is part of OSSP l2, a flexible logging library which ** can be found at http://www.ossp.org/pkg/lib/l2/. ** ** Permission to use, copy, modify, and distribute this software for ** any purpose with or without fee is hereby granted, provided that ** the above copyright notice and this permission notice appear in all ** copies. ** ** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED ** WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF ** MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. ** IN NO EVENT SHALL THE AUTHORS AND COPYRIGHT HOLDERS AND THEIR ** CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, ** SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT ** LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF ** USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ** ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, ** OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT ** OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF ** SUCH DAMAGE. ** ** l2_ch_syslog.c: syslog(3) channel implementation */ #include "l2.h" #include "l2_p.h" #include #include #include #include #include /* declare private channel configuration */ typedef struct { char *szTarget; char *szRemoteHost; int nRemotePort; char *szLocalHost; char *szFacility; int nFacility; char *szIdent; int bLogPid; sa_t *saRemoteSock; sa_addr_t *saaRemoteAddr; } l2_ch_syslog_t; /* mapping from L2 log levels to syslog(3) log levels */ static struct { int levelL2; int levelSL; } l2_ch_syslog_L2toSL[] = { { L2_LEVEL_PANIC, LOG_EMERG }, { L2_LEVEL_CRITICAL, LOG_CRIT }, { L2_LEVEL_ERROR, LOG_ERR }, { L2_LEVEL_WARNING, LOG_WARNING }, { L2_LEVEL_NOTICE, LOG_NOTICE }, { L2_LEVEL_INFO, LOG_INFO }, { L2_LEVEL_TRACE, LOG_INFO }, { L2_LEVEL_DEBUG, LOG_DEBUG }, { -1, -1 } }; /* Syslog Facility Table */ static struct { char *name; /* the common name */ int numREMOTE; /* number according to RFC3164 */ int numLOCAL; /* local encoding */ } l2_ch_syslog_SLfac[] = { { "kern", 0, LOG_KERN }, { "user", 1, LOG_USER }, { "mail", 2, LOG_MAIL }, { "daemon", 3, LOG_DAEMON }, { "auth", 4, LOG_AUTH }, #ifndef LOG_SYSLOG #define LOG_SYSLOG (5 << 3) #endif { "syslog", 5, LOG_SYSLOG }, { "lpr", 6, LOG_LPR }, { "news", 7, LOG_NEWS }, { "uucp", 8, LOG_UUCP }, { "cron", 9, LOG_CRON }, #ifndef LOG_AUTHPRIV #define LOG_AUTHPRIV (10 << 3) #endif { "authpriv", 10, LOG_AUTHPRIV }, #ifndef LOG_FTP #define LOG_FTP (11 << 3) #endif { "ftp", 11, LOG_FTP }, #ifndef LOG_NTP #define LOG_NTP (12 << 3) #endif { "ntp", 12, LOG_NTP }, #ifndef LOG_SECURITY #define LOG_SECURITY (13 << 3) #endif { "security", 13, LOG_SECURITY }, #ifndef LOG_CONSOLE #define LOG_CONSOLE (14 << 3) #endif { "console", 14, LOG_CONSOLE }, #ifndef LOG_CLOCK #define LOG_CLOCK (15 << 3) #endif { "clock", 15, LOG_CLOCK }, { "local0", 16, LOG_LOCAL0 }, { "local1", 17, LOG_LOCAL1 }, { "local2", 18, LOG_LOCAL2 }, { "local3", 19, LOG_LOCAL3 }, { "local4", 20, LOG_LOCAL4 }, { "local5", 21, LOG_LOCAL5 }, { "local6", 22, LOG_LOCAL6 }, { "local7", 23, LOG_LOCAL7 }, { NULL, 0, 0 } }; /* create channel */ static l2_result_t hook_create(l2_context_t *ctx, l2_channel_t *ch) { l2_ch_syslog_t *cfg; struct utsname uts; char *cp; /* allocate private channel configuration */ if ((cfg = (l2_ch_syslog_t *)malloc(sizeof(l2_ch_syslog_t))) == NULL) return L2_ERR_MEM; /* initialize configuration with reasonable defaults */ cfg->szTarget = strdup("local"); cfg->szRemoteHost = NULL; cfg->nRemotePort = 514; /*FIXME[thl] better use getservbyname()*/ if (uname(&uts) == 0) { cfg->szLocalHost = strdup(uts.nodename); if ((cp = strchr(cfg->szLocalHost, '.')) != NULL) *cp = '\0'; } else cfg->szLocalHost = strdup("localhost"); cfg->szFacility = strdup("user"); cfg->nFacility = LOG_USER; cfg->szIdent = NULL; cfg->bLogPid = FALSE; cfg->saRemoteSock = NULL; cfg->saaRemoteAddr = NULL; /* link private channel configuration into channel context */ ctx->vp = cfg; return L2_OK; } /* configure channel */ static l2_result_t hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap) { l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp; l2_param_t pa[8]; l2_result_t rv; l2_env_t *env; int i; /* feed and call generic parameter parsing engine */ L2_PARAM_SET(pa[0], target, STR, &cfg->szTarget); L2_PARAM_SET(pa[1], remotehost, STR, &cfg->szRemoteHost); L2_PARAM_SET(pa[2], remoteport, INT, &cfg->nRemotePort); L2_PARAM_SET(pa[3], localhost, STR, &cfg->szLocalHost); L2_PARAM_SET(pa[4], facility, STR, &cfg->szFacility); L2_PARAM_SET(pa[5], ident, STR, &cfg->szIdent); L2_PARAM_SET(pa[6], logpid, INT, &cfg->bLogPid); L2_PARAM_END(pa[7]); /* sanity checking & post-processing */ l2_channel_env(ch, &env); rv = l2_util_setparams(env, pa, fmt, ap); if (cfg->szTarget == NULL || cfg->szFacility == NULL) return L2_ERR_USE; if (!( strcmp(cfg->szTarget, "local") == 0 || strcmp(cfg->szTarget, "remote") == 0)) return L2_ERR_USE; for (i = 0; l2_ch_syslog_SLfac[i].name != NULL; i++) if (strcmp(l2_ch_syslog_SLfac[i].name, cfg->szFacility) == 0) break; if (l2_ch_syslog_SLfac[i].name == NULL) return L2_ERR_USE; if (strcmp(cfg->szTarget, "local") == 0) cfg->nFacility = l2_ch_syslog_SLfac[i].numLOCAL; else cfg->nFacility = (l2_ch_syslog_SLfac[i].numREMOTE << 3); if ( strcmp(cfg->szTarget, "remote") == 0 && (cfg->szRemoteHost == NULL || (cfg->nRemotePort <= 0 || cfg->nRemotePort >= 65536))) return L2_ERR_USE; if ( cfg->szLocalHost == NULL || strchr(cfg->szLocalHost, '.') != NULL) return L2_ERR_USE; if (cfg->szIdent != NULL && strlen(cfg->szIdent) > (32-(1+5+1))) return L2_ERR_USE; return rv; } /* open channel */ static l2_result_t hook_open(l2_context_t *ctx, l2_channel_t *ch) { l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp; int opt; sa_rc_t rc; sa_addr_t *la; if (cfg->szIdent == NULL) return L2_ERR_USE; if (strcmp(cfg->szTarget, "local") == 0) { /* open local syslog connection via syslog(3) */ opt = 0; if (cfg->bLogPid) opt |= LOG_PID; openlog(cfg->szIdent, opt, cfg->nFacility); /* setlogmask(0); */ } else { /* open remote syslog connection via UDP socket */ if (cfg->szRemoteHost == NULL) return L2_ERR_USE; if ((rc = sa_addr_create(&cfg->saaRemoteAddr)) != SA_OK) return (rc == SA_ERR_SYS ? L2_ERR_SYS : L2_ERR_INT); if ((rc = sa_addr_u2a(cfg->saaRemoteAddr, "inet://%s:%d", cfg->szRemoteHost, cfg->nRemotePort)) != SA_OK) return (rc == SA_ERR_SYS ? L2_ERR_SYS : L2_ERR_INT); if ((rc = sa_create(&cfg->saRemoteSock)) != SA_OK) return (rc == SA_ERR_SYS ? L2_ERR_SYS : L2_ERR_INT); sa_type(cfg->saRemoteSock, SA_TYPE_DATAGRAM); sa_timeout(cfg->saRemoteSock, SA_TIMEOUT_ALL, 10, 0); if ((rc = sa_addr_create(&la)) != SA_OK) return (rc == SA_ERR_SYS ? L2_ERR_SYS : L2_ERR_INT); /* FIXME: if uid == 0 -> use port 514 */ if ((rc = sa_addr_u2a(la, "inet://0.0.0.0:0")) != SA_OK) return (rc == SA_ERR_SYS ? L2_ERR_SYS : L2_ERR_INT); if ((rc = sa_bind(cfg->saRemoteSock, la)) != SA_OK) return (rc == SA_ERR_SYS ? L2_ERR_SYS : L2_ERR_INT); sa_addr_destroy(la); } return L2_OK; } /* write to channel */ static l2_result_t hook_write(l2_context_t *ctx, l2_channel_t *ch, l2_level_t level, const char *buf, size_t buf_size) { l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp; int prio; int i; char caTime[15+1]; char caBuf[2048]; time_t t; struct tm *tm; size_t n; sa_rc_t rc; /* determine syslog priority */ prio = 0; for (i = 0; l2_ch_syslog_L2toSL[i].levelL2 != -1; i++) { if (l2_ch_syslog_L2toSL[i].levelL2 == level) { prio = l2_ch_syslog_L2toSL[i].levelSL; break; } } if (l2_ch_syslog_L2toSL[i].levelL2 == -1) return L2_ERR_USE; /* FIXME: nul-terminate buf? */ if (strcmp(cfg->szTarget, "local") == 0) { /* send to local syslogd via syslog(3) */ syslog(prio, "%s", buf); } else { /* send to remote syslogd via UDP */ if (strlen(buf) > 1024) return L2_ERR_MEM; prio += cfg->nFacility; t = time(NULL); tm = localtime(&t); strftime(caTime, sizeof(caTime), "%b %d %H:%M:%S", tm); if (caTime[4] == '0') caTime[4] = ' '; if (cfg->bLogPid) n = l2_util_sprintf(caBuf, sizeof(caBuf), "<%d>%s %s %s[%lu]: %s", prio, caTime, cfg->szLocalHost, cfg->szIdent, (unsigned long)getpid(), buf); else n = l2_util_sprintf(caBuf, sizeof(caBuf), "<%d>%s %s %s: %s", prio, caTime, cfg->szLocalHost, cfg->szIdent, buf); if ((n = strlen(caBuf)) > 1024) return L2_ERR_IO; if ((rc = sa_send(cfg->saRemoteSock, cfg->saaRemoteAddr, caBuf, n, NULL)) != SA_OK) return (rc == SA_ERR_SYS ? L2_ERR_SYS : L2_ERR_IO); } return L2_OK; } /* close channel */ static l2_result_t hook_close(l2_context_t *ctx, l2_channel_t *ch) { l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp; if (strcmp(cfg->szTarget, "local") == 0) { closelog(); } else { if (cfg->saRemoteSock != NULL) { sa_destroy(cfg->saRemoteSock); cfg->saRemoteSock = NULL; } if (cfg->saaRemoteAddr != NULL) { sa_addr_destroy(cfg->saaRemoteAddr); cfg->saaRemoteAddr = NULL; } } return L2_OK; } /* destroy channel */ static l2_result_t hook_destroy(l2_context_t *ctx, l2_channel_t *ch) { l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp; /* destroy channel configuration */ if (cfg->szTarget != NULL) free(cfg->szTarget); if (cfg->szRemoteHost != NULL) free(cfg->szRemoteHost); if (cfg->szLocalHost != NULL) free(cfg->szLocalHost); if (cfg->szFacility != NULL) free(cfg->szFacility); if (cfg->szIdent != NULL) free(cfg->szIdent); if (cfg->saRemoteSock != NULL) sa_destroy(cfg->saRemoteSock); if (cfg->saaRemoteAddr != NULL) sa_addr_destroy(cfg->saaRemoteAddr); free(cfg); return L2_OK; } /* exported channel handler structure */ l2_handler_t l2_handler_syslog = { "syslog", L2_CHANNEL_OUTPUT, hook_create, hook_configure, hook_open, hook_write, NULL, hook_close, hook_destroy }; @ 1.34 log @Adjust copyright messages for new year 2005. @ text @d3 3 a5 3 ** Copyright (c) 2001-2004 Cable & Wireless ** Copyright (c) 2001-2004 The OSSP Project ** Copyright (c) 2001-2004 Ralf S. Engelschall @ 1.33 log @- remove trailing whitespaces - adjust copyright messages - consistently use "OSSP l2" - consistently talk about "Flexible Logging" - use standard OSSP ASCII-art @ text @d3 3 a5 3 ** Copyright (c) 2001-2003 Cable & Wireless Deutschland GmbH ** Copyright (c) 2001-2003 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001-2003 Ralf S. Engelschall @ 1.32 log @Upgrade to OSSP sa 1.0.1 @ text @d2 4 a5 3 ** OSSP l2 - Logging Library ** Copyright (c) 2001-2002 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001-2002 Cable & Wireless Deutschland (http://www.cw.com/de/) d7 1 a7 1 ** This file is part of OSSP L2, a flexible logging library which d195 1 a195 1 if ( strcmp(cfg->szTarget, "remote") == 0 d231 1 a231 1 if ((rc = sa_addr_u2a(cfg->saaRemoteAddr, "inet://%s:%d", d291 3 a293 3 if (cfg->bLogPid) n = l2_util_sprintf(caBuf, sizeof(caBuf), "<%d>%s %s %s[%lu]: %s", prio, caTime, cfg->szLocalHost, d296 2 a297 2 n = l2_util_sprintf(caBuf, sizeof(caBuf), "<%d>%s %s %s: %s", prio, caTime, cfg->szLocalHost, @ 1.31 log @polish for release @ text @d300 2 a301 2 if ((rc = sa_send(cfg->saRemoteSock, caBuf, n, NULL, cfg->saaRemoteAddr)) != SA_OK) @ 1.30 log @proposal to use getservbyname() or successor @ text @d2 1 a2 1 ** L2 - OSSP Logging Library d7 1 a7 1 ** can be found at http://www.ossp.org/pkg/l2/. @ 1.29 log @bump copyright year @ text @d137 1 a137 1 cfg->nRemotePort = 514; @ 1.28 log @fix big security hole @ text @d3 2 a4 2 ** Copyright (c) 2001 The OSSP Project (http://www.ossp.org/) ** Copyright (c) 2001 Cable & Wireless Deutschland (http://www.cw.com/de/) @ 1.27 log @Hell, I've seldom seen that it is needed to prepare and adjust such a lot of subtle details of existing code in order to make a new feature implementable in a straight-forward way. Anyway, here comes one more preparation change for the forthcoming channel tree specification parser: - change l2_util_setparam() to take an l2_env_t parameter which allows the function to report better error messages. - completely rewrite l2_util_setparam() to support calls l2_channel_configure(ch, "n1=v1,n2=v2,n3=v3") and/or l2_channel_configure(ch, "n1=%x,n2=%x,n3=%x", v1, v2, v3) instead of l2_channel_configure(ch, "n1,n2,n3", v1, v2, v3) This is both a step forward to make the interface of l2_channel_configure() more flexible (because one now can directly inline values instead of having them to be passed explicitly) and allows the spec parser not having to know the type (integer, floating point or string) of a parameter (which is important if one wants the parser to be independent of the implementing channel handlers). @ text @d278 1 a278 1 syslog(prio, buf); @ 1.26 log @More preparations for forthcoming channel tree specification parser (especially to allow the parser to determine the handler structure from a handler name without introducing another and this way redundant sub-API): - add "char *name" to l2_handler_t in order to tag each handler structure with the corresponding channel name - add l2_env_handler() function to add handler to l2_env_t objects. All l2_handler_xxxx are automatically pre-configured there after l2_env_create(). - change l2_channel_create() to take a "const char *name" (handler name) instead of the "l2_handler_t *h" (handler pointer) to make the stuff consistent and more clear. - adjust l2_test.c to reflect the changes. @ text @d164 1 d168 7 a174 7 L2_PARAM_SET(pa[0], target, STRING, &cfg->szTarget); L2_PARAM_SET(pa[1], remotehost, STRING, &cfg->szRemoteHost); L2_PARAM_SET(pa[2], remoteport, INT, &cfg->nRemotePort); L2_PARAM_SET(pa[3], localhost, STRING, &cfg->szLocalHost); L2_PARAM_SET(pa[4], facility, STRING, &cfg->szFacility); L2_PARAM_SET(pa[5], ident, STRING, &cfg->szIdent); L2_PARAM_SET(pa[6], logpid, INT, &cfg->bLogPid); d178 2 a179 1 rv = l2_util_setparams(pa, fmt, ap); @ 1.25 log @portability fix for Solaris 2.8 @ text @d354 1 @ 1.24 log @Upgrade to the latest and greatest OSSP SA. @ text @d92 3 @ 1.23 log @Use save l2_util_sprintf instead of unsafe sprintf and correctly set variable "n" (number of characters). @ text @d231 1 a231 1 sa_timeout(cfg->saRemoteSock, 10, 0); @ 1.22 log @Upgrade to latest OSSP SA snapshot. This time by using SA_PREFIX to hide SA inside the l2_util_ namespace prefix. @ text @d286 3 a288 3 sprintf(caBuf, "<%d>%s %s %s[%lu]: %s", prio, caTime, cfg->szLocalHost, cfg->szIdent, (unsigned long)getpid(), buf); d290 3 a292 3 sprintf(caBuf, "<%d>%s %s %s: %s", prio, caTime, cfg->szLocalHost, cfg->szIdent, buf); @ 1.21 log @Revamp Syslog output channel. It now fully supports local _AND_ remote logging. The local variant is still based on syslog(3), the remote variant is based on manual network connections with the syslog protocol as defined in RFC3164. @ text @d223 4 a226 2 if ((rc = sa_u2a(&cfg->saaRemoteAddr, "udp://%s:%d", cfg->szRemoteHost, cfg->nRemotePort)) != SA_OK) d230 1 d232 2 d235 1 a235 1 if ((rc = sa_u2a(&la, "udp://0.0.0.0:0")) != SA_OK) d239 1 d295 2 a296 2 if ((rc = sa_writeto(cfg->saRemoteSock, caBuf, n, NULL, cfg->saaRemoteAddr)) != SA_OK) d317 1 a317 1 free(cfg->saaRemoteAddr); d343 1 a343 1 free(cfg->saaRemoteAddr); @ 1.20 log @Upgraded both stream and channel-level APIs to include new L2_LEVEL parameter design. @ text @d31 1 d34 4 d41 10 a50 5 char *pszIdent; /* String to prepend to each syslog message */ int iLogopt; /* Manipulates how kernel interacts with syslogd */ int iFacility; /* Which part of the system generates this message */ int iPriority; /* EMERG, ALERT, CRIT, ERR, WARNING, NOTICE, INFO... */ int iMaskpri; /* Controls which priorities are or are not logged */ d53 67 d124 2 d132 16 a147 5 cfg->pszIdent = NULL; cfg->iLogopt = 0; cfg->iFacility = LOG_USER; cfg->iPriority = (LOG_DEBUG|LOG_ERR); cfg->iMaskpri = (0xFFFFFFFF); /* Allow all priorities to pass through */ d159 1 a159 1 l2_param_t pa[6]; d161 1 d164 10 a173 6 L2_PARAM_SET(pa[0], ident, CHARPTR, &cfg->pszIdent); L2_PARAM_SET(pa[1], logopts, INT, &cfg->iLogopt); L2_PARAM_SET(pa[2], facility, INT, &cfg->iFacility); L2_PARAM_SET(pa[3], priority, INT, &cfg->iPriority); L2_PARAM_SET(pa[4], maskpriority, INT, &cfg->iMaskpri); L2_PARAM_END(pa[5]); d175 23 a197 1 d205 30 a234 5 /* open channel syslog */ openlog(cfg->pszIdent, cfg->iLogopt, cfg->iFacility); setlogmask(cfg->iMaskpri); d243 50 a292 3 /* write message to channel syslog */ syslog(cfg->iPriority, buf); d300 1 a300 2 /* close channel syslog */ closelog(); d302 13 d324 14 @ 1.19 log @Removed unused variable. @ text @d97 2 a98 2 static l2_result_t hook_write(l2_context_t *ctx, l2_channel_t *ch, const char *buf, size_t buf_size) @ 1.18 log @minor modifications for compile run to survive --pendantic-errors. Please review. @ text @a110 2 //FIXME l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp; @ 1.17 log @Simplify channels again: The channel framework gurranties that the handler context is available if the handler has set it, so there is no need to perform an additional run-time check and try to return L2_ERR_ARG. @ text @d111 1 a111 1 l2_ch_syslog_t *cfg = (l2_ch_syslog_t *)ctx->vp; @ 1.16 log @It is fully legal to have some handler operations not implemented in case there is nothing to do for the handler. So remove the No-op hooks. @ text @d68 1 a68 1 l2_ch_syslog_t *cfg; a71 4 /* parameter checks */ if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL) return L2_ERR_ARG; d87 1 a87 5 l2_ch_syslog_t *cfg; /* parameter checks */ if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL) return L2_ERR_ARG; d100 1 a100 5 l2_ch_syslog_t *cfg; /* parameter checks */ if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL) return L2_ERR_ARG; d111 1 a111 5 l2_ch_syslog_t *cfg; /* parameter checks */ if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL) return L2_ERR_ARG; d122 1 a122 3 /* parameter checks */ if (ctx->vp == NULL) return L2_ERR_ARG; d125 1 a125 1 free(ctx->vp); @ 1.15 log @Replace generic L2_ERROR with more granular L2_ERR_XXX and make sure that we always check with "!= L2_OK". @ text @a119 8 /* flush channel */ static l2_result_t hook_flush(l2_context_t *ctx, l2_channel_t *ch) { /* Noop for this channel, because syslog entries are unbuffered */ return L2_OK; } d155 1 a155 1 hook_flush, @ 1.14 log @Be politically correct: channels are intended to be implemented also by users, which have only access to the public API (l2.h), so do not even try to use anything more in our own shipped channels. @ text @d50 1 a50 1 return L2_ERROR; d74 1 a74 1 return L2_ERROR; d95 1 a95 1 return L2_ERROR; d112 1 a112 1 return L2_ERROR; d135 1 a135 1 return L2_ERROR; d148 1 a148 1 return L2_ERROR; @ 1.13 log @Array bug fixes and code to test sockets. @ text @a30 1 #include "l2_p.h" @ 1.12 log @Be pedantically correct: handler hooks return "l2_result_t" and not "int", although currently it is just an int/enum. @ text @d70 1 a70 1 l2_param_t pa[3]; d80 4 a83 4 L2_PARAM_SET(pa[1], facility, INT, &cfg->iFacility); L2_PARAM_SET(pa[1], priority, INT, &cfg->iPriority); L2_PARAM_SET(pa[1], maskpriority, INT, &cfg->iMaskpri); L2_PARAM_END(pa[2]); @ 1.11 log @Whohooo, now we can simplify output channels: because output channels are guarrantied to be not on top of other channels, they do not have any downstream channels. So remove all downstream handling from them. Only filter channels have to be aware of downstream channels. @ text @d45 1 a45 1 static int hook_create(l2_context_t *ctx, l2_channel_t *ch) d67 1 a67 1 static int hook_configure(l2_context_t *ctx, l2_channel_t *ch, const char *fmt, va_list ap) d90 1 a90 1 static int hook_open(l2_context_t *ctx, l2_channel_t *ch) d106 1 a106 1 static int hook_write(l2_context_t *ctx, l2_channel_t *ch, d122 1 a122 1 static int hook_flush(l2_context_t *ctx, l2_channel_t *ch) d130 1 a130 1 static int hook_close(l2_context_t *ctx, l2_channel_t *ch) d145 1 a145 1 static int hook_destroy(l2_context_t *ctx, l2_channel_t *ch) @ 1.10 log @Revamp channel handler API: Instead of passing the downstream channel to all channels we instead provide a l2_channel_downstream() function and provide the current channel. This way the handler API is prototype-wise fully orthogonal with the channel API (which it implements) and we no longer pass information to 2/3 of our (output) channels which is of no use there. Additionally add a channel type field to l2_handler_t which allows a handler to say what type of channel it implements (filter or output). This information is now used in l2_channel_stack() to make sure that one can only stack a filter channel on top of another channel. For convinience reasons there is also a new l2_channel_type() function which allows one to query the type of a particular channel. @ text @a92 1 l2_channel_t *downstream; a101 5 /* optionally open downstream channel, too */ if ((downstream = l2_channel_downstream(ch)) != NULL) if (l2_channel_open(downstream) == L2_ERROR) return L2_ERROR; a109 1 l2_channel_t *downstream; a117 5 /* optionally write to downstream channel, too */ if ((downstream = l2_channel_downstream(ch)) != NULL) if (l2_channel_write(downstream, buf, buf_size) == L2_ERROR) return L2_ERROR; a123 2 l2_channel_t *downstream; a125 5 /* optionally flush downstream channel, too */ if ((downstream = l2_channel_downstream(ch)) != NULL) if (l2_channel_flush(downstream) == L2_ERROR) return L2_ERROR; a132 6 l2_channel_t *downstream; /* optionally close downstream channel, too */ if ((downstream = l2_channel_downstream(ch)) != NULL) if (l2_channel_close(downstream) == L2_ERROR) return L2_ERROR; @ 1.9 log @Wohhooooo! Here comes the underlying message formatting support: 1. renamed l2_channel_setparam() to l2_util_setparam() because it is just a utility function and is not tied to any channel. 2. moved l2_util_setparam() to its own l2_ut_param.c source file. 3. added l2_ut_format.c which contains a slightly adjusted version of Str's str_format() stuff under the name l2_util_format(). 4. use l2_util_format() in l2_stream.c instead of vsnprintf() and this way finally support l2_formatter_t callbacks. 5. cleanup adjustments to the l2_stream_formatter() API. Let's rock... @ text @d45 1 a45 1 static int hook_create(l2_context_t *ctx) d67 1 a67 1 static int hook_configure(l2_context_t *ctx, const char *fmt, va_list ap) d90 1 a90 1 static int hook_open(l2_context_t *ctx, l2_channel_t *downstream) d93 1 d104 1 a104 1 if (downstream != NULL) d112 1 a112 1 static int hook_write(l2_context_t *ctx, l2_channel_t *downstream, d116 1 d126 1 a126 1 if (downstream != NULL) d134 1 a134 1 static int hook_flush(l2_context_t *ctx, l2_channel_t *downstream) d136 2 d141 1 a141 1 if (downstream != NULL) d149 1 a149 1 static int hook_close(l2_context_t *ctx, l2_channel_t *downstream) d152 1 d155 1 a155 1 if (downstream != NULL) d170 1 a170 1 static int hook_destroy(l2_context_t *ctx) d184 1 @ 1.8 log @Completed syslog channel implementation - might need trimming down. @ text @d84 1 a84 1 rv = l2_channel_setparams(pa, fmt, ap); @ 1.7 log @Upgraded skeleton of syslog channel module. @ text @d37 5 a41 2 int iEtwas; char *pszNada; d50 2 d54 5 d61 1 d70 1 a70 1 l2_param_t pa[3]; d78 5 a82 2 L2_PARAM_SET(pa[0], iEtwas, CHARPTR, &cfg->iEtwas); L2_PARAM_SET(pa[1], pszNada, INT, &cfg->pszNada); a96 2 if (cfg->pszNada == NULL) /* ATTENTION */ return L2_ERROR; d99 2 d121 1 d134 1 a134 5 l2_ch_syslog_t *cfg; /* parameter checks */ if ((cfg = (l2_ch_syslog_t *)ctx->vp) == NULL) return L2_ERROR; d159 1 @ 1.6 log @Fix more ossp.com references by replacing with the correct domain name ossp.org. @ text @d35 7 d44 8 d55 1 d58 15 a72 1 return L2_OK; d75 1 d78 15 d96 2 a97 1 static int hook_write(l2_context_t *ctx, l2_channel_t *downstream, d100 13 d116 1 d119 11 d133 1 d136 13 d152 1 d155 7 d165 1 @ 1.5 log @cleanup style @ text @d7 1 a7 1 ** can be found at http://www.ossp.com/pkg/l2/. @ 1.4 log @change terminology: below -> downstream @ text @d52 1 a52 2 { syslog(LOG_INFO, buf); d54 1 a54 1 } @ 1.3 log @Implemented write() method of the syslog handler. @ text @d45 1 a45 1 static int hook_open(l2_context_t *ctx, l2_channel_t *below) d50 1 a50 1 static int hook_write(l2_context_t *ctx, l2_channel_t *below, d57 1 a57 1 static int hook_flush(l2_context_t *ctx, l2_channel_t *below) d62 1 a62 1 static int hook_close(l2_context_t *ctx, l2_channel_t *below) @ 1.2 log @Fill in channel handler template code. @ text @d33 2 d50 1 a50 1 static int hook_write(l2_context_t *ctx, l2_channel_t *below, d52 2 a53 1 { d55 1 a55 1 } @ 1.1 log @Initial revision @ text @d33 46 @ 1.1.1.1 log @L2 initial source tree @ text @@