/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, /* maileruid */ |
68 | | ROOT_GID, /* mailergid */ |
69 | | false, /* omit_hostname */ |
70 | | NULL, /* maileruser */ |
71 | | _PATH_SUDO_LOGFILE, /* logpath */ |
72 | | "%h %e %T", /* time_fmt */ |
73 | | #ifdef _PATH_SUDO_SENDMAIL |
74 | | _PATH_SUDO_SENDMAIL, /* mailerpath */ |
75 | | #else |
76 | | NULL, /* mailerpath (disabled) */ |
77 | | #endif |
78 | | "-t", /* mailerflags */ |
79 | | NULL, /* mailfrom */ |
80 | | MAILTO, /* mailto */ |
81 | | N_(MAILSUBJECT), /* mailsub */ |
82 | | eventlog_stub_open_log, /* open_log */ |
83 | | eventlog_stub_close_log /* close_log */ |
84 | | }; |
85 | | |
86 | | static FILE * |
87 | | eventlog_stub_open_log(int type, const char *logfile) |
88 | 0 | { |
89 | 0 | debug_decl(eventlog_stub_open_log, SUDO_DEBUG_UTIL); |
90 | 0 | sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO, |
91 | 0 | "open_log not set, using stub"); |
92 | 0 | debug_return_ptr(NULL); |
93 | 0 | } |
94 | | |
95 | | static void |
96 | | eventlog_stub_close_log(int type, FILE *fp) |
97 | 0 | { |
98 | 0 | debug_decl(eventlog_stub_close_log, SUDO_DEBUG_UTIL); |
99 | 0 | sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO, |
100 | 0 | "close_log not set, using stub"); |
101 | 0 | debug_return; |
102 | 0 | } |
103 | | |
104 | | /* |
105 | | * eventlog config setters. |
106 | | */ |
107 | | |
108 | | void |
109 | | eventlog_set_type(int type) |
110 | 47.9k | { |
111 | 47.9k | evl_conf.type = type; |
112 | 47.9k | } |
113 | | |
114 | | void |
115 | | eventlog_set_format(enum eventlog_format format) |
116 | 0 | { |
117 | 0 | evl_conf.format = format; |
118 | 0 | } |
119 | | |
120 | | void |
121 | | eventlog_set_syslog_acceptpri(int pri) |
122 | 23.9k | { |
123 | 23.9k | evl_conf.syslog_acceptpri = pri; |
124 | 23.9k | } |
125 | | |
126 | | void |
127 | | eventlog_set_syslog_rejectpri(int pri) |
128 | 23.9k | { |
129 | 23.9k | evl_conf.syslog_rejectpri = pri; |
130 | 23.9k | } |
131 | | |
132 | | void |
133 | | eventlog_set_syslog_alertpri(int pri) |
134 | 23.9k | { |
135 | 23.9k | evl_conf.syslog_alertpri = pri; |
136 | 23.9k | } |
137 | | |
138 | | void |
139 | | eventlog_set_syslog_maxlen(size_t len) |
140 | 23.9k | { |
141 | 23.9k | evl_conf.syslog_maxlen = len; |
142 | 23.9k | } |
143 | | |
144 | | void |
145 | | eventlog_set_file_maxlen(size_t len) |
146 | 23.9k | { |
147 | 23.9k | evl_conf.file_maxlen = len; |
148 | 23.9k | } |
149 | | |
150 | | void |
151 | | eventlog_set_maileruser(const char *name, uid_t uid, gid_t gid) |
152 | 0 | { |
153 | 0 | evl_conf.maileruid = uid; |
154 | 0 | evl_conf.mailergid = gid; |
155 | 0 | evl_conf.maileruser = name; |
156 | 0 | } |
157 | | |
158 | | void |
159 | | eventlog_set_omit_hostname(bool omit_hostname) |
160 | 23.9k | { |
161 | 23.9k | evl_conf.omit_hostname = omit_hostname; |
162 | 23.9k | } |
163 | | |
164 | | void |
165 | | eventlog_set_logpath(const char *path) |
166 | 23.9k | { |
167 | 23.9k | evl_conf.logpath = path; |
168 | 23.9k | } |
169 | | |
170 | | void |
171 | | eventlog_set_time_fmt(const char *fmt) |
172 | 23.9k | { |
173 | 23.9k | evl_conf.time_fmt = fmt; |
174 | 23.9k | } |
175 | | |
176 | | void |
177 | | eventlog_set_mailerpath(const char *path) |
178 | 23.9k | { |
179 | 23.9k | evl_conf.mailerpath = path; |
180 | 23.9k | } |
181 | | |
182 | | void |
183 | | eventlog_set_mailerflags(const char *mflags) |
184 | 23.9k | { |
185 | 23.9k | evl_conf.mailerflags = mflags; |
186 | 23.9k | } |
187 | | |
188 | | void |
189 | | eventlog_set_mailfrom(const char *from_addr) |
190 | 23.9k | { |
191 | 23.9k | evl_conf.mailfrom = from_addr; |
192 | 23.9k | } |
193 | | |
194 | | void |
195 | | eventlog_set_mailto(const char *to_addr) |
196 | 23.9k | { |
197 | 23.9k | evl_conf.mailto = to_addr; |
198 | 23.9k | } |
199 | | |
200 | | void |
201 | | eventlog_set_mailsub(const char *subject) |
202 | 23.9k | { |
203 | 23.9k | evl_conf.mailsub = subject; |
204 | 23.9k | } |
205 | | |
206 | | void |
207 | | eventlog_set_open_log(FILE *(*fn)(int type, const char *)) |
208 | 0 | { |
209 | 0 | evl_conf.open_log = fn; |
210 | 0 | } |
211 | | |
212 | | void |
213 | | eventlog_set_close_log(void (*fn)(int type, FILE *)) |
214 | 0 | { |
215 | 0 | evl_conf.close_log = fn; |
216 | 0 | } |
217 | | |
218 | | /* |
219 | | * get eventlog config. |
220 | | */ |
221 | | const struct eventlog_config * |
222 | | eventlog_getconf(void) |
223 | 0 | { |
224 | 0 | return &evl_conf; |
225 | 0 | } |