dumpon.c (82725ba9bf1fd59746a4006a06f24d4d61d142f2) dumpon.c (6026dcd7ca888f3433f4df34ede69a77c1eb7701)
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 59 unchanged lines hidden (view full) ---

68#endif
69
70static int verbose;
71
72static void
73usage(void)
74{
75 fprintf(stderr, "%s\n%s\n%s\n",
1/*-
2 * SPDX-License-Identifier: BSD-3-Clause
3 *
4 * Copyright (c) 1980, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions

--- 59 unchanged lines hidden (view full) ---

68#endif
69
70static int verbose;
71
72static void
73usage(void)
74{
75 fprintf(stderr, "%s\n%s\n%s\n",
76 "usage: dumpon [-v] [-k public_key_file] [-z] special_file",
76 "usage: dumpon [-v] [-k public_key_file] [-Zz] special_file",
77 " dumpon [-v] off",
78 " dumpon [-v] -l");
79 exit(EX_USAGE);
80}
81
82static void
83check_size(int fd, const char *fn)
84{

--- 102 unchanged lines hidden (view full) ---

187int
188main(int argc, char *argv[])
189{
190 struct diocskerneldump_arg kda;
191 const char *pubkeyfile;
192 int ch;
193 int i, fd;
194 int do_listdumpdev = 0;
77 " dumpon [-v] off",
78 " dumpon [-v] -l");
79 exit(EX_USAGE);
80}
81
82static void
83check_size(int fd, const char *fn)
84{

--- 102 unchanged lines hidden (view full) ---

187int
188main(int argc, char *argv[])
189{
190 struct diocskerneldump_arg kda;
191 const char *pubkeyfile;
192 int ch;
193 int i, fd;
194 int do_listdumpdev = 0;
195 bool enable, gzip;
195 bool enable, gzip, zstd;
196
196
197 gzip = false;
197 gzip = zstd = false;
198 pubkeyfile = NULL;
199
198 pubkeyfile = NULL;
199
200 while ((ch = getopt(argc, argv, "k:lvz")) != -1)
200 while ((ch = getopt(argc, argv, "k:lvZz")) != -1)
201 switch((char)ch) {
202 case 'k':
203 pubkeyfile = optarg;
204 break;
205 case 'l':
206 do_listdumpdev = 1;
207 break;
208 case 'v':
209 verbose = 1;
210 break;
201 switch((char)ch) {
202 case 'k':
203 pubkeyfile = optarg;
204 break;
205 case 'l':
206 do_listdumpdev = 1;
207 break;
208 case 'v':
209 verbose = 1;
210 break;
211 case 'Z':
212 zstd = true;
213 break;
211 case 'z':
212 gzip = true;
213 break;
214 default:
215 usage();
216 }
217
214 case 'z':
215 gzip = true;
216 break;
217 default:
218 usage();
219 }
220
221 if (gzip && zstd)
222 errx(EX_USAGE, "The -z and -Z options are mutually exclusive.");
223
218 argc -= optind;
219 argv += optind;
220
221 if (do_listdumpdev) {
222 listdumpdev();
223 exit(EX_OK);
224 }
225

--- 23 unchanged lines hidden (view full) ---

249 err(EX_DATAERR, "%s", argv[0]);
250 }
251 dumpdev = tmp;
252 }
253 fd = open(dumpdev, O_RDONLY);
254 if (fd < 0)
255 err(EX_OSFILE, "%s", dumpdev);
256
224 argc -= optind;
225 argv += optind;
226
227 if (do_listdumpdev) {
228 listdumpdev();
229 exit(EX_OK);
230 }
231

--- 23 unchanged lines hidden (view full) ---

255 err(EX_DATAERR, "%s", argv[0]);
256 }
257 dumpdev = tmp;
258 }
259 fd = open(dumpdev, O_RDONLY);
260 if (fd < 0)
261 err(EX_OSFILE, "%s", dumpdev);
262
257 if (!gzip)
263 if (!gzip && !zstd)
258 check_size(fd, dumpdev);
259
260 bzero(&kda, sizeof(kda));
261 kda.kda_enable = 0;
262 i = ioctl(fd, DIOCSKERNELDUMP, &kda);
263 explicit_bzero(&kda, sizeof(kda));
264
265#ifdef HAVE_CRYPTO
266 if (pubkeyfile != NULL)
267 genkey(pubkeyfile, &kda);
268#endif
269
270 kda.kda_enable = 1;
264 check_size(fd, dumpdev);
265
266 bzero(&kda, sizeof(kda));
267 kda.kda_enable = 0;
268 i = ioctl(fd, DIOCSKERNELDUMP, &kda);
269 explicit_bzero(&kda, sizeof(kda));
270
271#ifdef HAVE_CRYPTO
272 if (pubkeyfile != NULL)
273 genkey(pubkeyfile, &kda);
274#endif
275
276 kda.kda_enable = 1;
271 kda.kda_compression = gzip ? KERNELDUMP_COMP_GZIP :
272 KERNELDUMP_COMP_NONE;
277 kda.kda_compression = KERNELDUMP_COMP_NONE;
278 if (zstd)
279 kda.kda_compression = KERNELDUMP_COMP_ZSTD;
280 else if (gzip)
281 kda.kda_compression = KERNELDUMP_COMP_GZIP;
273 i = ioctl(fd, DIOCSKERNELDUMP, &kda);
274 explicit_bzero(kda.kda_encryptedkey, kda.kda_encryptedkeysize);
275 free(kda.kda_encryptedkey);
276 explicit_bzero(&kda, sizeof(kda));
277 if (i == 0 && verbose)
278 printf("kernel dumps on %s\n", dumpdev);
279 } else {
280 fd = open(_PATH_DEVNULL, O_RDONLY);

--- 14 unchanged lines hidden ---
282 i = ioctl(fd, DIOCSKERNELDUMP, &kda);
283 explicit_bzero(kda.kda_encryptedkey, kda.kda_encryptedkeysize);
284 free(kda.kda_encryptedkey);
285 explicit_bzero(&kda, sizeof(kda));
286 if (i == 0 && verbose)
287 printf("kernel dumps on %s\n", dumpdev);
288 } else {
289 fd = open(_PATH_DEVNULL, O_RDONLY);

--- 14 unchanged lines hidden ---