Coverage Report

Created: 2023-06-07 06:46

/src/sudo/lib/util/logfac.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 facilities[] = {
47
#ifdef LOG_AUTHPRIV
48
  { "authpriv", LOG_AUTHPRIV },
49
#endif
50
  { "auth", LOG_AUTH },
51
  { "daemon", LOG_DAEMON },
52
  { "user", LOG_USER },
53
  { "local0", LOG_LOCAL0 },
54
  { "local1", LOG_LOCAL1 },
55
  { "local2", LOG_LOCAL2 },
56
  { "local3", LOG_LOCAL3 },
57
  { "local4", LOG_LOCAL4 },
58
  { "local5", LOG_LOCAL5 },
59
  { "local6", LOG_LOCAL6 },
60
  { "local7", LOG_LOCAL7 },
61
  { NULL,   -1 }
62
};
63
64
bool
65
sudo_str2logfac_v1(const char *str, int *logfac)
66
4.40k
{
67
4.40k
    const struct strmap *fac;
68
4.40k
    debug_decl(sudo_str2logfac, SUDO_DEBUG_UTIL);
69
70
4.40k
    for (fac = facilities; fac->name != NULL; fac++) {
71
4.40k
  if (strcmp(str, fac->name) == 0) {
72
4.40k
      *logfac = fac->num;
73
4.40k
      debug_return_bool(true);
74
4.40k
  }
75
4.40k
    }
76
0
    debug_return_bool(false);
77
0
}
78
79
const char *
80
sudo_logfac2str_v1(int num)
81
0
{
82
0
    const struct strmap *fac;
83
0
    debug_decl(sudo_logfac2str, SUDO_DEBUG_UTIL);
84
85
0
    for (fac = facilities; fac->name != NULL; fac++) {
86
0
  if (fac->num == num)
87
0
      break;
88
0
    }
89
0
    debug_return_const_str(fac->name);
90
0
}