/*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 priorities[] = {41{ "alert", LOG_ALERT },42{ "crit", LOG_CRIT },43{ "debug", LOG_DEBUG },44{ "emerg", LOG_EMERG },45{ "err", LOG_ERR },46{ "info", LOG_INFO },47{ "notice", LOG_NOTICE },48{ "warning", LOG_WARNING },49{ "none", -1 },50{ NULL, -1 }51};5253bool54sudo_str2logpri_v1(const char *str, int *logpri)55{56const struct strmap *pri;57debug_decl(sudo_str2logpri, SUDO_DEBUG_UTIL);5859for (pri = priorities; pri->name != NULL; pri++) {60if (strcmp(str, pri->name) == 0) {61*logpri = pri->num;62debug_return_bool(true);63}64}65debug_return_bool(false);66}6768const char *69sudo_logpri2str_v1(int num)70{71const struct strmap *pri;72debug_decl(sudo_logpri2str, SUDO_DEBUG_UTIL);7374for (pri = priorities; pri->name != NULL; pri++) {75if (pri->num == num)76break;77}78debug_return_const_str(pri->name);79}808182