mirror of
https://git.freebsd.org/src.git
synced 2026-01-11 19:57:22 +00:00
lsvfs(1): Capsicumise
Signed-off-by: Faraz Vahedi <kfv@kfv.io> Reviewed by: asomers, markj Pull Request: https://github.com/freebsd/freebsd-src/pull/1498
This commit is contained in:
parent
09f925b57a
commit
a0c709ab5a
1 changed files with 26 additions and 23 deletions
|
|
@ -5,10 +5,12 @@
|
|||
*
|
||||
*/
|
||||
|
||||
#include <sys/capsicum.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <sys/sysctl.h>
|
||||
|
||||
#include <capsicum_helpers.h>
|
||||
#include <err.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -38,41 +40,42 @@ static const char *fmt_flags(int);
|
|||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
struct xvfsconf vfc, *xvfsp;
|
||||
struct xvfsconf *xvfsp;
|
||||
size_t cnt, buflen;
|
||||
int rv = 0;
|
||||
|
||||
argc--, argv++;
|
||||
|
||||
if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
|
||||
err(EXIT_FAILURE, "sysctl(vfs.conflist)");
|
||||
if ((xvfsp = malloc(buflen)) == NULL)
|
||||
errx(EXIT_FAILURE, "malloc failed");
|
||||
if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0)
|
||||
err(EXIT_FAILURE, "sysctl(vfs.conflist)");
|
||||
cnt = buflen / sizeof(struct xvfsconf);
|
||||
|
||||
caph_cache_catpages();
|
||||
if (caph_enter() != 0)
|
||||
err(EXIT_FAILURE, "failed to enter capability mode");
|
||||
|
||||
printf(HDRFMT, "Filesystem", "Num", "Refs", "Flags");
|
||||
fputs(DASHES, stdout);
|
||||
|
||||
if (argc > 0) {
|
||||
for (; argc > 0; argc--, argv++) {
|
||||
if (getvfsbyname(*argv, &vfc) == 0) {
|
||||
printf(FMT, vfc.vfc_name, vfc.vfc_typenum,
|
||||
vfc.vfc_refcount, fmt_flags(vfc.vfc_flags));
|
||||
} else {
|
||||
warnx("VFS %s unknown or not loaded", *argv);
|
||||
rv++;
|
||||
for (size_t i = 0; i < cnt; i++) {
|
||||
if (argc > 0) {
|
||||
int j;
|
||||
for (j = 0; j < argc; j++) {
|
||||
if (strcmp(argv[j], xvfsp[i].vfc_name) == 0)
|
||||
break;
|
||||
}
|
||||
if (j == argc)
|
||||
continue;
|
||||
}
|
||||
} else {
|
||||
if (sysctlbyname("vfs.conflist", NULL, &buflen, NULL, 0) < 0)
|
||||
err(EXIT_FAILURE, "sysctl(vfs.conflist)");
|
||||
if ((xvfsp = malloc(buflen)) == NULL)
|
||||
errx(EXIT_FAILURE, "malloc failed");
|
||||
if (sysctlbyname("vfs.conflist", xvfsp, &buflen, NULL, 0) < 0)
|
||||
err(EXIT_FAILURE, "sysctl(vfs.conflist)");
|
||||
cnt = buflen / sizeof(struct xvfsconf);
|
||||
|
||||
for (size_t i = 0; i < cnt; i++) {
|
||||
printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_typenum,
|
||||
xvfsp[i].vfc_refcount,
|
||||
fmt_flags(xvfsp[i].vfc_flags));
|
||||
}
|
||||
free(xvfsp);
|
||||
printf(FMT, xvfsp[i].vfc_name, xvfsp[i].vfc_typenum,
|
||||
xvfsp[i].vfc_refcount, fmt_flags(xvfsp[i].vfc_flags));
|
||||
}
|
||||
free(xvfsp);
|
||||
|
||||
return (rv);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue