xref: /netbsd-src/external/mpl/bind/dist/lib/isc/syslog.c (revision bcda20f65a8566e103791ec395f7f499ef322704)
1*bcda20f6Schristos /*	$NetBSD: syslog.c,v 1.3 2025/01/26 16:25:38 christos Exp $	*/
28aaca124Schristos 
38aaca124Schristos /*
48aaca124Schristos  * Copyright (C) Internet Systems Consortium, Inc. ("ISC")
58aaca124Schristos  *
68aaca124Schristos  * SPDX-License-Identifier: MPL-2.0
78aaca124Schristos  *
88aaca124Schristos  * This Source Code Form is subject to the terms of the Mozilla Public
98aaca124Schristos  * License, v. 2.0. If a copy of the MPL was not distributed with this
108aaca124Schristos  * file, you can obtain one at https://mozilla.org/MPL/2.0/.
118aaca124Schristos  *
128aaca124Schristos  * See the COPYRIGHT file distributed with this work for additional
138aaca124Schristos  * information regarding copyright ownership.
148aaca124Schristos  */
158aaca124Schristos 
168aaca124Schristos /*! \file */
178aaca124Schristos 
188aaca124Schristos #include <stdlib.h>
198aaca124Schristos #include <syslog.h>
208aaca124Schristos 
218aaca124Schristos #include <isc/result.h>
228aaca124Schristos #include <isc/string.h>
238aaca124Schristos #include <isc/syslog.h>
248aaca124Schristos #include <isc/util.h>
258aaca124Schristos 
268aaca124Schristos static struct dsn_c_pvt_sfnt {
278aaca124Schristos 	int val;
288aaca124Schristos 	const char *strval;
298aaca124Schristos } facilities[] = { { LOG_KERN, "kern" },
308aaca124Schristos 		   { LOG_USER, "user" },
318aaca124Schristos 		   { LOG_MAIL, "mail" },
328aaca124Schristos 		   { LOG_DAEMON, "daemon" },
338aaca124Schristos 		   { LOG_AUTH, "auth" },
348aaca124Schristos 		   { LOG_SYSLOG, "syslog" },
358aaca124Schristos 		   { LOG_LPR, "lpr" },
368aaca124Schristos #ifdef LOG_NEWS
378aaca124Schristos 		   { LOG_NEWS, "news" },
388aaca124Schristos #endif /* ifdef LOG_NEWS */
398aaca124Schristos #ifdef LOG_UUCP
408aaca124Schristos 		   { LOG_UUCP, "uucp" },
418aaca124Schristos #endif /* ifdef LOG_UUCP */
428aaca124Schristos #ifdef LOG_CRON
438aaca124Schristos 		   { LOG_CRON, "cron" },
448aaca124Schristos #endif /* ifdef LOG_CRON */
458aaca124Schristos #ifdef LOG_AUTHPRIV
468aaca124Schristos 		   { LOG_AUTHPRIV, "authpriv" },
478aaca124Schristos #endif /* ifdef LOG_AUTHPRIV */
488aaca124Schristos #ifdef LOG_FTP
498aaca124Schristos 		   { LOG_FTP, "ftp" },
508aaca124Schristos #endif /* ifdef LOG_FTP */
518aaca124Schristos 		   { LOG_LOCAL0, "local0" },
528aaca124Schristos 		   { LOG_LOCAL1, "local1" },
538aaca124Schristos 		   { LOG_LOCAL2, "local2" },
548aaca124Schristos 		   { LOG_LOCAL3, "local3" },
558aaca124Schristos 		   { LOG_LOCAL4, "local4" },
568aaca124Schristos 		   { LOG_LOCAL5, "local5" },
578aaca124Schristos 		   { LOG_LOCAL6, "local6" },
588aaca124Schristos 		   { LOG_LOCAL7, "local7" },
598aaca124Schristos 		   { 0, NULL } };
608aaca124Schristos 
618aaca124Schristos isc_result_t
628aaca124Schristos isc_syslog_facilityfromstring(const char *str, int *facilityp) {
638aaca124Schristos 	int i;
648aaca124Schristos 
658aaca124Schristos 	REQUIRE(str != NULL);
668aaca124Schristos 	REQUIRE(facilityp != NULL);
678aaca124Schristos 
688aaca124Schristos 	for (i = 0; facilities[i].strval != NULL; i++) {
698aaca124Schristos 		if (strcasecmp(facilities[i].strval, str) == 0) {
708aaca124Schristos 			*facilityp = facilities[i].val;
71*bcda20f6Schristos 			return ISC_R_SUCCESS;
728aaca124Schristos 		}
738aaca124Schristos 	}
74*bcda20f6Schristos 	return ISC_R_NOTFOUND;
758aaca124Schristos }
76