/src/sudo/lib/util/logpri.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * SPDX-License-Identifier: ISC |
3 | | * |
4 | | * Copyright (c) 1999-2005, 2007-2019 |
5 | | * Todd C. Miller <Todd.Miller@sudo.ws> |
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 | | /* |
25 | | * This is an open source non-commercial project. Dear PVS-Studio, please check it. |
26 | | * PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com |
27 | | */ |
28 | | |
29 | | #include <config.h> |
30 | | |
31 | | #include <string.h> |
32 | | #include <syslog.h> |
33 | | |
34 | | #include "sudo_compat.h" |
35 | | #include "sudo_debug.h" |
36 | | #include "sudo_util.h" |
37 | | |
38 | | /* |
39 | | * For converting between syslog numbers and strings. |
40 | | */ |
41 | | struct strmap { |
42 | | const char *name; |
43 | | int num; |
44 | | }; |
45 | | |
46 | | static const struct strmap priorities[] = { |
47 | | { "alert", LOG_ALERT }, |
48 | | { "crit", LOG_CRIT }, |
49 | | { "debug", LOG_DEBUG }, |
50 | | { "emerg", LOG_EMERG }, |
51 | | { "err", LOG_ERR }, |
52 | | { "info", LOG_INFO }, |
53 | | { "notice", LOG_NOTICE }, |
54 | | { "warning", LOG_WARNING }, |
55 | | { "none", -1 }, |
56 | | { NULL, -1 } |
57 | | }; |
58 | | |
59 | | bool |
60 | | sudo_str2logpri_v1(const char *str, int *logpri) |
61 | 8.81k | { |
62 | 8.81k | const struct strmap *pri; |
63 | 8.81k | debug_decl(sudo_str2logpri, SUDO_DEBUG_UTIL); |
64 | | |
65 | 35.2k | for (pri = priorities; pri->name != NULL; pri++) { |
66 | 35.2k | if (strcmp(str, pri->name) == 0) { |
67 | 8.81k | *logpri = pri->num; |
68 | 8.81k | debug_return_bool(true); |
69 | 8.81k | } |
70 | 35.2k | } |
71 | 0 | debug_return_bool(false); |
72 | 0 | } |
73 | | |
74 | | const char * |
75 | | sudo_logpri2str_v1(int num) |
76 | 0 | { |
77 | 0 | const struct strmap *pri; |
78 | 0 | debug_decl(sudo_logpri2str, SUDO_DEBUG_UTIL); |
79 | |
|
80 | 0 | for (pri = priorities; pri->name != NULL; pri++) { |
81 | 0 | if (pri->num == num) |
82 | 0 | break; |
83 | 0 | } |
84 | 0 | debug_return_const_str(pri->name); |
85 | 0 | } |