diff options
Diffstat (limited to 'util/libreboot-utils/include')
| -rw-r--r-- | util/libreboot-utils/include/common.h | 65 |
1 files changed, 34 insertions, 31 deletions
diff --git a/util/libreboot-utils/include/common.h b/util/libreboot-utils/include/common.h index b26448db..fb3aa886 100644 --- a/util/libreboot-utils/include/common.h +++ b/util/libreboot-utils/include/common.h @@ -13,24 +13,13 @@ #include <sys/types.h> #include <sys/stat.h> #include <limits.h> +#include <errno.h> /* for linux getrandom */ #if defined(__linux__) -#include <errno.h> -#if defined(__has_include) -#if __has_include(<sys/random.h>) #include <sys/random.h> -#define HAVE_GETRANDOM 1 -#endif -#endif -#if !defined(HAVE_GETRANDOM) #include <sys/syscall.h> -#if defined(SYS_getrandom) -#define HAVE_GETRANDOM_SYSCALL 1 -#endif -#endif - #endif #define items(x) (sizeof((x)) / sizeof((x)[0])) @@ -287,6 +276,11 @@ struct xfile { unsigned char bufcmp[GBE_BUF_SIZE]; /* compare gbe/tmp/reads */ unsigned char pad[GBE_WORK_SIZE]; /* the file that wouldn't die */ + + /* we later rename in-place, using old fd. renameat() */ + int dirfd; + char *base; + char *tmpbase; }; /* Command table, MAC address, files @@ -379,24 +373,18 @@ int slen(const char *scmp, size_t maxlen, size_t *rval); int scmp(const char *a, const char *b, size_t maxlen, int *rval); - +int sdup(const char *s, + size_t n, char **dest); +int scat(const char *s1, const char *s2, + size_t n, char **dest); +int dcat(const char *s, size_t n, + size_t off, char **dest1, + char **dest2); /* numerical functions */ unsigned short hextonum(char ch_s); size_t rlong(void); -#if !(defined(FALLBACK_RAND_1989) && \ - ((FALLBACK_RAND_1989) > 0)) -#if defined(__linux__) -#if defined(HAVE_GETRANDOM) || \ - defined(HAVE_GETRANDOM_SYSCALL) -int fallback_rand_getrandom(void *buf, size_t len); -#endif -#endif -#else -size_t fallback_rand_1989(void); -size_t entropy_jitter(void); -#endif /* Helper functions for command: dump */ @@ -489,17 +477,22 @@ int try_err(int loop_err, int errval); */ void usage(void); -void err_no_cleanup(int nvm_errval, const char *msg, ...); -void err(int nvm_errval, const char *msg, ...); +void err_no_cleanup(int stfu, int nvm_errval, const char *msg, ...); +void b0rk(int nvm_errval, const char *msg, ...); int exit_cleanup(void); const char *getnvmprogname(void); +void err_mkhtemp(int stfu, int errval, const char *msg, ...); + /* libc hardening */ -int new_tmpfile(int *fd, char **path); -int new_tmpdir(int *fd, char **path); -int new_tmp_common(int *fd, char **path, int type); +int new_tmpfile(int *fd, char **path, char *tmpdir, + const char *template); +int new_tmpdir(int *fd, char **path, char *tmpdir, + const char *template); +int new_tmp_common(int *fd, char **path, int type, + char *tmpdir, const char *template); int mkhtemp_try_create(int dirfd, struct stat *st_dir_initial, char *fname_copy, @@ -508,6 +501,14 @@ int mkhtemp_try_create(int dirfd, int *fd, struct stat *st, int type); +int +mkhtemp_tmpfile_linux(int dirfd, + struct stat *st_dir_initial, + char *fname_copy, + char *p, + size_t xc, + int *fd, + struct stat *st); int mkhtemp(int *fd, struct stat *st, char *template, int dirfd, const char *fname, struct stat *st_dir_initial, int type); @@ -517,7 +518,8 @@ int world_writeable_and_sticky(const char *s, int same_dir(const char *a, const char *b); int tmpdir_policy(const char *path, int *allow_noworld_unsticky); -char *env_tmpdir(int always_sticky, char **tmpdir); +char *env_tmpdir(int always_sticky, char **tmpdir, + char *override_tmpdir); int secure_file(int *fd, struct stat *st, struct stat *expected, @@ -547,6 +549,7 @@ int mkdirat_on_eintr(int dirfd, const char *pathname, mode_t mode); int if_err(int condition, int errval); int if_err_sys(int condition); +char *lbgetprogname(char *argv0); /* asserts */ |
