xref: /freebsd/contrib/netbsd-tests/lib/libc/c063/t_o_search.c (revision 44e86fbdcf5a3e625095652a3d0ab99532e54eea)
1*850e0825SKyle Evans /*	$NetBSD: t_o_search.c,v 1.10 2020/02/08 19:58:36 kamil Exp $ */
257718be8SEnji Cooper 
357718be8SEnji Cooper /*-
457718be8SEnji Cooper  * Copyright (c) 2012 The NetBSD Foundation, Inc.
557718be8SEnji Cooper  * All rights reserved.
657718be8SEnji Cooper  *
757718be8SEnji Cooper  * This code is derived from software contributed to The NetBSD Foundation
857718be8SEnji Cooper  * by Emmanuel Dreyfus.
957718be8SEnji Cooper  *
1057718be8SEnji Cooper  * Redistribution and use in source and binary forms, with or without
1157718be8SEnji Cooper  * modification, are permitted provided that the following conditions
1257718be8SEnji Cooper  * are met:
1357718be8SEnji Cooper  * 1. Redistributions of source code must retain the above copyright
1457718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer.
1557718be8SEnji Cooper  * 2. Redistributions in binary form must reproduce the above copyright
1657718be8SEnji Cooper  *    notice, this list of conditions and the following disclaimer in the
1757718be8SEnji Cooper  *    documentation and/or other materials provided with the distribution.
1857718be8SEnji Cooper  *
1957718be8SEnji Cooper  * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
2057718be8SEnji Cooper  * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
2157718be8SEnji Cooper  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
2257718be8SEnji Cooper  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
2357718be8SEnji Cooper  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
2457718be8SEnji Cooper  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
2557718be8SEnji Cooper  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
2657718be8SEnji Cooper  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
2757718be8SEnji Cooper  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
2857718be8SEnji Cooper  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
2957718be8SEnji Cooper  * POSSIBILITY OF SUCH DAMAGE.
3057718be8SEnji Cooper  */
3157718be8SEnji Cooper #include <sys/cdefs.h>
32*850e0825SKyle Evans __RCSID("$NetBSD: t_o_search.c,v 1.10 2020/02/08 19:58:36 kamil Exp $");
3357718be8SEnji Cooper 
3457718be8SEnji Cooper #include <atf-c.h>
35ddba0402SEnji Cooper 
366a5abb1eSKyle Evans #include <sys/types.h>
3714d3b069SKyle Evans #include <sys/mount.h>
3814d3b069SKyle Evans #include <sys/statvfs.h>
39ddba0402SEnji Cooper #include <sys/stat.h>
40ddba0402SEnji Cooper 
416a5abb1eSKyle Evans #include <dirent.h>
4257718be8SEnji Cooper #include <errno.h>
4357718be8SEnji Cooper #include <fcntl.h>
4457718be8SEnji Cooper #include <limits.h>
4557718be8SEnji Cooper #include <paths.h>
4657718be8SEnji Cooper #include <stdio.h>
4757718be8SEnji Cooper #include <string.h>
4857718be8SEnji Cooper #include <unistd.h>
4957718be8SEnji Cooper #include <pwd.h>
5057718be8SEnji Cooper 
5157718be8SEnji Cooper /*
5257718be8SEnji Cooper  * dholland 20130112: disable tests that require O_SEARCH semantics
5357718be8SEnji Cooper  * until a decision is reached about the semantics of O_SEARCH and a
5457718be8SEnji Cooper  * non-broken implementation is available.
5557718be8SEnji Cooper  */
566a5abb1eSKyle Evans #if defined(__FreeBSD__) || (O_MASK & O_SEARCH) != 0
5757718be8SEnji Cooper #define USE_O_SEARCH
5857718be8SEnji Cooper #endif
5957718be8SEnji Cooper 
60*850e0825SKyle Evans #ifdef __FreeBSD__
61*850e0825SKyle Evans #define	statvfs		statfs
62*850e0825SKyle Evans #define	fstatvfs	fstatfs
63*850e0825SKyle Evans #endif
64*850e0825SKyle Evans 
6557718be8SEnji Cooper #define DIR "dir"
6657718be8SEnji Cooper #define FILE "dir/o_search"
6757718be8SEnji Cooper #define BASEFILE "o_search"
6857718be8SEnji Cooper 
6957718be8SEnji Cooper 
7057718be8SEnji Cooper ATF_TC(o_search_perm1);
ATF_TC_HEAD(o_search_perm1,tc)7157718be8SEnji Cooper ATF_TC_HEAD(o_search_perm1, tc)
7257718be8SEnji Cooper {
7357718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "See that openat enforces search permission");
7457718be8SEnji Cooper 	atf_tc_set_md_var(tc, "require.user", "unprivileged");
7557718be8SEnji Cooper }
ATF_TC_BODY(o_search_perm1,tc)7657718be8SEnji Cooper ATF_TC_BODY(o_search_perm1, tc)
7757718be8SEnji Cooper {
7857718be8SEnji Cooper 	int dfd;
7957718be8SEnji Cooper 	int fd;
8057718be8SEnji Cooper 
8157718be8SEnji Cooper 	ATF_REQUIRE(mkdir(DIR, 0755) == 0);
8257718be8SEnji Cooper 	ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
8357718be8SEnji Cooper 	ATF_REQUIRE(close(fd) == 0);
8457718be8SEnji Cooper 
8557718be8SEnji Cooper 	ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
8657718be8SEnji Cooper 
8757718be8SEnji Cooper 	ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
8857718be8SEnji Cooper 	ATF_REQUIRE(close(fd) == 0);
8957718be8SEnji Cooper 
9045c88a3cSKyle Evans 	ATF_REQUIRE(fchmod(dfd, 0644) == 0);
9157718be8SEnji Cooper 
9257718be8SEnji Cooper 	ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) == -1);
9357718be8SEnji Cooper 	ATF_REQUIRE(errno == EACCES);
9457718be8SEnji Cooper 
9557718be8SEnji Cooper 	ATF_REQUIRE(close(dfd) == 0);
9657718be8SEnji Cooper }
9757718be8SEnji Cooper 
9857718be8SEnji Cooper #ifdef USE_O_SEARCH
9957718be8SEnji Cooper 
10057718be8SEnji Cooper ATF_TC(o_search_root_flag1);
ATF_TC_HEAD(o_search_root_flag1,tc)10157718be8SEnji Cooper ATF_TC_HEAD(o_search_root_flag1, tc)
10257718be8SEnji Cooper {
10357718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "See that root openat honours O_SEARCH");
10457718be8SEnji Cooper 	atf_tc_set_md_var(tc, "require.user", "root");
10557718be8SEnji Cooper }
ATF_TC_BODY(o_search_root_flag1,tc)10657718be8SEnji Cooper ATF_TC_BODY(o_search_root_flag1, tc)
10757718be8SEnji Cooper {
10857718be8SEnji Cooper 	int dfd;
10957718be8SEnji Cooper 	int fd;
11057718be8SEnji Cooper 
11157718be8SEnji Cooper 	ATF_REQUIRE(mkdir(DIR, 0755) == 0);
11257718be8SEnji Cooper 	ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
11357718be8SEnji Cooper 	ATF_REQUIRE(close(fd) == 0);
11457718be8SEnji Cooper 
11557718be8SEnji Cooper 	ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1);
11657718be8SEnji Cooper 
11757718be8SEnji Cooper 	ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
11857718be8SEnji Cooper 	ATF_REQUIRE(close(fd) == 0);
11957718be8SEnji Cooper 
12045c88a3cSKyle Evans 	ATF_REQUIRE(fchmod(dfd, 0644) == 0);
12157718be8SEnji Cooper 
12257718be8SEnji Cooper 	ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
12357718be8SEnji Cooper 	ATF_REQUIRE(close(fd) == 0);
12457718be8SEnji Cooper 
12545c88a3cSKyle Evans 	ATF_REQUIRE(fchmod(dfd, 0444) == 0);
12657718be8SEnji Cooper 
12757718be8SEnji Cooper 	ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
12857718be8SEnji Cooper 
12957718be8SEnji Cooper 	ATF_REQUIRE(close(dfd) == 0);
13057718be8SEnji Cooper }
13157718be8SEnji Cooper 
13257718be8SEnji Cooper ATF_TC(o_search_unpriv_flag1);
ATF_TC_HEAD(o_search_unpriv_flag1,tc)13357718be8SEnji Cooper ATF_TC_HEAD(o_search_unpriv_flag1, tc)
13457718be8SEnji Cooper {
13557718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "See that openat honours O_SEARCH");
13657718be8SEnji Cooper 	atf_tc_set_md_var(tc, "require.user", "unprivileged");
13757718be8SEnji Cooper }
ATF_TC_BODY(o_search_unpriv_flag1,tc)13857718be8SEnji Cooper ATF_TC_BODY(o_search_unpriv_flag1, tc)
13957718be8SEnji Cooper {
14057718be8SEnji Cooper 	int dfd;
14157718be8SEnji Cooper 	int fd;
14257718be8SEnji Cooper 
14357718be8SEnji Cooper 	ATF_REQUIRE(mkdir(DIR, 0755) == 0);
14457718be8SEnji Cooper 	ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
14557718be8SEnji Cooper 	ATF_REQUIRE(close(fd) == 0);
14657718be8SEnji Cooper 
14757718be8SEnji Cooper 	ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1);
14857718be8SEnji Cooper 
14957718be8SEnji Cooper 	ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
15057718be8SEnji Cooper 	ATF_REQUIRE(close(fd) == 0);
15157718be8SEnji Cooper 
15245c88a3cSKyle Evans 	ATF_REQUIRE(fchmod(dfd, 0644) == 0);
15357718be8SEnji Cooper 
15457718be8SEnji Cooper 	ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
15557718be8SEnji Cooper 	ATF_REQUIRE(close(fd) == 0);
15657718be8SEnji Cooper 
15745c88a3cSKyle Evans 	ATF_REQUIRE(fchmod(dfd, 0444) == 0);
15857718be8SEnji Cooper 
15957718be8SEnji Cooper 	ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) != -1);
16057718be8SEnji Cooper 
16157718be8SEnji Cooper 	ATF_REQUIRE(close(dfd) == 0);
16257718be8SEnji Cooper }
16357718be8SEnji Cooper 
16457718be8SEnji Cooper #endif /* USE_O_SEARCH */
16557718be8SEnji Cooper 
16657718be8SEnji Cooper ATF_TC(o_search_perm2);
ATF_TC_HEAD(o_search_perm2,tc)16757718be8SEnji Cooper ATF_TC_HEAD(o_search_perm2, tc)
16857718be8SEnji Cooper {
16957718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "See that faccessat enforces search permission");
17057718be8SEnji Cooper 	atf_tc_set_md_var(tc, "require.user", "unprivileged");
17157718be8SEnji Cooper }
ATF_TC_BODY(o_search_perm2,tc)17257718be8SEnji Cooper ATF_TC_BODY(o_search_perm2, tc)
17357718be8SEnji Cooper {
17457718be8SEnji Cooper 	int dfd;
17557718be8SEnji Cooper 	int fd;
17657718be8SEnji Cooper 	ATF_REQUIRE(mkdir(DIR, 0755) == 0);
17757718be8SEnji Cooper 	ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
17857718be8SEnji Cooper 	ATF_REQUIRE(close(fd) == 0);
17957718be8SEnji Cooper 
18057718be8SEnji Cooper 	ATF_REQUIRE((dfd = open(DIR, O_RDONLY, 0)) != -1);
18157718be8SEnji Cooper 
18257718be8SEnji Cooper 	ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
18357718be8SEnji Cooper 
18445c88a3cSKyle Evans 	ATF_REQUIRE(fchmod(dfd, 0644) == 0);
18557718be8SEnji Cooper 
18657718be8SEnji Cooper 	ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == -1);
18757718be8SEnji Cooper 	ATF_REQUIRE(errno == EACCES);
18857718be8SEnji Cooper 
18957718be8SEnji Cooper 	ATF_REQUIRE(close(dfd) == 0);
19057718be8SEnji Cooper }
19157718be8SEnji Cooper 
19257718be8SEnji Cooper #ifdef USE_O_SEARCH
19357718be8SEnji Cooper 
19457718be8SEnji Cooper ATF_TC(o_search_root_flag2);
ATF_TC_HEAD(o_search_root_flag2,tc)19557718be8SEnji Cooper ATF_TC_HEAD(o_search_root_flag2, tc)
19657718be8SEnji Cooper {
19757718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "See that root fstatat honours O_SEARCH");
19857718be8SEnji Cooper 	atf_tc_set_md_var(tc, "require.user", "root");
19957718be8SEnji Cooper }
ATF_TC_BODY(o_search_root_flag2,tc)20057718be8SEnji Cooper ATF_TC_BODY(o_search_root_flag2, tc)
20157718be8SEnji Cooper {
20257718be8SEnji Cooper 	int dfd;
20357718be8SEnji Cooper 	int fd;
20457718be8SEnji Cooper 
20557718be8SEnji Cooper 	ATF_REQUIRE(mkdir(DIR, 0755) == 0);
20657718be8SEnji Cooper 	ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
20757718be8SEnji Cooper 	ATF_REQUIRE(close(fd) == 0);
20857718be8SEnji Cooper 
20957718be8SEnji Cooper 	ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1);
21057718be8SEnji Cooper 
21157718be8SEnji Cooper 	ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
21257718be8SEnji Cooper 
21345c88a3cSKyle Evans 	ATF_REQUIRE(fchmod(dfd, 0644) == 0);
21457718be8SEnji Cooper 
21557718be8SEnji Cooper 	ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
21657718be8SEnji Cooper 
21745c88a3cSKyle Evans 	ATF_REQUIRE(fchmod(dfd, 0444) == 0);
21857718be8SEnji Cooper 
21957718be8SEnji Cooper 	ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
22057718be8SEnji Cooper 
22157718be8SEnji Cooper 	ATF_REQUIRE(close(dfd) == 0);
22257718be8SEnji Cooper }
22357718be8SEnji Cooper 
22457718be8SEnji Cooper ATF_TC(o_search_unpriv_flag2);
ATF_TC_HEAD(o_search_unpriv_flag2,tc)22557718be8SEnji Cooper ATF_TC_HEAD(o_search_unpriv_flag2, tc)
22657718be8SEnji Cooper {
22757718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "See that fstatat honours O_SEARCH");
22857718be8SEnji Cooper 	atf_tc_set_md_var(tc, "require.user", "unprivileged");
22957718be8SEnji Cooper }
ATF_TC_BODY(o_search_unpriv_flag2,tc)23057718be8SEnji Cooper ATF_TC_BODY(o_search_unpriv_flag2, tc)
23157718be8SEnji Cooper {
23257718be8SEnji Cooper 	int dfd;
23357718be8SEnji Cooper 	int fd;
23457718be8SEnji Cooper 
23557718be8SEnji Cooper 	ATF_REQUIRE(mkdir(DIR, 0755) == 0);
23657718be8SEnji Cooper 	ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
23757718be8SEnji Cooper 	ATF_REQUIRE(close(fd) == 0);
23857718be8SEnji Cooper 
23957718be8SEnji Cooper 	ATF_REQUIRE((dfd = open(DIR, O_RDONLY|O_SEARCH, 0)) != -1);
24057718be8SEnji Cooper 
24157718be8SEnji Cooper 	ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
24257718be8SEnji Cooper 
24345c88a3cSKyle Evans 	ATF_REQUIRE(fchmod(dfd, 0644) == 0);
24457718be8SEnji Cooper 
24557718be8SEnji Cooper 	ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
24657718be8SEnji Cooper 
24745c88a3cSKyle Evans 	ATF_REQUIRE(fchmod(dfd, 0444) == 0);
24857718be8SEnji Cooper 
24957718be8SEnji Cooper 	ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) == 0);
25057718be8SEnji Cooper 
25157718be8SEnji Cooper 	ATF_REQUIRE(close(dfd) == 0);
25257718be8SEnji Cooper }
25357718be8SEnji Cooper 
25457718be8SEnji Cooper #endif /* USE_O_SEARCH */
25557718be8SEnji Cooper 
25657718be8SEnji Cooper 
25757718be8SEnji Cooper ATF_TC(o_search_notdir);
ATF_TC_HEAD(o_search_notdir,tc)25857718be8SEnji Cooper ATF_TC_HEAD(o_search_notdir, tc)
25957718be8SEnji Cooper {
26057718be8SEnji Cooper 	atf_tc_set_md_var(tc, "descr", "See that openat fails with non dir fd");
26157718be8SEnji Cooper }
ATF_TC_BODY(o_search_notdir,tc)26257718be8SEnji Cooper ATF_TC_BODY(o_search_notdir, tc)
26357718be8SEnji Cooper {
26457718be8SEnji Cooper 	int dfd;
26557718be8SEnji Cooper 	int fd;
26657718be8SEnji Cooper 
26757718be8SEnji Cooper 	ATF_REQUIRE(mkdir(DIR, 0755) == 0);
2686a5abb1eSKyle Evans 	ATF_REQUIRE((dfd = open(FILE, O_CREAT|O_SEARCH, 0644)) != -1);
26957718be8SEnji Cooper 	ATF_REQUIRE((fd = openat(dfd, BASEFILE, O_RDWR, 0)) == -1);
27057718be8SEnji Cooper 	ATF_REQUIRE(errno == ENOTDIR);
27156cc8b75SKyle Evans 	ATF_REQUIRE(close(dfd) == 0);
27257718be8SEnji Cooper }
27357718be8SEnji Cooper 
2746a5abb1eSKyle Evans #ifdef USE_O_SEARCH
2756a5abb1eSKyle Evans ATF_TC(o_search_nord);
ATF_TC_HEAD(o_search_nord,tc)2766a5abb1eSKyle Evans ATF_TC_HEAD(o_search_nord, tc)
2776a5abb1eSKyle Evans {
2786a5abb1eSKyle Evans 	atf_tc_set_md_var(tc, "descr", "See that openat succeeds with no read permission");
2796a5abb1eSKyle Evans 	atf_tc_set_md_var(tc, "require.user", "unprivileged");
2806a5abb1eSKyle Evans }
ATF_TC_BODY(o_search_nord,tc)2816a5abb1eSKyle Evans ATF_TC_BODY(o_search_nord, tc)
2826a5abb1eSKyle Evans {
2836a5abb1eSKyle Evans 	int dfd, fd;
2846a5abb1eSKyle Evans 
2856a5abb1eSKyle Evans 	ATF_REQUIRE(mkdir(DIR, 0755) == 0);
2866a5abb1eSKyle Evans 	ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
2876a5abb1eSKyle Evans 	ATF_REQUIRE(close(fd) == 0);
2886a5abb1eSKyle Evans 
2896a5abb1eSKyle Evans 	ATF_REQUIRE(chmod(DIR, 0100) == 0);
2906a5abb1eSKyle Evans 	ATF_REQUIRE((dfd = open(DIR, O_SEARCH, 0)) != -1);
2916a5abb1eSKyle Evans 
2926a5abb1eSKyle Evans 	ATF_REQUIRE(faccessat(dfd, BASEFILE, W_OK, 0) != -1);
2936a5abb1eSKyle Evans 
2946a5abb1eSKyle Evans 	ATF_REQUIRE(close(dfd) == 0);
2956a5abb1eSKyle Evans }
2966a5abb1eSKyle Evans 
2976a5abb1eSKyle Evans ATF_TC(o_search_getdents);
ATF_TC_HEAD(o_search_getdents,tc)2986a5abb1eSKyle Evans ATF_TC_HEAD(o_search_getdents, tc)
2996a5abb1eSKyle Evans {
3006a5abb1eSKyle Evans 	atf_tc_set_md_var(tc, "descr", "See that O_SEARCH forbids getdents");
3016a5abb1eSKyle Evans }
ATF_TC_BODY(o_search_getdents,tc)3026a5abb1eSKyle Evans ATF_TC_BODY(o_search_getdents, tc)
3036a5abb1eSKyle Evans {
3046a5abb1eSKyle Evans 	char buf[1024];
3056a5abb1eSKyle Evans 	int dfd;
3066a5abb1eSKyle Evans 
3076a5abb1eSKyle Evans 	ATF_REQUIRE(mkdir(DIR, 0755) == 0);
3086a5abb1eSKyle Evans 	ATF_REQUIRE((dfd = open(DIR, O_SEARCH, 0)) != -1);
3096a5abb1eSKyle Evans 	ATF_REQUIRE(getdents(dfd, buf, sizeof(buf)) < 0);
3106a5abb1eSKyle Evans 	ATF_REQUIRE(close(dfd) == 0);
3116a5abb1eSKyle Evans }
3126a5abb1eSKyle Evans 
3136a5abb1eSKyle Evans ATF_TC(o_search_revokex);
ATF_TC_HEAD(o_search_revokex,tc)3146a5abb1eSKyle Evans ATF_TC_HEAD(o_search_revokex, tc)
3156a5abb1eSKyle Evans {
3166a5abb1eSKyle Evans 	atf_tc_set_md_var(tc, "descr", "See that *at behaves after chmod -x");
3176a5abb1eSKyle Evans 	atf_tc_set_md_var(tc, "require.user", "unprivileged");
3186a5abb1eSKyle Evans }
ATF_TC_BODY(o_search_revokex,tc)3196a5abb1eSKyle Evans ATF_TC_BODY(o_search_revokex, tc)
3206a5abb1eSKyle Evans {
321*850e0825SKyle Evans 	struct statvfs vst;
3226a5abb1eSKyle Evans 	struct stat sb;
323*850e0825SKyle Evans 	int dfd, fd;
3246a5abb1eSKyle Evans 
3256a5abb1eSKyle Evans 	ATF_REQUIRE(mkdir(DIR, 0755) == 0);
3266a5abb1eSKyle Evans 	ATF_REQUIRE((fd = open(FILE, O_CREAT|O_RDWR, 0644)) != -1);
3276a5abb1eSKyle Evans 	ATF_REQUIRE(close(fd) == 0);
3286a5abb1eSKyle Evans 
3296a5abb1eSKyle Evans 	ATF_REQUIRE((dfd = open(DIR, O_SEARCH, 0)) != -1);
3306a5abb1eSKyle Evans 
3316a5abb1eSKyle Evans 	/* Drop permissions. The kernel must still not check the exec bit. */
3326a5abb1eSKyle Evans 	ATF_REQUIRE(chmod(DIR, 0000) == 0);
33314d3b069SKyle Evans 
33414d3b069SKyle Evans 	fstatvfs(dfd, &vst);
335*850e0825SKyle Evans 	if (strcmp(vst.f_fstypename, "nfs") == 0)
336*850e0825SKyle Evans 		atf_tc_expect_fail("NFS protocol cannot observe O_SEARCH semantics");
337*850e0825SKyle Evans 
3386a5abb1eSKyle Evans 	ATF_REQUIRE(fstatat(dfd, BASEFILE, &sb, 0) == 0);
3396a5abb1eSKyle Evans 
3406a5abb1eSKyle Evans 	ATF_REQUIRE(close(dfd) == 0);
3416a5abb1eSKyle Evans }
3426a5abb1eSKyle Evans #endif /* USE_O_SEARCH */
3436a5abb1eSKyle Evans 
ATF_TP_ADD_TCS(tp)34457718be8SEnji Cooper ATF_TP_ADD_TCS(tp)
34557718be8SEnji Cooper {
34657718be8SEnji Cooper 
34757718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, o_search_perm1);
34857718be8SEnji Cooper #ifdef USE_O_SEARCH
34957718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, o_search_root_flag1);
35057718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, o_search_unpriv_flag1);
35157718be8SEnji Cooper #endif
35257718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, o_search_perm2);
35357718be8SEnji Cooper #ifdef USE_O_SEARCH
35457718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, o_search_root_flag2);
35557718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, o_search_unpriv_flag2);
35657718be8SEnji Cooper #endif
35757718be8SEnji Cooper 	ATF_TP_ADD_TC(tp, o_search_notdir);
3586a5abb1eSKyle Evans #ifdef USE_O_SEARCH
3596a5abb1eSKyle Evans 	ATF_TP_ADD_TC(tp, o_search_nord);
3606a5abb1eSKyle Evans 	ATF_TP_ADD_TC(tp, o_search_getdents);
3616a5abb1eSKyle Evans 	ATF_TP_ADD_TC(tp, o_search_revokex);
3626a5abb1eSKyle Evans #endif
36357718be8SEnji Cooper 
36457718be8SEnji Cooper 	return atf_no_error();
36557718be8SEnji Cooper }
366