xref: /titanic_41/usr/src/cmd/ipf/lib/common/facpri.c (revision ea394cb00fd96864e34d2841b4a22357b621c78f)
1 /*
2  * Copyright (C) 1993-2001 by Darren Reed.
3  *
4  * See the IPFILTER.LICENCE file for details on licencing.
5  *
6  * $Id: facpri.c,v 1.6 2003/12/01 01:59:43 darrenr Exp $
7  */
8 
9 #include <stdio.h>
10 #include <string.h>
11 #include <limits.h>
12 #include <sys/types.h>
13 #if !defined(__SVR4) && !defined(__svr4__)
14 #include <strings.h>
15 #endif
16 #include <stdlib.h>
17 #include <unistd.h>
18 #include <stddef.h>
19 #include <syslog.h>
20 #include "facpri.h"
21 
22 #if !defined(lint)
23 static const char rcsid[] = "@(#)$Id: facpri.c,v 1.6 2003/12/01 01:59:43 darrenr Exp $";
24 #endif
25 
26 
27 typedef	struct	table	{
28 	char	*name;
29 	int	value;
30 } table_t;
31 
32 table_t	facs[] = {
33 	{ "kern", LOG_KERN },	{ "user", LOG_USER },
34 	{ "mail", LOG_MAIL },	{ "daemon", LOG_DAEMON },
35 	{ "auth", LOG_AUTH },	{ "syslog", LOG_SYSLOG },
36 	{ "lpr", LOG_LPR },	{ "news", LOG_NEWS },
37 	{ "uucp", LOG_UUCP },
38 #if LOG_CRON == LOG_CRON2
39 	{ "cron2", LOG_CRON1 },
40 #else
41 	{ "cron", LOG_CRON1 },
42 #endif
43 #ifdef	LOG_FTP
44 	{ "ftp", LOG_FTP },
45 #endif
46 #ifdef	LOG_AUTHPRIV
47 	{ "authpriv", LOG_AUTHPRIV },
48 #endif
49 #ifdef	LOG_AUDIT
50 	{ "audit", LOG_AUDIT },
51 #endif
52 #ifdef	LOG_LFMT
53 	{ "logalert", LOG_LFMT },
54 #endif
55 #if LOG_CRON == LOG_CRON1
56 	{ "cron", LOG_CRON2 },
57 #else
58 	{ "cron2", LOG_CRON2 },
59 #endif
60 #ifdef	LOG_SECURITY
61 	{ "security", LOG_SECURITY },
62 #endif
63 	{ "local0", LOG_LOCAL0 },	{ "local1", LOG_LOCAL1 },
64 	{ "local2", LOG_LOCAL2 },	{ "local3", LOG_LOCAL3 },
65 	{ "local4", LOG_LOCAL4 },	{ "local5", LOG_LOCAL5 },
66 	{ "local6", LOG_LOCAL6 },	{ "local7", LOG_LOCAL7 },
67 	{ NULL, 0 }
68 };
69 
70 
71 /*
72  * map a facility number to its name
73  */
74 char *
75 fac_toname(facpri)
76 	int facpri;
77 {
78 	int	i, j, fac;
79 
80 	fac = facpri & LOG_FACMASK;
81 	j = fac >> 3;
82 	if (j < 24) {
83 		if (facs[j].value == fac)
84 			return facs[j].name;
85 		for (i = 0; facs[i].name; i++)
86 			if (fac == facs[i].value)
87 				return facs[i].name;
88 	}
89 
90 	return NULL;
91 }
92 
93 
94 /*
95  * map a facility name to its number
96  */
97 int
98 fac_findname(name)
99 	char *name;
100 {
101 	int	i;
102 
103 	for (i = 0; facs[i].name; i++)
104 		if (!strcmp(facs[i].name, name))
105 			return facs[i].value;
106 	return -1;
107 }
108 
109 
110 table_t	pris[] = {
111 	{ "emerg", LOG_EMERG },		{ "alert", LOG_ALERT  },
112 	{ "crit", LOG_CRIT },		{ "err", LOG_ERR  },
113 	{ "warn", LOG_WARNING },	{ "notice", LOG_NOTICE  },
114 	{ "info", LOG_INFO },		{ "debug", LOG_DEBUG  },
115 	{ NULL, 0 }
116 };
117 
118 
119 /*
120  * map a priority name to its number
121  */
122 int
123 pri_findname(name)
124 	char *name;
125 {
126 	int	i;
127 
128 	for (i = 0; pris[i].name; i++)
129 		if (!strcmp(pris[i].name, name))
130 			return pris[i].value;
131 	return -1;
132 }
133 
134 
135 /*
136  * map a priority number to its name
137  */
138 char *
139 pri_toname(facpri)
140 	int facpri;
141 {
142 	int	i, pri;
143 
144 	pri = facpri & LOG_PRIMASK;
145 	if (pris[pri].value == pri)
146 		return pris[pri].name;
147 	for (i = 0; pris[i].name; i++)
148 		if (pri == pris[i].value)
149 			return pris[i].name;
150 	return NULL;
151 }
152