Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/tests/net/net add getpeereid tests for non-unix sockets, ret...
details: https://anonhg.NetBSD.org/src/rev/35ed90c8943f
branches: trunk
changeset: 359590:35ed90c8943f
user: christos <christos%NetBSD.org@localhost>
date: Fri Feb 16 16:23:15 2018 +0000
description:
add getpeereid tests for non-unix sockets, returns garbage...
diffstat:
tests/net/net/t_tcp.c | 36 +++++++++++++++++---------------
tests/net/net/t_unix.c | 27 ++++++------------------
tests/net/net/test.h | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 81 insertions(+), 37 deletions(-)
diffs (197 lines):
diff -r 5ef8e04e8a7b -r 35ed90c8943f tests/net/net/t_tcp.c
--- a/tests/net/net/t_tcp.c Fri Feb 16 16:08:22 2018 +0000
+++ b/tests/net/net/t_tcp.c Fri Feb 16 16:23:15 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_tcp.c,v 1.6 2017/08/28 10:19:57 christos Exp $ */
+/* $NetBSD: t_tcp.c,v 1.7 2018/02/16 16:23:15 christos Exp $ */
/*-
* Copyright (c) 2013 The NetBSD Foundation, Inc.
@@ -35,7 +35,7 @@
#include <sys/cdefs.h>
#ifdef __RCSID
-__RCSID("$Id: t_tcp.c,v 1.6 2017/08/28 10:19:57 christos Exp $");
+__RCSID("$Id: t_tcp.c,v 1.7 2018/02/16 16:23:15 christos Exp $");
#endif
/* Example code. Should block; does with accept not paccept. */
@@ -55,20 +55,8 @@
#include <stdlib.h>
#include <signal.h>
-#ifdef TEST
-#define FAIL(msg) err(EXIT_FAILURE, msg)
-#define FAILX(msg, ...) err(EXIT_FAILURE, msg, ## __VA_ARGS__)
-#else
-#include <atf-c.h>
-#define FAIL(msg) do { \
- ATF_CHECK_MSG(0, msg " (%s)", strerror(errno)); \
- goto fail; \
- } while (/*CONSTCOND*/0)
-#define FAILX(msg, ...) do { \
- ATF_CHECK_MSG(0, msg, ## __VA_ARGS__); \
- goto fail; \
- } while (/*CONSTCOND*/0)
-#endif
+
+#include "test.h"
#ifdef __linux__
#define paccept(a, b, c, d, e) accept4((a), (b), (c), (e))
@@ -93,6 +81,8 @@
struct sockaddr_in6 *sin6;
struct sigaction sa;
socklen_t slen;
+ uid_t euid;
+ gid_t egid;
srvr = socket(sfamily, SOCK_STREAM | SOCK_NONBLOCK, 0);
if (srvr == -1)
@@ -192,6 +182,18 @@
FAIL("fnctl setfl");
#endif
+ if (getpeereid(clnt, &euid, &egid) == -1)
+ FAIL("getpeereid(clnt)");
+ CHECK_EQUAL(euid, geteuid(), "client");
+ CHECK_EQUAL(egid, getegid(), "client");
+
+ /* This is not symmetric? */
+ if (getpeereid(srvr, &euid, &egid) == -1)
+ FAIL("getpeereid(srvr)");
+ CHECK_EQUAL(euid, geteuid(), "server");
+ CHECK_EQUAL(egid, getegid(), "server");
+
+
if (as == -1) { /* not true under NetBSD */
as = paccept(srvr, NULL, NULL, NULL, pacceptblock ? 0 : SOCK_NONBLOCK);
if (as == -1)
@@ -202,7 +204,7 @@
if (fl == -1)
FAIL("fnctl");
if (fl != (O_RDWR|O_NONBLOCK))
- FAILX("fl 0x%x != 0x%x\n", fl, O_RDWR|O_NONBLOCK);
+ FAIL("fl 0x%x != 0x%x\n", fl, O_RDWR|O_NONBLOCK);
ok = fcntl(as, F_SETFL, fl & ~O_NONBLOCK);
if (ok == -1)
FAIL("fnctl setfl");
diff -r 5ef8e04e8a7b -r 35ed90c8943f tests/net/net/t_unix.c
--- a/tests/net/net/t_unix.c Fri Feb 16 16:08:22 2018 +0000
+++ b/tests/net/net/t_unix.c Fri Feb 16 16:23:15 2018 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: t_unix.c,v 1.12 2018/02/16 16:08:22 christos Exp $ */
+/* $NetBSD: t_unix.c,v 1.13 2018/02/16 16:23:15 christos Exp $ */
/*-
* Copyright (c) 2011 The NetBSD Foundation, Inc.
@@ -38,7 +38,7 @@
#include <sys/cdefs.h>
#ifdef __RCSID
-__RCSID("$Id: t_unix.c,v 1.12 2018/02/16 16:08:22 christos Exp $");
+__RCSID("$Id: t_unix.c,v 1.13 2018/02/16 16:23:15 christos Exp $");
#else
#define getprogname() argv[0]
#endif
@@ -60,20 +60,7 @@
#include <unistd.h>
#include <stdbool.h>
-#ifdef TEST
-#define FAIL(msg, ...) err(EXIT_FAILURE, msg, ## __VA_ARGS__)
-#define CHECK_EQUAL(a, b) if ((a) != (b)) \
- errx(EXIT_FAILURE, # a "(%ju) != " # b "(%ju)", (uintmax_t)(a), (uintmax_t)((b));
-#else
-
-#include <atf-c.h>
-#define FAIL(msg, ...) \
- do { \
- ATF_CHECK_MSG(0, msg, ## __VA_ARGS__); \
- goto fail; \
- } while (/*CONSTCOND*/0)
-#define CHECK_EQUAL(a, b) ATF_CHECK_EQ(a, b)
-#endif
+#include "test.h"
#define OF offsetof(struct sockaddr_un, sun_path)
@@ -192,15 +179,15 @@
if (getpeereid(clnt, &euid, &egid) == -1)
FAIL("getpeereid(clnt)");
- CHECK_EQUAL(euid, geteuid());
- CHECK_EQUAL(egid, getegid());
+ CHECK_EQUAL(euid, geteuid(), "client");
+ CHECK_EQUAL(egid, getegid(), "client");
#if 0
/* This is not symmetric? */
if (getpeereid(srvr, &euid, &egid) == -1)
FAIL("getpeereid(srvr)");
- CHECK_EQUAL(euid, geteuid());
- CHECK_EQUAL(egid, getegid());
+ CHECK_EQUAL(euid, geteuid(), "server");
+ CHECK_EQUAL(egid, getegid(), "server");
#endif
if (closeit) {
diff -r 5ef8e04e8a7b -r 35ed90c8943f tests/net/net/test.h
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/net/net/test.h Fri Feb 16 16:23:15 2018 +0000
@@ -0,0 +1,55 @@
+/*-
+ * Copyright (c) 2018 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Christos Zoulas.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ * notice, this list of conditions and the following disclaimer in the
+ * documentation and/or other materials provided with the distribution.
+ * 3. All advertising materials mentioning features or use of this software
+ * must display the following acknowledgement:
+ * This product includes software developed by the NetBSD
+ * Foundation, Inc. and its contributors.
+ * 4. Neither the name of The NetBSD Foundation nor the names of its
+ * contributors may be used to endorse or promote products derived
+ * from this software without specific prior written permission.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
+ * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
+ * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
+ * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
+ * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifdef TEST
+# define FAIL(msg, ...) err(EXIT_FAILURE, msg, ## __VA_ARGS__)
+# define CHECK_EQUAL(a, b, msg) \
+ do { \
+ if ((a) != (b)) \
+ errx(EXIT_FAILURE, "%s: " # a "(%ju) != " # b "(%ju)", \
+ msg, (uintmax_t)(a), (uintmax_t)(b)); \
+ } while (/*CONSTCOND*/0)
+#else
+
+#include <atf-c.h>
+# define FAIL(msg, ...) \
+ do { \
+ ATF_CHECK_MSG(0, msg, ## __VA_ARGS__); \
+ goto fail; \
+ } while (/*CONSTCOND*/0)
+# define CHECK_EQUAL(a, b, msg) ATF_CHECK_EQ_MSG(a, b, "%s: " \
+ # a "(%ju) != " # b "(%ju) ", msg, (uintmax_t)(a), (uintmax_t)(b));
+#endif
Home |
Main Index |
Thread Index |
Old Index