Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sudo-project
GitHub Repository: sudo-project/sudo
Path: blob/main/lib/iolog/iolog_conf.c
1532 views
1
/*
2
* SPDX-License-Identifier: ISC
3
*
4
* Copyright (c) 2009-2021 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
19
#include <config.h>
20
21
#include <sys/types.h>
22
#include <sys/stat.h>
23
#include <stdio.h>
24
#include <stdlib.h>
25
#ifdef HAVE_STDBOOL_H
26
# include <stdbool.h>
27
#else
28
# include <compat/stdbool.h>
29
#endif
30
31
#include <pathnames.h>
32
#include <sudo_compat.h>
33
#include <sudo_debug.h>
34
#include <sudo_util.h>
35
#include <sudo_iolog.h>
36
37
static unsigned int sessid_max = SESSID_MAX;
38
static mode_t iolog_filemode = S_IRUSR|S_IWUSR;
39
static mode_t iolog_dirmode = S_IRWXU;
40
static uid_t iolog_uid = ROOT_UID;
41
static gid_t iolog_gid = ROOT_GID;
42
static bool iolog_gid_set;
43
static bool iolog_docompress;
44
static bool iolog_doflush;
45
46
/*
47
* Reset I/O log settings to default values.
48
*/
49
void
50
iolog_set_defaults(void)
51
{
52
sessid_max = SESSID_MAX;
53
iolog_filemode = S_IRUSR|S_IWUSR;
54
iolog_dirmode = S_IRWXU;
55
iolog_uid = ROOT_UID;
56
iolog_gid = ROOT_GID;
57
iolog_gid_set = false;
58
iolog_docompress = false;
59
iolog_doflush = false;
60
}
61
62
/*
63
* Set max sequence number (aka session ID)
64
*/
65
void
66
iolog_set_maxseq(unsigned int newval)
67
{
68
debug_decl(iolog_set_maxseq, SUDO_DEBUG_UTIL);
69
70
/* Clamp to SESSID_MAX as documented. */
71
if (newval > SESSID_MAX)
72
newval = SESSID_MAX;
73
sessid_max = newval;
74
75
debug_return;
76
}
77
78
/*
79
* Set iolog_uid (and iolog_gid if gid not explicitly set).
80
*/
81
void
82
iolog_set_owner(uid_t uid, gid_t gid)
83
{
84
debug_decl(iolog_set_owner, SUDO_DEBUG_UTIL);
85
86
iolog_uid = uid;
87
if (!iolog_gid_set)
88
iolog_gid = gid;
89
90
debug_return;
91
}
92
93
/*
94
* Set iolog_gid.
95
*/
96
void
97
iolog_set_gid(gid_t gid)
98
{
99
debug_decl(iolog_set_gid, SUDO_DEBUG_UTIL);
100
101
iolog_gid = gid;
102
iolog_gid_set = true;
103
104
debug_return;
105
}
106
107
/*
108
* Set iolog_filemode and iolog_dirmode.
109
*/
110
void
111
iolog_set_mode(mode_t mode)
112
{
113
debug_decl(iolog_set_mode, SUDO_DEBUG_UTIL);
114
115
/* I/O log files must be readable and writable by owner. */
116
iolog_filemode = S_IRUSR|S_IWUSR;
117
118
/* Add in group and other read/write if specified. */
119
iolog_filemode |= mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
120
121
/* For directory mode, add execute bits as needed. */
122
iolog_dirmode = iolog_filemode | S_IXUSR;
123
if (iolog_dirmode & (S_IRGRP|S_IWGRP))
124
iolog_dirmode |= S_IXGRP;
125
if (iolog_dirmode & (S_IROTH|S_IWOTH))
126
iolog_dirmode |= S_IXOTH;
127
128
debug_return;
129
}
130
131
/*
132
* Set iolog_docompress
133
*/
134
void
135
iolog_set_compress(bool newval)
136
{
137
debug_decl(iolog_set_compress, SUDO_DEBUG_UTIL);
138
iolog_docompress = newval;
139
debug_return;
140
}
141
142
/*
143
* Set iolog_doflush
144
*/
145
void
146
iolog_set_flush(bool newval)
147
{
148
debug_decl(iolog_set_flush, SUDO_DEBUG_UTIL);
149
iolog_doflush = newval;
150
debug_return;
151
}
152
153
/*
154
* Getters.
155
*/
156
157
unsigned int
158
iolog_get_maxseq(void)
159
{
160
return sessid_max;
161
}
162
163
uid_t
164
iolog_get_uid(void)
165
{
166
return iolog_uid;
167
}
168
169
gid_t
170
iolog_get_gid(void)
171
{
172
return iolog_gid;
173
}
174
175
mode_t
176
iolog_get_file_mode(void)
177
{
178
return iolog_filemode;
179
}
180
181
mode_t
182
iolog_get_dir_mode(void)
183
{
184
return iolog_dirmode;
185
}
186
187
bool
188
iolog_get_compress(void)
189
{
190
return iolog_docompress;
191
}
192
193
bool
194
iolog_get_flush(void)
195
{
196
return iolog_doflush;
197
}
198
199