Home | History | Annotate | Line # | Download | only in umapfs
t_basic.c revision 1.4.28.1
      1  1.4.28.1  pgoyette /*	$NetBSD: t_basic.c,v 1.4.28.1 2017/03/20 06:57:56 pgoyette 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.4.28.1  pgoyette #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 static void
     32       1.1     pooka xtouch(const char *path)
     33       1.1     pooka {
     34       1.1     pooka 	int fd;
     35       1.1     pooka 
     36       1.1     pooka 	fd = rump_sys_open(path, O_CREAT | O_RDWR, 0777);
     37       1.1     pooka 	if (fd == -1)
     38       1.1     pooka 		atf_tc_fail_errno("create %s", path);
     39       1.1     pooka 	rump_sys_close(fd);
     40       1.1     pooka }
     41       1.1     pooka 
     42       1.1     pooka static void
     43       1.1     pooka xchown(const char *path, uid_t uid, gid_t gid)
     44       1.1     pooka {
     45       1.1     pooka 
     46       1.1     pooka 	if (rump_sys_chown(path, uid, gid) == -1)
     47       1.1     pooka 		atf_tc_fail_errno("chown %s failed", path);
     48       1.1     pooka }
     49       1.1     pooka 
     50       1.1     pooka static void
     51       1.1     pooka testuidgid(const char *path, uid_t uid, gid_t gid)
     52       1.1     pooka {
     53       1.1     pooka 	struct stat sb;
     54       1.1     pooka 
     55       1.4     pooka 	if (rump_sys_stat(path, &sb) == -1)
     56       1.1     pooka 		atf_tc_fail_errno("stat %s", path);
     57       1.1     pooka 	if (uid != (uid_t)-1) {
     58       1.1     pooka 		if (sb.st_uid != uid)
     59       1.1     pooka 			atf_tc_fail("%s: expected uid %d, got %d",
     60       1.1     pooka 			    path, uid, sb.st_uid);
     61       1.1     pooka 	}
     62       1.1     pooka 	if (gid != (gid_t)-1) {
     63       1.1     pooka 		if (sb.st_gid != gid)
     64       1.1     pooka 			atf_tc_fail("%s: expected gid %d, got %d",
     65       1.1     pooka 			    path, gid, sb.st_gid);
     66       1.1     pooka 	}
     67       1.1     pooka }
     68       1.1     pooka 
     69       1.1     pooka ATF_TC_BODY(basic, tc)
     70       1.1     pooka {
     71       1.1     pooka 	struct umap_args umargs;
     72       1.1     pooka 	struct tmpfs_args targs;
     73       1.1     pooka 	u_long umaps[2][2];
     74       1.1     pooka 	u_long gmaps[2][2];
     75       1.1     pooka 
     76       1.1     pooka 	rump_init();
     77       1.1     pooka 	if (rump_sys_mkdir("/td1", 0777) == -1)
     78       1.1     pooka 		atf_tc_fail_errno("mp1");
     79       1.1     pooka 	if (rump_sys_mkdir("/td2", 0777) == -1)
     80       1.1     pooka 		atf_tc_fail_errno("mp1");
     81       1.1     pooka 
     82       1.1     pooka 	/* use tmpfs because rumpfs doesn't support ownership */
     83       1.1     pooka 	memset(&targs, 0, sizeof(targs));
     84       1.1     pooka 	targs.ta_version = TMPFS_ARGS_VERSION;
     85       1.1     pooka 	targs.ta_root_mode = 0777;
     86       1.1     pooka 	if (rump_sys_mount(MOUNT_TMPFS, "/td1", 0, &targs, sizeof(targs)) == -1)
     87       1.1     pooka 		atf_tc_fail_errno("could not mount tmpfs td1");
     88       1.1     pooka 
     89       1.1     pooka 	memset(&umargs, 0, sizeof(umargs));
     90       1.1     pooka 
     91       1.1     pooka 	/*
     92       1.1     pooka 	 * Map td1 uid 555 to td2 uid 777 (yes, IMHO the umapfs
     93       1.1     pooka 	 * mapping format is counter-intuitive).
     94       1.1     pooka 	 */
     95       1.1     pooka 	umaps[0][0] = 777;
     96       1.1     pooka 	umaps[0][1] = 555;
     97       1.1     pooka 	umaps[1][0] = 0;
     98       1.1     pooka 	umaps[1][1] = 0;
     99       1.1     pooka 	gmaps[0][0] = 4321;
    100       1.1     pooka 	gmaps[0][1] = 1234;
    101       1.1     pooka 	gmaps[1][0] = 0;
    102       1.1     pooka 	gmaps[1][1] = 0;
    103       1.1     pooka 
    104       1.1     pooka 	umargs.umap_target = __UNCONST("/td1");
    105       1.1     pooka 	umargs.nentries = 2;
    106       1.1     pooka 	umargs.gnentries = 2;
    107       1.1     pooka 	umargs.mapdata = umaps;
    108       1.1     pooka 	umargs.gmapdata = gmaps;
    109       1.1     pooka 
    110       1.1     pooka 	if (rump_sys_mount(MOUNT_UMAP, "/td2", 0, &umargs,sizeof(umargs)) == -1)
    111       1.1     pooka 		atf_tc_fail_errno("could not mount umapfs");
    112       1.1     pooka 
    113       1.1     pooka 	xtouch("/td1/noch");
    114       1.1     pooka 	testuidgid("/td1/noch", 0, 0);
    115       1.1     pooka 	testuidgid("/td2/noch", 0, 0);
    116       1.1     pooka 
    117       1.1     pooka 	xtouch("/td1/nomap");
    118       1.1     pooka 	xchown("/td1/nomap", 1, 2);
    119       1.1     pooka 	testuidgid("/td1/nomap", 1, 2);
    120       1.1     pooka 	testuidgid("/td2/nomap", -1, -1);
    121       1.1     pooka 
    122       1.1     pooka 	xtouch("/td1/forwmap");
    123       1.1     pooka 	xchown("/td1/forwmap", 555, 1234);
    124       1.1     pooka 	testuidgid("/td1/forwmap", 555, 1234);
    125       1.1     pooka 	testuidgid("/td2/forwmap", 777, 4321);
    126       1.1     pooka 
    127       1.1     pooka 	/*
    128       1.1     pooka 	 * this *CANNOT* be correct???
    129       1.1     pooka 	 */
    130       1.1     pooka 	xtouch("/td1/revmap");
    131       1.1     pooka 	/*
    132       1.1     pooka 	 * should be 777 / 4321 (?), but makes first test fail since
    133       1.1     pooka 	 * it gets 777 / 4321, i.e. unmapped results.
    134       1.1     pooka 	 */
    135       1.1     pooka 	xchown("/td2/revmap", 555, 1234);
    136       1.1     pooka 	testuidgid("/td1/revmap", 555, 1234);
    137       1.1     pooka 	testuidgid("/td2/revmap", 777, 4321);
    138       1.1     pooka 
    139       1.1     pooka }
    140       1.1     pooka 
    141       1.1     pooka ATF_TP_ADD_TCS(tp)
    142       1.1     pooka {
    143       1.1     pooka 	ATF_TP_ADD_TC(tp, basic);
    144       1.1     pooka 	return 0; /*XXX?*/
    145       1.1     pooka }
    146