Coverage Report

Created: 2025-10-10 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/sudo/lib/util/logpri.c
Line
Count
Source
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
#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
13.6k
{
57
13.6k
    const struct strmap *pri;
58
13.6k
    debug_decl(sudo_str2logpri, SUDO_DEBUG_UTIL);
59
60
45.9k
    for (pri = priorities; pri->name != NULL; pri++) {
61
45.8k
  if (strcmp(str, pri->name) == 0) {
62
13.5k
      *logpri = pri->num;
63
13.5k
      debug_return_bool(true);
64
13.5k
  }
65
45.8k
    }
66
78
    debug_return_bool(false);
67
78
}
68
69
const char *
70
sudo_logpri2str_v1(int num)
71
0
{
72
0
    const struct strmap *pri;
73
0
    debug_decl(sudo_logpri2str, SUDO_DEBUG_UTIL);
74
75
0
    for (pri = priorities; pri->name != NULL; pri++) {
76
0
  if (pri->num == num)
77
0
      break;
78
0
    }
79
0
    debug_return_const_str(pri->name);
80
0
}