mod_syslog.c revision 7cac5c72d80c4dc740e6ae7bae29d41ffdbd4b05
a78048ccbdb6256da15e6b0e7e95355e480c2301nd/* Licensed to the Apache Software Foundation (ASF) under one or more
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * contributor license agreements. See the NOTICE file distributed with
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * this work for additional information regarding copyright ownership.
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * The ASF licenses this file to You under the Apache License, Version 2.0
fd9abdda70912b99b24e3bf1a38f26fde908a74cnd * (the "License"); you may not use this file except in compliance with
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * the License. You may obtain a copy of the License at
a78048ccbdb6256da15e6b0e7e95355e480c2301nd *
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * http://www.apache.org/licenses/LICENSE-2.0
a78048ccbdb6256da15e6b0e7e95355e480c2301nd *
96ad5d81ee4a2cc66a4ae19893efc8aa6d06fae7jailletc * Unless required by applicable law or agreed to in writing, software
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * distributed under the License is distributed on an "AS IS" BASIS,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen * See the License for the specific language governing permissions and
2e545ce2450a9953665f701bb05350f0d3f26275nd * limitations under the License.
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen *
d29d9ab4614ff992b0e8de6e2b88d52b6f1f153erbowen */
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include <stdint.h>
af33a4994ae2ff15bc67d19ff1a7feb906745bf8rbowen#include <ap_config.h>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd#include "ap_mpm.h"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include "ap_provider.h"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include <http_core.h>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include <httpd.h>
3f08db06526d6901aa08c110b5bc7dde6bc39905nd#include <http_log.h>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include <http_main.h>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include <apr_version.h>
253547fb9cc7986e84ff68aef076f664fc4169dctakashi#include <apr_pools.h>
f086b4b402fa9a2fefc7dda85de2a3cc1cd0a654rjung#include <apr_strings.h>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include "unixd.h"
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem#include "scoreboard.h"
4b575a6b6704b516f22d65a3ad35696d7b9ba372rpluem#include "mpm_common.h"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include "syslog.h"
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#if APR_HAVE_UNISTD_H
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#include <unistd.h>
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndtypedef struct {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const char *t_name;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd int t_val;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd} TRANS;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic const TRANS facilities[] = {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"auth", LOG_AUTH},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_AUTHPRIV
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"authpriv",LOG_AUTHPRIV},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_CRON
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"cron", LOG_CRON},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_DAEMON
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"daemon", LOG_DAEMON},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_FTP
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"ftp", LOG_FTP},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_KERN
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"kern", LOG_KERN},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_LPR
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"lpr", LOG_LPR},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
30471a4650391f57975f60bbb6e4a90be7b284bfhumbedooh#ifdef LOG_MAIL
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"mail", LOG_MAIL},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_NEWS
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"news", LOG_NEWS},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_SYSLOG
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"syslog", LOG_SYSLOG},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_USER
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"user", LOG_USER},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_UUCP
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"uucp", LOG_UUCP},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_LOCAL0
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"local0", LOG_LOCAL0},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_LOCAL1
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"local1", LOG_LOCAL1},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_LOCAL2
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"local2", LOG_LOCAL2},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_LOCAL3
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"local3", LOG_LOCAL3},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_LOCAL4
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"local4", LOG_LOCAL4},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_LOCAL5
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"local5", LOG_LOCAL5},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_LOCAL6
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"local6", LOG_LOCAL6},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#ifdef LOG_LOCAL7
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {"local7", LOG_LOCAL7},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd#endif
a78048ccbdb6256da15e6b0e7e95355e480c2301nd {NULL, -1},
a78048ccbdb6256da15e6b0e7e95355e480c2301nd};
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic void *syslog_error_log_init(apr_pool_t *p, server_rec *s)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{
a78048ccbdb6256da15e6b0e7e95355e480c2301nd char *fname = s->error_fname;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (*fname == '\0') {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID, LOG_LOCAL7);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd else {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd const TRANS *fac;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd for (fac = facilities; fac->t_name; fac++) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (!strcasecmp(fname, fac->t_name)) {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd openlog(ap_server_argv0, LOG_NDELAY|LOG_CONS|LOG_PID,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd fac->t_val);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return NULL;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
d05e31513e1ed1df255774920b11ccad0262ad9cnd return NULL;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd}
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic apr_status_t syslog_error_log(const ap_errorlog_info *info,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd void *handle, const char *errstr,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd apr_size_t len)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{
5652dbe450e4fcfdf36d4cfb42d7f2345ded29a4maczniak int level = info->level;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd if (level != APLOG_NOTICE) {
d05e31513e1ed1df255774920b11ccad0262ad9cnd syslog(level < LOG_PRIMASK ? level : APLOG_DEBUG, "%.*s", (int)len, errstr);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd }
a78048ccbdb6256da15e6b0e7e95355e480c2301nd return APR_SUCCESS;
a78048ccbdb6256da15e6b0e7e95355e480c2301nd}
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndstatic void syslog_register_hooks(apr_pool_t *p)
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{
a78048ccbdb6256da15e6b0e7e95355e480c2301nd static const ap_errorlog_provider syslog_provider = {
a78048ccbdb6256da15e6b0e7e95355e480c2301nd &syslog_error_log_init,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd &syslog_error_log,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd 0
a78048ccbdb6256da15e6b0e7e95355e480c2301nd };
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301nd ap_register_provider(p, AP_ERRORLOG_PROVIDER_GROUP, "syslog",
a78048ccbdb6256da15e6b0e7e95355e480c2301nd AP_ERRORLOG_PROVIDER_VERSION, &syslog_provider);
a78048ccbdb6256da15e6b0e7e95355e480c2301nd}
a78048ccbdb6256da15e6b0e7e95355e480c2301nd
a78048ccbdb6256da15e6b0e7e95355e480c2301ndAP_DECLARE_MODULE(syslog) =
a78048ccbdb6256da15e6b0e7e95355e480c2301nd{
a78048ccbdb6256da15e6b0e7e95355e480c2301nd STANDARD20_MODULE_STUFF,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd NULL,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd NULL,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd NULL,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd NULL,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd NULL,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd syslog_register_hooks,
a78048ccbdb6256da15e6b0e7e95355e480c2301nd};
a78048ccbdb6256da15e6b0e7e95355e480c2301nd