xref: /minix3/external/bsd/bind/dist/lib/isc/unix/syslog.c (revision 00b67f09dd46474d133c95011a48590a8e8f94c7)
1 /*	$NetBSD: syslog.c,v 1.4 2014/12/10 04:38:01 christos Exp $	*/
2 
3 /*
4  * Copyright (C) 2004, 2005, 2007  Internet Systems Consortium, Inc. ("ISC")
5  * Copyright (C) 2001  Internet Software Consortium.
6  *
7  * Permission to use, copy, modify, and/or distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES WITH
12  * REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
13  * AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR ANY SPECIAL, DIRECT,
14  * INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
15  * LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE
16  * OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
17  * PERFORMANCE OF THIS SOFTWARE.
18  */
19 
20 /* Id: syslog.c,v 1.8 2007/09/13 04:45:18 each Exp  */
21 
22 /*! \file */
23 
24 #include <config.h>
25 
26 #include <stdlib.h>
27 #include <syslog.h>
28 
29 #include <isc/result.h>
30 #include <isc/string.h>
31 #include <isc/syslog.h>
32 #include <isc/util.h>
33 
34 static struct dsn_c_pvt_sfnt {
35 	int val;
36 	const char *strval;
37 } facilities[] = {
38 	{ LOG_KERN,			"kern" },
39 	{ LOG_USER,			"user" },
40 	{ LOG_MAIL,			"mail" },
41 	{ LOG_DAEMON,			"daemon" },
42 	{ LOG_AUTH,			"auth" },
43 	{ LOG_SYSLOG,			"syslog" },
44 	{ LOG_LPR,			"lpr" },
45 #ifdef LOG_NEWS
46 	{ LOG_NEWS,			"news" },
47 #endif
48 #ifdef LOG_UUCP
49 	{ LOG_UUCP,			"uucp" },
50 #endif
51 #ifdef LOG_CRON
52 	{ LOG_CRON,			"cron" },
53 #endif
54 #ifdef LOG_AUTHPRIV
55 	{ LOG_AUTHPRIV,			"authpriv" },
56 #endif
57 #ifdef LOG_FTP
58 	{ LOG_FTP,			"ftp" },
59 #endif
60 	{ LOG_LOCAL0,			"local0"},
61 	{ LOG_LOCAL1,			"local1"},
62 	{ LOG_LOCAL2,			"local2"},
63 	{ LOG_LOCAL3,			"local3"},
64 	{ LOG_LOCAL4,			"local4"},
65 	{ LOG_LOCAL5,			"local5"},
66 	{ LOG_LOCAL6,			"local6"},
67 	{ LOG_LOCAL7,			"local7"},
68 	{ 0,				NULL }
69 };
70 
71 isc_result_t
isc_syslog_facilityfromstring(const char * str,int * facilityp)72 isc_syslog_facilityfromstring(const char *str, int *facilityp) {
73 	int i;
74 
75 	REQUIRE(str != NULL);
76 	REQUIRE(facilityp != NULL);
77 
78 	for (i = 0; facilities[i].strval != NULL; i++) {
79 		if (strcasecmp(facilities[i].strval, str) == 0) {
80 			*facilityp = facilities[i].val;
81 			return (ISC_R_SUCCESS);
82 		}
83 	}
84 	return (ISC_R_NOTFOUND);
85 
86 }
87