/src/sudo/lib/eventlog/eventlog_conf.c
Line | Count | Source |
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 | | #include <config.h> |
24 | | |
25 | | #include <sys/types.h> |
26 | | #include <sys/socket.h> |
27 | | #include <sys/stat.h> |
28 | | #include <sys/wait.h> |
29 | | #include <netinet/in.h> |
30 | | |
31 | | #include <ctype.h> |
32 | | #include <errno.h> |
33 | | #include <fcntl.h> |
34 | | #include <grp.h> |
35 | | #include <locale.h> |
36 | | #include <pwd.h> |
37 | | #include <signal.h> |
38 | | #include <stdio.h> |
39 | | #include <stdlib.h> |
40 | | #include <string.h> |
41 | | #include <syslog.h> |
42 | | #include <time.h> |
43 | | #include <unistd.h> |
44 | | |
45 | | #include <pathnames.h> |
46 | | #include <sudo_compat.h> |
47 | | #include <sudo_debug.h> |
48 | | #include <sudo_eventlog.h> |
49 | | #include <sudo_fatal.h> |
50 | | #include <sudo_gettext.h> |
51 | | #include <sudo_json.h> |
52 | | #include <sudo_queue.h> |
53 | | #include <sudo_util.h> |
54 | | |
55 | | static FILE *eventlog_stub_open_log(int type, const char *logfile); |
56 | | static void eventlog_stub_close_log(int type, FILE *fp); |
57 | | |
58 | | /* Eventlog config settings (default values). */ |
59 | | static struct eventlog_config evl_conf = { |
60 | | EVLOG_NONE, /* type */ |
61 | | EVLOG_SUDO, /* format */ |
62 | | 0, /* file_maxlen */ |
63 | | MAXSYSLOGLEN, /* syslog_maxlen */ |
64 | | LOG_NOTICE, /* syslog_acceptpri */ |
65 | | LOG_ALERT, /* syslog_rejectpri */ |
66 | | LOG_ALERT, /* syslog_alertpri */ |
67 | | ROOT_UID, /* mailuid */ |
68 | | ROOT_GID, /* mailgid */ |
69 | | false, /* omit_hostname */ |
70 | | _PATH_SUDO_LOGFILE, /* logpath */ |
71 | | "%h %e %T", /* time_fmt */ |
72 | | #ifdef _PATH_SUDO_SENDMAIL |
73 | | _PATH_SUDO_SENDMAIL, /* mailerpath */ |
74 | | #else |
75 | | NULL, /* mailerpath (disabled) */ |
76 | | #endif |
77 | | "-t", /* mailerflags */ |
78 | | NULL, /* mailfrom */ |
79 | | MAILTO, /* mailto */ |
80 | | N_(MAILSUBJECT), /* mailsub */ |
81 | | eventlog_stub_open_log, /* open_log */ |
82 | | eventlog_stub_close_log /* close_log */ |
83 | | }; |
84 | | |
85 | | static FILE * |
86 | | eventlog_stub_open_log(int type, const char *logfile) |
87 | 0 | { |
88 | 0 | debug_decl(eventlog_stub_open_log, SUDO_DEBUG_UTIL); |
89 | 0 | sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO, |
90 | 0 | "open_log not set, using stub"); |
91 | 0 | debug_return_ptr(NULL); |
92 | 0 | } |
93 | | |
94 | | static void |
95 | | eventlog_stub_close_log(int type, FILE *fp) |
96 | 0 | { |
97 | 0 | debug_decl(eventlog_stub_close_log, SUDO_DEBUG_UTIL); |
98 | 0 | sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO, |
99 | 0 | "close_log not set, using stub"); |
100 | 0 | debug_return; |
101 | 0 | } |
102 | | |
103 | | /* |
104 | | * eventlog config setters. |
105 | | */ |
106 | | |
107 | | void |
108 | | eventlog_set_type(int type) |
109 | 49.9k | { |
110 | 49.9k | evl_conf.type = type; |
111 | 49.9k | } |
112 | | |
113 | | void |
114 | | eventlog_set_format(enum eventlog_format format) |
115 | 0 | { |
116 | 0 | evl_conf.format = format; |
117 | 0 | } |
118 | | |
119 | | void |
120 | | eventlog_set_syslog_acceptpri(int pri) |
121 | 24.9k | { |
122 | 24.9k | evl_conf.syslog_acceptpri = pri; |
123 | 24.9k | } |
124 | | |
125 | | void |
126 | | eventlog_set_syslog_rejectpri(int pri) |
127 | 24.9k | { |
128 | 24.9k | evl_conf.syslog_rejectpri = pri; |
129 | 24.9k | } |
130 | | |
131 | | void |
132 | | eventlog_set_syslog_alertpri(int pri) |
133 | 24.9k | { |
134 | 24.9k | evl_conf.syslog_alertpri = pri; |
135 | 24.9k | } |
136 | | |
137 | | void |
138 | | eventlog_set_syslog_maxlen(size_t len) |
139 | 24.9k | { |
140 | 24.9k | evl_conf.syslog_maxlen = len; |
141 | 24.9k | } |
142 | | |
143 | | void |
144 | | eventlog_set_file_maxlen(size_t len) |
145 | 24.9k | { |
146 | 24.9k | evl_conf.file_maxlen = len; |
147 | 24.9k | } |
148 | | |
149 | | void |
150 | | eventlog_set_mailuser(uid_t uid, gid_t gid) |
151 | 0 | { |
152 | 0 | evl_conf.mailuid = uid; |
153 | 0 | evl_conf.mailgid = gid; |
154 | 0 | } |
155 | | |
156 | | void |
157 | | eventlog_set_omit_hostname(bool omit_hostname) |
158 | 24.9k | { |
159 | 24.9k | evl_conf.omit_hostname = omit_hostname; |
160 | 24.9k | } |
161 | | |
162 | | void |
163 | | eventlog_set_logpath(const char *path) |
164 | 24.9k | { |
165 | 24.9k | evl_conf.logpath = path; |
166 | 24.9k | } |
167 | | |
168 | | void |
169 | | eventlog_set_time_fmt(const char *fmt) |
170 | 24.9k | { |
171 | 24.9k | evl_conf.time_fmt = fmt; |
172 | 24.9k | } |
173 | | |
174 | | void |
175 | | eventlog_set_mailerpath(const char *path) |
176 | 24.9k | { |
177 | 24.9k | evl_conf.mailerpath = path; |
178 | 24.9k | } |
179 | | |
180 | | void |
181 | | eventlog_set_mailerflags(const char *mflags) |
182 | 24.9k | { |
183 | 24.9k | evl_conf.mailerflags = mflags; |
184 | 24.9k | } |
185 | | |
186 | | void |
187 | | eventlog_set_mailfrom(const char *from_addr) |
188 | 24.9k | { |
189 | 24.9k | evl_conf.mailfrom = from_addr; |
190 | 24.9k | } |
191 | | |
192 | | void |
193 | | eventlog_set_mailto(const char *to_addr) |
194 | 24.9k | { |
195 | 24.9k | evl_conf.mailto = to_addr; |
196 | 24.9k | } |
197 | | |
198 | | void |
199 | | eventlog_set_mailsub(const char *subject) |
200 | 24.9k | { |
201 | 24.9k | evl_conf.mailsub = subject; |
202 | 24.9k | } |
203 | | |
204 | | void |
205 | | eventlog_set_open_log(FILE *(*fn)(int type, const char *)) |
206 | 0 | { |
207 | 0 | evl_conf.open_log = fn; |
208 | 0 | } |
209 | | |
210 | | void |
211 | | eventlog_set_close_log(void (*fn)(int type, FILE *)) |
212 | 0 | { |
213 | 0 | evl_conf.close_log = fn; |
214 | 0 | } |
215 | | |
216 | | /* |
217 | | * get eventlog config. |
218 | | */ |
219 | | const struct eventlog_config * |
220 | | eventlog_getconf(void) |
221 | 0 | { |
222 | 0 | return &evl_conf; |
223 | 0 | } |