diff options
Diffstat (limited to 'util/libreboot-utils/lib')
| -rw-r--r-- | util/libreboot-utils/lib/mkhtemp.c | 33 |
1 files changed, 25 insertions, 8 deletions
diff --git a/util/libreboot-utils/lib/mkhtemp.c b/util/libreboot-utils/lib/mkhtemp.c index 8d58dcc5..e1ca0a10 100644 --- a/util/libreboot-utils/lib/mkhtemp.c +++ b/util/libreboot-utils/lib/mkhtemp.c @@ -63,6 +63,8 @@ new_tmp_common(int *fd, char **path, int type) struct stat st_dir_initial; + char *fail_dir = NULL; + if (path == NULL || fd == NULL) { errno = EFAULT; goto err; @@ -89,9 +91,9 @@ new_tmp_common(int *fd, char **path, int type) #if defined(PERMIT_NON_STICKY_ALWAYS) && \ ((PERMIT_NON_STICKY_ALWAYS) > 0) - tmpdir = env_tmpdir(PERMIT_NON_STICKY_ALWAYS); + tmpdir = env_tmpdir(PERMIT_NON_STICKY_ALWAYS, &fail_dir); #else - tmpdir = env_tmpdir(0); + tmpdir = env_tmpdir(0, &fail_dir); #endif if (tmpdir == NULL) goto err; @@ -176,6 +178,13 @@ err: *fd = -1; } + /* where a TMPDIR isn't found, and we err, + * we pass this back through for the + * error message + */ + if (fail_dir != NULL) + *path = fail_dir; + errno = saved_errno; return -1; } @@ -185,26 +194,31 @@ err: */ char * -env_tmpdir(int bypass_all_sticky_checks) +env_tmpdir(int bypass_all_sticky_checks, char **tmpdir) { char *t; int allow_noworld_unsticky; int saved_errno = errno; + char tmp[] = "/tmp"; + char vartmp[] = "/var/tmp"; + t = getenv("TMPDIR"); if (t != NULL && *t != '\0') { if (tmpdir_policy(t, &allow_noworld_unsticky) < 0) { - errno = EPERM; + if (tmpdir != NULL) + *tmpdir = t; return NULL; /* errno already set */ } if (!world_writeable_and_sticky(t, allow_noworld_unsticky, bypass_all_sticky_checks)) { - errno = EPERM; + if (tmpdir != NULL) + *tmpdir = t; return NULL; } @@ -218,6 +232,9 @@ env_tmpdir(int bypass_all_sticky_checks) allow_noworld_unsticky, bypass_all_sticky_checks)) { + if (tmpdir != NULL) + *tmpdir = tmp; + errno = saved_errno; return "/tmp"; } @@ -226,13 +243,13 @@ env_tmpdir(int bypass_all_sticky_checks) allow_noworld_unsticky, bypass_all_sticky_checks)) { + if (tmpdir != NULL) + *tmpdir = vartmp; + errno = saved_errno; return "/var/tmp"; } - if (errno == saved_errno) - errno = EPERM; - return NULL; } |
