diff options
Diffstat (limited to 'util/libreboot-utils/nvmutil.c')
| -rw-r--r-- | util/libreboot-utils/nvmutil.c | 101 |
1 files changed, 31 insertions, 70 deletions
diff --git a/util/libreboot-utils/nvmutil.c b/util/libreboot-utils/nvmutil.c index 0eed440c..bab1945d 100644 --- a/util/libreboot-utils/nvmutil.c +++ b/util/libreboot-utils/nvmutil.c @@ -6,70 +6,50 @@ * These images configure your Intel Gigabit Ethernet adapter. */ -#ifdef __OpenBSD__ -/* for pledge/unveil test: - */ -#include <sys/param.h> -#endif - #include <sys/types.h> #include <sys/stat.h> #include <errno.h> #include <fcntl.h> #include <limits.h> +#include <stdarg.h> #include <stddef.h> #include <stdio.h> #include <stdlib.h> #include <string.h> +#include <unistd.h> #include "include/common.h" +static void +exit_cleanup(void); + int main(int argc, char *argv[]) { struct xstate *x; - struct commands *cmd; struct xfile *f; - size_t c; + (void) errhook(exit_cleanup); + if (lbgetprogname(argv[0]) == NULL) - err_no_cleanup(0, errno, "could not set progname"); - -/* https://man.openbsd.org/pledge.2 - https://man.openbsd.org/unveil.2 */ -#if defined(__OpenBSD__) && defined(OpenBSD) -#if (OpenBSD) >= 604 - if (pledge("stdio flock rpath wpath cpath unveil", NULL) == -1) - err_no_cleanup(0, errno, "pledge plus unveil, main"); -#if defined(USE_URANDOM) && \ - ((USE_URANDOM) > 0) - if (unveil("/dev/null", "r") == -1) - err_no_cleanup(0, errno, "unveil r: /dev/null"); -#else - if (unveil("/dev/urandom", "r") == -1) - err_no_cleanup(0, errno, "unveil r: /dev/urandom"); -#endif -#elif (OpenBSD) >= 509 - if (pledge("stdio flock rpath wpath cpath", NULL) == -1) - err_no_cleanup(0, errno, "pledge, main"); -#endif -#endif + err_exit(errno, "could not set progname"); + + xpledgex("stdio flock rpath wpath cpath unveil", NULL); + xunveilx("/dev/urandom", "r"); #ifndef S_ISREG - err_no_cleanup(0, ECANCELED, + err_exit(ECANCELED, "Can't determine file types (S_ISREG undefined)"); #endif #if ((CHAR_BIT) != 8) - err_no_cleanup(0, ECANCELED, "Unsupported char size"); + err_exit(ECANCELED, "Unsupported char size"); #endif - x = xstart(argc, argv); - - if (x == NULL) - err_no_cleanup(0, ECANCELED, "NULL state on init"); + if ((x = xstart(argc, argv)) == NULL) + err_exit(ECANCELED, "NULL state on init"); /* parse user command */ /* TODO: CHECK ACCESSES VIA xstatus() */ @@ -79,45 +59,22 @@ main(int argc, char *argv[]) cmd = &x->cmd[x->i]; f = &x->f; -/* https://man.openbsd.org/pledge.2 - https://man.openbsd.org/unveil.2 */ -#if defined(__OpenBSD__) && defined(OpenBSD) -#if (OpenBSD) >= 604 - - if ((us.cmd[i].flags & O_ACCMODE) == O_RDONLY) { - if (unveil(us.f.fname, "r") == -1) - b0rk(errno, "%s: unveil r", us.f.fname); - } else { - if (unveil(us.f.fname, "rwc") == -1) - b0rk(errno, "%s: unveil rw", us.f.fname); - } + if ((cmd->flags & O_ACCMODE) == O_RDONLY) + xunveilx(f->fname, "r"); + else + xunveilx(f->fname, "rwc"); - if (unveil(us.f.tname, "rwc") == -1) - b0rk(errno, "unveil rwc: %s", us.f.tname); - - if (unveil(NULL, NULL) == -1) - b0rk(errno, "unveil block (rw)"); - - if (pledge("stdio flock rpath wpath cpath", NULL) == -1) - b0rk(errno, "pledge (kill unveil)"); - -#elif (OpenBSD) >= 509 - if (pledge("stdio flock rpath wpath cpath", NULL) == -1) - b0rk(errno, "pledge"); -#endif -#endif + xunveilx(f->tname, "rwc"); + xunveilx(NULL, NULL); + xpledgex("stdio flock rpath wpath cpath", NULL); if (cmd->run == NULL) - b0rk(errno, "Command not set"); - + err_exit(errno, "Command not set"); sanitize_command_list(); - open_gbe_file(); - copy_gbe(); read_checksums(); - cmd->run(); for (c = 0; c < items(x->cmd); c++) @@ -126,13 +83,17 @@ main(int argc, char *argv[]) if ((cmd->flags & O_ACCMODE) == O_RDWR) write_to_gbe_bin(); - if (exit_cleanup() == -1) - b0rk(EIO, "%s: close", f->fname); - + exit_cleanup(); if (f->io_err_gbe_bin) - b0rk(EIO, "%s: error writing final file"); + err_exit(EIO, "%s: error writing final file"); free_and_set_null(&f->tname); return EXIT_SUCCESS; } + +static void +exit_cleanup(void) +{ + return; +} |
