diff --git a/bin/cp/tests/cp_test.sh b/bin/cp/tests/cp_test.sh --- a/bin/cp/tests/cp_test.sh +++ b/bin/cp/tests/cp_test.sh @@ -563,17 +563,8 @@ mkdir -m 0755 dir echo "foo" >dir/file umask 0177 - #atf_check cp -R dir dst -#begin - # atf-check stupidly refuses to work if the current umask is - # weird, instead of just dealing with the situation - cp -R dir dst >stdout 2>stderr - rc=$? + atf_check cp -R dir dst umask 022 - atf_check_equal 0 $rc - atf_check cat stdout - atf_check cat stderr -#end atf_check -o inline:"40600\n" stat -f%p dst atf_check chmod 0750 dst atf_check cmp dir/file dst/file diff --git a/contrib/atf/atf-c/check_test.c b/contrib/atf/atf-c/check_test.c --- a/contrib/atf/atf-c/check_test.c +++ b/contrib/atf/atf-c/check_test.c @@ -458,8 +458,7 @@ ATF_TC_HEAD(exec_umask, tc) { atf_tc_set_md_var(tc, "descr", "Checks that atf_check_exec_array " - "correctly reports an error if the umask is too " - "restrictive to create temporary files"); + "works regardless of umask"); } ATF_TC_BODY(exec_umask, tc) { @@ -473,10 +472,7 @@ argv[2] = NULL; umask(0222); - atf_error_t err = atf_check_exec_array(argv, &result); - ATF_CHECK(atf_is_error(err)); - ATF_CHECK(atf_error_is(err, "invalid_umask")); - atf_error_free(err); + RE(atf_check_exec_array(argv, &result)); atf_fs_path_fini(&process_helpers); } diff --git a/contrib/atf/atf-c/detail/fs.c b/contrib/atf/atf-c/detail/fs.c --- a/contrib/atf/atf-c/detail/fs.c +++ b/contrib/atf/atf-c/detail/fs.c @@ -54,71 +54,13 @@ * Prototypes for auxiliary functions. * --------------------------------------------------------------------- */ -static bool check_umask(const mode_t, const mode_t); static atf_error_t copy_contents(const atf_fs_path_t *, char **); -static mode_t current_umask(void); static atf_error_t do_mkdtemp(char *); static atf_error_t normalize(atf_dynstr_t *, char *); static atf_error_t normalize_ap(atf_dynstr_t *, const char *, va_list); static void replace_contents(atf_fs_path_t *, const char *); static const char *stat_type_to_string(const int); -/* --------------------------------------------------------------------- - * The "invalid_umask" error type. - * --------------------------------------------------------------------- */ - -struct invalid_umask_error_data { - /* One of atf_fs_stat_*_type. */ - int m_type; - - /* The original path causing the error. */ - /* XXX: Ideally this would be an atf_fs_path_t, but if we create it - * from the error constructor, we cannot delete the path later on. - * Can't remember why atf_error_new does not take a hook for - * deletion. */ - char m_path[1024]; - - /* The umask that caused the error. */ - mode_t m_umask; -}; -typedef struct invalid_umask_error_data invalid_umask_error_data_t; - -static -void -invalid_umask_format(const atf_error_t err, char *buf, size_t buflen) -{ - const invalid_umask_error_data_t *data; - - PRE(atf_error_is(err, "invalid_umask")); - - data = atf_error_data(err); - snprintf(buf, buflen, "Could not create the temporary %s %s because " - "it will not have enough access rights due to the current " - "umask %05o", stat_type_to_string(data->m_type), - data->m_path, (unsigned int)data->m_umask); -} - -static -atf_error_t -invalid_umask_error(const atf_fs_path_t *path, const int type, - const mode_t failing_mask) -{ - atf_error_t err; - invalid_umask_error_data_t data; - - data.m_type = type; - - strncpy(data.m_path, atf_fs_path_cstring(path), sizeof(data.m_path)); - data.m_path[sizeof(data.m_path) - 1] = '\0'; - - data.m_umask = failing_mask; - - err = atf_error_new("invalid_umask", &data, sizeof(data), - invalid_umask_format); - - return err; -} - /* --------------------------------------------------------------------- * The "unknown_file_type" error type. * --------------------------------------------------------------------- */ @@ -162,14 +104,6 @@ * Auxiliary functions. * --------------------------------------------------------------------- */ -static -bool -check_umask(const mode_t exp_mode, const mode_t min_mode) -{ - const mode_t actual_mode = (~current_umask() & exp_mode); - return (actual_mode & min_mode) == min_mode; -} - static atf_error_t copy_contents(const atf_fs_path_t *p, char **buf) @@ -189,15 +123,6 @@ return err; } -static -mode_t -current_umask(void) -{ - const mode_t current = umask(0); - (void)umask(current); - return current; -} - static atf_error_t do_mkdtemp(char *tmpl) @@ -794,11 +719,10 @@ { atf_error_t err; char *buf; + mode_t mask; - if (!check_umask(S_IRWXU, S_IRWXU)) { - err = invalid_umask_error(p, atf_fs_stat_dir_type, current_umask()); - goto out; - } + mask = umask(0); + umask(mask & 077); err = copy_contents(p, &buf); if (atf_is_error(err)) @@ -814,6 +738,7 @@ out_buf: free(buf); out: + umask(mask); return err; } @@ -823,11 +748,10 @@ atf_error_t err; char *buf; int fd; + mode_t mask; - if (!check_umask(S_IRWXU, S_IRWXU)) { - err = invalid_umask_error(p, atf_fs_stat_reg_type, current_umask()); - goto out; - } + mask = umask(0); + umask(mask & 077); err = copy_contents(p, &buf); if (atf_is_error(err)) @@ -844,6 +768,7 @@ out_buf: free(buf); out: + umask(mask); return err; } diff --git a/contrib/atf/atf-c/detail/fs_test.c b/contrib/atf/atf-c/detail/fs_test.c --- a/contrib/atf/atf-c/detail/fs_test.c +++ b/contrib/atf/atf-c/detail/fs_test.c @@ -896,25 +896,25 @@ static void do_umask_check(atf_error_t (*const mk_func)(atf_fs_path_t *), - atf_fs_path_t *path, const mode_t test_mask, - const char *str_mask, const char *exp_name) + atf_error_t (*const rm_func)(const atf_fs_path_t *), + atf_fs_path_t *tmpl, const mode_t test_mask, + const char *exp_name) { - char buf[1024]; - int old_umask; + atf_fs_path_t path; + int pre_mask, post_mask; atf_error_t err; - printf("Creating temporary %s with umask %s\n", exp_name, str_mask); + printf("Creating temporary %s with umask %05o\n", exp_name, test_mask); - old_umask = umask(test_mask); - err = mk_func(path); - (void)umask(old_umask); + RE(atf_fs_path_copy(&path, tmpl)); - ATF_REQUIRE(atf_is_error(err)); - ATF_REQUIRE(atf_error_is(err, "invalid_umask")); - atf_error_format(err, buf, sizeof(buf)); - ATF_CHECK(strstr(buf, exp_name) != NULL); - ATF_CHECK(strstr(buf, str_mask) != NULL); - atf_error_free(err); + pre_mask = umask(test_mask); + err = mk_func(&path); + post_mask = umask(pre_mask); + + ATF_REQUIRE(!atf_is_error(err)); + ATF_CHECK_EQ(post_mask, test_mask); + RE(rm_func(&path)); } ATF_TC(mkdtemp_umask); @@ -929,11 +929,11 @@ RE(atf_fs_path_init_fmt(&p, "testdir.XXXXXX")); - do_umask_check(atf_fs_mkdtemp, &p, 00100, "00100", "directory"); - do_umask_check(atf_fs_mkdtemp, &p, 00200, "00200", "directory"); - do_umask_check(atf_fs_mkdtemp, &p, 00400, "00400", "directory"); - do_umask_check(atf_fs_mkdtemp, &p, 00500, "00500", "directory"); - do_umask_check(atf_fs_mkdtemp, &p, 00600, "00600", "directory"); + do_umask_check(atf_fs_mkdtemp, atf_fs_rmdir, &p, 00100, "directory"); + do_umask_check(atf_fs_mkdtemp, atf_fs_rmdir, &p, 00200, "directory"); + do_umask_check(atf_fs_mkdtemp, atf_fs_rmdir, &p, 00400, "directory"); + do_umask_check(atf_fs_mkdtemp, atf_fs_rmdir, &p, 00500, "directory"); + do_umask_check(atf_fs_mkdtemp, atf_fs_rmdir, &p, 00600, "directory"); atf_fs_path_fini(&p); } @@ -1039,9 +1039,9 @@ RE(atf_fs_path_init_fmt(&p, "testfile.XXXXXX")); - do_umask_check(mkstemp_discard_fd, &p, 00100, "00100", "regular file"); - do_umask_check(mkstemp_discard_fd, &p, 00200, "00200", "regular file"); - do_umask_check(mkstemp_discard_fd, &p, 00400, "00400", "regular file"); + do_umask_check(mkstemp_discard_fd, atf_fs_unlink, &p, 00100, "regular file"); + do_umask_check(mkstemp_discard_fd, atf_fs_unlink, &p, 00200, "regular file"); + do_umask_check(mkstemp_discard_fd, atf_fs_unlink, &p, 00400, "regular file"); atf_fs_path_fini(&p); } diff --git a/contrib/atf/atf-sh/atf-check_test.sh b/contrib/atf/atf-sh/atf-check_test.sh --- a/contrib/atf/atf-sh/atf-check_test.sh +++ b/contrib/atf/atf-sh/atf-check_test.sh @@ -389,21 +389,19 @@ atf_fail "atf-check does not seem to respect stdin" } -atf_test_case invalid_umask -invalid_umask_head() +atf_test_case unusual_umask +unusual_umask_head() { - atf_set "descr" "Tests for a correct error condition if the umask is" \ - "too restrictive" + atf_set "descr" "Tests that atf-check doesn't care about unusual umasks" } -invalid_umask_body() +unusual_umask_body() { - umask 0222 - ${Atf_Check} false 2>stderr && \ - atf_fail "atf-check returned 0 but it should have failed" - cat stderr - grep 'temporary.*current umask.*0222' stderr >/dev/null || \ - atf_fail "atf-check did not report an error related to the" \ - "current umask" + for mask in 022 027 0222 0177 0777 ; do + umask $mask + ${Atf_Check} true || \ + atf_fail "atf-check failed with umask $mask" + done + umask 022 } atf_init_test_cases() @@ -435,7 +433,7 @@ atf_add_test_case stdin - atf_add_test_case invalid_umask + atf_add_test_case unusual_umask } # vim: syntax=sh:expandtab:shiftwidth=4:softtabstop=4