|
31 | 31 | #include <unistd.h> |
32 | 32 | #include <stdlib.h> |
33 | 33 | #include <libgen.h> |
| 34 | +#include <linux/limits.h> |
34 | 35 | #include "audispd-pconfig.h" |
35 | 36 | #include "private.h" |
36 | 37 |
|
@@ -143,12 +144,10 @@ int load_pconfig(plugin_conf_t *config, int dirfd, char *file) |
143 | 144 |
|
144 | 145 | clear_pconfig(config); |
145 | 146 |
|
146 | | - /* O_NONBLOCK avoids blocking when opening a FIFO file accidentially. |
147 | | - * It does however block if someone symlinks /dev/ttyX into the plugin directory. |
| 147 | + /* O_PATH avoids blocking, as no read/seek is done. |
148 | 148 | * We do not pass O_NOFOLLOW, which allows for symlinked configs. |
149 | 149 | */ |
150 | | - mode = O_RDONLY | O_NONBLOCK; |
151 | | - rc = openat(dirfd, file, mode); |
| 150 | + rc = openat(dirfd, file, O_PATH); |
152 | 151 | if (rc < 0) { |
153 | 152 | if (errno != ENOENT) { |
154 | 153 | audit_msg(LOG_ERR, "Error opening %s (%s)", file, |
@@ -190,13 +189,22 @@ int load_pconfig(plugin_conf_t *config, int dirfd, char *file) |
190 | 189 | return 1; |
191 | 190 | } |
192 | 191 |
|
193 | | - if (fcntl(fd, F_SETFL, mode & (~O_NONBLOCK)) < 0) { |
194 | | - audit_msg(LOG_ERR, "Error - Failed to remove nonblock flag for %s", |
| 192 | + // reopen with read perms |
| 193 | + char fname[PATH_MAX]; |
| 194 | + snprintf(fname, PATH_MAX, "/proc/self/fd/%i", fd); |
| 195 | + mode = O_RDONLY; |
| 196 | + rc = open(fname, mode); |
| 197 | + |
| 198 | + if (rc < 0) { |
| 199 | + audit_msg(LOG_ERR, "Error - Failed to reopen %s for reading", |
195 | 200 | file); |
196 | 201 | close(fd); |
197 | 202 | return 1; |
198 | 203 | } |
199 | 204 |
|
| 205 | + close(fd); |
| 206 | + fd = rc; |
| 207 | + |
200 | 208 | /* it's ok, read line by line */ |
201 | 209 | f = fdopen(fd, "rm"); |
202 | 210 | if (f == NULL) { |
|
0 commit comments