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