249d09d51808cb7981af99762c3b3736ca126cd5jkaluza/* Licensed to the Apache Software Foundation (ASF) under one or more
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza * contributor license agreements. See the NOTICE file distributed with
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza * this work for additional information regarding copyright ownership.
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza * The ASF licenses this file to You under the Apache License, Version 2.0
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza * (the "License"); you may not use this file except in compliance with
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza * the License. You may obtain a copy of the License at
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza *
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza * http://www.apache.org/licenses/LICENSE-2.0
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza *
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza * Unless required by applicable law or agreed to in writing, software
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza * distributed under the License is distributed on an "AS IS" BASIS,
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza * See the License for the specific language governing permissions and
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza * limitations under the License.
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza *
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza */
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include <stdint.h>
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include <ap_config.h>
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include "ap_mpm.h"
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include "ap_provider.h"
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include <http_core.h>
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include <httpd.h>
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include <http_log.h>
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include <http_main.h>
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include <apr_version.h>
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include <apr_pools.h>
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include <apr_strings.h>
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include "unixd.h"
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include "scoreboard.h"
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include "mpm_common.h"
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include "syslog.h"
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#if APR_HAVE_UNISTD_H
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#include <unistd.h>
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
249d09d51808cb7981af99762c3b3736ca126cd5jkaluzatypedef struct {
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza const char *t_name;
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza int t_val;
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza} TRANS;
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
249d09d51808cb7981af99762c3b3736ca126cd5jkaluzastatic const TRANS facilities[] = {
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"auth", LOG_AUTH},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_AUTHPRIV
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"authpriv",LOG_AUTHPRIV},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_CRON
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"cron", LOG_CRON},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_DAEMON
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"daemon", LOG_DAEMON},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_FTP
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"ftp", LOG_FTP},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_KERN
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"kern", LOG_KERN},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_LPR
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"lpr", LOG_LPR},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_MAIL
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"mail", LOG_MAIL},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_NEWS
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"news", LOG_NEWS},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_SYSLOG
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"syslog", LOG_SYSLOG},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_USER
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"user", LOG_USER},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_UUCP
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"uucp", LOG_UUCP},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_LOCAL0
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"local0", LOG_LOCAL0},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_LOCAL1
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"local1", LOG_LOCAL1},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_LOCAL2
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"local2", LOG_LOCAL2},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_LOCAL3
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"local3", LOG_LOCAL3},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_LOCAL4
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"local4", LOG_LOCAL4},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_LOCAL5
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"local5", LOG_LOCAL5},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_LOCAL6
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"local6", LOG_LOCAL6},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#ifdef LOG_LOCAL7
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {"local7", LOG_LOCAL7},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza#endif
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza {NULL, -1},
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza};
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
249d09d51808cb7981af99762c3b3736ca126cd5jkaluzastatic void *syslog_error_log_init(apr_pool_t *p, server_rec *s)
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza{
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza char *fname = s->error_fname;
c62cc8593d17deefcd6879923ccfcd80f07eaa40trawick void *success = (void *)p; /* anything non-NULL is success */
c62cc8593d17deefcd6879923ccfcd80f07eaa40trawick
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza if (*fname == '\0') {
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7);
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza }
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza else {
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza const TRANS *fac;
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza for (fac = facilities; fac->t_name; fac++) {
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza if (!strcasecmp(fname, fac->t_name)) {
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID,
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza fac->t_val);
c62cc8593d17deefcd6879923ccfcd80f07eaa40trawick return success;
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza }
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza }
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza }
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
c62cc8593d17deefcd6879923ccfcd80f07eaa40trawick return success;
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza}
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
249d09d51808cb7981af99762c3b3736ca126cd5jkaluzastatic apr_status_t syslog_error_log(const ap_errorlog_info *info,
7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05jkaluza void *handle, const char *errstr,
7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05jkaluza apr_size_t len)
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza{
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza int level = info->level;
ac7ac5b79da100d59b176914c0d9448fadc03568trawick
ac7ac5b79da100d59b176914c0d9448fadc03568trawick if (level != APLOG_NOTICE) {
ac7ac5b79da100d59b176914c0d9448fadc03568trawick syslog(level < LOG_PRIMASK ? level : APLOG_DEBUG, "%.*s", (int)len, errstr);
ac7ac5b79da100d59b176914c0d9448fadc03568trawick }
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza return APR_SUCCESS;
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza}
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
993d1261a278d7322bccef219101220b7b4fb8c5jkaluzastatic const char *syslog_error_log_parse(cmd_parms *cmd, const char *arg)
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza{
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza const char *err = ap_check_cmd_context(cmd, GLOBAL_ONLY);
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza if (err != NULL) {
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza return apr_pstrcat(cmd->pool,
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza "When using syslog error log provider, ", err,
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza NULL);
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza }
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza return NULL;
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza}
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
249d09d51808cb7981af99762c3b3736ca126cd5jkaluzastatic void syslog_register_hooks(apr_pool_t *p)
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza{
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza static const ap_errorlog_provider syslog_provider = {
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza &syslog_error_log_init,
7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05jkaluza &syslog_error_log,
993d1261a278d7322bccef219101220b7b4fb8c5jkaluza &syslog_error_log_parse,
7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05jkaluza 0
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza };
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza ap_register_provider(p, AP_ERRORLOG_PROVIDER_GROUP, "syslog",
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza AP_ERRORLOG_PROVIDER_VERSION, &syslog_provider);
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza}
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza
249d09d51808cb7981af99762c3b3736ca126cd5jkaluzaAP_DECLARE_MODULE(syslog) =
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza{
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza STANDARD20_MODULE_STUFF,
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza NULL,
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza NULL,
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza NULL,
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza NULL,
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza NULL,
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza syslog_register_hooks,
249d09d51808cb7981af99762c3b3736ca126cd5jkaluza};