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