Changeset View
Changeset View
Standalone View
Standalone View
head/sbin/dumpon/dumpon.c
Show First 20 Lines • Show All 65 Lines • ▼ Show 20 Lines | |||||
#endif | #endif | ||||
static int verbose; | static int verbose; | ||||
static void | static void | ||||
usage(void) | usage(void) | ||||
{ | { | ||||
fprintf(stderr, "%s\n%s\n%s\n", | fprintf(stderr, "%s\n%s\n%s\n", | ||||
"usage: dumpon [-v] [-k public_key_file] special_file", | "usage: dumpon [-v] [-k public_key_file] [-z] special_file", | ||||
" dumpon [-v] off", | " dumpon [-v] off", | ||||
" dumpon [-v] -l"); | " dumpon [-v] -l"); | ||||
exit(EX_USAGE); | exit(EX_USAGE); | ||||
} | } | ||||
static void | static void | ||||
check_size(int fd, const char *fn) | check_size(int fd, const char *fn) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 102 Lines • ▼ Show 20 Lines | |||||
int | int | ||||
main(int argc, char *argv[]) | main(int argc, char *argv[]) | ||||
{ | { | ||||
struct diocskerneldump_arg kda; | struct diocskerneldump_arg kda; | ||||
const char *pubkeyfile; | const char *pubkeyfile; | ||||
int ch; | int ch; | ||||
int i, fd; | int i, fd; | ||||
int do_listdumpdev = 0; | int do_listdumpdev = 0; | ||||
bool enable; | bool enable, gzip; | ||||
gzip = false; | |||||
pubkeyfile = NULL; | pubkeyfile = NULL; | ||||
while ((ch = getopt(argc, argv, "k:lv")) != -1) | while ((ch = getopt(argc, argv, "k:lvz")) != -1) | ||||
switch((char)ch) { | switch((char)ch) { | ||||
case 'k': | case 'k': | ||||
pubkeyfile = optarg; | pubkeyfile = optarg; | ||||
break; | break; | ||||
case 'l': | case 'l': | ||||
do_listdumpdev = 1; | do_listdumpdev = 1; | ||||
break; | break; | ||||
case 'v': | case 'v': | ||||
verbose = 1; | verbose = 1; | ||||
break; | break; | ||||
case 'z': | |||||
gzip = true; | |||||
break; | |||||
default: | default: | ||||
usage(); | usage(); | ||||
} | } | ||||
argc -= optind; | argc -= optind; | ||||
argv += optind; | argv += optind; | ||||
if (do_listdumpdev) { | if (do_listdumpdev) { | ||||
Show All 26 Lines | if (strncmp(argv[0], _PATH_DEV, sizeof(_PATH_DEV) - 1) == 0) { | ||||
errno = EINVAL; | errno = EINVAL; | ||||
err(EX_DATAERR, "%s", argv[0]); | err(EX_DATAERR, "%s", argv[0]); | ||||
} | } | ||||
dumpdev = tmp; | dumpdev = tmp; | ||||
} | } | ||||
fd = open(dumpdev, O_RDONLY); | fd = open(dumpdev, O_RDONLY); | ||||
if (fd < 0) | if (fd < 0) | ||||
err(EX_OSFILE, "%s", dumpdev); | err(EX_OSFILE, "%s", dumpdev); | ||||
if (!gzip) | |||||
check_size(fd, dumpdev); | check_size(fd, dumpdev); | ||||
bzero(&kda, sizeof(kda)); | |||||
bzero(&kda, sizeof(kda)); | |||||
kda.kda_enable = 0; | kda.kda_enable = 0; | ||||
i = ioctl(fd, DIOCSKERNELDUMP, &kda); | i = ioctl(fd, DIOCSKERNELDUMP, &kda); | ||||
explicit_bzero(&kda, sizeof(kda)); | explicit_bzero(&kda, sizeof(kda)); | ||||
#ifdef HAVE_CRYPTO | #ifdef HAVE_CRYPTO | ||||
if (pubkeyfile != NULL) | if (pubkeyfile != NULL) | ||||
genkey(pubkeyfile, &kda); | genkey(pubkeyfile, &kda); | ||||
#endif | #endif | ||||
kda.kda_enable = 1; | kda.kda_enable = 1; | ||||
kda.kda_compression = gzip ? KERNELDUMP_COMP_GZIP : | |||||
KERNELDUMP_COMP_NONE; | |||||
i = ioctl(fd, DIOCSKERNELDUMP, &kda); | i = ioctl(fd, DIOCSKERNELDUMP, &kda); | ||||
explicit_bzero(kda.kda_encryptedkey, kda.kda_encryptedkeysize); | explicit_bzero(kda.kda_encryptedkey, kda.kda_encryptedkeysize); | ||||
free(kda.kda_encryptedkey); | free(kda.kda_encryptedkey); | ||||
explicit_bzero(&kda, sizeof(kda)); | explicit_bzero(&kda, sizeof(kda)); | ||||
if (i == 0 && verbose) | if (i == 0 && verbose) | ||||
printf("kernel dumps on %s\n", dumpdev); | printf("kernel dumps on %s\n", dumpdev); | ||||
} else { | } else { | ||||
fd = open(_PATH_DEVNULL, O_RDONLY); | fd = open(_PATH_DEVNULL, O_RDONLY); | ||||
Show All 14 Lines |