1 /* 2 * Copyright (c) 1982, 1986, 1988, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * Redistribution and use in source and binary forms, with or without 6 * modification, are permitted provided that the following conditions 7 * are met: 8 * 1. Redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer. 10 * 2. Redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution. 13 * 4. Neither the name of the University nor the names of its contributors 14 * may be used to endorse or promote products derived from this software 15 * without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27 * SUCH DAMAGE. 28 * 29 * @(#)syslog.h 8.1 (Berkeley) 6/2/93 30 */ 31 32 /*********************************************************************** 33 * Copyright (c) 2009, Secure Endpoints Inc. 34 * All rights reserved. 35 * 36 * Redistribution and use in source and binary forms, with or without 37 * modification, are permitted provided that the following conditions 38 * are met: 39 * 40 * - Redistributions of source code must retain the above copyright 41 * notice, this list of conditions and the following disclaimer. 42 * 43 * - Redistributions in binary form must reproduce the above copyright 44 * notice, this list of conditions and the following disclaimer in 45 * the documentation and/or other materials provided with the 46 * distribution. 47 * 48 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 49 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 50 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 51 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE 52 * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, 53 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 54 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR 55 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 56 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, 57 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 58 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED 59 * OF THE POSSIBILITY OF SUCH DAMAGE. 60 * 61 **********************************************************************/ 62 63 #ifndef _SYS_SYSLOG_H 64 #define _SYS_SYSLOG_H 1 65 66 #include <stdarg.h> 67 68 /* 69 * priorities/facilities are encoded into a single 32-bit quantity, where the 70 * bottom 3 bits are the priority (0-7) and the top 28 bits are the facility 71 * (0-big number). Both the priorities and the facilities map roughly 72 * one-to-one to strings in the syslogd(8) source code. This mapping is 73 * included in this file. 74 * 75 * priorities (these are ordered) 76 */ 77 #define LOG_EMERG 0 /* system is unusable */ 78 #define LOG_ALERT 1 /* action must be taken immediately */ 79 #define LOG_CRIT 2 /* critical conditions */ 80 #define LOG_ERR 3 /* error conditions */ 81 #define LOG_WARNING 4 /* warning conditions */ 82 #define LOG_NOTICE 5 /* normal but significant condition */ 83 #define LOG_INFO 6 /* informational */ 84 #define LOG_DEBUG 7 /* debug-level messages */ 85 86 #define LOG_PRIMASK 0x07 /* mask to extract priority part (internal) */ 87 /* extract priority */ 88 #define LOG_PRI(p) ((p) & LOG_PRIMASK) 89 #define LOG_MAKEPRI(fac, pri) (((fac) << 3) | (pri)) 90 91 #ifdef SYSLOG_NAMES 92 #define INTERNAL_NOPRI 0x10 /* the "no priority" priority */ 93 /* mark "facility" */ 94 #define INTERNAL_MARK LOG_MAKEPRI(LOG_NFACILITIES, 0) 95 typedef struct _code { 96 char *c_name; 97 int c_val; 98 } CODE; 99 100 CODE prioritynames[] = 101 { 102 { "alert", LOG_ALERT }, 103 { "crit", LOG_CRIT }, 104 { "debug", LOG_DEBUG }, 105 { "emerg", LOG_EMERG }, 106 { "err", LOG_ERR }, 107 { "error", LOG_ERR }, /* DEPRECATED */ 108 { "info", LOG_INFO }, 109 { "none", INTERNAL_NOPRI }, /* INTERNAL */ 110 { "notice", LOG_NOTICE }, 111 { "panic", LOG_EMERG }, /* DEPRECATED */ 112 { "warn", LOG_WARNING }, /* DEPRECATED */ 113 { "warning", LOG_WARNING }, 114 { NULL, -1 } 115 }; 116 #endif 117 118 /* facility codes */ 119 #define LOG_KERN (0<<3) /* kernel messages */ 120 #define LOG_USER (1<<3) /* random user-level messages */ 121 #define LOG_MAIL (2<<3) /* mail system */ 122 #define LOG_DAEMON (3<<3) /* system daemons */ 123 #define LOG_AUTH (4<<3) /* security/authorization messages */ 124 #define LOG_SYSLOG (5<<3) /* messages generated internally by syslogd */ 125 #define LOG_LPR (6<<3) /* line printer subsystem */ 126 #define LOG_NEWS (7<<3) /* network news subsystem */ 127 #define LOG_UUCP (8<<3) /* UUCP subsystem */ 128 #define LOG_CRON (9<<3) /* clock daemon */ 129 #define LOG_AUTHPRIV (10<<3) /* security/authorization messages (private) */ 130 #define LOG_FTP (11<<3) /* ftp daemon */ 131 132 /* other codes through 15 reserved for system use */ 133 #define LOG_LOCAL0 (16<<3) /* reserved for local use */ 134 #define LOG_LOCAL1 (17<<3) /* reserved for local use */ 135 #define LOG_LOCAL2 (18<<3) /* reserved for local use */ 136 #define LOG_LOCAL3 (19<<3) /* reserved for local use */ 137 #define LOG_LOCAL4 (20<<3) /* reserved for local use */ 138 #define LOG_LOCAL5 (21<<3) /* reserved for local use */ 139 #define LOG_LOCAL6 (22<<3) /* reserved for local use */ 140 #define LOG_LOCAL7 (23<<3) /* reserved for local use */ 141 142 #define LOG_NFACILITIES 24 /* current number of facilities */ 143 #define LOG_FACMASK 0x03f8 /* mask to extract facility part */ 144 /* facility of pri */ 145 #define LOG_FAC(p) (((p) & LOG_FACMASK) >> 3) 146 147 #ifdef SYSLOG_NAMES 148 CODE facilitynames[] = 149 { 150 { "auth", LOG_AUTH }, 151 { "authpriv", LOG_AUTHPRIV }, 152 { "cron", LOG_CRON }, 153 { "daemon", LOG_DAEMON }, 154 { "ftp", LOG_FTP }, 155 { "kern", LOG_KERN }, 156 { "lpr", LOG_LPR }, 157 { "mail", LOG_MAIL }, 158 { "mark", INTERNAL_MARK }, /* INTERNAL */ 159 { "news", LOG_NEWS }, 160 { "security", LOG_AUTH }, /* DEPRECATED */ 161 { "syslog", LOG_SYSLOG }, 162 { "user", LOG_USER }, 163 { "uucp", LOG_UUCP }, 164 { "local0", LOG_LOCAL0 }, 165 { "local1", LOG_LOCAL1 }, 166 { "local2", LOG_LOCAL2 }, 167 { "local3", LOG_LOCAL3 }, 168 { "local4", LOG_LOCAL4 }, 169 { "local5", LOG_LOCAL5 }, 170 { "local6", LOG_LOCAL6 }, 171 { "local7", LOG_LOCAL7 }, 172 { NULL, -1 } 173 }; 174 #endif 175 176 /* 177 * arguments to setlogmask. 178 */ 179 #define LOG_MASK(pri) (1 << (pri)) /* mask for one priority */ 180 #define LOG_UPTO(pri) ((1 << ((pri)+1)) - 1) /* all priorities through pri */ 181 182 /* 183 * Option flags for openlog. 184 * 185 * LOG_ODELAY no longer does anything. 186 * LOG_NDELAY is the inverse of what it used to be. 187 */ 188 #define LOG_PID 0x01 /* log the pid with each message */ 189 #define LOG_CONS 0x02 /* log on the console if errors in sending */ 190 #define LOG_ODELAY 0x04 /* delay open until first syslog() (default) */ 191 #define LOG_NDELAY 0x08 /* don't delay open */ 192 #define LOG_NOWAIT 0x10 /* don't wait for console forks: DEPRECATED */ 193 #define LOG_PERROR 0x20 /* log to stderr as well */ 194 195 #define SYSLOG_PORT 514 196 197 #ifdef __cplusplus 198 extern "C" { 199 #endif 200 201 /* Close desriptor used to write to system logger. */ 202 extern void closelog (void); 203 204 /* Open connection to system logger. */ 205 extern void openlog (char *__ident, int __option, int __facility); 206 207 /* Set the log mask level. */ 208 extern int setlogmask (int __mask); 209 210 /* Generate a log message using FMT string and option arguments. */ 211 extern void syslog (int __pri, char *__fmt, ...); 212 213 /* Generate a log message using FMT and using arguments pointed to by AP. */ 214 extern void vsyslog (int __pri, char *__fmt, va_list __ap); 215 216 #ifdef _WIN32 217 /* Windows specific. 218 219 init_syslog() *must* be called before calling any of the above 220 functions. exit_syslog() will be scheduled using atexit(). 221 However, it is not an error and encouraged to call 222 exit_syslog() before the application exits. 223 224 During operation, the application is free to call exit_syslog() 225 followed by init_syslog() to re-initialize the library. i.e. if 226 a different syslog host is to be used. 227 228 */ 229 230 /* Initializes the syslog library and sets the syslog host. The 231 hostname parameter is of the form "<hostname>[:<port>]". The 232 <port> may be a numeric port or it may be a name of a service. 233 If the <port> is specified using a service name, it will be 234 looked up using getservbyname(). 235 236 On failure, the hostname and port will be set to "localhost" 237 and SYSLOG_PORT respectively. 238 */ 239 extern void init_syslog(const char * hostname); 240 241 extern void exit_syslog(void); 242 #endif 243 244 #ifdef __cplusplus 245 } 246 #endif 247 248 #endif /* syslog.h */ 249