xref: /netbsd-src/external/mpl/dhcp/bind/dist/lib/isc/unix/syslog.c (revision 4afad4b7fa6d4a0d3dedf41d1587a7250710ae54)
1 /*	$NetBSD: syslog.c,v 1.1 2024/02/18 20:57:57 christos Exp $	*/
2 
3 /*
4  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
5  *
6  * SPDX-License-Identifier: MPL-2.0
7  *
8  * This Source Code Form is subject to the terms of the Mozilla Public
9  * License, v. 2.0. If a copy of the MPL was not distributed with this
10  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
11  *
12  * See the COPYRIGHT file distributed with this work for additional
13  * information regarding copyright ownership.
14  */
15 
16 /*! \file */
17 
18 #include <stdlib.h>
19 #include <syslog.h>
20 
21 #include <isc/result.h>
22 #include <isc/string.h>
23 #include <isc/syslog.h>
24 #include <isc/util.h>
25 
26 static struct dsn_c_pvt_sfnt {
27 	int val;
28 	const char *strval;
29 } facilities[] = { { LOG_KERN, "kern" },
30 		   { LOG_USER, "user" },
31 		   { LOG_MAIL, "mail" },
32 		   { LOG_DAEMON, "daemon" },
33 		   { LOG_AUTH, "auth" },
34 		   { LOG_SYSLOG, "syslog" },
35 		   { LOG_LPR, "lpr" },
36 #ifdef LOG_NEWS
37 		   { LOG_NEWS, "news" },
38 #endif /* ifdef LOG_NEWS */
39 #ifdef LOG_UUCP
40 		   { LOG_UUCP, "uucp" },
41 #endif /* ifdef LOG_UUCP */
42 #ifdef LOG_CRON
43 		   { LOG_CRON, "cron" },
44 #endif /* ifdef LOG_CRON */
45 #ifdef LOG_AUTHPRIV
46 		   { LOG_AUTHPRIV, "authpriv" },
47 #endif /* ifdef LOG_AUTHPRIV */
48 #ifdef LOG_FTP
49 		   { LOG_FTP, "ftp" },
50 #endif /* ifdef LOG_FTP */
51 		   { LOG_LOCAL0, "local0" },
52 		   { LOG_LOCAL1, "local1" },
53 		   { LOG_LOCAL2, "local2" },
54 		   { LOG_LOCAL3, "local3" },
55 		   { LOG_LOCAL4, "local4" },
56 		   { LOG_LOCAL5, "local5" },
57 		   { LOG_LOCAL6, "local6" },
58 		   { LOG_LOCAL7, "local7" },
59 		   { 0, NULL } };
60 
61 isc_result_t
isc_syslog_facilityfromstring(const char * str,int * facilityp)62 isc_syslog_facilityfromstring(const char *str, int *facilityp) {
63 	int i;
64 
65 	REQUIRE(str != NULL);
66 	REQUIRE(facilityp != NULL);
67 
68 	for (i = 0; facilities[i].strval != NULL; i++) {
69 		if (strcasecmp(facilities[i].strval, str) == 0) {
70 			*facilityp = facilities[i].val;
71 			return (ISC_R_SUCCESS);
72 		}
73 	}
74 	return (ISC_R_NOTFOUND);
75 }
76