Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/lib/eventlog/eventlog_conf.c
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 1994-1996, 1998-2020 Todd C. Miller <[email protected]>
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
{
88
debug_decl(eventlog_stub_open_log, SUDO_DEBUG_UTIL);
89
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
90
"open_log not set, using stub");
91
debug_return_ptr(NULL);
92
}
93
94
static void
95
eventlog_stub_close_log(int type, FILE *fp)
96
{
97
debug_decl(eventlog_stub_close_log, SUDO_DEBUG_UTIL);
98
sudo_debug_printf(SUDO_DEBUG_WARN|SUDO_DEBUG_LINENO,
99
"close_log not set, using stub");
100
debug_return;
101
}
102
103
/*
104
* eventlog config setters.
105
*/
106
107
void
108
eventlog_set_type(int type)
109
{
110
evl_conf.type = type;
111
}
112
113
void
114
eventlog_set_format(enum eventlog_format format)
115
{
116
evl_conf.format = format;
117
}
118
119
void
120
eventlog_set_syslog_acceptpri(int pri)
121
{
122
evl_conf.syslog_acceptpri = pri;
123
}
124
125
void
126
eventlog_set_syslog_rejectpri(int pri)
127
{
128
evl_conf.syslog_rejectpri = pri;
129
}
130
131
void
132
eventlog_set_syslog_alertpri(int pri)
133
{
134
evl_conf.syslog_alertpri = pri;
135
}
136
137
void
138
eventlog_set_syslog_maxlen(size_t len)
139
{
140
evl_conf.syslog_maxlen = len;
141
}
142
143
void
144
eventlog_set_file_maxlen(size_t len)
145
{
146
evl_conf.file_maxlen = len;
147
}
148
149
void
150
eventlog_set_mailuser(uid_t uid, gid_t gid)
151
{
152
evl_conf.mailuid = uid;
153
evl_conf.mailgid = gid;
154
}
155
156
void
157
eventlog_set_omit_hostname(bool omit_hostname)
158
{
159
evl_conf.omit_hostname = omit_hostname;
160
}
161
162
void
163
eventlog_set_logpath(const char *path)
164
{
165
evl_conf.logpath = path;
166
}
167
168
void
169
eventlog_set_time_fmt(const char *fmt)
170
{
171
evl_conf.time_fmt = fmt;
172
}
173
174
void
175
eventlog_set_mailerpath(const char *path)
176
{
177
evl_conf.mailerpath = path;
178
}
179
180
void
181
eventlog_set_mailerflags(const char *mflags)
182
{
183
evl_conf.mailerflags = mflags;
184
}
185
186
void
187
eventlog_set_mailfrom(const char *from_addr)
188
{
189
evl_conf.mailfrom = from_addr;
190
}
191
192
void
193
eventlog_set_mailto(const char *to_addr)
194
{
195
evl_conf.mailto = to_addr;
196
}
197
198
void
199
eventlog_set_mailsub(const char *subject)
200
{
201
evl_conf.mailsub = subject;
202
}
203
204
void
205
eventlog_set_open_log(FILE *(*fn)(int type, const char *))
206
{
207
evl_conf.open_log = fn;
208
}
209
210
void
211
eventlog_set_close_log(void (*fn)(int type, FILE *))
212
{
213
evl_conf.close_log = fn;
214
}
215
216
/*
217
* get eventlog config.
218
*/
219
const struct eventlog_config *
220
eventlog_getconf(void)
221
{
222
return &evl_conf;
223
}
224
225