Beispiel #1
0
ATF_TC_BODY(setlogin_err, tc)
{
	char buf[MAXLOGNAME + 1];
	char *name;
	pid_t pid;
	int sta;

	pid = fork();
	ATF_REQUIRE(pid >= 0);

	(void)memset(buf, 'x', sizeof(buf));

	if (pid == 0) {

		(void)setsid();

		errno = 0;

		if (setlogin(buf) != -1)
			_exit(EINVAL);

		if (errno != EINVAL)
			_exit(EINVAL);

		errno = 0;

		if (setlogin((void *)-1) != -1)
			_exit(EFAULT);

		if (errno != EFAULT)
			_exit(EFAULT);

		name = getlogin();

		if (name == NULL)
			_exit(EXIT_FAILURE);

		if (strcmp(name, "foobar") == 0)
			_exit(EXIT_FAILURE);

		_exit(EXIT_SUCCESS);
	}

	(void)wait(&sta);

	if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS) {

		if (WEXITSTATUS(sta) == EFAULT)
			atf_tc_fail("expected EFAULT, but the call succeeded");

		if (WEXITSTATUS(sta) == EINVAL)
			atf_tc_fail("expected EINVAL, but the call succeeded");

		atf_tc_fail("setlogin(2) failed, but login name was set");
	}
}
Beispiel #2
0
ATF_TC_BODY(ia_na_negative, tc)
{
    uint32_t iaid;
    struct ia_xx *ia_na;
    struct ia_xx *ia_na_copy;

    /* set up dhcp globals */
    dhcp_context_create();

    /* tests */
    /* bogus allocate arguments */
    if (ia_allocate(NULL, 123, "", 0, MDL) != DHCP_R_INVALIDARG) {
        atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL);
    }
    ia_na = (struct ia_xx *)1;
    if (ia_allocate(&ia_na, 456, "", 0, MDL) != DHCP_R_INVALIDARG) {
        atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL);
    }

    /* bogus reference arguments */
    iaid = 666;
    ia_na = NULL;
    if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
        atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL);
    }
    if (ia_reference(NULL, ia_na, MDL) != DHCP_R_INVALIDARG) {
        atf_tc_fail("ERROR: ia_reference() %s:%d", MDL);
    }
    ia_na_copy = (struct ia_xx *)1;
    if (ia_reference(&ia_na_copy, ia_na, MDL) != DHCP_R_INVALIDARG) {
        atf_tc_fail("ERROR: ia_reference() %s:%d", MDL);
    }
    ia_na_copy = NULL;
    if (ia_reference(&ia_na_copy, NULL, MDL) != DHCP_R_INVALIDARG) {
        atf_tc_fail("ERROR: ia_reference() %s:%d", MDL);
    }
    if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
        atf_tc_fail("ERROR: ia_dereference() %s:%d", MDL);
    }

    /* bogus dereference arguments */
    if (ia_dereference(NULL, MDL) != DHCP_R_INVALIDARG) {
        atf_tc_fail("ERROR: ia_dereference() %s:%d", MDL);
    }

    /* bogus remove */
    iaid = 666;
    ia_na = NULL;
    if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
        atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL);
    }
    ia_remove_iasubopt(ia_na, NULL, MDL);
    if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
        atf_tc_fail("ERROR: ia_dereference() %s:%d", MDL);
    }
}
Beispiel #3
0
ATF_TC_BODY(setrlimit_memlock, tc)
{
	struct rlimit res;
	void *buf;
	long page;
	pid_t pid;
	int sta;

#ifdef __FreeBSD__
	/* Set max_wired really really high to avoid EAGAIN */
	set_vm_max_wired(INT_MAX);
#endif

	page = sysconf(_SC_PAGESIZE);
	ATF_REQUIRE(page >= 0);

	buf = malloc(page);
	pid = fork();

	if (buf == NULL || pid < 0)
		atf_tc_fail("initialization failed");

	if (pid == 0) {

		/*
		 * Try to lock a page while
		 * RLIMIT_MEMLOCK is zero.
		 */
		if (mlock(buf, page) != 0)
			_exit(EXIT_FAILURE);

		if (munlock(buf, page) != 0)
			_exit(EXIT_FAILURE);

		res.rlim_cur = 0;
		res.rlim_max = 0;

		if (setrlimit(RLIMIT_MEMLOCK, &res) != 0)
			_exit(EXIT_FAILURE);

		if (mlock(buf, page) != 0)
			_exit(EXIT_SUCCESS);

		(void)munlock(buf, page);

		_exit(EXIT_FAILURE);
	}

	free(buf);

	(void)wait(&sta);

	if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
		atf_tc_fail("RLIMIT_MEMLOCK not enforced");
}
Beispiel #4
0
ATF_TC_BODY(connect_low_port, tc)
{
	struct sockaddr_in sin, sinlist;
	int sd, val, slist;
	socklen_t slen;

	slist = socket(AF_INET, SOCK_STREAM, 0);
	sd = socket(AF_INET, SOCK_STREAM, 0);

#ifdef __FreeBSD__
	ATF_REQUIRE(sd > 0);
	ATF_REQUIRE(slist > 0);
#endif

	/* bind listening socket */
	memset(&sinlist, 0, sizeof(sinlist));
	sinlist.sin_family = AF_INET;
	sinlist.sin_port = htons(31522);
	sinlist.sin_addr.s_addr = inet_addr("127.0.0.1");

	ATF_REQUIRE_EQ(bind(slist,
	    (struct sockaddr *)&sinlist, sizeof(sinlist)), 0);
	ATF_REQUIRE_EQ(listen(slist, 1), 0);

	val = IP_PORTRANGE_LOW;
	if (setsockopt(sd, IPPROTO_IP, IP_PORTRANGE, &val,
	    sizeof(val)) == -1)
		atf_tc_fail("setsockopt failed: %s", strerror(errno));

	memset(&sin, 0, sizeof(sin));

	sin.sin_port = htons(31522);
	sin.sin_addr.s_addr = inet_addr("127.0.0.1");
	sin.sin_family = AF_INET;

	if (connect(sd, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
		int serrno = errno;
		atf_tc_fail("connect failed: %s%s",
		    strerror(serrno),
		    serrno != EACCES ? "" :
		    " (see http://mail-index.netbsd.org/"
		    "source-changes/2007/12/16/0011.html)");
	}

	slen = sizeof(sin);
	ATF_REQUIRE_EQ(getsockname(sd, (struct sockaddr *)&sin, &slen), 0);
	ATF_REQUIRE_EQ(slen, sizeof(sin));
	ATF_REQUIRE(ntohs(sin.sin_port) <= IPPORT_RESERVEDMAX);

	close(sd);
#ifdef __FreeBSD__
	close(slist);
#endif
}
Beispiel #5
0
ATF_TC_BODY(rcvbuf_oversized, tc)
{
	int s, i, j;
	int sv[2];
	const size_t sndbufsize = 8192;
	const size_t rcvbufsize = 131072;
	const size_t geom_mean_bufsize = 32768;
	const int pktsize = 1024;
	char sndbuf[pktsize];
	char recv_buf[pktsize];
	size_t datalen;
	ssize_t ssize, rsize;

	/* setup the socket pair */
	do_socketpair_nonblocking(sv);

	/* 
	 * Send and receive packets that are collectively greater than the send
	 * buffer, but less than the receive buffer
	 */
	for (i=0; i < geom_mean_bufsize / pktsize; i++) {
		/* Fill the buffer */
		memset(sndbuf, i, pktsize);

		/* send the packet */
		ssize = send(sv[0], sndbuf, pktsize, MSG_EOR);
		if (ssize < 0) {
			perror("send");
			atf_tc_fail("send returned < 0");
		}
		ATF_CHECK_EQ_MSG(pktsize, ssize,
		    "expected %zd=send(...) but got %zd", pktsize, ssize);

		/* Receive it */

		rsize = recv(sv[1], recv_buf, pktsize, MSG_WAITALL);
		if (rsize < 0) {
			perror("recv");
			atf_tc_fail("recv returned < 0");
		}
		ATF_CHECK_EQ_MSG(pktsize, rsize,
		    "expected %zd=send(...) but got %zd", pktsize, rsize);

		/* Verify the contents */
		ATF_CHECK_EQ_MSG(0, memcmp(sndbuf, recv_buf, pktsize), 
		    "Received data miscompare");
	}

	/* Trying to receive again should return EAGAIN */
	rsize = recv(sv[1], recv_buf, pktsize, MSG_WAITALL);
	ATF_CHECK_EQ(EAGAIN, errno);
	ATF_CHECK_EQ(-1, rsize);
}
Beispiel #6
0
ATF_TC_BODY(setrlimit_basic, tc)
{
	struct rlimit res;
	int *buf, lim;
	size_t i;

	buf = calloc(__arraycount(rlimit), sizeof(int));

	if (buf == NULL)
		atf_tc_fail("initialization failed");

	for (i = lim = 0; i < __arraycount(rlimit); i++) {

		(void)memset(&res, 0, sizeof(struct rlimit));

		if (getrlimit(rlimit[i], &res) != 0)
			continue;

		if (res.rlim_cur == RLIM_INFINITY || res.rlim_cur == 0)
			continue;

		if (res.rlim_cur == res.rlim_max) /* An unprivileged run. */
			continue;

		buf[i] = res.rlim_cur;
		res.rlim_cur = res.rlim_cur - 1;

		if (setrlimit(rlimit[i], &res) != 0) {
			lim = rlimit[i];
			goto out;
		}
	}

out:
	for (i = 0; i < __arraycount(rlimit); i++) {

		(void)memset(&res, 0, sizeof(struct rlimit));

		if (buf[i] == 0)
			continue;

		if (getrlimit(rlimit[i], &res) != 0)
			continue;

		res.rlim_cur = buf[i];

		(void)setrlimit(rlimit[i], &res);
	}

	if (lim != 0)
		atf_tc_fail("failed to set limit (%d)", lim);
	free(buf);
}
Beispiel #7
0
ATF_TC_BODY(aio_fifo_test, tc)
{
	int error, read_fd = -1, write_fd = -1;
	struct aio_fifo_arg arg;
	char pathname[PATH_MAX];
	struct aio_context ac;

	ATF_REQUIRE_KERNEL_MODULE("aio");
	ATF_REQUIRE_UNSAFE_AIO();

	/*
	 * In theory, mkstemp() can return a name that is then collided with.
	 * Because this is a regression test, we treat that as a test failure
	 * rather than retrying.
	 */
	strcpy(pathname, PATH_TEMPLATE);
	ATF_REQUIRE_MSG(mkstemp(pathname) != -1,
	    "mkstemp failed: %s", strerror(errno));
	ATF_REQUIRE_MSG(unlink(pathname) == 0,
	    "unlink failed: %s", strerror(errno));
	ATF_REQUIRE_MSG(mkfifo(pathname, 0600) != -1,
	    "mkfifo failed: %s", strerror(errno));
	arg.afa_pathname = pathname;
	arg.afa_read_fd = -1;
	arg.afa_write_fd = -1;

	read_fd = open(pathname, O_RDONLY | O_NONBLOCK);
	if (read_fd == -1) {
		error = errno;
		aio_fifo_cleanup(&arg);
		errno = error;
		atf_tc_fail("read_fd open failed: %s",
		    strerror(errno));
	}
	arg.afa_read_fd = read_fd;

	write_fd = open(pathname, O_WRONLY);
	if (write_fd == -1) {
		error = errno;
		aio_fifo_cleanup(&arg);
		errno = error;
		atf_tc_fail("write_fd open failed: %s",
		    strerror(errno));
	}
	arg.afa_write_fd = write_fd;

	aio_context_init(&ac, read_fd, write_fd, FIFO_LEN,
	    FIFO_TIMEOUT, aio_fifo_cleanup, &arg);
	aio_write_test(&ac);
	aio_read_test(&ac);

	aio_fifo_cleanup(&arg);
}
ATF_TC_BODY(msgctl_pid, tc)
{
	struct msg msg = { MSG_MTYPE_1, { 'a', 'b', 'c' } };
	struct msqid_ds msgds;
	int id, sta;
	pid_t pid;

	id = msgget(MSG_KEY, IPC_CREAT | 0600);
	ATF_REQUIRE(id != -1);

	pid = fork();
	ATF_REQUIRE(pid >= 0);

	if (pid == 0) {

		(void)msgsnd(id, &msg, sizeof(struct msg), IPC_NOWAIT);

		_exit(EXIT_SUCCESS);
	}

	(void)sleep(1);
	(void)wait(&sta);
	(void)memset(&msgds, 0, sizeof(struct msqid_ds));

	ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0);

	if (pid != msgds.msg_lspid)
		atf_tc_fail("the PID of last msgsnd(2) was not updated");

	pid = fork();
	ATF_REQUIRE(pid >= 0);

	if (pid == 0) {

		(void)msgrcv(id, &msg,
		    sizeof(struct msg), MSG_MTYPE_1, IPC_NOWAIT);

		_exit(EXIT_SUCCESS);
	}

	(void)sleep(1);
	(void)wait(&sta);
	(void)memset(&msgds, 0, sizeof(struct msqid_ds));

	ATF_REQUIRE(msgctl(id, IPC_STAT, &msgds) == 0);

	if (pid != msgds.msg_lrpid)
		atf_tc_fail("the PID of last msgrcv(2) was not updated");

	ATF_REQUIRE(msgctl(id, IPC_RMID, 0) == 0);
}
Beispiel #9
0
static void
h_check(int test)
{
	struct sigaction sa;
	jmp_buf jb;
	sigjmp_buf sjb;
	sigset_t ss;
	int i, x;

	i = getpid();

	if (test == TEST_SETJMP || test == TEST_SIGSETJMP_SAVE)
		expectsignal = 0;
	else if (test == TEST_U_SETJMP || test == TEST_SIGSETJMP_NOSAVE)
		expectsignal = 1;
	else
		atf_tc_fail("unknown test");

	sa.sa_handler = aborthandler;
	sigemptyset(&sa.sa_mask);
	sa.sa_flags = 0;
	REQUIRE_ERRNO(sigaction(SIGABRT, &sa, NULL) != -1);
	REQUIRE_ERRNO(sigemptyset(&ss) != -1);
	REQUIRE_ERRNO(sigaddset(&ss, SIGABRT) != -1);
	REQUIRE_ERRNO(sigprocmask(SIG_BLOCK, &ss, NULL) != -1);

	if (test == TEST_SETJMP)
		x = setjmp(jb);
	else if (test == TEST_U_SETJMP)
		x = _setjmp(jb);
	else 
		x = sigsetjmp(sjb, !expectsignal);

	if (x != 0) {
		ATF_REQUIRE_MSG(x == i, "setjmp returned wrong value");
		kill(i, SIGABRT);
		ATF_REQUIRE_MSG(!expectsignal, "kill(SIGABRT) failed");
		atf_tc_pass();
	}

	REQUIRE_ERRNO(sigprocmask(SIG_UNBLOCK, &ss, NULL) != -1);

	if (test == TEST_SETJMP)
		longjmp(jb, i);
	else if (test == TEST_U_SETJMP)
		_longjmp(jb, i);
	else 
		siglongjmp(sjb, i);

	atf_tc_fail("jmp failed");
}
Beispiel #10
0
ATF_TC_BODY(data_string_new, tc) {
    struct data_string new_string;
    const char *src = "Really? Latin? ... geeks";
    int len_arg = 0;
    const char *error;

    /* Case 1: Call with an invalid data_string pointer, should fail */
    if (data_string_new(NULL, src, len_arg, MDL)) {
        atf_tc_fail("case 1: call should have failed");
    }

    /* Case 2: Passing in NULL src should fail */
    if (data_string_new(&new_string, NULL, 10, MDL)) {
        atf_tc_fail("case 2: did not return success");
    }

    /* Case 3: Call with valid params, length includes NULL */
    len_arg = strlen(src) + 1;
    if (data_string_new(&new_string, src, len_arg, MDL) == 0) {
        atf_tc_fail("case 3: did not return success");
    }

    error = checkString(&new_string, src);
    ATF_REQUIRE_MSG((error == NULL), "case 3: %s", error);
    data_string_forget(&new_string, MDL);


    /* Case 4: Call with valid params, length does not include NULL */
    len_arg = 7;
    if (data_string_new(&new_string, src, len_arg, MDL) == 0) {
        atf_tc_fail("case 4: did not return success");
    }

    error = checkString(&new_string, "Really?");
    ATF_REQUIRE_MSG((error == NULL), "case 4: %s", error);
    data_string_forget(&new_string, MDL);


    /* Case 5: Call with valid params, source string is "" */
    len_arg = 0;
    if (data_string_new(&new_string, "", len_arg, MDL) == 0) {
        atf_tc_fail("case 5: did not return success");
    }

    error = checkString(&new_string, "");
    ATF_REQUIRE_MSG((error == NULL), "case 4: %s", error);
    data_string_forget(&new_string, MDL);


}
Beispiel #11
0
ATF_TC_BODY(resize_connected_buffers, tc)
{
	int sv[2];
	int sndbuf = 12345;
	int rcvbuf = 23456;
	int err;
	int ls, lr, rs, rr;
	socklen_t sl = sizeof(ls);

	/* setup the socket pair */
	do_socketpair(sv);

	printf("                       Socket Buffer Sizes\n");
	printf("                              | Left Socket       | Right Socket      |\n");
	printf("                              | SNDBUF  | RCVBUF  | SNDBUF  | RCVBUF  |\n");
	ATF_CHECK_EQ(0, getsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &ls, &sl));
	ATF_CHECK_EQ(0, getsockopt(sv[0], SOL_SOCKET, SO_RCVBUF, &lr, &sl));
	ATF_CHECK_EQ(0, getsockopt(sv[1], SOL_SOCKET, SO_SNDBUF, &rs, &sl));
	ATF_CHECK_EQ(0, getsockopt(sv[1], SOL_SOCKET, SO_RCVBUF, &rr, &sl));
	printf("Default                       | %7d | %7d | %7d | %7d |\n",
	    ls, lr, rs, rr);

	/* Update one side's send buffer */
	err = setsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &sndbuf, sizeof(sndbuf));
	if (err != 0){
		perror("setsockopt");
		atf_tc_fail("setsockopt(SO_SNDBUF) failed");
	}

	ATF_CHECK_EQ(0, getsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &ls, &sl));
	ATF_CHECK_EQ(0, getsockopt(sv[0], SOL_SOCKET, SO_RCVBUF, &lr, &sl));
	ATF_CHECK_EQ(0, getsockopt(sv[1], SOL_SOCKET, SO_SNDBUF, &rs, &sl));
	ATF_CHECK_EQ(0, getsockopt(sv[1], SOL_SOCKET, SO_RCVBUF, &rr, &sl));
	printf("After changing Left's SNDBUF  | %7d | %7d | %7d | %7d |\n",
	    ls, lr, rs, rr);

	/* Update the same side's receive buffer */
	err = setsockopt(sv[0], SOL_SOCKET, SO_RCVBUF, &rcvbuf, sizeof(rcvbuf));
	if (err != 0){
		perror("setsockopt");
		atf_tc_fail("setsockopt(SO_RCVBUF) failed");
	}

	ATF_CHECK_EQ(0, getsockopt(sv[0], SOL_SOCKET, SO_SNDBUF, &ls, &sl));
	ATF_CHECK_EQ(0, getsockopt(sv[0], SOL_SOCKET, SO_RCVBUF, &lr, &sl));
	ATF_CHECK_EQ(0, getsockopt(sv[1], SOL_SOCKET, SO_SNDBUF, &rs, &sl));
	ATF_CHECK_EQ(0, getsockopt(sv[1], SOL_SOCKET, SO_RCVBUF, &rr, &sl));
	printf("After changing Left's RCVBUF  | %7d | %7d | %7d | %7d |\n",
	    ls, lr, rs, rr);
}
Beispiel #12
0
static
void
check_prepend(atf_error_t (*prepend)(atf_dynstr_t *, const char *, ...))
{
    const size_t maxlen = 8192;
    char buf[maxlen + 1];
    size_t i;
    atf_dynstr_t str;

    printf("Prepending with plain string\n");
    buf[0] = '\0';
    RE(atf_dynstr_init(&str));
    for (i = 0; i < maxlen; i++) {
        if (strcmp(atf_dynstr_cstring(&str), buf) != 0) {
            fprintf(stderr, "Failed at iteration %zd\n", i);
            atf_tc_fail("Failed to prepend character at iteration %zd", i);
        }

        memmove(buf + 1, buf, i + 1);
        if (i % 2 == 0) {
            RE(prepend(&str, "%s", "a"));
            buf[0] = 'a';
        } else {
            RE(prepend(&str, "%s", "b"));
            buf[0] = 'b';
        }
    }
    atf_dynstr_fini(&str);

    printf("Prepending with formatted string\n");
    buf[0] = '\0';
    RE(atf_dynstr_init(&str));
    for (i = 0; i < maxlen; i++) {
        if (strcmp(atf_dynstr_cstring(&str), buf) != 0) {
            fprintf(stderr, "Failed at iteration %zd\n", i);
            atf_tc_fail("Failed to prepend character at iteration %zd", i);
        }

        memmove(buf + 1, buf, i + 1);
        if (i % 2 == 0) {
            RE(prepend(&str, "%s", "a"));
            buf[0] = 'a';
        } else {
            RE(prepend(&str, "%s", "b"));
            buf[0] = 'b';
        }
    }
    atf_dynstr_fini(&str);
}
Beispiel #13
0
ATF_TC_BODY(ia_na_basic, tc)
{
    uint32_t iaid;
    struct ia_xx *ia_na;
    struct ia_xx *ia_na_copy;
    struct iasubopt *iaaddr;

    /* set up dhcp globals */
    dhcp_context_create();

    /* and other common arguments */
    iaid = 666;
    ia_na = NULL;
    ia_na_copy = NULL;
    iaaddr = NULL;

    /* tests */
    if (ia_allocate(&ia_na, iaid, "TestDUID", 8, MDL) != ISC_R_SUCCESS) {
        atf_tc_fail("ERROR: ia_allocate() %s:%d", MDL);
    }
    if (memcmp(ia_na->iaid_duid.data, &iaid, sizeof(iaid)) != 0) {
        atf_tc_fail("ERROR: bad IAID_DUID %s:%d", MDL);
    }
    if (memcmp(ia_na->iaid_duid.data+sizeof(iaid), "TestDUID", 8) != 0) {
        atf_tc_fail("ERROR: bad IAID_DUID %s:%d", MDL);
    }
    if (ia_na->num_iasubopt != 0) {
        atf_tc_fail("ERROR: bad num_iasubopt %s:%d", MDL);
    }
    if (ia_reference(&ia_na_copy, ia_na, MDL) != ISC_R_SUCCESS) {
        atf_tc_fail("ERROR: ia_reference() %s:%d", MDL);
    }
    if (iasubopt_allocate(&iaaddr, MDL) != ISC_R_SUCCESS) {
        atf_tc_fail("ERROR: iasubopt_allocate() %s:%d", MDL);
    }
    if (ia_add_iasubopt(ia_na, iaaddr, MDL) != ISC_R_SUCCESS) {
        atf_tc_fail("ERROR: ia_add_iasubopt() %s:%d", MDL);
    }
    ia_remove_iasubopt(ia_na, iaaddr, MDL);
    if (iasubopt_dereference(&iaaddr, MDL) != ISC_R_SUCCESS) {
        atf_tc_fail("ERROR: iasubopt_reference() %s:%d", MDL);
    }
    if (ia_dereference(&ia_na, MDL) != ISC_R_SUCCESS) {
        atf_tc_fail("ERROR: ia_dereference() %s:%d", MDL);
    }
    if (ia_dereference(&ia_na_copy, MDL) != ISC_R_SUCCESS) {
        atf_tc_fail("ERROR: ia_dereference() %s:%d", MDL);
    }
}
ATF_TC_BODY(link_count, tc)
{
	struct stat sa, sb;
	int fd;

	(void)memset(&sa, 0, sizeof(struct stat));
	(void)memset(&sb, 0, sizeof(struct stat));

	pathl = getpath();
	fd = open(path, O_RDWR | O_CREAT, 0600);

	ATF_REQUIRE(fd >= 0);
	ATF_REQUIRE(pathl != NULL);

	ATF_REQUIRE(stat(path, &sa) == 0);
	ATF_REQUIRE(link(path, pathl) == 0);
	ATF_REQUIRE(stat(path, &sb) == 0);

	if (sa.st_nlink != sb.st_nlink - 1)
		atf_tc_fail("incorrect link(2) count");

	ATF_REQUIRE(close(fd) == 0);
	ATF_REQUIRE(unlink(path) == 0);
	ATF_REQUIRE(unlink(pathl) == 0);
}
Beispiel #15
0
static void
getnsec3parameters(isc_assertioncallback_t callback) {
	isc_result_t result;
	dns_hash_t hash;
	isc_uint8_t flags;
	isc_uint16_t iterations;
	unsigned char salt[DNS_NSEC3_SALTSIZE];
	size_t salt_length = sizeof(salt);

	result = dns_test_begin(NULL, ISC_FALSE);
	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);

	setup_db();

	isc_assertion_setcallback(callback);
	result = dns_db_getnsec3parameters(db1, VERSION(callback), &hash,
					   &flags, &iterations, salt,
					   &salt_length);
	if (callback != NULL)
		atf_tc_fail("dns_db_dump did not assert");
	ATF_REQUIRE_EQ(result, ISC_R_NOTFOUND);

	close_db();

	dns_test_end();
}
Beispiel #16
0
static void
dump(isc_assertioncallback_t callback) {
	isc_result_t result;
	FILE *f = NULL;

	result = dns_test_begin(NULL, ISC_FALSE);
	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);

	setup_db();

	result = isc_file_openunique(tempname, &f);
	fclose(f);
	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);

	isc_assertion_setcallback(callback);
	result = dns_db_dump(db1, VERSION(callback), tempname);
	(void)unlink(tempname);
	if (callback != NULL)
		atf_tc_fail("dns_db_dump did not assert");
	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);

	close_db();

	dns_test_end();
}
Beispiel #17
0
static void
deleterdataset(isc_assertioncallback_t callback) {
	isc_result_t result;
	dns_rdataset_t rdataset;
	dns_fixedname_t fixed;
	dns_dbnode_t *node = NULL;

	result = dns_test_begin(NULL, ISC_FALSE);
	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);

	setup_db();

	dns_rdataset_init(&rdataset);
	dns_fixedname_init(&fixed);

	result = dns_db_findnode(db1, dns_rootname, ISC_FALSE, &node);
	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);

	isc_assertion_setcallback(callback);
	result = dns_db_deleterdataset(db1, node, VERSION(callback),
				       dns_rdatatype_soa, 0);
	if (callback != NULL)
		atf_tc_fail("dns_db_deleterdataset did not assert");
	ATF_REQUIRE_EQ(result, DNS_R_UNCHANGED);

	dns_db_detachnode(db1, &node);
	ATF_REQUIRE_EQ(node, NULL);

	close_db();

	dns_test_end();
}
Beispiel #18
0
static void
allrdatasets(isc_assertioncallback_t callback) {
	isc_result_t result;
	dns_dbnode_t *node = NULL;
	dns_rdatasetiter_t *iterator = NULL;

	result = dns_test_begin(NULL, ISC_FALSE);
	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);

	setup_db();

	result = dns_db_findnode(db1, dns_rootname, ISC_FALSE, &node);
	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);

	isc_assertion_setcallback(callback);
	result = dns_db_allrdatasets(db1, node, VERSION(callback), 0,
				     &iterator);
	if (callback != NULL)
		atf_tc_fail("dns_db_allrdatasets did not assert");
	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);

	dns_rdatasetiter_destroy(&iterator);
	ATF_REQUIRE_EQ(iterator, NULL);

	dns_db_detachnode(db1, &node);
	ATF_REQUIRE_EQ(node, NULL);

	close_db();

	dns_test_end();
}
Beispiel #19
0
static void*
test_pipe_reader(void* args)
{
	test_pipe_thread_data_t* td = args;
	char rcvbuf[td->pktsize];
	char comparebuf[td->pktsize];
	ssize_t rsize;
	int i, d;

	for(i=0; i < td->numpkts; i++) {
		memset(comparebuf, i, td->pktsize);
		rsize = recv(td->so, rcvbuf, td->pktsize, MSG_WAITALL);
		if (rsize < 0) {
			perror("recv");
			atf_tc_fail("recv returned < 0");
		}
		ATF_CHECK_EQ_MSG(td->pktsize, rsize,
		    		 "expected %zd=send(...) but got %zd",
				 td->pktsize, rsize);
		d = memcmp(comparebuf, rcvbuf, td->pktsize);
		ATF_CHECK_EQ_MSG(0, d, 
		    		 "Received data miscompare on packet %d", i);
	}
	return (0);
}
Beispiel #20
0
ATF_TC_BODY(stat_mtime, tc)
{
	struct stat sa, sb;
	int fd[3];
	size_t i;

	for (i = 0; i < __arraycount(fd); i++) {

		(void)memset(&sa, 0, sizeof(struct stat));
		(void)memset(&sb, 0, sizeof(struct stat));

		fd[i] = open(path, O_WRONLY | O_CREAT);

		ATF_REQUIRE(fd[i] != -1);
		ATF_REQUIRE(write(fd[i], "X", 1) == 1);
		ATF_REQUIRE(stat(path, &sa) == 0);

		(void)sleep(1);

		ATF_REQUIRE(write(fd[i], "X", 1) == 1);
		ATF_REQUIRE(stat(path, &sb) == 0);

		ATF_REQUIRE(close(fd[i]) == 0);
		ATF_REQUIRE(unlink(path) == 0);

		if (sa.st_mtime == sb.st_mtime)
			atf_tc_fail("mtimes did not change");
	}
}
Beispiel #21
0
static void
rename_dotdot(const atf_tc_t *tc, const char *mp)
{

	if (FSTYPE_RUMPFS(tc))
		atf_tc_skip("rename not supported by file system");

	USES_DIRS;

	if (rump_sys_chdir(mp) == -1)
		atf_tc_fail_errno("chdir mountpoint");

	if (rump_sys_mkdir("dir1", 0777) == -1)
		atf_tc_fail_errno("mkdir 1");
	if (rump_sys_mkdir("dir2", 0777) == -1)
		atf_tc_fail_errno("mkdir 2");

	if (rump_sys_rename("dir1", "dir1/..") != -1 || errno != EINVAL)
		atf_tc_fail_errno("self-dotdot to");

	if (rump_sys_rename("dir1/..", "sometarget") != -1 || errno != EINVAL)
		atf_tc_fail_errno("self-dotdot from");

	if (rump_sys_rename("dir1", "dir2/..") != -1 || errno != EINVAL)
		atf_tc_fail("other-dotdot");

	rump_sys_chdir("/");
}
Beispiel #22
0
ATF_TC_BODY(send_recv_nonblocking, tc)
{
	int s;
	int sv[2];
	const int bufsize = 64;
	const char *data = "data";
	char recv_buf[bufsize];
	size_t datalen;
	ssize_t ssize, rsize;

	/* setup the socket pair */
	do_socketpair_nonblocking(sv);

	/* Verify that there is nothing to receive */
	rsize = recv(sv[1], recv_buf, bufsize, MSG_WAITALL);
	ATF_CHECK_EQ(EAGAIN, errno);
	ATF_CHECK_EQ(-1, rsize);

	/* send and receive a small packet */
	datalen = strlen(data) + 1;	/* +1 for the null */
	ssize = send(sv[0], data, datalen, MSG_EOR);
	if (ssize < 0) {
		perror("send");
		atf_tc_fail("send returned < 0");
	}
	ATF_CHECK_EQ_MSG(datalen, ssize, "expected %zd=send(...) but got %zd",
	    datalen, ssize);

	rsize = recv(sv[1], recv_buf, bufsize, MSG_WAITALL);
	ATF_CHECK_EQ(datalen, rsize);
}
Beispiel #23
0
ATF_TC_BODY(setitimer_basic, tc)
{
	struct itimerval it;

	it.it_value.tv_sec = 0;
	it.it_value.tv_usec = 100;

	it.it_interval.tv_sec = 0;
	it.it_interval.tv_usec = 0;

	fail = true;

	ATF_REQUIRE(signal(SIGALRM, sighandler) != SIG_ERR);
	ATF_REQUIRE(setitimer(ITIMER_REAL, &it, NULL) == 0);

	/*
	 * Although the interaction between
	 * setitimer(2) and sleep(3) can be
	 * unspecified, it is assumed that one
	 * second suspension will be enough for
	 * the timer to fire.
	 */
	(void)sleep(1);

	if (fail != false)
		atf_tc_fail("timer did not fire");
}
Beispiel #24
0
key_t get_ftok(int id)
{
    int fd;
    char token_key[64], token_dir[64];
    char *tmpdir;
    key_t key;

    strlcpy(token_key, "/tmp/t_sysv.XXXXXX", sizeof(token_key));
    tmpdir = mkdtemp(token_key);
    ATF_REQUIRE_MSG(tmpdir != NULL, "mkdtemp() failed: %d", errno);

    strlcpy(token_dir, tmpdir, sizeof(token_dir));
    strlcpy(token_key, tmpdir, sizeof(token_key));
    strlcat(token_key, "/token_key", sizeof(token_key));

    /* Create the file, since ftok() requires it to exist! */

    fd = open(token_key, O_RDWR | O_CREAT | O_EXCL);
    if (fd == -1) {
        rmdir(tmpdir);
        atf_tc_fail("open() of temp file failed: %d", errno);
        return (key_t)-1;
    } else
        close(fd);

    key = ftok(token_key, id);

    ATF_REQUIRE_MSG(unlink(token_key) != -1, "unlink() failed: %d", errno);
    ATF_REQUIRE_MSG(rmdir(token_dir) != -1, "rmdir() failed: %d", errno);

    return key;
}
Beispiel #25
0
ATF_TC_BODY(connect, tc)
{
	struct sockaddr_un sun;
	/* ATF's isolation mechanisms will guarantee uniqueness of this file */
	const char *path = "sock";
	int s, r, err, l, s2;

	s = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
	ATF_REQUIRE(s >= 0);

	bzero(&sun, sizeof(sun));
	sun.sun_family = AF_LOCAL;
	sun.sun_len = sizeof(sun);
	strlcpy(sun.sun_path, path, sizeof(sun.sun_path));
	r = bind(s, (struct sockaddr *)&sun, sizeof(sun));
	l = listen(s, -1);
	ATF_CHECK_EQ(0, r);
	ATF_CHECK_EQ(0, l);

	/* Create the other socket */
	s2 = socket(PF_LOCAL, SOCK_SEQPACKET, 0);
	ATF_REQUIRE(s2 >= 0);
	err = connect(s2, (struct sockaddr*)&sun, sizeof(sun));
	if (err != 0) {
		perror("connect");
		atf_tc_fail("connect(2) failed");
	}
}
Beispiel #26
0
static
void
safe_remove(const char* path)
{
    if (unlink(path) == -1)
        atf_tc_fail("unlink(2) of %s failed", path);
}
Beispiel #27
0
static void
find(isc_assertioncallback_t callback) {
	isc_result_t result;
	dns_rdataset_t rdataset;
	dns_fixedname_t fixed;

	result = dns_test_begin(NULL, ISC_FALSE);
	ATF_REQUIRE_EQ(result, ISC_R_SUCCESS);

	setup_db();

	dns_rdataset_init(&rdataset);
	dns_fixedname_init(&fixed);

	isc_assertion_setcallback(callback);
	result = dns_db_find(db1, dns_rootname, VERSION(callback),
			     dns_rdatatype_soa, 0, 0, NULL,
			     dns_fixedname_name(&fixed), &rdataset, NULL);
	if (callback != NULL)
		atf_tc_fail("dns_db_find did not assert");
	ATF_REQUIRE_EQ(result, DNS_R_NXDOMAIN);

	close_db();

	dns_test_end();
}
Beispiel #28
0
ATF_TC_BODY(getitimer_empty, tc)
{
	struct itimerval it;

	/*
	 * Verify that the passed structure remains
	 * empty after calling getitimer(2) but before
	 * actually arming the timer with setitimer(2).
	 */
	(void)memset(&it, 0, sizeof(struct itimerval));

	ATF_REQUIRE(getitimer(ITIMER_REAL, &it) == 0);

	if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0)
		goto fail;

	ATF_REQUIRE(getitimer(ITIMER_VIRTUAL, &it) == 0);

	if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0)
		goto fail;

	ATF_REQUIRE(getitimer(ITIMER_PROF, &it) == 0);

	if (it.it_value.tv_sec != 0 || it.it_value.tv_usec != 0)
		goto fail;

	return;

