Merge remote-tracking branch 'origin/master'
[unleashed/lotheac.git] / usr / src / cmd / ipf / lib / common / facpri.c
blob2cfc4bacfd30e5adbb71dcfd7ef1e38822d22584
1 /*
2 * Copyright (C) 1993-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * $Id: facpri.c,v 1.6 2003/12/01 01:59:43 darrenr Exp $
7 */
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"
22 static const char rcsid[] = "@(#)$Id: facpri.c,v 1.6 2003/12/01 01:59:43 darrenr Exp $";
25 typedef struct table {
26 char *name;
27 int value;
28 } table_t;
30 table_t facs[] = {
31 { "kern", LOG_KERN }, { "user", LOG_USER },
32 { "mail", LOG_MAIL }, { "daemon", LOG_DAEMON },
33 { "auth", LOG_AUTH }, { "syslog", LOG_SYSLOG },
34 { "lpr", LOG_LPR }, { "news", LOG_NEWS },
35 { "uucp", LOG_UUCP },
36 #if LOG_CRON == LOG_CRON2
37 { "cron2", LOG_CRON1 },
38 #else
39 { "cron", LOG_CRON1 },
40 #endif
41 #ifdef LOG_FTP
42 { "ftp", LOG_FTP },
43 #endif
44 #ifdef LOG_AUTHPRIV
45 { "authpriv", LOG_AUTHPRIV },
46 #endif
47 #ifdef LOG_AUDIT
48 { "audit", LOG_AUDIT },
49 #endif
50 #ifdef LOG_LFMT
51 { "logalert", LOG_LFMT },
52 #endif
53 #if LOG_CRON == LOG_CRON1
54 { "cron", LOG_CRON2 },
55 #else
56 { "cron2", LOG_CRON2 },
57 #endif
58 #ifdef LOG_SECURITY
59 { "security", LOG_SECURITY },
60 #endif
61 { "local0", LOG_LOCAL0 }, { "local1", LOG_LOCAL1 },
62 { "local2", LOG_LOCAL2 }, { "local3", LOG_LOCAL3 },
63 { "local4", LOG_LOCAL4 }, { "local5", LOG_LOCAL5 },
64 { "local6", LOG_LOCAL6 }, { "local7", LOG_LOCAL7 },
65 { NULL, 0 }
70 * map a facility number to its name
72 char *
73 fac_toname(facpri)
74 int facpri;
76 int i, j, fac;
78 fac = facpri & LOG_FACMASK;
79 j = fac >> 3;
80 if (j < 24) {
81 if (facs[j].value == fac)
82 return facs[j].name;
83 for (i = 0; facs[i].name; i++)
84 if (fac == facs[i].value)
85 return facs[i].name;
88 return NULL;
93 * map a facility name to its number
95 int
96 fac_findname(name)
97 char *name;
99 int i;
101 for (i = 0; facs[i].name; i++)
102 if (!strcmp(facs[i].name, name))
103 return facs[i].value;
104 return -1;
108 table_t pris[] = {
109 { "emerg", LOG_EMERG }, { "alert", LOG_ALERT },
110 { "crit", LOG_CRIT }, { "err", LOG_ERR },
111 { "warn", LOG_WARNING }, { "notice", LOG_NOTICE },
112 { "info", LOG_INFO }, { "debug", LOG_DEBUG },
113 { NULL, 0 }
118 * map a priority name to its number
121 pri_findname(name)
122 char *name;
124 int i;
126 for (i = 0; pris[i].name; i++)
127 if (!strcmp(pris[i].name, name))
128 return pris[i].value;
129 return -1;
134 * map a priority number to its name
136 char *
137 pri_toname(facpri)
138 int facpri;
140 int i, pri;
142 pri = facpri & LOG_PRIMASK;
143 if (pris[pri].value == pri)
144 return pris[pri].name;
145 for (i = 0; pris[i].name; i++)
146 if (pri == pris[i].value)
147 return pris[i].name;
148 return NULL;