Changeset View
Changeset View
Standalone View
Standalone View
sbin/fsck_msdosfs/main.c
Show All 33 Lines | |||||
#endif /* not lint */ | #endif /* not lint */ | ||||
#include <stdlib.h> | #include <stdlib.h> | ||||
#include <string.h> | #include <string.h> | ||||
#include <stdio.h> | #include <stdio.h> | ||||
#include <unistd.h> | #include <unistd.h> | ||||
#include <errno.h> | #include <errno.h> | ||||
#include <stdarg.h> | #include <stdarg.h> | ||||
#include <err.h> | |||||
#ifdef HAVE_CAPSICUM | |||||
#include <libcasper.h> | |||||
#include <casper/cap_fileargs.h> | |||||
#include <capsicum_helpers.h> | |||||
#endif | |||||
#include "fsutil.h" | #include "fsutil.h" | ||||
#include "ext.h" | #include "ext.h" | ||||
int alwaysno; /* assume "no" for all questions */ | int alwaysno; /* assume "no" for all questions */ | ||||
int alwaysyes; /* assume "yes" for all questions */ | int alwaysyes; /* assume "yes" for all questions */ | ||||
int preen; /* set when preening */ | int preen; /* set when preening */ | ||||
int rdonly; /* device is opened read only (supersedes above) */ | int rdonly; /* device is opened read only (supersedes above) */ | ||||
int skipclean; /* skip clean file systems if preening */ | int skipclean; /* skip clean file systems if preening */ | ||||
Show All 9 Lines | fprintf(stderr, "%s\n%s\n", | ||||
"usage: fsck_msdosfs -p [-f] filesystem ...", | "usage: fsck_msdosfs -p [-f] filesystem ...", | ||||
" fsck_msdosfs [-ny] filesystem ..."); | " fsck_msdosfs [-ny] filesystem ..."); | ||||
exit(1); | exit(1); | ||||
} | } | ||||
int | int | ||||
main(int argc, char **argv) | main(int argc, char **argv) | ||||
{ | { | ||||
int dosfs; | |||||
int ret = 0, erg; | int ret = 0, erg; | ||||
int ch; | int ch; | ||||
char *fname; | |||||
#ifdef HAVE_CAPSICUM | |||||
cap_rights_t rights, *rights_init; | |||||
fileargs_t *fa_alwaysno; | |||||
fileargs_t *fa_rdonly; | |||||
#endif | |||||
skipclean = 1; | skipclean = 1; | ||||
allow_mmap = 1; | allow_mmap = 1; | ||||
while ((ch = getopt(argc, argv, "CfFnpyM")) != -1) { | while ((ch = getopt(argc, argv, "CfFnpyM")) != -1) { | ||||
switch (ch) { | switch (ch) { | ||||
case 'C': /* for fsck_ffs compatibility */ | case 'C': /* for fsck_ffs compatibility */ | ||||
break; | break; | ||||
case 'f': | case 'f': | ||||
Show All 32 Lines | while ((ch = getopt(argc, argv, "CfFnpyM")) != -1) { | ||||
} | } | ||||
} | } | ||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
if (!argc) | if (!argc) | ||||
usage(); | usage(); | ||||
#ifdef HAVE_CAPSICUM | |||||
rights_init = cap_rights_init(&rights, CAP_MMAP_RW); | |||||
oshogbo: fileargs_init creates an casper instance, it's not a big deal but we may use fileargs_cinit and… | |||||
fa_alwaysno = fileargs_init(argc, argv, alwaysno ? O_RDONLY : O_RDWR , 0, | |||||
rights_init, FA_OPEN); | |||||
if (fa_alwaysno == NULL) | |||||
err(1, "unable to open first system.fileargs service"); | |||||
fa_rdonly = fileargs_init(argc, argv, O_RDONLY , 0, | |||||
Not Done Inline ActionsI'm not sure I'm getting this cap_right_init part. The ident is broken. oshogbo: I'm not sure I'm getting this cap_right_init part. The ident is broken. | |||||
rights_init, FA_OPEN); | |||||
if (fa_rdonly == NULL) | |||||
err(1, "unable to second open system.fileargs service"); | |||||
/* | |||||
* Here we enter capability mode. Further down access to global | |||||
* namespaces (e.g filesystem) is restricted (see capsicum(4)). | |||||
* We must connect(2) our socket before this point. | |||||
oshogboUnsubmitted Not Done Inline ActionsConnect? oshogbo: Connect? | |||||
*/ | |||||
Not Done Inline Actionscaph_enter_casper? oshogbo: caph_enter_casper? | |||||
if (caph_enter_casper() < 0) { | |||||
err(1, "unable to enter capability mode"); | |||||
} | |||||
#endif | |||||
while (--argc >= 0) { | while (--argc >= 0) { | ||||
setcdevname(*argv, preen); | setcdevname(*argv, preen); | ||||
erg = checkfilesys(*argv++); | fname = *argv++; | ||||
rdonly = alwaysno; | |||||
if (!preen) | |||||
printf("** %s", fname); | |||||
#ifdef HAVE_CAPSICUM | |||||
dosfs = fileargs_open(fa_alwaysno, fname); | |||||
if (dosfs < 0 && !rdonly) { | |||||
dosfs = fileargs_open(fa_rdonly, fname); | |||||
#else | |||||
dosfs = open(fname, rdonly ? O_RDONLY : O_RDWR, 0); | |||||
if (dosfs < 0 && !rdonly) { | |||||
dosfs = open(fname, O_RDONLY, 0); | |||||
#endif | |||||
if (dosfs >= 0) | |||||
pwarn(" (NO WRITE)\n"); | |||||
else if (!preen) | |||||
printf("\n"); | |||||
rdonly = 1; | |||||
} else if (!preen) | |||||
printf("\n"); | |||||
erg = checkfilesys(fname, dosfs); | |||||
if (erg > ret) | if (erg > ret) | ||||
ret = erg; | ret = erg; | ||||
} | } | ||||
#ifdef HAVE_CAPSICUM | |||||
fileargs_free(fa_alwaysno); | |||||
fileargs_free(fa_rdonly); | |||||
#endif | |||||
return ret; | return ret; | ||||
} | } | ||||
/*VARARGS*/ | /*VARARGS*/ | ||||
int | int | ||||
ask(int def, const char *fmt, ...) | ask(int def, const char *fmt, ...) | ||||
Show All 32 Lines |
fileargs_init creates an casper instance, it's not a big deal but we may use fileargs_cinit and create casper only once.