[BACK]Return to log-server.c CVS log [TXT][DIR] Up to [local] / src / usr.bin / ssh

Annotation of src/usr.bin/ssh/log-server.c, Revision 1.17.2.1

1.1       deraadt     1: /*
1.11      deraadt     2:  * Author: Tatu Ylonen <ylo@cs.hut.fi>
                      3:  * Copyright (c) 1995 Tatu Ylonen <ylo@cs.hut.fi>, Espoo, Finland
                      4:  *                    All rights reserved
                      5:  * Server-side versions of debug(), log(), etc.  These normally send the output
                      6:  * to the system log.
1.14      markus      7:  *
1.16      deraadt     8:  * As far as I am concerned, the code I have written for this software
                      9:  * can be used freely for any purpose.  Any derived versions of this
                     10:  * software must be clearly marked as such, and if the derived work is
                     11:  * incompatible with the protocol description in the RFC file, it must be
                     12:  * called by a name other than "ssh" or "Secure Shell".
                     13:  *
                     14:  *
                     15:  * Copyright (c) 2000 Markus Friedl.  All rights reserved.
                     16:  *
                     17:  * Redistribution and use in source and binary forms, with or without
                     18:  * modification, are permitted provided that the following conditions
                     19:  * are met:
                     20:  * 1. Redistributions of source code must retain the above copyright
                     21:  *    notice, this list of conditions and the following disclaimer.
                     22:  * 2. Redistributions in binary form must reproduce the above copyright
                     23:  *    notice, this list of conditions and the following disclaimer in the
                     24:  *    documentation and/or other materials provided with the distribution.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
                     27:  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
                     28:  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     29:  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
                     30:  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
                     31:  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
                     32:  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
                     33:  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
                     34:  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
                     35:  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1.11      deraadt    36:  */
1.1       deraadt    37:
                     38: #include "includes.h"
1.17.2.1! jason      39: RCSID("$OpenBSD: log-server.c,v 1.20 2001/01/21 19:05:50 markus Exp $");
1.1       deraadt    40:
                     41: #include <syslog.h>
                     42: #include "packet.h"
                     43: #include "xmalloc.h"
1.17.2.1! jason      44: #include "log.h"
1.1       deraadt    45:
1.7       markus     46: static LogLevel log_level = SYSLOG_LEVEL_INFO;
1.1       deraadt    47: static int log_on_stderr = 0;
1.8       markus     48: static int log_facility = LOG_AUTH;
1.1       deraadt    49:
                     50: /* Initialize the log.
1.10      markus     51:  *   av0       program name (should be argv[0])
                     52:  *   on_stderr print also on stderr
                     53:  *   level     logging level
                     54:  */
1.1       deraadt    55:
1.14      markus     56: void
1.10      markus     57: log_init(char *av0, LogLevel level, SyslogFacility facility, int on_stderr)
1.1       deraadt    58: {
1.10      markus     59:        switch (level) {
                     60:        case SYSLOG_LEVEL_QUIET:
                     61:        case SYSLOG_LEVEL_FATAL:
1.17.2.1! jason      62:        case SYSLOG_LEVEL_ERROR:
1.10      markus     63:        case SYSLOG_LEVEL_INFO:
                     64:        case SYSLOG_LEVEL_VERBOSE:
1.17      markus     65:        case SYSLOG_LEVEL_DEBUG1:
                     66:        case SYSLOG_LEVEL_DEBUG2:
                     67:        case SYSLOG_LEVEL_DEBUG3:
1.10      markus     68:                log_level = level;
                     69:                break;
                     70:        default:
                     71:                fprintf(stderr, "Unrecognized internal syslog level code %d\n",
                     72:                        (int) level);
                     73:                exit(1);
                     74:        }
                     75:        switch (facility) {
                     76:        case SYSLOG_FACILITY_DAEMON:
                     77:                log_facility = LOG_DAEMON;
                     78:                break;
                     79:        case SYSLOG_FACILITY_USER:
                     80:                log_facility = LOG_USER;
                     81:                break;
                     82:        case SYSLOG_FACILITY_AUTH:
                     83:                log_facility = LOG_AUTH;
                     84:                break;
                     85:        case SYSLOG_FACILITY_LOCAL0:
                     86:                log_facility = LOG_LOCAL0;
                     87:                break;
                     88:        case SYSLOG_FACILITY_LOCAL1:
                     89:                log_facility = LOG_LOCAL1;
                     90:                break;
                     91:        case SYSLOG_FACILITY_LOCAL2:
                     92:                log_facility = LOG_LOCAL2;
                     93:                break;
                     94:        case SYSLOG_FACILITY_LOCAL3:
                     95:                log_facility = LOG_LOCAL3;
                     96:                break;
                     97:        case SYSLOG_FACILITY_LOCAL4:
                     98:                log_facility = LOG_LOCAL4;
                     99:                break;
                    100:        case SYSLOG_FACILITY_LOCAL5:
                    101:                log_facility = LOG_LOCAL5;
                    102:                break;
                    103:        case SYSLOG_FACILITY_LOCAL6:
                    104:                log_facility = LOG_LOCAL6;
                    105:                break;
                    106:        case SYSLOG_FACILITY_LOCAL7:
                    107:                log_facility = LOG_LOCAL7;
                    108:                break;
                    109:        default:
                    110:                fprintf(stderr, "Unrecognized internal syslog facility code %d\n",
                    111:                        (int) facility);
                    112:                exit(1);
                    113:        }
                    114:        log_on_stderr = on_stderr;
1.1       deraadt   115: }
                    116:
1.12      deraadt   117: #define MSGBUFSIZ 1024
1.1       deraadt   118:
1.7       markus    119: void
                    120: do_log(LogLevel level, const char *fmt, va_list args)
1.1       deraadt   121: {
1.12      deraadt   122:        char msgbuf[MSGBUFSIZ];
                    123:        char fmtbuf[MSGBUFSIZ];
1.10      markus    124:        char *txt = NULL;
                    125:        int pri = LOG_INFO;
                    126:        extern char *__progname;
                    127:
                    128:        if (level > log_level)
                    129:                return;
                    130:        switch (level) {
                    131:        case SYSLOG_LEVEL_FATAL:
                    132:                txt = "fatal";
1.17.2.1! jason     133:                pri = LOG_CRIT;
        !           134:                break;
        !           135:        case SYSLOG_LEVEL_ERROR:
        !           136:                txt = "error";
1.10      markus    137:                pri = LOG_ERR;
                    138:                break;
                    139:        case SYSLOG_LEVEL_INFO:
1.17.2.1! jason     140:                pri = LOG_INFO;
        !           141:                break;
1.10      markus    142:        case SYSLOG_LEVEL_VERBOSE:
                    143:                pri = LOG_INFO;
                    144:                break;
1.17      markus    145:        case SYSLOG_LEVEL_DEBUG1:
                    146:                txt = "debug1";
                    147:                pri = LOG_DEBUG;
                    148:                break;
                    149:        case SYSLOG_LEVEL_DEBUG2:
                    150:                txt = "debug2";
                    151:                pri = LOG_DEBUG;
                    152:                break;
                    153:        case SYSLOG_LEVEL_DEBUG3:
                    154:                txt = "debug3";
1.10      markus    155:                pri = LOG_DEBUG;
                    156:                break;
                    157:        default:
                    158:                txt = "internal error";
                    159:                pri = LOG_ERR;
                    160:                break;
                    161:        }
                    162:        if (txt != NULL) {
                    163:                snprintf(fmtbuf, sizeof(fmtbuf), "%s: %s", txt, fmt);
                    164:                vsnprintf(msgbuf, sizeof(msgbuf), fmtbuf, args);
                    165:        } else {
                    166:                vsnprintf(msgbuf, sizeof(msgbuf), fmt, args);
                    167:        }
1.13      markus    168:        if (log_on_stderr) {
1.10      markus    169:                fprintf(stderr, "%s\n", msgbuf);
1.13      markus    170:        } else {
                    171:                openlog(__progname, LOG_PID, log_facility);
                    172:                syslog(pri, "%.500s", msgbuf);
                    173:                closelog();
                    174:        }
1.1       deraadt   175: }