Home | History | Annotate | Line # | Download | only in umapfs
t_basic.c revision 1.3
      1  1.3     pooka /*	$NetBSD: t_basic.c,v 1.3 2010/05/31 23:44:54 pooka Exp $	*/
      2  1.1     pooka 
      3  1.1     pooka #include <sys/types.h>
      4  1.2  dholland #include <sys/param.h>
      5  1.1     pooka #include <sys/mount.h>
      6  1.1     pooka 
      7  1.1     pooka #include <atf-c.h>
      8  1.1     pooka #include <err.h>
      9  1.1     pooka #include <errno.h>
     10  1.1     pooka #include <fcntl.h>
     11  1.1     pooka #include <stdio.h>
     12  1.1     pooka #include <unistd.h>
     13  1.1     pooka #include <string.h>
     14  1.1     pooka #include <stdlib.h>
     15  1.1     pooka 
     16  1.1     pooka #include <rump/rump.h>
     17  1.1     pooka #include <rump/rump_syscalls.h>
     18  1.1     pooka #include <rump/rumpvfs_if_pub.h>
     19  1.1     pooka 
     20  1.1     pooka #include <fs/tmpfs/tmpfs_args.h>
     21  1.1     pooka #include <miscfs/umapfs/umap.h>
     22  1.1     pooka 
     23  1.1     pooka #include "../../h_macros.h"
     24  1.1     pooka 
     25  1.1     pooka ATF_TC(basic);
     26  1.1     pooka ATF_TC_HEAD(basic, tc)
     27  1.1     pooka {
     28  1.1     pooka 	atf_tc_set_md_var(tc, "descr", "basic umapfs mapping");
     29  1.1     pooka }
     30  1.1     pooka 
     31  1.1     pooka /* deal with time_t change for running this on 5.0 */
     32  1.1     pooka #if __NetBSD_Prereq__(5,99,7)
     33  1.1     pooka #define statfn rump_sys_stat
     34  1.1     pooka #else
     35  1.1     pooka #define statfn rump_pub_sys___stat30
     36  1.1     pooka #endif
     37  1.1     pooka 
     38  1.1     pooka static void
     39  1.1     pooka xtouch(const char *path)
     40  1.1     pooka {
     41  1.1     pooka 	int fd;
     42  1.1     pooka 
     43  1.1     pooka 	fd = rump_sys_open(path, O_CREAT | O_RDWR, 0777);
     44  1.1     pooka 	if (fd == -1)
     45  1.1     pooka 		atf_tc_fail_errno("create %s", path);
     46  1.1     pooka 	rump_sys_close(fd);
     47  1.1     pooka }
     48  1.1     pooka 
     49  1.1     pooka static void
     50  1.1     pooka xchown(const char *path, uid_t uid, gid_t gid)
     51  1.1     pooka {
     52  1.1     pooka 
     53  1.1     pooka 	if (rump_sys_chown(path, uid, gid) == -1)
     54  1.1     pooka 		atf_tc_fail_errno("chown %s failed", path);
     55  1.1     pooka }
     56  1.1     pooka 
     57  1.1     pooka static void
     58  1.1     pooka testuidgid(const char *path, uid_t uid, gid_t gid)
     59  1.1     pooka {
     60  1.1     pooka 	struct stat sb;
     61  1.1     pooka 
     62  1.1     pooka 	if (statfn(path, &sb) == -1)
     63  1.1     pooka 		atf_tc_fail_errno("stat %s", path);
     64  1.1     pooka 	if (uid != (uid_t)-1) {
     65  1.1     pooka 		if (sb.st_uid != uid)
     66  1.1     pooka 			atf_tc_fail("%s: expected uid %d, got %d",
     67  1.1     pooka 			    path, uid, sb.st_uid);
     68  1.1     pooka 	}
     69  1.1     pooka 	if (gid != (gid_t)-1) {
     70  1.1     pooka 		if (sb.st_gid != gid)
     71  1.1     pooka 			atf_tc_fail("%s: expected gid %d, got %d",
     72  1.1     pooka 			    path, gid, sb.st_gid);
     73  1.1     pooka 	}
     74  1.1     pooka }
     75  1.1     pooka 
     76  1.1     pooka ATF_TC_BODY(basic, tc)
     77  1.1     pooka {
     78  1.1     pooka 	struct umap_args umargs;
     79  1.1     pooka 	struct tmpfs_args targs;
     80  1.1     pooka 	u_long umaps[2][2];
     81  1.1     pooka 	u_long gmaps[2][2];
     82  1.1     pooka 
     83  1.1     pooka 	rump_init();
     84  1.1     pooka 	if (rump_sys_mkdir("/td1", 0777) == -1)
     85  1.1     pooka 		atf_tc_fail_errno("mp1");
     86  1.1     pooka 	if (rump_sys_mkdir("/td2", 0777) == -1)
     87  1.1     pooka 		atf_tc_fail_errno("mp1");
     88  1.1     pooka 
     89  1.1     pooka 	/* use tmpfs because rumpfs doesn't support ownership */
     90  1.1     pooka 	memset(&targs, 0, sizeof(targs));
     91  1.1     pooka 	targs.ta_version = TMPFS_ARGS_VERSION;
     92  1.1     pooka 	targs.ta_root_mode = 0777;
     93  1.1     pooka 	if (rump_sys_mount(MOUNT_TMPFS, "/td1", 0, &targs, sizeof(targs)) == -1)
     94  1.1     pooka 		atf_tc_fail_errno("could not mount tmpfs td1");
     95  1.1     pooka 
     96  1.1     pooka 	memset(&umargs, 0, sizeof(umargs));
     97  1.1     pooka 
     98  1.1     pooka 	/*
     99  1.1     pooka 	 * Map td1 uid 555 to td2 uid 777 (yes, IMHO the umapfs
    100  1.1     pooka 	 * mapping format is counter-intuitive).
    101  1.1     pooka 	 */
    102  1.1     pooka 	umaps[0][0] = 777;
    103  1.1     pooka 	umaps[0][1] = 555;
    104  1.1     pooka 	umaps[1][0] = 0;
    105  1.1     pooka 	umaps[1][1] = 0;
    106  1.1     pooka 	gmaps[0][0] = 4321;
    107  1.1     pooka 	gmaps[0][1] = 1234;
    108  1.1     pooka 	gmaps[1][0] = 0;
    109  1.1     pooka 	gmaps[1][1] = 0;
    110  1.1     pooka 
    111  1.1     pooka 	umargs.umap_target = __UNCONST("/td1");
    112  1.1     pooka 	umargs.nentries = 2;
    113  1.1     pooka 	umargs.gnentries = 2;
    114  1.1     pooka 	umargs.mapdata = umaps;
    115  1.1     pooka 	umargs.gmapdata = gmaps;
    116  1.1     pooka 
    117  1.1     pooka 	if (rump_sys_mount(MOUNT_UMAP, "/td2", 0, &umargs,sizeof(umargs)) == -1)
    118  1.1     pooka 		atf_tc_fail_errno("could not mount umapfs");
    119  1.1     pooka 
    120  1.1     pooka 	xtouch("/td1/noch");
    121  1.1     pooka 	testuidgid("/td1/noch", 0, 0);
    122  1.1     pooka 	testuidgid("/td2/noch", 0, 0);
    123  1.1     pooka 
    124  1.1     pooka 	xtouch("/td1/nomap");
    125  1.1     pooka 	xchown("/td1/nomap", 1, 2);
    126  1.1     pooka 	testuidgid("/td1/nomap", 1, 2);
    127  1.1     pooka 	testuidgid("/td2/nomap", -1, -1);
    128  1.1     pooka 
    129  1.1     pooka 	xtouch("/td1/forwmap");
    130  1.1     pooka 	xchown("/td1/forwmap", 555, 1234);
    131  1.1     pooka 	testuidgid("/td1/forwmap", 555, 1234);
    132  1.1     pooka 	testuidgid("/td2/forwmap", 777, 4321);
    133  1.1     pooka 
    134  1.1     pooka 	/*
    135  1.1     pooka 	 * this *CANNOT* be correct???
    136  1.1     pooka 	 */
    137  1.1     pooka 	xtouch("/td1/revmap");
    138  1.1     pooka 	/*
    139  1.1     pooka 	 * should be 777 / 4321 (?), but makes first test fail since
    140  1.1     pooka 	 * it gets 777 / 4321, i.e. unmapped results.
    141  1.1     pooka 	 */
    142  1.1     pooka 	xchown("/td2/revmap", 555, 1234);
    143  1.1     pooka 	testuidgid("/td1/revmap", 555, 1234);
    144  1.1     pooka 	testuidgid("/td2/revmap", 777, 4321);
    145  1.1     pooka 
    146  1.1     pooka }
    147  1.1     pooka 
    148  1.1     pooka ATF_TP_ADD_TCS(tp)
    149  1.1     pooka {
    150  1.1     pooka 	ATF_TP_ADD_TC(tp, basic);
    151  1.1     pooka 	return 0; /*XXX?*/
    152  1.1     pooka }
    153