static void * wrkwrkwrk(void *unused) { int fd, fail; fail = 0; rump_sys_chdir(FSTEST_MNTNAME); while (!quit) { fd = rump_sys_open("file", O_RDWR | O_CREAT); if (fd == -1) { if (errno == EACCES) { fail++; break; } } rump_sys_close(fd); if (rump_sys_unlink("file") == -1) { if (errno == EACCES) { fail++; break; } } } rump_sys_chdir("/"); quit = 1; return fail ? wrkwrkwrk : NULL; }
static void read_after_unlink(const atf_tc_t *tc, const char *mp) { char buf[TBSIZE], buf2[TBSIZE]; int fd; FSTEST_ENTER(); /* create file and put some content into it */ RL(fd = rump_sys_open("file", O_RDWR|O_CREAT, 0666)); memset(buf, 'D', TBSIZE); ATF_REQUIRE_EQ(rump_sys_write(fd, buf, TBSIZE), TBSIZE); rump_sys_close(fd); /* flush buffers from UBC to file system */ ATF_REQUIRE_ERRNO(EBUSY, rump_sys_unmount(mp, 0) == -1); RL(fd = rump_sys_open("file", O_RDWR)); RL(rump_sys_unlink("file")); ATF_REQUIRE_EQ(rump_sys_read(fd, buf2, TBSIZE), TBSIZE); ATF_REQUIRE_EQ(memcmp(buf, buf2, TBSIZE), 0); rump_sys_close(fd); FSTEST_EXIT(); }
static void dir_notempty(const atf_tc_t *tc, const char *mountpath) { char pb[MAXPATHLEN], pb2[MAXPATHLEN]; int fd, rv; USES_DIRS; /* check we can create directories */ sprintf(pb, "%s/dir", mountpath); if (rump_sys_mkdir(pb, 0777) == -1) atf_tc_fail_errno("mkdir"); sprintf(pb2, "%s/dir/file", mountpath); fd = rump_sys_open(pb2, O_RDWR | O_CREAT, 0777); if (fd == -1) atf_tc_fail_errno("create file"); rump_sys_close(fd); rv = rump_sys_rmdir(pb); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rv != -1 || errno != ENOTEMPTY) atf_tc_fail("non-empty directory removed succesfully"); if (rump_sys_unlink(pb2) == -1) atf_tc_fail_errno("cannot remove dir/file"); if (rump_sys_rmdir(pb) == -1) atf_tc_fail_errno("remove directory"); }
static void dirperms(const atf_tc_t *tc, const char *mp) { char name[] = "dir.test/file.test"; char *dir = dirname(name); int fd; if (FSTYPE_SYSVBFS(tc)) atf_tc_skip("directories not supported by file system"); FSTEST_ENTER(); if (rump_sys_mkdir(dir, 0777) == -1) atf_tc_fail_errno("mkdir"); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rump_sys_open(name, O_RDWR|O_CREAT, 0666) != -1 || errno != EACCES) atf_tc_fail_errno("open"); rump_pub_lwproc_releaselwp(); if ((fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)) == -1) atf_tc_fail_errno("open"); if (rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (rump_sys_unlink(name) != -1 || errno != EACCES) atf_tc_fail_errno("unlink"); rump_pub_lwproc_releaselwp(); if (rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); if (rump_sys_rmdir(dir) == -1) atf_tc_fail_errno("rmdir"); FSTEST_EXIT(); }
static void create_exist(const atf_tc_t *tc, const char *mp) { const char *name = "hoge"; int fd; RL(rump_sys_chdir(mp)); RL(fd = rump_sys_open(name, O_RDWR|O_CREAT|O_EXCL, 0666)); RL(rump_sys_close(fd)); RL(rump_sys_unlink(name)); RL(fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)); RL(rump_sys_close(fd)); RL(fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)); RL(rump_sys_close(fd)); ATF_REQUIRE_ERRNO(EEXIST, (fd = rump_sys_open(name, O_RDWR|O_CREAT|O_EXCL, 0666))); RL(rump_sys_unlink(name)); RL(rump_sys_chdir("/")); }
static void times(const atf_tc_t *tc, const char *mp) { const char *name = "file.test"; int fd; unsigned int i, j; struct timeval tmv[2]; static struct timeval tmvs[] = { { QUAD_MIN, 0 }, { 0, 0 }, { QUAD_MAX, 999999 } }; FSTEST_ENTER(); if ((fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)) == -1) atf_tc_fail_errno("open"); if (rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rump_sys_utimes(name, NULL) != -1 || errno != EACCES) atf_tc_fail_errno("utimes"); rump_pub_lwproc_releaselwp(); if (rump_sys_utimes(name, NULL) == -1) atf_tc_fail_errno("utimes"); for (i = 0; i < sizeof(tmvs) / sizeof(tmvs[0]); i++) { for (j = 0; j < sizeof(tmvs) / sizeof(tmvs[0]); j++) { tmv[0] = tmvs[i]; tmv[1] = tmvs[j]; rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); if (rump_sys_utimes(name, tmv) != -1 || errno != EPERM) atf_tc_fail_errno("utimes"); rump_pub_lwproc_releaselwp(); if (rump_sys_utimes(name, tmv) == -1) atf_tc_fail_errno("utimes"); } } if (rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); FSTEST_EXIT(); }
static void rename_nametoolong(const atf_tc_t *tc, const char *mp) { char *name; int res, fd; long val; size_t len; if (FSTYPE_RUMPFS(tc)) atf_tc_skip("rename not supported by file system"); if (rump_sys_chdir(mp) == -1) atf_tc_fail_errno("chdir mountpoint"); val = rump_sys_pathconf(".", _PC_NAME_MAX); if (val == -1) atf_tc_fail_errno("pathconf"); len = val + 1; name = malloc(len+1); if (name == NULL) atf_tc_fail_errno("malloc"); memset(name, 'a', len); *(name+len) = '\0'; fd = rump_sys_open("dummy", O_RDWR|O_CREAT, 0666); if (fd == -1) atf_tc_fail_errno("open"); if (rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); val = rump_sys_pathconf(".", _PC_NO_TRUNC); if (val == -1) atf_tc_fail_errno("pathconf"); res = rump_sys_rename("dummy", name); if (val != 0 && (res != -1 || errno != ENAMETOOLONG)) atf_tc_fail_errno("rename"); if (val == 0 && rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); free(name); rump_sys_chdir("/"); }
static void flags(const atf_tc_t *tc, const char *mp) { const char *name = "file.test"; int fd, fflags; struct stat st; FSTEST_ENTER(); if ((fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666)) == -1) atf_tc_fail_errno("open"); if (rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); if (rump_sys_stat(name, &st) == -1) atf_tc_fail_errno("stat"); if (FSTYPE_ZFS(tc)) atf_tc_expect_fail("PR kern/47656: Test known to be broken"); if (rump_sys_chflags(name, st.st_flags) == -1) { if (errno == EOPNOTSUPP) atf_tc_skip("file flags not supported by file system"); atf_tc_fail_errno("chflags"); } fflags = st.st_flags | UF_IMMUTABLE; rump_pub_lwproc_rfork(RUMP_RFCFDG); if (rump_sys_setuid(1) == -1) atf_tc_fail_errno("setuid"); fflags |= UF_IMMUTABLE; if (rump_sys_chflags(name, fflags) != -1 || errno != EPERM) atf_tc_fail_errno("chflags"); rump_pub_lwproc_releaselwp(); if (rump_sys_chflags(name, fflags) == -1) atf_tc_fail_errno("chflags"); fflags &= ~UF_IMMUTABLE; if (rump_sys_chflags(name, fflags) == -1) atf_tc_fail_errno("chflags"); if (rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); FSTEST_EXIT(); }
static void create_nametoolong(const atf_tc_t *tc, const char *mp) { char *name; int fd; long val; size_t len; if (rump_sys_chdir(mp) == -1) atf_tc_fail_errno("chdir mountpoint"); val = rump_sys_pathconf(".", _PC_NAME_MAX); if (val == -1) atf_tc_fail_errno("pathconf"); len = val + 1; name = malloc(len+1); if (name == NULL) atf_tc_fail_errno("malloc"); memset(name, 'a', len); *(name+len) = '\0'; val = rump_sys_pathconf(".", _PC_NO_TRUNC); if (val == -1) atf_tc_fail_errno("pathconf"); fd = rump_sys_open(name, O_RDWR|O_CREAT, 0666); if (val != 0 && (fd != -1 || errno != ENAMETOOLONG)) atf_tc_fail_errno("open"); if (val == 0 && rump_sys_close(fd) == -1) atf_tc_fail_errno("close"); if (val == 0 && rump_sys_unlink(name) == -1) atf_tc_fail_errno("unlink"); free(name); rump_sys_chdir("/"); }
/* * Test creating a symlink whose length is "len" bytes, not including * the terminating NUL. */ static void symlink_len(const atf_tc_t *tc, const char *mp, size_t len) { char *buf; int r; USES_SYMLINKS; RL(rump_sys_chdir(mp)); buf = malloc(len + 1); ATF_REQUIRE(buf); memset(buf, 'a', len); buf[len] = '\0'; r = rump_sys_symlink(buf, "afile"); if (r == -1) { ATF_REQUIRE_ERRNO(ENAMETOOLONG, r); } else { RL(rump_sys_unlink("afile")); } free(buf); RL(rump_sys_chdir("/")); }
int copy_file(FTSENT *entp, int dne) { static unsigned char buf[MAXBSIZE]; struct stat to_stat, *fs; int ch, checkch, rv, rcount, rval, tolnk, wcount, fdin, fdout; off_t off; fs = entp->fts_statp; tolnk = ((Rflag && !(Lflag || Hflag)) || Pflag); /* * If the file exists and we're interactive, verify with the user. * If the file DNE, set the mode to be the from file, minus setuid * bits, modified by the umask; arguably wrong, but it makes copying * executables work right and it's been that way forever. (The * other choice is 666 or'ed with the execute bits on the from file * modified by the umask.) */ if (!dne) { if (iflag) { (void)fprintf(stderr, "overwrite %s? ", to.p_path); checkch = ch = getchar(); while (ch != '\n' && ch != EOF) ch = getchar(); if (checkch != 'y' && checkch != 'Y') return (0); } rump_sys_unlink(to.p_path); } rv = rump_sys_open(to.p_path, fs->st_mode & ~(S_ISUID | S_ISGID)); if (rv == -1 && (fflag || tolnk)) { /* * attempt to remove existing destination file name and * create a new file */ rump_sys_unlink(to.p_path); rv = rump_sys_open(to.p_path, fs->st_mode & ~(S_ISUID | S_ISGID)); if (rv == -1) { warn("%s", to.p_path); return (1); } } fdout = rv; fdin = rump_sys_open(entp->fts_path, O_RDONLY); rval = 0; /* * There's no reason to do anything other than close the file * now if it's empty, so let's not bother. */ off = 0; if (fs->st_size > 0) { while ((rcount = rump_sys_read(fdin, buf, MAXBSIZE)) > 0) { wcount = rump_sys_write(fdout, buf, (size_t)rcount); if (rcount != wcount || wcount == -1) { warn("%s", to.p_path); rval = 1; break; } off += rcount; } if (rcount < 0) { warn("%s", entp->fts_path); rval = 1; } } if (rval == 1) return (1); if (pflag && setfile(fs, 0)) rval = 1; /* * If the source was setuid or setgid, lose the bits unless the * copy is owned by the same user and group. */ #define RETAINBITS \ (S_ISUID | S_ISGID | S_ISVTX | S_IRWXU | S_IRWXG | S_IRWXO) if (!pflag && dne && fs->st_mode & (S_ISUID | S_ISGID) && fs->st_uid == myuid) { if (rump_sys_stat(to.p_path, &to_stat)) { warn("%s", to.p_path); rval = 1; } else if (fs->st_gid == to_stat.st_gid && rump_sys_chmod(to.p_path, fs->st_mode & RETAINBITS & ~myumask)) { warn("%s", to.p_path); rval = 1; } } /* set the mod/access times now after close of the fd */ if (pflag && set_utimes(to.p_path, fs)) { rval = 1; } return (rval); }
/* * Adds the entry into the rpcbind database. * If PORTMAP, then for UDP and TCP, it adds the entries for version 2 also * Returns 0 if succeeds, else fails */ static int init_transport(struct netconfig *nconf) { int fd; struct t_bind taddr; struct addrinfo hints, *res = NULL; struct __rpc_sockinfo si; SVCXPRT *my_xprt; int status; /* bound checking ? */ int aicode; int addrlen; struct sockaddr *sa; struct sockaddr_un sun; const int one = 1; if ((nconf->nc_semantics != NC_TPI_CLTS) && (nconf->nc_semantics != NC_TPI_COTS) && (nconf->nc_semantics != NC_TPI_COTS_ORD)) return 1; /* not my type */ #ifdef RPCBIND_DEBUG if (debugging) { int i; char **s; (void)fprintf(stderr, "%s: %ld lookup routines :\n", nconf->nc_netid, nconf->nc_nlookups); for (i = 0, s = nconf->nc_lookups; i < nconf->nc_nlookups; i++, s++) (void)fprintf(stderr, "[%d] - %s\n", i, *s); } #endif /* * XXX - using RPC library internal functions. */ if ((fd = __rpc_nconf2fd(nconf)) < 0) { if (errno == EAFNOSUPPORT) return 1; warn("Cannot create socket for `%s'", nconf->nc_netid); return 1; } if (!__rpc_nconf2sockinfo(nconf, &si)) { warnx("Cannot get information for `%s'", nconf->nc_netid); return 1; } if (si.si_af == AF_INET6) { /* * We're doing host-based access checks here, so don't allow * v4-in-v6 to confuse things. */ if (setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &one, sizeof one) < 0) { warn("Can't make socket ipv6 only"); return 1; } } if (!strcmp(nconf->nc_netid, "local")) { (void)memset(&sun, 0, sizeof sun); sun.sun_family = AF_LOCAL; #ifdef RPCBIND_RUMP (void)rump_sys_unlink(_PATH_RPCBINDSOCK); #else (void)unlink(_PATH_RPCBINDSOCK); #endif (void)strlcpy(sun.sun_path, _PATH_RPCBINDSOCK, sizeof(sun.sun_path)); sun.sun_len = SUN_LEN(&sun); addrlen = sizeof(struct sockaddr_un); sa = (struct sockaddr *)&sun; } else { /* Get rpcbind's address on this transport */ (void)memset(&hints, 0, sizeof hints); hints.ai_flags = AI_PASSIVE; hints.ai_family = si.si_af; hints.ai_socktype = si.si_socktype; hints.ai_protocol = si.si_proto; if ((aicode = getaddrinfo(NULL, servname, &hints, &res)) != 0) { warnx("Cannot get local address for `%s' (%s)", nconf->nc_netid, gai_strerror(aicode)); return 1; } addrlen = res->ai_addrlen; sa = (struct sockaddr *)res->ai_addr; } if (bind(fd, sa, addrlen) < 0) { warn("Cannot bind `%s'", nconf->nc_netid); if (res != NULL) freeaddrinfo(res); return 1; } #ifndef RPCBIND_RUMP if (sa->sa_family == AF_LOCAL) if (chmod(sun.sun_path, S_IRWXU|S_IRWXG|S_IRWXO) == -1) warn("Cannot chmod `%s'", sun.sun_path); #endif /* Copy the address */ taddr.addr.len = taddr.addr.maxlen = addrlen; taddr.addr.buf = malloc(addrlen); if (taddr.addr.buf == NULL) { warn("Cannot allocate memory for `%s' address", nconf->nc_netid); if (res != NULL) freeaddrinfo(res); return 1; } (void)memcpy(taddr.addr.buf, sa, addrlen); #ifdef RPCBIND_DEBUG if (debugging) { /* for debugging print out our universal address */ char *uaddr; struct netbuf nb; nb.buf = sa; nb.len = nb.maxlen = sa->sa_len; uaddr = taddr2uaddr(nconf, &nb); (void)fprintf(stderr, "rpcbind: my address is %s fd=%d\n", uaddr, fd); (void)free(uaddr); } #endif if (res != NULL) freeaddrinfo(res); if (nconf->nc_semantics != NC_TPI_CLTS) listen(fd, SOMAXCONN); my_xprt = (SVCXPRT *)svc_tli_create(fd, nconf, &taddr, RPC_MAXDATASIZE, RPC_MAXDATASIZE); if (my_xprt == NULL) { warnx("Could not create service for `%s'", nconf->nc_netid); goto error; } #ifdef PORTMAP /* * Register both the versions for tcp/ip, udp/ip and local. */ if ((strcmp(nconf->nc_protofmly, NC_INET) == 0 && (strcmp(nconf->nc_proto, NC_TCP) == 0 || strcmp(nconf->nc_proto, NC_UDP) == 0)) || strcmp(nconf->nc_netid, "local") == 0) { struct pmaplist *pml; if (!svc_register(my_xprt, PMAPPROG, PMAPVERS, pmap_service, 0)) { warn("Could not register on `%s'", nconf->nc_netid); goto error; } pml = malloc(sizeof (struct pmaplist)); if (pml == NULL) { warn("Cannot allocate memory"); goto error; } pml->pml_map.pm_prog = PMAPPROG; pml->pml_map.pm_vers = PMAPVERS; pml->pml_map.pm_port = PMAPPORT; if (strcmp(nconf->nc_proto, NC_TCP) == 0) { if (tcptrans[0]) { warnx( "Cannot have more than one TCP transport"); free(pml); goto error; } tcptrans = strdup(nconf->nc_netid); if (tcptrans == NULL) { free(pml); warn("Cannot allocate memory"); goto error; } pml->pml_map.pm_prot = IPPROTO_TCP; /* Let's snarf the universal address */ /* "h1.h2.h3.h4.p1.p2" */ tcp_uaddr = taddr2uaddr(nconf, &taddr.addr); } else if (strcmp(nconf->nc_proto, NC_UDP) == 0) { if (udptrans[0]) { free(pml); warnx( "Cannot have more than one UDP transport"); goto error; } udptrans = strdup(nconf->nc_netid); if (udptrans == NULL) { free(pml); warn("Cannot allocate memory"); goto error; } pml->pml_map.pm_prot = IPPROTO_UDP; /* Let's snarf the universal address */ /* "h1.h2.h3.h4.p1.p2" */ udp_uaddr = taddr2uaddr(nconf, &taddr.addr); } pml->pml_next = list_pml; list_pml = pml; /* Add version 3 information */ pml = malloc(sizeof (struct pmaplist)); if (pml == NULL) { warn("Cannot allocate memory"); goto error; } pml->pml_map = list_pml->pml_map; pml->pml_map.pm_vers = RPCBVERS; pml->pml_next = list_pml; list_pml = pml; /* Add version 4 information */ pml = malloc(sizeof (struct pmaplist)); if (pml == NULL) { warn("Cannot allocate memory"); goto error; } pml->pml_map = list_pml->pml_map; pml->pml_map.pm_vers = RPCBVERS4; pml->pml_next = list_pml; list_pml = pml; /* Also add version 2 stuff to rpcbind list */ rbllist_add(PMAPPROG, PMAPVERS, nconf, &taddr.addr); } #endif /* version 3 registration */ if (!svc_reg(my_xprt, RPCBPROG, RPCBVERS, rpcb_service_3, NULL)) { warn("Could not register %s version 3", nconf->nc_netid); goto error; } rbllist_add(RPCBPROG, RPCBVERS, nconf, &taddr.addr); /* version 4 registration */ if (!svc_reg(my_xprt, RPCBPROG, RPCBVERS4, rpcb_service_4, NULL)) { warn("Could not register %s version 4", nconf->nc_netid); goto error; } rbllist_add(RPCBPROG, RPCBVERS4, nconf, &taddr.addr); /* decide if bound checking works for this transport */ status = add_bndlist(nconf, &taddr.addr); #ifdef RPCBIND_DEBUG if (debugging) { if (status < 0) { fprintf(stderr, "Error in finding bind status for %s\n", nconf->nc_netid); } else if (status == 0) { fprintf(stderr, "check binding for %s\n", nconf->nc_netid); } else if (status > 0) { fprintf(stderr, "No check binding for %s\n", nconf->nc_netid); } } #else __USE(status); #endif /* * rmtcall only supported on CLTS transports for now. */ if (nconf->nc_semantics == NC_TPI_CLTS) { status = create_rmtcall_fd(nconf); #ifdef RPCBIND_DEBUG if (debugging) { if (status < 0) { fprintf(stderr, "Could not create rmtcall fd for %s\n", nconf->nc_netid); } else { fprintf(stderr, "rmtcall fd for %s is %d\n", nconf->nc_netid, status); } } #endif } return (0); error: #ifdef RPCBIND_RUMP (void)rump_sys_close(fd); #else (void)close(fd); #endif return (1); }