1 /* $NetBSD: t_basic.c,v 1.5 2017/01/13 21:30:40 christos Exp $ */
16 #include <rump/rump.h>
17 #include <rump/rump_syscalls.h>
18 #include <rump/rumpvfs_if_pub.h>
20 #include <fs/tmpfs/tmpfs_args.h>
21 #include <miscfs/umapfs/umap.h>
26 ATF_TC_HEAD(basic, tc)
28 atf_tc_set_md_var(tc, "descr", "basic umapfs mapping");
32 xtouch(const char *path)
36 fd = rump_sys_open(path, O_CREAT | O_RDWR, 0777);
38 atf_tc_fail_errno("create %s", path);
43 xchown(const char *path, uid_t uid, gid_t gid)
46 if (rump_sys_chown(path, uid, gid) == -1)
47 atf_tc_fail_errno("chown %s failed", path);
51 testuidgid(const char *path, uid_t uid, gid_t gid)
55 if (rump_sys_stat(path, &sb) == -1)
56 atf_tc_fail_errno("stat %s", path);
57 if (uid != (uid_t)-1) {
59 atf_tc_fail("%s: expected uid %d, got %d",
60 path, uid, sb.st_uid);
62 if (gid != (gid_t)-1) {
64 atf_tc_fail("%s: expected gid %d, got %d",
65 path, gid, sb.st_gid);
69 ATF_TC_BODY(basic, tc)
71 struct umap_args umargs;
72 struct tmpfs_args targs;
77 if (rump_sys_mkdir("/td1", 0777) == -1)
78 atf_tc_fail_errno("mp1");
79 if (rump_sys_mkdir("/td2", 0777) == -1)
80 atf_tc_fail_errno("mp1");
82 /* use tmpfs because rumpfs doesn't support ownership */
83 memset(&targs, 0, sizeof(targs));
84 targs.ta_version = TMPFS_ARGS_VERSION;
85 targs.ta_root_mode = 0777;
86 if (rump_sys_mount(MOUNT_TMPFS, "/td1", 0, &targs, sizeof(targs)) == -1)
87 atf_tc_fail_errno("could not mount tmpfs td1");
89 memset(&umargs, 0, sizeof(umargs));
92 * Map td1 uid 555 to td2 uid 777 (yes, IMHO the umapfs
93 * mapping format is counter-intuitive).
104 umargs.umap_target = __UNCONST("/td1");
106 umargs.gnentries = 2;
107 umargs.mapdata = umaps;
108 umargs.gmapdata = gmaps;
110 if (rump_sys_mount(MOUNT_UMAP, "/td2", 0, &umargs,sizeof(umargs)) == -1)
111 atf_tc_fail_errno("could not mount umapfs");
114 testuidgid("/td1/noch", 0, 0);
115 testuidgid("/td2/noch", 0, 0);
117 xtouch("/td1/nomap");
118 xchown("/td1/nomap", 1, 2);
119 testuidgid("/td1/nomap", 1, 2);
120 testuidgid("/td2/nomap", -1, -1);
122 xtouch("/td1/forwmap");
123 xchown("/td1/forwmap", 555, 1234);
124 testuidgid("/td1/forwmap", 555, 1234);
125 testuidgid("/td2/forwmap", 777, 4321);
128 * this *CANNOT* be correct???
130 xtouch("/td1/revmap");
132 * should be 777 / 4321 (?), but makes first test fail since
133 * it gets 777 / 4321, i.e. unmapped results.
135 xchown("/td2/revmap", 555, 1234);
136 testuidgid("/td1/revmap", 555, 1234);
137 testuidgid("/td2/revmap", 777, 4321);
143 ATF_TP_ADD_TC(tp, basic);