/*1* SPDX-License-Identifier: ISC2*3* Copyright (c) 1999-2005, 2007-20194* Todd C. Miller <[email protected]>5*6* Permission to use, copy, modify, and distribute this software for any7* purpose with or without fee is hereby granted, provided that the above8* copyright notice and this permission notice appear in all copies.9*10* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES11* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF12* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR13* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES14* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN15* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF16* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.17*18* Sponsored in part by the Defense Advanced Research Projects19* Agency (DARPA) and Air Force Research Laboratory, Air Force20* Materiel Command, USAF, under agreement number F39502-99-1-0512.21*/2223#include <config.h>2425#include <string.h>26#include <syslog.h>2728#include <sudo_compat.h>29#include <sudo_debug.h>30#include <sudo_util.h>3132/*33* For converting between syslog numbers and strings.34*/35struct strmap {36const char *name;37int num;38};3940static const struct strmap facilities[] = {41#ifdef LOG_AUTHPRIV42{ "authpriv", LOG_AUTHPRIV },43#endif44{ "auth", LOG_AUTH },45{ "daemon", LOG_DAEMON },46{ "user", LOG_USER },47{ "local0", LOG_LOCAL0 },48{ "local1", LOG_LOCAL1 },49{ "local2", LOG_LOCAL2 },50{ "local3", LOG_LOCAL3 },51{ "local4", LOG_LOCAL4 },52{ "local5", LOG_LOCAL5 },53{ "local6", LOG_LOCAL6 },54{ "local7", LOG_LOCAL7 },55{ NULL, -1 }56};5758bool59sudo_str2logfac_v1(const char *str, int *logfac)60{61const struct strmap *fac;62debug_decl(sudo_str2logfac, SUDO_DEBUG_UTIL);6364for (fac = facilities; fac->name != NULL; fac++) {65if (strcmp(str, fac->name) == 0) {66*logfac = fac->num;67debug_return_bool(true);68}69}70debug_return_bool(false);71}7273const char *74sudo_logfac2str_v1(int num)75{76const struct strmap *fac;77debug_decl(sudo_logfac2str, SUDO_DEBUG_UTIL);7879for (fac = facilities; fac->name != NULL; fac++) {80if (fac->num == num)81break;82}83debug_return_const_str(fac->name);84}858687