ssl_engine_log.c revision 35b9e4d5f3452cad4b3bec6829ce87a5ce9e9227
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton/* _ _
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** _ __ ___ ___ __| | ___ ___| | mod_ssl
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** | '_ ` _ \ / _ \ / _` | / __/ __| | Apache Interface to OpenSSL
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** | | | | | | (_) | (_| | \__ \__ \ | www.modssl.org
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** |_| |_| |_|\___/ \__,_|___|___/___/_| ftp.modssl.org
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** |_____|
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** ssl_engine_log.c
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** Logging Facility
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton*/
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton/* ====================================================================
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * The Apache Software License, Version 1.1
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton *
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * Copyright (c) 2000-2002 The Apache Software Foundation. All rights
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * reserved.
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton *
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * Redistribution and use in source and binary forms, with or without
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * modification, are permitted provided that the following conditions
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * are met:
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton *
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * 1. Redistributions of source code must retain the above copyright
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * notice, this list of conditions and the following disclaimer.
292707b9868335763d6f2bb74a263134eeeb8cadkbrand *
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * 2. Redistributions in binary form must reproduce the above copyright
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * notice, this list of conditions and the following disclaimer in
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * the documentation and/or other materials provided with the
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * distribution.
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton *
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * 3. The end-user documentation included with the redistribution,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * if any, must include the following acknowledgment:
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * "This product includes software developed by the
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * Apache Software Foundation (http://www.apache.org/)."
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * Alternately, this acknowledgment may appear in the software itself,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * if and wherever such third-party acknowledgments normally appear.
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton *
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * 4. The names "Apache" and "Apache Software Foundation" must
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * not be used to endorse or promote products derived from this
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * software without prior written permission. For written
12b2973ae4fdb19829e3ccd9d5d3938451c67f41jorton * permission, please contact apache@apache.org.
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton *
91ef999a69527d2a64983681c92aaef9270697b4rpluem * 5. Products derived from this software may not be called "Apache",
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * nor may "Apache" appear in their name, without prior written
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * permission of the Apache Software Foundation.
338eb440128c076c0418429cbc4845148d52a09ejorton *
338eb440128c076c0418429cbc4845148d52a09ejorton * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * SUCH DAMAGE.
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * ====================================================================
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton */
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim /* ``The difference between a computer
0de29985d3f84de428d0744b9dafb8a6b086d034jorton industry job and open-source software
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton hacking is about 30 hours a week.''
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton -- Ralf S. Engelschall */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton#include "mod_ssl.h"
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton/* _________________________________________________________________
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton**
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** Logfile Support
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton** _________________________________________________________________
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton*/
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
185aa71728867671e105178b4c66fbc22b65ae26sf/*
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim * Open the SSL logfile
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton */
39c7699ec0799d394d3f67145d4a12ed82f587b8jortonvoid ssl_log_open(server_rec *s_main, server_rec *s, apr_pool_t *p)
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton{
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim const char *szLogFile;
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim SSLSrvConfigRec *sc_main = mySrvConfig(s_main);
185aa71728867671e105178b4c66fbc22b65ae26sf SSLSrvConfigRec *sc = mySrvConfig(s);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton piped_log *pl;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /*
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * Short-circuit for inherited logfiles in order to save
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * filedescriptors in mass-vhost situation. Be careful, this works
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * fine because the close happens implicitly by the pool facility.
0de29985d3f84de428d0744b9dafb8a6b086d034jorton */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if ((s != s_main) &&
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton (sc_main->log_file != NULL) &&
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ((sc->log_file_name == NULL) ||
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ((sc->log_file_name != NULL) &&
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton (sc_main->log_file_name != NULL) &&
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton strEQ(sc->log_file_name, sc_main->log_file_name))))
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton sc->log_file = sc_main->log_file;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton else if (sc->log_file_name != NULL) {
185aa71728867671e105178b4c66fbc22b65ae26sf if (strEQ(sc->log_file_name, "/dev/null"))
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton return;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton else if (sc->log_file_name[0] == '|') {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton szLogFile = sc->log_file_name + 1;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if ((pl = ap_open_piped_log(p, szLogFile)) == NULL) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ssl_log(s, SSL_LOG_ERROR|SSL_ADD_ERRNO,
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim "Cannot open reliable pipe to SSL logfile filter %s", szLogFile);
185aa71728867671e105178b4c66fbc22b65ae26sf ssl_die();
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton sc->log_file = ap_piped_log_write_fd(pl);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton else {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton szLogFile = ap_server_root_relative(p, sc->log_file_name);
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim if (!szLogFile) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ssl_log(s, SSL_LOG_ERROR|SSL_ADD_ERRNO,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton "Invalid SSL logfile path %s", sc->log_file_name);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ssl_die();
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if ((apr_file_open(&(sc->log_file), szLogFile,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton APR_WRITE|APR_APPEND|APR_CREATE, APR_OS_DEFAULT, p))
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton != APR_SUCCESS) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ssl_log(s, SSL_LOG_ERROR|SSL_ADD_ERRNO,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton "Cannot open SSL logfile %s", szLogFile);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ssl_die();
185aa71728867671e105178b4c66fbc22b65ae26sf }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton return;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton}
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jortonstatic struct {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton int nLevel;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton char *szLevel;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton} ssl_log_level2string[] = {
a128f7088d23bc32870fc994b8acbeabb0845790jorton { SSL_LOG_ERROR, "error" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { SSL_LOG_WARN, "warn" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { SSL_LOG_INFO, "info" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { SSL_LOG_TRACE, "trace" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { SSL_LOG_DEBUG, "debug" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { 0, NULL }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton};
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jortonstatic struct {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton char *cpPattern;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton char *cpAnnotation;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton} ssl_log_annotate[] = {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*envelope*bad*decrypt*", "wrong pass phrase!?" },
185aa71728867671e105178b4c66fbc22b65ae26sf { "*CLIENT_HELLO*unknown*protocol*", "speaking not SSL to HTTPS port!?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*CLIENT_HELLO*http*request*", "speaking HTTP to HTTPS port!?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*SSL3_READ_BYTES:sslv3*alert*bad*certificate*", "Subject CN in certificate not server name or identical to CA!?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*self signed certificate in certificate chain*", "Client certificate signed by CA not known to server?" },
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim { "*peer did not return a certificate*", "No CAs known to server for verification?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*no shared cipher*", "Too restrictive SSLCipherSuite or using DSA server certificate?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*no start line*", "Bad file contents or format - or even just a forgotten SSLCertificateKeyFile?" },
185aa71728867671e105178b4c66fbc22b65ae26sf { "*bad password read*", "You entered an incorrect pass phrase!?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { "*bad mac decode*", "Browser still remembered details of a re-created server certificate?" },
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton { NULL, NULL }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton};
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
3efea4a958cbb2e193a2f34ba5afdfe216a34324jortonstatic char *ssl_log_annotation(char *error)
3efea4a958cbb2e193a2f34ba5afdfe216a34324jorton{
3efea4a958cbb2e193a2f34ba5afdfe216a34324jorton char *errstr;
3efea4a958cbb2e193a2f34ba5afdfe216a34324jorton int i;
3efea4a958cbb2e193a2f34ba5afdfe216a34324jorton
3efea4a958cbb2e193a2f34ba5afdfe216a34324jorton errstr = NULL;
3efea4a958cbb2e193a2f34ba5afdfe216a34324jorton for (i = 0; ssl_log_annotate[i].cpPattern != NULL; i++) {
185aa71728867671e105178b4c66fbc22b65ae26sf if (ap_strcmp_match(error, ssl_log_annotate[i].cpPattern) == 0) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton errstr = ssl_log_annotate[i].cpAnnotation;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton break;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton return errstr;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton}
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jortonvoid ssl_log(server_rec *s, int level, const char *msg, ...)
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton{
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton char tstr[80];
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton char lstr[256];
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton char vstr[1024];
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton char str[1024];
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton char *nstr;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_size_t len;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_time_exp_t t;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton va_list ap;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton int add;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton int i;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton char *astr;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton int safe_errno;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton unsigned long e;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton SSLSrvConfigRec *sc;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton char *cpE;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton char *cpA;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* initialization */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton safe_errno = errno;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton sc = mySrvConfig(s);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* strip out additional flags */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton add = (level & ~SSL_LOG_MASK);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton level = (level & SSL_LOG_MASK);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* reduce flags when not reasonable in context */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if (add & SSL_ADD_ERRNO && errno == 0)
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton add &= ~SSL_ADD_ERRNO;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if (add & SSL_ADD_SSLERR && ERR_peek_error() == 0)
185aa71728867671e105178b4c66fbc22b65ae26sf add &= ~SSL_ADD_SSLERR;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* we log only levels below, except for errors */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if ( sc->log_file == NULL
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton && !(level & SSL_LOG_ERROR))
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton return;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if ( level > sc->log_level
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton && !(level & SSL_LOG_ERROR))
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton return;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* determine the time entry string */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if (add & SSL_NO_TIMESTAMP)
185aa71728867671e105178b4c66fbc22b65ae26sf tstr[0] = NUL;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton else {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_time_exp_lt(&t, apr_time_now());
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_strftime(tstr, &len, 80, "[%d/%b/%Y %H:%M:%S", &t);
ad412abff68c20db6deb528298c772b9ac4a0706jorton apr_snprintf(tstr + strlen(tstr), 80 - strlen(tstr), " %05d] ",
185aa71728867671e105178b4c66fbc22b65ae26sf (unsigned int)getpid());
ad412abff68c20db6deb528298c772b9ac4a0706jorton }
ad412abff68c20db6deb528298c772b9ac4a0706jorton
ad412abff68c20db6deb528298c772b9ac4a0706jorton /* determine whether newline should be written */
ad412abff68c20db6deb528298c772b9ac4a0706jorton if (add & SSL_NO_NEWLINE)
ad412abff68c20db6deb528298c772b9ac4a0706jorton nstr = "";
185aa71728867671e105178b4c66fbc22b65ae26sf else {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton nstr = APR_EOL_STR;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* determine level name */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton lstr[0] = NUL;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if (!(add & SSL_NO_LEVELID)) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton for (i = 0; ssl_log_level2string[i].nLevel != 0; i++) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if (ssl_log_level2string[i].nLevel == level) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_snprintf(lstr, sizeof(lstr), "[%s]", ssl_log_level2string[i].szLevel);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton break;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton for (i = strlen(lstr); i <= 7; i++)
1de839c61281d58dc75715c1ae06b4b00764c4efjorton lstr[i] = ' ';
185aa71728867671e105178b4c66fbc22b65ae26sf lstr[i] = NUL;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if (add & SSL_INIT) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton len = strlen(lstr);
185aa71728867671e105178b4c66fbc22b65ae26sf apr_snprintf(&lstr[len], sizeof(lstr) - len,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton "Init: (%s) ", sc->vhost_id);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
1de839c61281d58dc75715c1ae06b4b00764c4efjorton /* create custom message */
1de839c61281d58dc75715c1ae06b4b00764c4efjorton va_start(ap, msg);
1de839c61281d58dc75715c1ae06b4b00764c4efjorton apr_vsnprintf(vstr, sizeof(vstr), msg, ap);
1de839c61281d58dc75715c1ae06b4b00764c4efjorton va_end(ap);
1de839c61281d58dc75715c1ae06b4b00764c4efjorton
1de839c61281d58dc75715c1ae06b4b00764c4efjorton /* write out SSLog message */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if ((add & SSL_ADD_ERRNO) && (add & SSL_ADD_SSLERR))
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton astr = " (System and " SSL_LIBRARY_NAME " library errors follow)";
185aa71728867671e105178b4c66fbc22b65ae26sf else if (add & SSL_ADD_ERRNO)
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton astr = " (System error follows)";
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton else if (add & SSL_ADD_SSLERR)
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton astr = " (" SSL_LIBRARY_NAME " library error follows)";
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton else
185aa71728867671e105178b4c66fbc22b65ae26sf astr = "";
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim if (level <= sc->log_level && sc->log_file != NULL) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_snprintf(str, sizeof(str), "%s%s%s%s%s",
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton tstr, lstr, vstr, astr, nstr);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_file_printf(sc->log_file, "%s", str);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if (level & SSL_LOG_ERROR)
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton "mod_ssl: %s%s", vstr, astr);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* write out additional attachment messages */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if (add & SSL_ADD_ERRNO) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if (level <= sc->log_level && sc->log_file != NULL) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_snprintf(str, sizeof(str), "%s%sSystem: %s (errno: %d)%s",
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton tstr, lstr, strerror(safe_errno), safe_errno, nstr);
185aa71728867671e105178b4c66fbc22b65ae26sf apr_file_printf(sc->log_file, "%s", str);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
e47aa5660a4528d412f855baa50524a04efff767kbrand if (level & SSL_LOG_ERROR)
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton "System: %s (errno: %d)",
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton strerror(safe_errno), safe_errno);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if (add & SSL_ADD_SSLERR) {
0de29985d3f84de428d0744b9dafb8a6b086d034jorton while ((e = ERR_get_error())) {
0de29985d3f84de428d0744b9dafb8a6b086d034jorton cpE = ERR_error_string(e, NULL);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton cpA = ssl_log_annotation(cpE);
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim if (level <= sc->log_level && sc->log_file != NULL) {
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_snprintf(str, sizeof(str), "%s%s%s: %s%s%s%s%s",
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton tstr, lstr, SSL_LIBRARY_NAME, cpE,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton cpA != NULL ? " [Hint: " : "",
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton cpA != NULL ? cpA : "", cpA != NULL ? "]" : "",
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton nstr);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_file_printf(sc->log_file, "%s", str);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton }
185aa71728867671e105178b4c66fbc22b65ae26sf if (level & SSL_LOG_ERROR)
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton ap_log_error(APLOG_MARK, APLOG_ERR|APLOG_NOERRNO, 0, s,
e47aa5660a4528d412f855baa50524a04efff767kbrand "%s: %s%s%s%s", SSL_LIBRARY_NAME, cpE,
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton cpA != NULL ? " [Hint: " : "",
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton cpA != NULL ? cpA : "", cpA != NULL ? "]" : "");
5bfaaf573bacb45c1cf290ce85ecc676587e8a64jim }
0de29985d3f84de428d0744b9dafb8a6b086d034jorton }
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* make sure the next log starts from a clean base */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* ERR_clear_error(); */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /* cleanup and return */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton if (sc->log_file != NULL)
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton apr_file_flush(sc->log_file);
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton errno = safe_errno;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton return;
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton}
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton
39c7699ec0799d394d3f67145d4a12ed82f587b8jortonvoid ssl_die(void)
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton{
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton /*
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * This is used for fatal errors and here
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * it is common module practice to really
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton * exit from the complete program.
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton */
39c7699ec0799d394d3f67145d4a12ed82f587b8jorton exit(1);
}