fail:
	atf_tc_fail("getitimer(2) modfied the timer before it was armed");
}
Beispiel #29
0
ATF_TC_BODY(strtol_range, tc)
{

#if LONG_MAX == 0x7fffffff	/* XXX: Is this portable? */

	struct test t[] = {
		{ "20000000000", 2147483647, 8, NULL },
		{ "2147483648",  2147483647, 10, NULL },
		{ "80000000",	 2147483647, 16, NULL },
	};
#else
	struct test t[] = {
		{ "1000000000000000000000", 9223372036854775807, 8, NULL },
		{ "9223372036854775808",    9223372036854775807, 10, NULL },
		{ "8000000000000000",       9223372036854775807, 16, NULL },
	};
#endif

	long int li;
	char *end;
	size_t i;

	for (i = 0; i < __arraycount(t); i++) {

		errno = 0;
		li = strtol(t[i].str, &end, t[i].base);

		if (errno != ERANGE)
			atf_tc_fail("strtol(3) did not catch ERANGE");

		check(&t[i], li, -1, end);
	}
}
Beispiel #30
0
ATF_TC_BODY(send_recv_with_connect, tc)
{
	const char* path;
	int sv[2];
	const int bufsize = 64;
	const char *data = "data";
	char recv_buf[bufsize];
	size_t datalen;
	ssize_t ssize, rsize;

	mk_pair_of_sockets(sv);

	/* send and receive a small packet */
	datalen = strlen(data) + 1;	/* +1 for the null */
	ssize = send(sv[0], data, datalen, MSG_EOR);
	if (ssize < 0) {
		perror("send");
		atf_tc_fail("send returned < 0");
	}
	ATF_CHECK_EQ_MSG(datalen, ssize, "expected %zd=send(...) but got %zd",
	    datalen, ssize);

	rsize = recv(sv[1], recv_buf, bufsize, MSG_WAITALL);
	ATF_CHECK_EQ(datalen, rsize);
}