Page Menu
Home
FreeBSD
Search
Configure Global Search
Log In
Files
F109244393
D7998.diff
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Mute Notifications
Flag For Later
Award Token
Size
2 KB
Referenced Files
None
Subscribers
None
D7998.diff
View Options
Index: lib/libc/gen/getutxent.c
===================================================================
--- lib/libc/gen/getutxent.c
+++ lib/libc/gen/getutxent.c
@@ -28,10 +28,12 @@
__FBSDID("$FreeBSD$");
#include "namespace.h"
+#include <sys/capsicum.h>
#include <sys/endian.h>
#include <sys/param.h>
#include <sys/stat.h>
#include <errno.h>
+#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <utmpx.h>
@@ -41,15 +43,48 @@
#ifdef __NO_TLS
static FILE *uf = NULL;
static int udb;
+static int varlog_fd = -1;
+static int varrun_fd = -1;
#else
static _Thread_local FILE *uf = NULL;
static _Thread_local int udb;
+static _Thread_local int varlog_fd = -1;
+static _Thread_local int varrun_fd = -1;
#endif
+static int
+cache_directory_fds(void)
+{
+ cap_rights_t rights;
+
+ if (varlog_fd < 0) {
+ varlog_fd = _open("/var/log", O_RDONLY);
+ if (varlog_fd < 0)
+ return (-1);
+ cap_rights_init(&rights, CAP_FCNTL, CAP_FSTAT, CAP_IOCTL,
+ CAP_LOOKUP, CAP_READ);
+ if (cap_rights_limit(varlog_fd, &rights) < 0 &&
+ errno != ENOSYS)
+ return (-1);
+ }
+ if (varrun_fd < 0) {
+ varrun_fd = _open("/var/run", O_RDONLY);
+ if (varrun_fd < 0)
+ return (-1);
+ cap_rights_init(&rights, CAP_FCNTL, CAP_FSTAT, CAP_IOCTL,
+ CAP_LOOKUP, CAP_READ);
+ if (cap_rights_limit(varrun_fd, &rights) < 0 &&
+ errno != ENOSYS)
+ return (-1);
+ }
+ return (0);
+}
+
int
setutxdb(int db, const char *file)
{
struct stat sb;
+ int fd, dirfd;
switch (db) {
case UTXDB_ACTIVE:
@@ -69,9 +104,27 @@
return (-1);
}
+ if (cache_directory_fds() < 0)
+ return (-1);
+
if (uf != NULL)
fclose(uf);
- uf = fopen(file, "re");
+
+ if (strncmp(file, "/var/log/", 9) == 0)
+ dirfd = varlog_fd;
+ else if (strncmp(file, "/var/run/", 9) == 0)
+ dirfd = varrun_fd;
+ else
+ dirfd = AT_FDCWD;
+
+ if (dirfd != AT_FDCWD)
+ fd = _openat(dirfd, &file[9], O_RDONLY | O_CLOEXEC);
+ else
+ fd = _openat(dirfd, file, O_RDONLY | O_CLOEXEC);
+ if (fd < 0)
+ return (-1);
+
+ uf = fdopen(fd, "re");
if (uf == NULL)
return (-1);
File Metadata
Details
Attached
Mime Type
text/plain
Expires
Mon, Feb 3, 1:17 PM (21 h, 21 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
16417287
Default Alt Text
D7998.diff (2 KB)
Attached To
Mode
D7998: getutxent: Cache directories for use with Capsicum
Attached
Detach File
Event Timeline
Log In to Comment