17c478bd9Sstevel@tonic-gate /* 27c478bd9Sstevel@tonic-gate * Copyright (C) 1993-2001 by Darren Reed. 37c478bd9Sstevel@tonic-gate * 47c478bd9Sstevel@tonic-gate * See the IPFILTER.LICENCE file for details on licencing. 57c478bd9Sstevel@tonic-gate * 6*ab25eeb5Syz155240 * $Id: facpri.c,v 1.6 2003/12/01 01:59:43 darrenr Exp $ 77c478bd9Sstevel@tonic-gate */ 87c478bd9Sstevel@tonic-gate 97c478bd9Sstevel@tonic-gate #include <stdio.h> 107c478bd9Sstevel@tonic-gate #include <string.h> 117c478bd9Sstevel@tonic-gate #include <limits.h> 127c478bd9Sstevel@tonic-gate #include <sys/types.h> 137c478bd9Sstevel@tonic-gate #if !defined(__SVR4) && !defined(__svr4__) 147c478bd9Sstevel@tonic-gate #include <strings.h> 157c478bd9Sstevel@tonic-gate #endif 167c478bd9Sstevel@tonic-gate #include <stdlib.h> 177c478bd9Sstevel@tonic-gate #include <unistd.h> 187c478bd9Sstevel@tonic-gate #include <stddef.h> 197c478bd9Sstevel@tonic-gate #include <syslog.h> 207c478bd9Sstevel@tonic-gate #include "facpri.h" 217c478bd9Sstevel@tonic-gate 227c478bd9Sstevel@tonic-gate #if !defined(lint) 23*ab25eeb5Syz155240 static const char rcsid[] = "@(#)$Id: facpri.c,v 1.6 2003/12/01 01:59:43 darrenr Exp $"; 247c478bd9Sstevel@tonic-gate #endif 257c478bd9Sstevel@tonic-gate 267c478bd9Sstevel@tonic-gate 277c478bd9Sstevel@tonic-gate typedef struct table { 287c478bd9Sstevel@tonic-gate char *name; 297c478bd9Sstevel@tonic-gate int value; 307c478bd9Sstevel@tonic-gate } table_t; 317c478bd9Sstevel@tonic-gate 327c478bd9Sstevel@tonic-gate table_t facs[] = { 337c478bd9Sstevel@tonic-gate { "kern", LOG_KERN }, { "user", LOG_USER }, 347c478bd9Sstevel@tonic-gate { "mail", LOG_MAIL }, { "daemon", LOG_DAEMON }, 357c478bd9Sstevel@tonic-gate { "auth", LOG_AUTH }, { "syslog", LOG_SYSLOG }, 367c478bd9Sstevel@tonic-gate { "lpr", LOG_LPR }, { "news", LOG_NEWS }, 377c478bd9Sstevel@tonic-gate { "uucp", LOG_UUCP }, 387c478bd9Sstevel@tonic-gate #if LOG_CRON == LOG_CRON2 397c478bd9Sstevel@tonic-gate { "cron2", LOG_CRON1 }, 407c478bd9Sstevel@tonic-gate #else 417c478bd9Sstevel@tonic-gate { "cron", LOG_CRON1 }, 427c478bd9Sstevel@tonic-gate #endif 437c478bd9Sstevel@tonic-gate #ifdef LOG_FTP 447c478bd9Sstevel@tonic-gate { "ftp", LOG_FTP }, 457c478bd9Sstevel@tonic-gate #endif 467c478bd9Sstevel@tonic-gate #ifdef LOG_AUTHPRIV 477c478bd9Sstevel@tonic-gate { "authpriv", LOG_AUTHPRIV }, 487c478bd9Sstevel@tonic-gate #endif 497c478bd9Sstevel@tonic-gate #ifdef LOG_AUDIT 507c478bd9Sstevel@tonic-gate { "audit", LOG_AUDIT }, 517c478bd9Sstevel@tonic-gate #endif 527c478bd9Sstevel@tonic-gate #ifdef LOG_LFMT 537c478bd9Sstevel@tonic-gate { "logalert", LOG_LFMT }, 547c478bd9Sstevel@tonic-gate #endif 557c478bd9Sstevel@tonic-gate #if LOG_CRON == LOG_CRON1 567c478bd9Sstevel@tonic-gate { "cron", LOG_CRON2 }, 577c478bd9Sstevel@tonic-gate #else 587c478bd9Sstevel@tonic-gate { "cron2", LOG_CRON2 }, 597c478bd9Sstevel@tonic-gate #endif 607c478bd9Sstevel@tonic-gate #ifdef LOG_SECURITY 617c478bd9Sstevel@tonic-gate { "security", LOG_SECURITY }, 627c478bd9Sstevel@tonic-gate #endif 637c478bd9Sstevel@tonic-gate { "local0", LOG_LOCAL0 }, { "local1", LOG_LOCAL1 }, 647c478bd9Sstevel@tonic-gate { "local2", LOG_LOCAL2 }, { "local3", LOG_LOCAL3 }, 657c478bd9Sstevel@tonic-gate { "local4", LOG_LOCAL4 }, { "local5", LOG_LOCAL5 }, 667c478bd9Sstevel@tonic-gate { "local6", LOG_LOCAL6 }, { "local7", LOG_LOCAL7 }, 677c478bd9Sstevel@tonic-gate { NULL, 0 } 687c478bd9Sstevel@tonic-gate }; 697c478bd9Sstevel@tonic-gate 707c478bd9Sstevel@tonic-gate 717c478bd9Sstevel@tonic-gate /* 727c478bd9Sstevel@tonic-gate * map a facility number to its name 737c478bd9Sstevel@tonic-gate */ 747c478bd9Sstevel@tonic-gate char * 757c478bd9Sstevel@tonic-gate fac_toname(facpri) 767c478bd9Sstevel@tonic-gate int facpri; 777c478bd9Sstevel@tonic-gate { 787c478bd9Sstevel@tonic-gate int i, j, fac; 797c478bd9Sstevel@tonic-gate 807c478bd9Sstevel@tonic-gate fac = facpri & LOG_FACMASK; 817c478bd9Sstevel@tonic-gate j = fac >> 3; 827c478bd9Sstevel@tonic-gate if (j < 24) { 837c478bd9Sstevel@tonic-gate if (facs[j].value == fac) 847c478bd9Sstevel@tonic-gate return facs[j].name; 857c478bd9Sstevel@tonic-gate for (i = 0; facs[i].name; i++) 867c478bd9Sstevel@tonic-gate if (fac == facs[i].value) 877c478bd9Sstevel@tonic-gate return facs[i].name; 887c478bd9Sstevel@tonic-gate } 897c478bd9Sstevel@tonic-gate 907c478bd9Sstevel@tonic-gate return NULL; 917c478bd9Sstevel@tonic-gate } 927c478bd9Sstevel@tonic-gate 937c478bd9Sstevel@tonic-gate 947c478bd9Sstevel@tonic-gate /* 957c478bd9Sstevel@tonic-gate * map a facility name to its number 967c478bd9Sstevel@tonic-gate */ 977c478bd9Sstevel@tonic-gate int 987c478bd9Sstevel@tonic-gate fac_findname(name) 997c478bd9Sstevel@tonic-gate char *name; 1007c478bd9Sstevel@tonic-gate { 1017c478bd9Sstevel@tonic-gate int i; 1027c478bd9Sstevel@tonic-gate 1037c478bd9Sstevel@tonic-gate for (i = 0; facs[i].name; i++) 1047c478bd9Sstevel@tonic-gate if (!strcmp(facs[i].name, name)) 1057c478bd9Sstevel@tonic-gate return facs[i].value; 1067c478bd9Sstevel@tonic-gate return -1; 1077c478bd9Sstevel@tonic-gate } 1087c478bd9Sstevel@tonic-gate 1097c478bd9Sstevel@tonic-gate 1107c478bd9Sstevel@tonic-gate table_t pris[] = { 1117c478bd9Sstevel@tonic-gate { "emerg", LOG_EMERG }, { "alert", LOG_ALERT }, 1127c478bd9Sstevel@tonic-gate { "crit", LOG_CRIT }, { "err", LOG_ERR }, 1137c478bd9Sstevel@tonic-gate { "warn", LOG_WARNING }, { "notice", LOG_NOTICE }, 1147c478bd9Sstevel@tonic-gate { "info", LOG_INFO }, { "debug", LOG_DEBUG }, 1157c478bd9Sstevel@tonic-gate { NULL, 0 } 1167c478bd9Sstevel@tonic-gate }; 1177c478bd9Sstevel@tonic-gate 1187c478bd9Sstevel@tonic-gate 1197c478bd9Sstevel@tonic-gate /* 1207c478bd9Sstevel@tonic-gate * map a priority name to its number 1217c478bd9Sstevel@tonic-gate */ 1227c478bd9Sstevel@tonic-gate int 1237c478bd9Sstevel@tonic-gate pri_findname(name) 1247c478bd9Sstevel@tonic-gate char *name; 1257c478bd9Sstevel@tonic-gate { 1267c478bd9Sstevel@tonic-gate int i; 1277c478bd9Sstevel@tonic-gate 1287c478bd9Sstevel@tonic-gate for (i = 0; pris[i].name; i++) 1297c478bd9Sstevel@tonic-gate if (!strcmp(pris[i].name, name)) 1307c478bd9Sstevel@tonic-gate return pris[i].value; 1317c478bd9Sstevel@tonic-gate return -1; 1327c478bd9Sstevel@tonic-gate } 1337c478bd9Sstevel@tonic-gate 1347c478bd9Sstevel@tonic-gate 1357c478bd9Sstevel@tonic-gate /* 1367c478bd9Sstevel@tonic-gate * map a priority number to its name 1377c478bd9Sstevel@tonic-gate */ 1387c478bd9Sstevel@tonic-gate char * 1397c478bd9Sstevel@tonic-gate pri_toname(facpri) 1407c478bd9Sstevel@tonic-gate int facpri; 1417c478bd9Sstevel@tonic-gate { 1427c478bd9Sstevel@tonic-gate int i, pri; 1437c478bd9Sstevel@tonic-gate 1447c478bd9Sstevel@tonic-gate pri = facpri & LOG_PRIMASK; 1457c478bd9Sstevel@tonic-gate if (pris[pri].value == pri) 1467c478bd9Sstevel@tonic-gate return pris[pri].name; 1477c478bd9Sstevel@tonic-gate for (i = 0; pris[i].name; i++) 1487c478bd9Sstevel@tonic-gate if (pri == pris[i].value) 1497c478bd9Sstevel@tonic-gate return pris[i].name; 1507c478bd9Sstevel@tonic-gate return NULL; 1517c478bd9Sstevel@tonic-gate } 152