Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src Basic tests for issetugid(2).
details: https://anonhg.NetBSD.org/src/rev/a394f65e4136
branches: trunk
changeset: 766917:a394f65e4136
user: jruoho <jruoho%NetBSD.org@localhost>
date: Mon Jul 04 05:10:23 2011 +0000
description:
Basic tests for issetugid(2).
diffstat:
distrib/sets/lists/tests/mi | 4 +-
tests/syscall/Makefile | 4 +-
tests/syscall/t_issetugid.c | 148 ++++++++++++++++++++++++++++++++++++++++++++
3 files changed, 153 insertions(+), 3 deletions(-)
diffs (195 lines):
diff -r 1d9fc9983156 -r a394f65e4136 distrib/sets/lists/tests/mi
--- a/distrib/sets/lists/tests/mi Mon Jul 04 04:10:34 2011 +0000
+++ b/distrib/sets/lists/tests/mi Mon Jul 04 05:10:23 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: mi,v 1.360 2011/07/03 21:06:56 jruoho Exp $
+# $NetBSD: mi,v 1.361 2011/07/04 05:10:23 jruoho Exp $
#
# Note: don't delete entries from here - mark them as "obsolete" instead.
#
@@ -630,6 +630,7 @@
./usr/libdata/debug/usr/tests/syscall/t_getrusage.debug tests-syscall-debug debug,atf
./usr/libdata/debug/usr/tests/syscall/t_getsid.debug tests-syscall-debug debug,atf
./usr/libdata/debug/usr/tests/syscall/t_gettimeofday.debug tests-syscall-debug debug,atf
+./usr/libdata/debug/usr/tests/syscall/t_issetugid.debug tests-syscall-debug debug,atf
./usr/libdata/debug/usr/tests/syscall/t_itimer.debug tests-syscall-debug debug,atf
./usr/libdata/debug/usr/tests/syscall/t_kill.debug tests-syscall-debug debug,atf
./usr/libdata/debug/usr/tests/syscall/t_link.debug tests-syscall-debug debug,atf
@@ -2380,6 +2381,7 @@
./usr/tests/syscall/t_getrusage tests-syscall-tests atf
./usr/tests/syscall/t_getsid tests-syscall-tests atf
./usr/tests/syscall/t_gettimeofday tests-syscall-tests atf
+./usr/tests/syscall/t_issetugid tests-syscall-tests atf
./usr/tests/syscall/t_itimer tests-syscall-tests atf
./usr/tests/syscall/t_kill tests-syscall-tests atf
./usr/tests/syscall/t_link tests-syscall-tests atf
diff -r 1d9fc9983156 -r a394f65e4136 tests/syscall/Makefile
--- a/tests/syscall/Makefile Mon Jul 04 04:10:34 2011 +0000
+++ b/tests/syscall/Makefile Mon Jul 04 05:10:23 2011 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.37 2011/07/03 21:06:56 jruoho Exp $
+# $NetBSD: Makefile,v 1.38 2011/07/04 05:10:24 jruoho Exp $
.include <bsd.own.mk>
@@ -7,7 +7,7 @@
TESTS_C+= t_access t_cmsg t_dup t_fsync
TESTS_C+= t_getgroups t_getlogin t_getpid
TESTS_C+= t_getrusage t_getsid t_gettimeofday
-TESTS_C+= t_itimer t_kill t_link
+TESTS_C+= t_issetugid t_itimer t_kill t_link
TESTS_C+= t_mincore t_mknod t_mmap t_mprotect t_msync t_nanosleep
TESTS_C+= t_poll t_pollts t_pselect t_revoke
TESTS_C+= t_setrlimit t_setuid t_stat t_timer t_truncate
diff -r 1d9fc9983156 -r a394f65e4136 tests/syscall/t_issetugid.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/tests/syscall/t_issetugid.c Mon Jul 04 05:10:23 2011 +0000
@@ -0,0 +1,148 @@
+/* $NetBSD: t_issetugid.c,v 1.1 2011/07/04 05:10:24 jruoho Exp $ */
+
+/*-
+ * Copyright (c) 2011 The NetBSD Foundation, Inc.
+ * All rights reserved.
+ *
+ * This code is derived from software contributed to The NetBSD Foundation
+ * by Jukka Ruohonen.
+ *
+ * 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.
+ *
+ * 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.
+ */
+#include <sys/cdefs.h>
+__RCSID("$NetBSD: t_issetugid.c,v 1.1 2011/07/04 05:10:24 jruoho Exp $");
+
+#include <sys/wait.h>
+
+#include <atf-c.h>
+#include <errno.h>
+#include <pwd.h>
+#include <stdlib.h>
+#include <unistd.h>
+
+static bool check(int (*fuid)(uid_t), int (*fgid)(gid_t));
+
+static bool
+check(int (*fuid)(uid_t), int (*fgid)(gid_t))
+{
+ struct passwd *pw;
+ pid_t pid;
+ int sta;
+
+ pw = getpwnam("nobody");
+
+ if (pw == NULL)
+ return false;
+
+ pid = fork();
+
+ if (pid < 0)
+ return false;
+
+ if (pid == 0) {
+
+ if (fuid != NULL && (*fuid)(pw->pw_uid) != 0)
+ _exit(EXIT_FAILURE);
+
+ if (fgid != NULL && (*fgid)(pw->pw_gid) != 0)
+ _exit(EXIT_FAILURE);
+
+ if (issetugid() != 1)
+ _exit(EXIT_FAILURE);
+
+ _exit(EXIT_SUCCESS);
+ }
+
+ (void)wait(&sta);
+
+ if (WIFEXITED(sta) == 0 || WEXITSTATUS(sta) != EXIT_SUCCESS)
+ return false;
+
+ return true;
+}
+
+ATF_TC(issetugid_egid);
+ATF_TC_HEAD(issetugid_egid, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A test of issetugid(2), eff. GID");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(issetugid_egid, tc)
+{
+
+ if (check(NULL, setegid) != true)
+ atf_tc_fail("issetugid(2) failed with effective GID");
+}
+
+ATF_TC(issetugid_euid);
+ATF_TC_HEAD(issetugid_euid, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A test of issetugid(2), eff. UID");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(issetugid_euid, tc)
+{
+
+ if (check(seteuid, NULL) != true)
+ atf_tc_fail("issetugid(2) failed with effective UID");
+}
+
+ATF_TC(issetugid_rgid);
+ATF_TC_HEAD(issetugid_rgid, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A test of issetugid(2), real GID");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(issetugid_rgid, tc)
+{
+
+ if (check(NULL, setgid) != true)
+ atf_tc_fail("issetugid(2) failed with real GID");
+}
+
+ATF_TC(issetugid_ruid);
+ATF_TC_HEAD(issetugid_ruid, tc)
+{
+ atf_tc_set_md_var(tc, "descr", "A test of issetugid(2), real UID");
+ atf_tc_set_md_var(tc, "require.user", "root");
+}
+
+ATF_TC_BODY(issetugid_ruid, tc)
+{
+
+ if (check(setuid, NULL) != true)
+ atf_tc_fail("issetugid(2) failed with real UID");
+}
+
+ATF_TP_ADD_TCS(tp)
+{
+
+ ATF_TP_ADD_TC(tp, issetugid_egid);
+ ATF_TP_ADD_TC(tp, issetugid_euid);
+ ATF_TP_ADD_TC(tp, issetugid_rgid);
+ ATF_TP_ADD_TC(tp, issetugid_ruid);
+
+ return atf_no_error();
+}
Home |
Main Index |
Thread Index |
Old Index