/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 | 0 | { |
52 | 0 | sessid_max = SESSID_MAX; |
53 | 0 | iolog_filemode = S_IRUSR|S_IWUSR; |
54 | 0 | iolog_dirmode = S_IRWXU; |
55 | 0 | iolog_uid = ROOT_UID; |
56 | 0 | iolog_gid = ROOT_GID; |
57 | 0 | iolog_gid_set = false; |
58 | 0 | iolog_docompress = false; |
59 | 0 | iolog_doflush = false; |
60 | 0 | } |
61 | | |
62 | | /* |
63 | | * Set max sequence number (aka session ID) |
64 | | */ |
65 | | void |
66 | | iolog_set_maxseq(unsigned int newval) |
67 | 0 | { |
68 | 0 | debug_decl(iolog_set_maxseq, SUDO_DEBUG_UTIL); |
69 | | |
70 | | /* Clamp to SESSID_MAX as documented. */ |
71 | 0 | if (newval > SESSID_MAX) |
72 | 0 | newval = SESSID_MAX; |
73 | 0 | sessid_max = newval; |
74 | |
|
75 | 0 | debug_return; |
76 | 0 | } |
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 | 0 | { |
84 | 0 | debug_decl(iolog_set_owner, SUDO_DEBUG_UTIL); |
85 | |
|
86 | 0 | iolog_uid = uid; |
87 | 0 | if (!iolog_gid_set) |
88 | 0 | iolog_gid = gid; |
89 | |
|
90 | 0 | debug_return; |
91 | 0 | } |
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 | 0 | { |
113 | 0 | debug_decl(iolog_set_mode, SUDO_DEBUG_UTIL); |
114 | | |
115 | | /* I/O log files must be readable and writable by owner. */ |
116 | 0 | iolog_filemode = S_IRUSR|S_IWUSR; |
117 | | |
118 | | /* Add in group and other read/write if specified. */ |
119 | 0 | iolog_filemode |= mode & (S_IRGRP|S_IWGRP|S_IROTH|S_IWOTH); |
120 | | |
121 | | /* For directory mode, add execute bits as needed. */ |
122 | 0 | iolog_dirmode = iolog_filemode | S_IXUSR; |
123 | 0 | if (iolog_dirmode & (S_IRGRP|S_IWGRP)) |
124 | 0 | iolog_dirmode |= S_IXGRP; |
125 | 0 | if (iolog_dirmode & (S_IROTH|S_IWOTH)) |
126 | 0 | iolog_dirmode |= S_IXOTH; |
127 | |
|
128 | 0 | debug_return; |
129 | 0 | } |
130 | | |
131 | | /* |
132 | | * Set iolog_docompress |
133 | | */ |
134 | | void |
135 | | iolog_set_compress(bool newval) |
136 | 0 | { |
137 | 0 | debug_decl(iolog_set_compress, SUDO_DEBUG_UTIL); |
138 | 0 | iolog_docompress = newval; |
139 | 0 | debug_return; |
140 | 0 | } |
141 | | |
142 | | /* |
143 | | * Set iolog_doflush |
144 | | */ |
145 | | void |
146 | | iolog_set_flush(bool newval) |
147 | 0 | { |
148 | 0 | debug_decl(iolog_set_flush, SUDO_DEBUG_UTIL); |
149 | 0 | iolog_doflush = newval; |
150 | 0 | debug_return; |
151 | 0 | } |
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 | 825 | { |
166 | 825 | return iolog_uid; |
167 | 825 | } |
168 | | |
169 | | gid_t |
170 | | iolog_get_gid(void) |
171 | 825 | { |
172 | 825 | return iolog_gid; |
173 | 825 | } |
174 | | |
175 | | mode_t |
176 | | iolog_get_file_mode(void) |
177 | 825 | { |
178 | 825 | return iolog_filemode; |
179 | 825 | } |
180 | | |
181 | | mode_t |
182 | | iolog_get_dir_mode(void) |
183 | 825 | { |
184 | 825 | return iolog_dirmode; |
185 | 825 | } |
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 | } |