/src/sudo/lib/eventlog/eventlog_conf.c
Line | Count | Source (jump to first uncovered line) |
1 | | /* |
2 | | * SPDX-License-Identifier: ISC |
3 | | * |
4 | | * Copyright (c) 1994-1996, 1998-2020 Todd C. Miller <Todd.Miller@sudo.ws> |
5 | | * |
6 | | * Permission to use, copy, modify, and distribute this software for any |
7 | | * purpose with or without fee is hereby granted, provided that the above |
8 | | * copyright notice and this permission notice appear in all copies. |
9 | | * |
10 | | * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES |
11 | | * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF |
12 | | * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR |
13 | | * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES |
14 | | * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN |
15 | | * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
16 | | * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
17 | | * |
18 | | * Sponsored in part by the Defense Advanced Research Projects |
19 | | * Agency (DARPA) and Air Force Research Laboratory, Air Force |
20 | | * Materiel Command, USAF, under agreement number F39502-99-1-0512. |
21 | | */ |
22 | | |
23 | | /* |
24 | | * This is an open source non-commercial project. Dear PVS-Studio, please check it. |
25 | | * PVS-Studio Static Code Analyzer for C, C++ and C#: http://www.viva64.com |
26 | | */ |
27 | | |
28 | | #include <config.h> |
29 | | |
30 | | #include <sys/types.h> |
31 | | #include <sys/socket.h> |
32 | | #include <sys/stat.h> |
33 | | #include <sys/wait.h> |
34 | | #include <netinet/in.h> |
35 | | |
36 | | #include <ctype.h> |
37 | | #include <errno.h> |
38 | | #include <fcntl.h> |
39 | | #include <grp.h> |
40 | | #include <locale.h> |
41 | | #include <pwd.h> |
42 | | #include <signal.h> |
43 | | #include <stdio.h> |
44 | | #include <stdlib.h> |
45 | | #include <string.h> |
46 | | #include <syslog.h> |
47 | | #include <time.h> |
48 | | #include <unistd.h> |
49 | | |
50 | | #include "pathnames.h" |
51 | | #include "sudo_compat.h" |
52 | | #include "sudo_debug.h" |
53 | | #include "sudo_eventlog.h" |
54 | | #include "sudo_fatal.h" |
55 | | #include "sudo_gettext.h" |
56 | | #include "sudo_json.h" |
57 | | #include "sudo_queue.h" |
58 | | #include "sudo_util.h" |
59 | | |
60 | | static FILE *eventlog_stub_open_log(int type, const char *logfile); |
61 | | static void eventlog_stub_close_log(int type, FILE *fp); |
62 | | |
63 | | /* Eventlog config settings (default values). */ |
64 | | static struct eventlog_config evl_conf = { |
65 | | EVLOG_NONE, /* type */ |
66 | | EVLOG_SUDO, /* format */ |
67 | | LOG_NOTICE, /* syslog_acceptpri */ |
68 | | LOG_ALERT, /* syslog_rejectpri */ |
69 | | LOG_ALERT, /* syslog_alertpri */ |
70 | | MAXSYSLOGLEN, /* syslog_maxlen */ |
71 | | 0, /* file_maxlen */ |
72 | | ROOT_UID, /* mailuid */ |
73 | | false, /* omit_hostname */ |
74 | | _PATH_SUDO_LOGFILE, /* logpath */ |
75 | | "%h %e %T", /* time_fmt */ |
76 | | #ifdef _PATH_SUDO_SENDMAIL |
77 | | _PATH_SUDO_SENDMAIL, /* mailerpath */ |
78 | | #else |
79 | | NULL, /* mailerpath (disabled) */ |
80 | | #endif |
81 | | "-t", /* mailerflags */ |
82 | | NULL, /* mailfrom */ |
83 | | MAILTO, /* mailto */ |
84 | | N_(MAILSUBJECT), /* mailsub */ |
85 | | eventlog_stub_open_log, /* open_log */ |
86 | | eventlog_stub_close_log /* close_log */ |
87 | | }; |
88 | | |
89 | | static FILE * |
90 | | eventlog_stub_open_log(int type, const char *logfile) |
91 | 0 | { |
92 | 0 | debug_decl(eventlog_stub_open_log, SUDO_DEBUG_UTIL); |
93 | 0 | sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO, |
94 | 0 | "open_log not set, using stub"); |
95 | 0 | debug_return_ptr(NULL); |
96 | 0 | } |
97 | | |
98 | | static void |
99 | | eventlog_stub_close_log(int type, FILE *fp) |
100 | 0 | { |
101 | 0 | debug_decl(eventlog_stub_close_log, SUDO_DEBUG_UTIL); |
102 | 0 | sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO, |
103 | 0 | "close_log not set, using stub"); |
104 | 0 | debug_return; |
105 | 0 | } |
106 | | |
107 | | /* |
108 | | * eventlog config setters. |
109 | | */ |
110 | | |
111 | | void |
112 | | eventlog_set_type(int type) |
113 | 55.1k | { |
114 | 55.1k | evl_conf.type = type; |
115 | 55.1k | } |
116 | | |
117 | | void |
118 | | eventlog_set_format(enum eventlog_format format) |
119 | 0 | { |
120 | 0 | evl_conf.format = format; |
121 | 0 | } |
122 | | |
123 | | void |
124 | | eventlog_set_syslog_acceptpri(int pri) |
125 | 27.5k | { |
126 | 27.5k | evl_conf.syslog_acceptpri = pri; |
127 | 27.5k | } |
128 | | |
129 | | void |
130 | | eventlog_set_syslog_rejectpri(int pri) |
131 | 27.5k | { |
132 | 27.5k | evl_conf.syslog_rejectpri = pri; |
133 | 27.5k | } |
134 | | |
135 | | void |
136 | | eventlog_set_syslog_alertpri(int pri) |
137 | 27.5k | { |
138 | 27.5k | evl_conf.syslog_alertpri = pri; |
139 | 27.5k | } |
140 | | |
141 | | void |
142 | | eventlog_set_syslog_maxlen(int len) |
143 | 27.5k | { |
144 | 27.5k | evl_conf.syslog_maxlen = len; |
145 | 27.5k | } |
146 | | |
147 | | void |
148 | | eventlog_set_file_maxlen(int len) |
149 | 27.5k | { |
150 | 27.5k | evl_conf.file_maxlen = len; |
151 | 27.5k | } |
152 | | |
153 | | void |
154 | | eventlog_set_mailuid(uid_t uid) |
155 | 0 | { |
156 | 0 | evl_conf.mailuid = uid; |
157 | 0 | } |
158 | | |
159 | | void |
160 | | eventlog_set_omit_hostname(bool omit_hostname) |
161 | 27.5k | { |
162 | 27.5k | evl_conf.omit_hostname = omit_hostname; |
163 | 27.5k | } |
164 | | |
165 | | void |
166 | | eventlog_set_logpath(const char *path) |
167 | 27.5k | { |
168 | 27.5k | evl_conf.logpath = path; |
169 | 27.5k | } |
170 | | |
171 | | void |
172 | | eventlog_set_time_fmt(const char *fmt) |
173 | 27.5k | { |
174 | 27.5k | evl_conf.time_fmt = fmt; |
175 | 27.5k | } |
176 | | |
177 | | void |
178 | | eventlog_set_mailerpath(const char *path) |
179 | 27.5k | { |
180 | 27.5k | evl_conf.mailerpath = path; |
181 | 27.5k | } |
182 | | |
183 | | void |
184 | | eventlog_set_mailerflags(const char *mflags) |
185 | 27.5k | { |
186 | 27.5k | evl_conf.mailerflags = mflags; |
187 | 27.5k | } |
188 | | |
189 | | void |
190 | | eventlog_set_mailfrom(const char *from_addr) |
191 | 27.5k | { |
192 | 27.5k | evl_conf.mailfrom = from_addr; |
193 | 27.5k | } |
194 | | |
195 | | void |
196 | | eventlog_set_mailto(const char *to_addr) |
197 | 27.5k | { |
198 | 27.5k | evl_conf.mailto = to_addr; |
199 | 27.5k | } |
200 | | |
201 | | void |
202 | | eventlog_set_mailsub(const char *subject) |
203 | 27.5k | { |
204 | 27.5k | evl_conf.mailsub = subject; |
205 | 27.5k | } |
206 | | |
207 | | void |
208 | | eventlog_set_open_log(FILE *(*fn)(int type, const char *)) |
209 | 0 | { |
210 | 0 | evl_conf.open_log = fn; |
211 | 0 | } |
212 | | |
213 | | void |
214 | | eventlog_set_close_log(void (*fn)(int type, FILE *)) |
215 | 0 | { |
216 | 0 | evl_conf.close_log = fn; |
217 | 0 | } |
218 | | |
219 | | /* |
220 | | * get eventlog config. |
221 | | */ |
222 | | const struct eventlog_config * |
223 | | eventlog_getconf(void) |
224 | 0 | { |
225 | 0 | return &evl_conf; |
226 | 0 | } |