/src/sudo/lib/util/logfac.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 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 | 57.7k | { |
62 | 57.7k | const struct strmap *fac; |
63 | 57.7k | debug_decl(sudo_str2logfac, SUDO_DEBUG_UTIL); |
64 | | |
65 | 83.7k | for (fac = facilities; fac->name != NULL; fac++) { |
66 | 83.7k | if (strcmp(str, fac->name) == 0) { |
67 | 57.7k | *logfac = fac->num; |
68 | 57.7k | debug_return_bool(true); |
69 | 57.7k | } |
70 | 83.7k | } |
71 | 0 | debug_return_bool(false); |
72 | 0 | } |
73 | | |
74 | | const char * |
75 | | sudo_logfac2str_v1(int num) |
76 | 2.01k | { |
77 | 2.01k | const struct strmap *fac; |
78 | 2.01k | debug_decl(sudo_logfac2str, SUDO_DEBUG_UTIL); |
79 | | |
80 | 4.02k | for (fac = facilities; fac->name != NULL; fac++) { |
81 | 4.02k | if (fac->num == num) |
82 | 2.01k | break; |
83 | 4.02k | } |
84 | 2.01k | debug_return_const_str(fac->name); |
85 | 2.01k | } |