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