xref: /onnv-gate/usr/src/cmd/ipf/lib/common/facpri.c (revision 2393:76e0289ce525)
10Sstevel@tonic-gate /*
20Sstevel@tonic-gate  * Copyright (C) 1993-2001 by Darren Reed.
30Sstevel@tonic-gate  *
40Sstevel@tonic-gate  * See the IPFILTER.LICENCE file for details on licencing.
50Sstevel@tonic-gate  *
6*2393Syz155240  * $Id: facpri.c,v 1.6 2003/12/01 01:59:43 darrenr Exp $
70Sstevel@tonic-gate  */
80Sstevel@tonic-gate 
90Sstevel@tonic-gate #include <stdio.h>
100Sstevel@tonic-gate #include <string.h>
110Sstevel@tonic-gate #include <limits.h>
120Sstevel@tonic-gate #include <sys/types.h>
130Sstevel@tonic-gate #if !defined(__SVR4) && !defined(__svr4__)
140Sstevel@tonic-gate #include <strings.h>
150Sstevel@tonic-gate #endif
160Sstevel@tonic-gate #include <stdlib.h>
170Sstevel@tonic-gate #include <unistd.h>
180Sstevel@tonic-gate #include <stddef.h>
190Sstevel@tonic-gate #include <syslog.h>
200Sstevel@tonic-gate #include "facpri.h"
210Sstevel@tonic-gate 
220Sstevel@tonic-gate #if !defined(lint)
23*2393Syz155240 static const char rcsid[] = "@(#)$Id: facpri.c,v 1.6 2003/12/01 01:59:43 darrenr Exp $";
240Sstevel@tonic-gate #endif
250Sstevel@tonic-gate 
260Sstevel@tonic-gate 
270Sstevel@tonic-gate typedef	struct	table	{
280Sstevel@tonic-gate 	char	*name;
290Sstevel@tonic-gate 	int	value;
300Sstevel@tonic-gate } table_t;
310Sstevel@tonic-gate 
320Sstevel@tonic-gate table_t	facs[] = {
330Sstevel@tonic-gate 	{ "kern", LOG_KERN },	{ "user", LOG_USER },
340Sstevel@tonic-gate 	{ "mail", LOG_MAIL },	{ "daemon", LOG_DAEMON },
350Sstevel@tonic-gate 	{ "auth", LOG_AUTH },	{ "syslog", LOG_SYSLOG },
360Sstevel@tonic-gate 	{ "lpr", LOG_LPR },	{ "news", LOG_NEWS },
370Sstevel@tonic-gate 	{ "uucp", LOG_UUCP },
38*2393Syz155240 #if LOG_CRON == LOG_CRON2
390Sstevel@tonic-gate 	{ "cron2", LOG_CRON1 },
400Sstevel@tonic-gate #else
410Sstevel@tonic-gate 	{ "cron", LOG_CRON1 },
420Sstevel@tonic-gate #endif
430Sstevel@tonic-gate #ifdef	LOG_FTP
440Sstevel@tonic-gate 	{ "ftp", LOG_FTP },
450Sstevel@tonic-gate #endif
460Sstevel@tonic-gate #ifdef	LOG_AUTHPRIV
470Sstevel@tonic-gate 	{ "authpriv", LOG_AUTHPRIV },
480Sstevel@tonic-gate #endif
490Sstevel@tonic-gate #ifdef	LOG_AUDIT
500Sstevel@tonic-gate 	{ "audit", LOG_AUDIT },
510Sstevel@tonic-gate #endif
520Sstevel@tonic-gate #ifdef	LOG_LFMT
530Sstevel@tonic-gate 	{ "logalert", LOG_LFMT },
540Sstevel@tonic-gate #endif
550Sstevel@tonic-gate #if LOG_CRON == LOG_CRON1
560Sstevel@tonic-gate 	{ "cron", LOG_CRON2 },
570Sstevel@tonic-gate #else
580Sstevel@tonic-gate 	{ "cron2", LOG_CRON2 },
590Sstevel@tonic-gate #endif
600Sstevel@tonic-gate #ifdef	LOG_SECURITY
610Sstevel@tonic-gate 	{ "security", LOG_SECURITY },
620Sstevel@tonic-gate #endif
630Sstevel@tonic-gate 	{ "local0", LOG_LOCAL0 },	{ "local1", LOG_LOCAL1 },
640Sstevel@tonic-gate 	{ "local2", LOG_LOCAL2 },	{ "local3", LOG_LOCAL3 },
650Sstevel@tonic-gate 	{ "local4", LOG_LOCAL4 },	{ "local5", LOG_LOCAL5 },
660Sstevel@tonic-gate 	{ "local6", LOG_LOCAL6 },	{ "local7", LOG_LOCAL7 },
670Sstevel@tonic-gate 	{ NULL, 0 }
680Sstevel@tonic-gate };
690Sstevel@tonic-gate 
700Sstevel@tonic-gate 
710Sstevel@tonic-gate /*
720Sstevel@tonic-gate  * map a facility number to its name
730Sstevel@tonic-gate  */
740Sstevel@tonic-gate char *
fac_toname(facpri)750Sstevel@tonic-gate fac_toname(facpri)
760Sstevel@tonic-gate 	int facpri;
770Sstevel@tonic-gate {
780Sstevel@tonic-gate 	int	i, j, fac;
790Sstevel@tonic-gate 
800Sstevel@tonic-gate 	fac = facpri & LOG_FACMASK;
810Sstevel@tonic-gate 	j = fac >> 3;
820Sstevel@tonic-gate 	if (j < 24) {
830Sstevel@tonic-gate 		if (facs[j].value == fac)
840Sstevel@tonic-gate 			return facs[j].name;
850Sstevel@tonic-gate 		for (i = 0; facs[i].name; i++)
860Sstevel@tonic-gate 			if (fac == facs[i].value)
870Sstevel@tonic-gate 				return facs[i].name;
880Sstevel@tonic-gate 	}
890Sstevel@tonic-gate 
900Sstevel@tonic-gate 	return NULL;
910Sstevel@tonic-gate }
920Sstevel@tonic-gate 
930Sstevel@tonic-gate 
940Sstevel@tonic-gate /*
950Sstevel@tonic-gate  * map a facility name to its number
960Sstevel@tonic-gate  */
970Sstevel@tonic-gate int
fac_findname(name)980Sstevel@tonic-gate fac_findname(name)
990Sstevel@tonic-gate 	char *name;
1000Sstevel@tonic-gate {
1010Sstevel@tonic-gate 	int	i;
1020Sstevel@tonic-gate 
1030Sstevel@tonic-gate 	for (i = 0; facs[i].name; i++)
1040Sstevel@tonic-gate 		if (!strcmp(facs[i].name, name))
1050Sstevel@tonic-gate 			return facs[i].value;
1060Sstevel@tonic-gate 	return -1;
1070Sstevel@tonic-gate }
1080Sstevel@tonic-gate 
1090Sstevel@tonic-gate 
1100Sstevel@tonic-gate table_t	pris[] = {
1110Sstevel@tonic-gate 	{ "emerg", LOG_EMERG },		{ "alert", LOG_ALERT  },
1120Sstevel@tonic-gate 	{ "crit", LOG_CRIT },		{ "err", LOG_ERR  },
1130Sstevel@tonic-gate 	{ "warn", LOG_WARNING },	{ "notice", LOG_NOTICE  },
1140Sstevel@tonic-gate 	{ "info", LOG_INFO },		{ "debug", LOG_DEBUG  },
1150Sstevel@tonic-gate 	{ NULL, 0 }
1160Sstevel@tonic-gate };
1170Sstevel@tonic-gate 
1180Sstevel@tonic-gate 
1190Sstevel@tonic-gate /*
1200Sstevel@tonic-gate  * map a priority name to its number
1210Sstevel@tonic-gate  */
1220Sstevel@tonic-gate int
pri_findname(name)1230Sstevel@tonic-gate pri_findname(name)
1240Sstevel@tonic-gate 	char *name;
1250Sstevel@tonic-gate {
1260Sstevel@tonic-gate 	int	i;
1270Sstevel@tonic-gate 
1280Sstevel@tonic-gate 	for (i = 0; pris[i].name; i++)
1290Sstevel@tonic-gate 		if (!strcmp(pris[i].name, name))
1300Sstevel@tonic-gate 			return pris[i].value;
1310Sstevel@tonic-gate 	return -1;
1320Sstevel@tonic-gate }
1330Sstevel@tonic-gate 
1340Sstevel@tonic-gate 
1350Sstevel@tonic-gate /*
1360Sstevel@tonic-gate  * map a priority number to its name
1370Sstevel@tonic-gate  */
1380Sstevel@tonic-gate char *
pri_toname(facpri)1390Sstevel@tonic-gate pri_toname(facpri)
1400Sstevel@tonic-gate 	int facpri;
1410Sstevel@tonic-gate {
1420Sstevel@tonic-gate 	int	i, pri;
1430Sstevel@tonic-gate 
1440Sstevel@tonic-gate 	pri = facpri & LOG_PRIMASK;
1450Sstevel@tonic-gate 	if (pris[pri].value == pri)
1460Sstevel@tonic-gate 		return pris[pri].name;
1470Sstevel@tonic-gate 	for (i = 0; pris[i].name; i++)
1480Sstevel@tonic-gate 		if (pri == pris[i].value)
1490Sstevel@tonic-gate 			return pris[i].name;
1500Sstevel@tonic-gate 	return NULL;
1510Sstevel@tonic-gate }
152