Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/lib/util/logpri.c
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 1999-2005, 2007-2019
5
* Todd C. Miller <[email protected]>
6
*
7
* Permission to use, copy, modify, and distribute this software for any
8
* purpose with or without fee is hereby granted, provided that the above
9
* copyright notice and this permission notice appear in all copies.
10
*
11
* THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18
*
19
* Sponsored in part by the Defense Advanced Research Projects
20
* Agency (DARPA) and Air Force Research Laboratory, Air Force
21
* Materiel Command, USAF, under agreement number F39502-99-1-0512.
22
*/
23
24
#include <config.h>
25
26
#include <string.h>
27
#include <syslog.h>
28
29
#include <sudo_compat.h>
30
#include <sudo_debug.h>
31
#include <sudo_util.h>
32
33
/*
34
* For converting between syslog numbers and strings.
35
*/
36
struct strmap {
37
const char *name;
38
int num;
39
};
40
41
static const struct strmap priorities[] = {
42
{ "alert", LOG_ALERT },
43
{ "crit", LOG_CRIT },
44
{ "debug", LOG_DEBUG },
45
{ "emerg", LOG_EMERG },
46
{ "err", LOG_ERR },
47
{ "info", LOG_INFO },
48
{ "notice", LOG_NOTICE },
49
{ "warning", LOG_WARNING },
50
{ "none", -1 },
51
{ NULL, -1 }
52
};
53
54
bool
55
sudo_str2logpri_v1(const char *str, int *logpri)
56
{
57
const struct strmap *pri;
58
debug_decl(sudo_str2logpri, SUDO_DEBUG_UTIL);
59
60
for (pri = priorities; pri->name != NULL; pri++) {
61
if (strcmp(str, pri->name) == 0) {
62
*logpri = pri->num;
63
debug_return_bool(true);
64
}
65
}
66
debug_return_bool(false);
67
}
68
69
const char *
70
sudo_logpri2str_v1(int num)
71
{
72
const struct strmap *pri;
73
debug_decl(sudo_logpri2str, SUDO_DEBUG_UTIL);
74
75
for (pri = priorities; pri->name != NULL; pri++) {
76
if (pri->num == num)
77
break;
78
}
79
debug_return_const_str(pri->name);
80
}
81
82