Skip to content

Commit 5137261

Browse files
committed
lsvfs(1): Capsicumise
Signed-off-by: Faraz Vahedi <kfv@kfv.io>
1 parent 52a9423 commit 5137261

File tree

1 file changed

+27
-24
lines changed

1 file changed

+27
-24
lines changed

usr.bin/lsvfs/lsvfs.c

Lines changed: 27 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,12 @@
55
*
66
*/
77

8+
#include <sys/capsicum.h>
89
#include <sys/param.h>
910
#include <sys/mount.h>
1011
#include <sys/sysctl.h>
1112

13+
#include <capsicum_helpers.h>
1214
#include <err.h>
1315
#include <stdio.h>
1416
#include <stdlib.h>
@@ -38,41 +40,42 @@ static const char *fmt_flags(int);
3840
int
3941
main(int argc, char **argv)
4042
{
41-
struct xvfsconf vfc, *xvfsp;
43+
struct xvfsconf *xvfsp;
4244
size_t cnt, buflen;
4345
int rv = 0;
4446

4547
argc--, argv++;
4648

49+
if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
50+
err(EXIT_FAILURE, "sysctl(vfs.conflist)");
51+
if ((xvfsp = malloc(buflen)) == NULL)
52+
errx(EXIT_FAILURE, "malloc failed");
53+
if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0)
54+
err(EXIT_FAILURE, "sysctl(vfs.conflist)");
55+
cnt = buflen / sizeof(struct xvfsconf);
56+
57+
caph_cache_catpages();
58+
if (caph_enter() != 0)
59+
err(EXIT_FAILURE, "failed to enter capability mode");
60+
4761
printf(HDRFMT, "Filesystem", "Num", "Refs", "Flags");
4862
fputs(DASHES, stdout);
4963

50-
if (argc > 0) {
51-
for (; argc > 0; argc--, argv++) {
52-
if (getvfsbyname(*argv, &vfc) == 0) {
53-
printf(FMT, vfc.vfc_name, vfc.vfc_typenum,
54-
vfc.vfc_refcount, fmt_flags(vfc.vfc_flags));
55-
} else {
56-
warnx("VFS %s unknown or not loaded", *argv);
57-
rv++;
64+
for (size_t i = 0; i < cnt; i++) {
65+
if (argc > 0) {
66+
size_t j;
67+
for (j = 0; j < argc; j++) {
68+
if (strcmp(argv[j], xvfsp[i].vfc_name) == 0)
69+
break;
5870
}
71+
if (j == argc)
72+
continue;
5973
}
60-
} else {
61-
if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
62-
err(EXIT_FAILURE, "sysctl(vfs.conflist)");
63-
if ((xvfsp = malloc(buflen)) == NULL)
64-
errx(EXIT_FAILURE, "malloc failed");
65-
if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0)
66-
err(EXIT_FAILURE, "sysctl(vfs.conflist)");
67-
cnt = buflen / sizeof(struct xvfsconf);
68-
69-
for (size_t i = 0; i < cnt; i++) {
70-
printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_typenum,
71-
xvfsp[i].vfc_refcount,
72-
fmt_flags(xvfsp[i].vfc_flags));
73-
}
74-
free(xvfsp);
74+
75+
printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_typenum,
76+
xvfsp[i].vfc_refcount, fmt_flags(xvfsp[i].vfc_flags));
7577
}
78+
free(xvfsp);
7679

7780
return (rv);
7881
}

0 commit comments

Comments
 (0)