Coverage Report

Created: 2026-12-01 07:07

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/sudo/lib/iolog/iolog_conf.c
Line
Count
Source
1
/*
2
 * SPDX-License-Identifier: ISC
3
 *
4
 * Copyright (c) 2009-2021 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
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
773
{
52
773
    sessid_max = SESSID_MAX;
53
773
    iolog_filemode = S_IRUSR|S_IWUSR;
54
773
    iolog_dirmode = S_IRWXU;
55
773
    iolog_uid = ROOT_UID;
56
773
    iolog_gid = ROOT_GID;
57
773
    iolog_gid_set = false;
58
773
    iolog_docompress = false;
59
773
    iolog_doflush = false;
60
773
}
61
62
/*
63
 * Set max sequence number (aka session ID)
64
 */
65
void
66
iolog_set_maxseq(unsigned int newval)
67
773
{
68
773
    debug_decl(iolog_set_maxseq, SUDO_DEBUG_UTIL);
69
70
    /* Clamp to SESSID_MAX as documented. */
71
773
    if (newval > SESSID_MAX)
72
0
  newval = SESSID_MAX;
73
773
    sessid_max = newval;
74
75
773
    debug_return;
76
773
}
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
773
{
84
773
    debug_decl(iolog_set_owner, SUDO_DEBUG_UTIL);
85
86
773
    iolog_uid = uid;
87
773
    if (!iolog_gid_set)
88
773
  iolog_gid = gid;
89
90
773
    debug_return;
91
773
}
92
93
/*
94
 * Set iolog_gid.
95
 */
96
void
97
iolog_set_gid(gid_t gid)
98
0
{
99
0
    debug_decl(iolog_set_gid, SUDO_DEBUG_UTIL);
100
101
0
    iolog_gid = gid;
102
0
    iolog_gid_set = true;
103
104
0
    debug_return;
105
0
}
106
107
/*
108
 * Set iolog_filemode and iolog_dirmode.
109
 */
110
void
111
iolog_set_mode(mode_t mode)
112
773
{
113
773
    debug_decl(iolog_set_mode, SUDO_DEBUG_UTIL);
114
115
    /* I/O log files must be readable and writable by owner. */
116
773
    iolog_filemode = S_IRUSR|S_IWUSR;
117
118
    /* Add in group and other read/write if specified. */
119
773
    iolog_filemode |= mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH);
120
121
    /* For directory mode, add execute bits as needed. */
122
773
    iolog_dirmode = iolog_filemode | S_IXUSR;
123
773
    if (iolog_dirmode & (S_IRGRP|S_IWGRP))
124
2
  iolog_dirmode |= S_IXGRP;
125
773
    if (iolog_dirmode & (S_IROTH|S_IWOTH))
126
3
  iolog_dirmode |= S_IXOTH;
127
128
773
    debug_return;
129
773
}
130
131
/*
132
 * Set iolog_docompress
133
 */
134
void
135
iolog_set_compress(bool newval)
136
773
{
137
773
    debug_decl(iolog_set_compress, SUDO_DEBUG_UTIL);
138
773
    iolog_docompress = newval;
139
773
    debug_return;
140
773
}
141
142
/*
143
 * Set iolog_doflush
144
 */
145
void
146
iolog_set_flush(bool newval)
147
773
{
148
773
    debug_decl(iolog_set_flush, SUDO_DEBUG_UTIL);
149
773
    iolog_doflush = newval;
150
773
    debug_return;
151
773
}
152
153
/*
154
 * Getters.
155
 */
156
157
unsigned int
158
iolog_get_maxseq(void)
159
0
{
160
0
    return sessid_max;
161
0
}
162
163
uid_t
164
iolog_get_uid(void)
165
1.17k
{
166
1.17k
    return iolog_uid;
167
1.17k
}
168
169
gid_t
170
iolog_get_gid(void)
171
1.17k
{
172
1.17k
    return iolog_gid;
173
1.17k
}
174
175
mode_t
176
iolog_get_file_mode(void)
177
1.17k
{
178
1.17k
    return iolog_filemode;
179
1.17k
}
180
181
mode_t
182
iolog_get_dir_mode(void)
183
1.17k
{
184
1.17k
    return iolog_dirmode;
185
1.17k
}
186
187
bool
188
iolog_get_compress(void)
189
0
{
190
0
    return iolog_docompress;
191
0
}
192
193
bool
194
iolog_get_flush(void)
195
0
{
196
0
    return iolog_doflush;
197
0
}