-/* $OpenBSD: fsck.c,v 1.38 2015/11/23 19:19:29 deraadt Exp $ */
+/* $OpenBSD: fsck.c,v 1.39 2018/09/24 21:26:00 deraadt Exp $ */
/* $NetBSD: fsck.c,v 1.7 1996/10/03 20:06:30 christos Exp $ */
/*
#include <sys/mount.h>
#include <sys/queue.h>
#include <sys/resource.h>
+#include <sys/stat.h>
#include <sys/wait.h>
#include <err.h>
} else
warn("Can't get resource limit for data size");
+ checkroot();
+
+ if (unveil("/dev", "rw") == -1)
+ err(1, "unveil");
+ if (unveil(_PATH_FSTAB, "r") == -1)
+ err(1, "unveil");
+ if (unveil("/sbin", "x") == -1)
+ err(1, "unveil");
if (pledge("stdio rpath wpath disklabel proc exec", NULL) == -1)
err(1, "pledge");
-/* $OpenBSD: fsutil.c,v 1.22 2015/09/27 05:25:00 guenther Exp $ */
+/* $OpenBSD: fsutil.c,v 1.23 2018/09/24 21:26:00 deraadt Exp $ */
/* $NetBSD: fsutil.c,v 1.2 1996/10/03 20:06:31 christos Exp $ */
/*
static void vmsg(int, const char *, va_list);
+struct stat stslash;
+
+void
+checkroot(void)
+{
+ if (stat("/", &stslash) < 0) {
+ xperror("/");
+ printf("Can't stat root\n");
+ }
+}
+
void
setcdevname(const char *cd, const char *ocd, int pr)
{
char *
blockcheck(char *origname)
{
- struct stat stslash, stblock, stchar;
+ struct stat stblock, stchar;
char *newname, *raw;
struct fstab *fsp;
int retried = 0;
hot = 0;
- if (stat("/", &stslash) < 0) {
- xperror("/");
- printf("Can't stat root\n");
- return (origname);
- }
newname = origname;
retry:
if (stat(newname, &stblock) < 0)
-/* $OpenBSD: fsutil.h,v 1.7 2014/10/08 16:27:53 deraadt Exp $ */
+/* $OpenBSD: fsutil.h,v 1.8 2018/09/24 21:26:00 deraadt Exp $ */
/* $NetBSD: fsutil.h,v 1.3 1996/10/03 20:06:31 christos Exp $ */
/*
__attribute__((__noreturn__,__format__(__printf__,1,2)));
char *rawname(char *);
char *unrawname(char *);
+void checkroot(void);
char *blockcheck(char *);
const char *cdevname(void);
void setcdevname(const char *, const char *, int);
-/* $OpenBSD: main.c,v 1.27 2016/03/16 15:41:10 krw Exp $ */
+/* $OpenBSD: main.c,v 1.28 2018/09/24 21:26:02 deraadt Exp $ */
/* $NetBSD: main.c,v 1.1 1997/06/11 11:21:50 bouyer Exp $ */
/*
int ch;
int ret = 0;
+ checkroot();
+
sync();
skipclean = 1;
while ((ch = getopt(argc, argv, "b:dfm:npy")) != -1) {
-/* $OpenBSD: main.c,v 1.51 2018/01/05 09:33:47 otto Exp $ */
+/* $OpenBSD: main.c,v 1.52 2018/09/24 21:26:02 deraadt Exp $ */
/* $NetBSD: main.c,v 1.22 1996/10/11 20:15:48 thorpej Exp $ */
/*
int ch;
int ret = 0;
+ checkroot();
+
sync();
skipclean = 1;
while ((ch = getopt(argc, argv, "dfpnNyYb:c:m:")) != -1) {
-/* $OpenBSD: setup.c,v 1.64 2018/01/05 09:33:47 otto Exp $ */
+/* $OpenBSD: setup.c,v 1.65 2018/09/24 21:26:02 deraadt Exp $ */
/* $NetBSD: setup.c,v 1.27 1996/09/27 22:45:19 christos Exp $ */
/*
strlcpy(rdevname, realdev, sizeof(rdevname));
setcdevname(rdevname, dev, preen);
- if (isfsdb || !hotroot())
+ if (isfsdb || !hotroot()) {
+ if (unveil("/dev", "rw") == -1)
+ err(1, "unveil");
if (pledge("stdio rpath wpath getpw tty disklabel",
NULL) == -1)
err(1, "pledge");
+ }
}
+
if (fstat(fsreadfd, &statb) < 0) {
printf("Can't stat %s: %s\n", realdev, strerror(errno));
close(fsreadfd);
-/* $OpenBSD: check.c,v 1.18 2015/10/14 16:58:55 deraadt Exp $ */
+/* $OpenBSD: check.c,v 1.19 2018/09/24 21:26:02 deraadt Exp $ */
/* $NetBSD: check.c,v 1.8 1997/10/17 11:19:29 ws Exp $ */
/*
int i;
int mod = 0;
+ if (unveil("/dev", "rw") == -1)
+ err(1, "unveil");
+
rdonly = alwaysno;
dosfs = opendev(fname, rdonly ? O_RDONLY : O_RDWR, 0, &realdev);
-/* $OpenBSD: main.c,v 1.23 2016/05/28 18:00:42 tb Exp $ */
+/* $OpenBSD: main.c,v 1.24 2018/09/24 21:26:02 deraadt Exp $ */
/* $NetBSD: main.c,v 1.8 1996/10/17 20:29:53 cgd Exp $ */
/*
{
int ch;
+ checkroot();
+
while ((ch = getopt(argc, argv, "pynf")) != -1) {
switch (ch) {
case 'f':