public inbox for ltp@lists.linux.it
 help / color / mirror / Atom feed
* [LTP] 16-bit fixes for setreuid, setregid
@ 2013-10-21  7:25 Stanislav Kholmanskikh
  2013-10-21  7:25 ` [LTP] [PATCH 1/3] syscalls/setreuid: 16-bit fixes and minor cleanup Stanislav Kholmanskikh
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: Stanislav Kholmanskikh @ 2013-10-21  7:25 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko

Hi!

This series contains fixes for 16-bit version of syscalls for
setreuid, setregid system calls.

And some cleanup also.

Thanks.


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 1/3] syscalls/setreuid: 16-bit fixes and minor cleanup
  2013-10-21  7:25 [LTP] 16-bit fixes for setreuid, setregid Stanislav Kholmanskikh
@ 2013-10-21  7:25 ` Stanislav Kholmanskikh
  2013-10-21  7:25 ` [LTP] [PATCH 2/3] syscalls/setregid{01, 03, 04}: " Stanislav Kholmanskikh
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: Stanislav Kholmanskikh @ 2013-10-21  7:25 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 testcases/kernel/syscalls/setreuid/setreuid01.c |  172 +++------------------
 testcases/kernel/syscalls/setreuid/setreuid02.c |  157 +++++--------------
 testcases/kernel/syscalls/setreuid/setreuid03.c |  182 +++++++---------------
 testcases/kernel/syscalls/setreuid/setreuid04.c |  141 +++++-------------
 testcases/kernel/syscalls/setreuid/setreuid05.c |  186 +++++++----------------
 testcases/kernel/syscalls/setreuid/setreuid06.c |  104 ++++---------
 testcases/kernel/syscalls/setreuid/setreuid07.c |  124 ++++++----------
 testcases/kernel/syscalls/utils/compat_16.h     |    5 +
 8 files changed, 296 insertions(+), 775 deletions(-)

diff --git a/testcases/kernel/syscalls/setreuid/setreuid01.c b/testcases/kernel/syscalls/setreuid/setreuid01.c
index 1f54337..45d38cb 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid01.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid01.c
@@ -29,127 +29,41 @@
  *
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
  *
+ * Author: William Roske
+ * Co-pilot: Dave Fenner
+ */
+
+/*
+ * Testcase to test the basic functionality of setreuid(2) system call.
  */
-/* $Id: setreuid01.c,v 1.6 2009/11/02 13:57:18 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: setreuid01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for setreuid(2)
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 5
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: William Roske
- *
- *    CO-PILOT		: Dave Fenner
- *
- *    DATE STARTED	: 05/14/92
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- *	1.) setreuid(2) returns...(See Description)
- *
- *    INPUT SPECIFICATIONS
- *	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *    OUTPUT SPECIFICATIONS
- *
- *    DURATION
- *	Terminates - with frequency and infinite modes.
- *
- *    SIGNALS
- *	Uses SIGUSR1 to pause before test if option set.
- *	(See the parse_opts(3) man page).
- *
- *    RESOURCES
- *	None
- *
- *    ENVIRONMENTAL NEEDS
- *      No run-time environmental needs.
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- *	None
- *
- *    INTERCASE DEPENDENCIES
- *	None
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the setreuid(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	setreuid(2).
- *
- *	Setup:
- *	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- *	Test:
- *	 Loop if the proper options are given.
- *	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
 
 #include <errno.h>
 #include <string.h>
 #include <signal.h>
-
 #include <sys/types.h>
 
 #include "test.h"
 #include "usctest.h"
+#include "compat_16.h"
 
-void setup();
-void cleanup();
+static void setup();
+static void cleanup();
 
-char *TCID = "setreuid01";
+TCID_DEFINE(setreuid01);
 int TST_TOTAL = 5;
 
-int exp_enos[] = { 0, 0 };
-
-int ruid, euid;			/* real and effective user ids */
+static uid_t ruid, euid;	/* real and effective user ids */
 
 int main(int ac, char **av)
 {
 	int lc;
 	char *msg;
 
-    /***************************************************************
-     * parse standard options
-     ***************************************************************/
 	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-    /***************************************************************
-     * perform global setup for test
-     ***************************************************************/
 	setup();
 
-	/* set the expected errnos... */
-	TEST_EXP_ENOS(exp_enos);
-
-    /***************************************************************
-     * check looping state if -c option given
-     ***************************************************************/
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 
 		tst_count = 0;
@@ -159,21 +73,19 @@ int main(int ac, char **av)
 		 *  Don't change either real or effective uid
 		 */
 		ruid = getuid();	/* get real uid */
+		UID16_CHECK(ruid, setreuid, cleanup);
+
 		euid = geteuid();	/* get effective uid */
+		UID16_CHECK(euid, setreuid, cleanup);
 
-		/* Call setreuid(2) */
-		TEST(setreuid(-1, -1));
+		TEST(SETREUID(cleanup, -1, -1));
 
-		/* check return code */
 		if (TEST_RETURN == -1) {
 			TEST_ERROR_LOG(TEST_ERRNO);
 			tst_resm(TFAIL,
 				 "setreuid -  Don't change either real or effective uid failed, errno=%d : %s",
 				 TEST_ERRNO, strerror(TEST_ERRNO));
 		} else {
-	    /***************************************************************
-	     * only perform functional verification if flag set (-f not given)
-	     ***************************************************************/
 			if (STD_FUNCTIONAL_TEST) {
 				/* No Verification test, yet... */
 				tst_resm(TPASS,
@@ -187,21 +99,15 @@ int main(int ac, char **av)
 		 *  change effective to effective uid
 		 */
 
-		/* Call setreuid(2) */
-		TEST(setreuid(-1, euid));
+		TEST(SETREUID(cleanup, -1, euid));
 
-		/* check return code */
 		if (TEST_RETURN == -1) {
 			TEST_ERROR_LOG(TEST_ERRNO);
 			tst_resm(TFAIL,
 				 "setreuid -  change effective to effective uid failed, errno=%d : %s",
 				 TEST_ERRNO, strerror(TEST_ERRNO));
 		} else {
-	    /***************************************************************
-	     * only perform functional verification if flag set (-f not given)
-	     ***************************************************************/
 			if (STD_FUNCTIONAL_TEST) {
-				/* No Verification test, yet... */
 				tst_resm(TPASS,
 					 "setreuid -  change effective to effective uid returned %ld",
 					 TEST_RETURN);
@@ -213,21 +119,15 @@ int main(int ac, char **av)
 		 *  change real to real uid
 		 */
 
-		/* Call setreuid(2) */
-		TEST(setreuid(ruid, -1));
+		TEST(SETREUID(cleanup, ruid, -1));
 
-		/* check return code */
 		if (TEST_RETURN == -1) {
 			TEST_ERROR_LOG(TEST_ERRNO);
 			tst_resm(TFAIL,
 				 "setreuid -  change real to real uid failed, errno=%d : %s",
 				 TEST_ERRNO, strerror(TEST_ERRNO));
 		} else {
-	    /***************************************************************
-	     * only perform functional verification if flag set (-f not given)
-	     ***************************************************************/
 			if (STD_FUNCTIONAL_TEST) {
-				/* No Verification test, yet... */
 				tst_resm(TPASS,
 					 "setreuid -  change real to real uid returned %ld",
 					 TEST_RETURN);
@@ -239,21 +139,15 @@ int main(int ac, char **av)
 		 *  change effective to real uid
 		 */
 
-		/* Call setreuid(2) */
-		TEST(setreuid(-1, ruid));
+		TEST(SETREUID(cleanup, -1, ruid));
 
-		/* check return code */
 		if (TEST_RETURN == -1) {
 			TEST_ERROR_LOG(TEST_ERRNO);
 			tst_resm(TFAIL,
 				 "setreuid -  change effective to real uid failed, errno=%d : %s",
 				 TEST_ERRNO, strerror(TEST_ERRNO));
 		} else {
-	    /***************************************************************
-	     * only perform functional verification if flag set (-f not given)
-	     ***************************************************************/
 			if (STD_FUNCTIONAL_TEST) {
-				/* No Verification test, yet... */
 				tst_resm(TPASS,
 					 "setreuid -  change effective to real uid returned %ld",
 					 TEST_RETURN);
@@ -265,21 +159,15 @@ int main(int ac, char **av)
 		 *  try to change real to current real
 		 */
 
-		/* Call setreuid(2) */
-		TEST(setreuid(ruid, ruid));
+		TEST(SETREUID(cleanup, ruid, ruid));
 
-		/* check return code */
 		if (TEST_RETURN == -1) {
 			TEST_ERROR_LOG(TEST_ERRNO);
 			tst_resm(TFAIL,
 				 "setreuid -  try to change real to current real failed, errno=%d : %s",
 				 TEST_ERRNO, strerror(TEST_ERRNO));
 		} else {
-	    /***************************************************************
-	     * only perform functional verification if flag set (-f not given)
-	     ***************************************************************/
 			if (STD_FUNCTIONAL_TEST) {
-				/* No Verification test, yet... */
 				tst_resm(TPASS,
 					 "setreuid -  try to change real to current real returned %ld",
 					 TEST_RETURN);
@@ -288,41 +176,23 @@ int main(int ac, char **av)
 
 	}
 
-    /***************************************************************
-     * cleanup and exit
-     ***************************************************************/
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup()
+static void setup(void)
 {
 
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
 	TEST_PAUSE;
 
-	/* make a temp dir and cd to it */
 	tst_tmpdir();
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup()
+static void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
 
 	tst_rmdir();
-
 }
diff --git a/testcases/kernel/syscalls/setreuid/setreuid02.c b/testcases/kernel/syscalls/setreuid/setreuid02.c
index 5fdd918..050df17 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid02.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid02.c
@@ -1,87 +1,47 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Ported by John George
  */
 
 /*
- * NAME
- *	setreuid02.c
- *
- * DESCRIPTION
- *	Test setreuid() when executed by root.
- *
- * ALGORITHM
- *
- *	Setup:
- *	  Setup signal handling
- *	  Get user information.
- *	  Pause for SIGUSER1 if option specified.
- *	Setup test values.
- *	Loop if the proper options are given.
- *	For each test set execute the system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise,
- *		Verify the Functionality of system call
- *		if successful,
- *			Issue Functionality-Pass message.
- *		Otherwise,
- *			Issue Functionality-Fail message.
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given.
- *
- * USAGE:  <for command-line>
- *	setreuid02 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions
- *	This test must be ran as root.
- *	nobody, bin, and daemon must be valid users.
+ * Test setreuid() when executed by root.
  */
 
+#include <errno.h>
 #include <pwd.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include "test.h"
 #include "usctest.h"
-#include <errno.h>
+#include "compat_16.h"
 
-char *TCID = "setreuid02";
-uid_t nobody_pw_uid, root_pw_uid, daemon_pw_uid, bin_pw_uid;
-uid_t neg_one = -1;
-int exp_enos[] = { 0 };
+TCID_DEFINE(setreuid02);
 
-struct passwd nobody, daemonpw, root, bin;
+static uid_t neg_one = -1;
+static struct passwd nobody, daemonpw, root, bin;
 
 /*
  * The following structure contains all test data.  Each structure in the array
  * is used for a separate test.  The tests are executed in the for loop below.
  */
 
-struct test_data_t {
+static struct test_data_t {
 	uid_t *real_uid;
 	uid_t *eff_uid;
 	struct passwd *exp_real_usr;
@@ -90,20 +50,20 @@ struct test_data_t {
 } test_data[] = {
 	{
 	&neg_one, &neg_one, &root, &root, "After setreuid(-1, -1),"}, {
-	&nobody_pw_uid, &neg_one, &nobody, &root, "After setreuid(nobody, -1)"},
+	&nobody.pw_uid, &neg_one, &nobody, &root, "After setreuid(nobody, -1)"},
 	{
-	&root_pw_uid, &neg_one, &root, &root, "After setreuid(root,-1),"}, {
-	&neg_one, &daemon_pw_uid, &root, &daemonpw,
+	&root.pw_uid, &neg_one, &root, &root, "After setreuid(root,-1),"}, {
+	&neg_one, &daemonpw.pw_uid, &root, &daemonpw,
 		    "After setreuid(-1, daemon)"}, {
-	&neg_one, &root_pw_uid, &root, &root, "After setreuid(-1,root),"}, {
-	&bin_pw_uid, &neg_one, &bin, &root, "After setreuid(bin, -1)"}, {
-&root_pw_uid, &neg_one, &root, &root, "After setreuid(-1, root)"},};
+	&neg_one, &root.pw_uid, &root, &root, "After setreuid(-1,root),"}, {
+	&bin.pw_uid, &neg_one, &bin, &root, "After setreuid(bin, -1)"}, {
+&root.pw_uid, &neg_one, &root, &root, "After setreuid(-1, root)"},};
 
 int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
 
-void setup(void);
-void cleanup(void);
-void uid_verify(struct passwd *ru, struct passwd *eu, char *when);
+static void setup(void);
+static void cleanup(void);
+static void uid_verify(struct passwd *ru, struct passwd *eu, char *when);
 
 int main(int ac, char **av)
 {
@@ -120,12 +80,11 @@ int main(int ac, char **av)
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		int i;
 
-		/* reset tst_count in case we are looping */
 		tst_count = 0;
 
 		for (i = 0; i < TST_TOTAL; i++) {
 			/* Set the real or effective user id */
-			TEST(setreuid(*test_data[i].real_uid,
+			TEST(SETREUID(cleanup, *test_data[i].real_uid,
 				      *test_data[i].eff_uid));
 
 			if (TEST_RETURN == -1) {
@@ -134,10 +93,6 @@ int main(int ac, char **av)
 					 *test_data[i].real_uid,
 					 *test_data[i].eff_uid);
 			} else {
-				/*
-				 * Perform functional verification if test
-				 * executed without (-f) option.
-				 */
 				if (STD_FUNCTIONAL_TEST) {
 					uid_verify(test_data[i].exp_real_usr,
 						   test_data[i].exp_eff_usr,
@@ -150,71 +105,45 @@ int main(int ac, char **av)
 	}
 	cleanup();
 	tst_exit();
-
 }
 
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
+static void setup(void)
 {
+	tst_require_root(NULL);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
-	if (getpwnam("nobody") == NULL) {
+	if (getpwnam("nobody") == NULL)
 		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
-		tst_exit();
-	}
 
-	if (getpwnam("daemon") == NULL) {
+	if (getpwnam("daemon") == NULL)
 		tst_brkm(TBROK, NULL, "daemon must be a valid user.");
-		tst_exit();
-	}
 
-	/* Check that the test process id is root  */
-	if (geteuid() != 0) {
-		tst_brkm(TBROK, NULL, "Must be root for this test!");
-		tst_exit();
-	}
-
-	/* set the expected errnos... */
-	TEST_EXP_ENOS(exp_enos);
+	if (getpwnam("bin") == NULL)
+		tst_brkm(TBROK, NULL, "bin must be a valid user.");
 
 	root = *(getpwnam("root"));
-	root_pw_uid = root.pw_uid;
+	UID16_CHECK(root.pw_uid, setreuid, cleanup);
 
 	nobody = *(getpwnam("nobody"));
-	nobody_pw_uid = nobody.pw_uid;
+	UID16_CHECK(nobody.pw_uid, setreuid, cleanup);
 
 	daemonpw = *(getpwnam("daemon"));
-	daemon_pw_uid = daemonpw.pw_uid;
+	UID16_CHECK(daemonpw.pw_uid, setreuid, cleanup);
 
 	bin = *(getpwnam("bin"));
-	bin_pw_uid = bin.pw_uid;
+	UID16_CHECK(bin.pw_uid, setreuid, cleanup);
 
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
 	TEST_PAUSE;
 }
 
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
 
 }
 
-void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
+static void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
 {
 	if ((getuid() != ru->pw_uid) || (geteuid() != eu->pw_uid)) {
 		tst_resm(TFAIL, "ERROR: %s real uid = %d; effective uid = %d",
diff --git a/testcases/kernel/syscalls/setreuid/setreuid03.c b/testcases/kernel/syscalls/setreuid/setreuid03.c
index 5dcb1f6..24e52d5 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid03.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid03.c
@@ -1,94 +1,52 @@
 /*
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Ported by John George
  */
 
 /*
- * NAME
- *	setreuid03.c
- *
- * DESCRIPTION
- *	Test setreuid() when executed by an unpriviledged user.
- *
- * ALGORITHM
- *
- *	Setup:
- *	  Setup signal handling
- *	  Get user information.
- *	  Pause for SIGUSER1 if option specified.
- *
- *	Setup test values.
- *	Loop if the proper options are given.
- *	For each test set execute the system call
- *	  Check that we received the expected result.
- *	  If setreuid failed as expected
- *		check that the correct errno value was set.
- *	  otherwise
- *		Issue Pass message.
- *	  Verify that the uid and euid values are still correct.
- *	Cleanup:
- *	  Print errno log and/or timing stats if option given.
- *
- * USAGE:  <for command-line>
- *	setreuid03 [-c n] [-f] [-e] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-f   : Turn off functionality Testing.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions
- *	This test must be run by nobody.
+ * Test setreuid() when executed by an unpriviledged user.
  */
 
+#include <errno.h>
 #include <pwd.h>
 #include <stdlib.h>
+
 #include "test.h"
 #include "usctest.h"
-#include <errno.h>
+#include "compat_16.h"
 
 #define FAILED  1
 
-char *TCID = "setreuid03";
+TCID_DEFINE(setreuid03);
 
-int fail = -1;
-int pass = 0;
-uid_t neg_one = -1;
-int exp_enos[] = { EPERM, 0 };
+static int fail = -1;
+static int pass;
+static uid_t neg_one = -1;
 
-uid_t root_pw_uid, nobody_pw_uid, bin_pw_uid;
-char user1name[] = "nobody";
-char user2name[] = "bin";
-char rootname[] = "root";
-
-struct passwd nobody, bin, root;
+static struct passwd nobody, bin, root;
 
 /*
  * The following structure contains all test data.  Each structure in the array
  * is used for a separate test.  The tests are executed in the for loop below.
  */
 
-struct test_data_t {
+static struct test_data_t {
 	uid_t *real_uid;
 	uid_t *eff_uid;
 	int *exp_ret;
@@ -97,40 +55,40 @@ struct test_data_t {
 	char *test_msg;
 } test_data[] = {
 	{
-	&nobody_pw_uid, &nobody_pw_uid, &pass, &nobody, &nobody,
+	&nobody.pw_uid, &nobody.pw_uid, &pass, &nobody, &nobody,
 		    "After setreuid(nobody, nobody),"}, {
-	&neg_one, &nobody_pw_uid, &pass, &nobody, &nobody,
+	&neg_one, &nobody.pw_uid, &pass, &nobody, &nobody,
 		    "After setreuid(-1, nobody),"}, {
-	&nobody_pw_uid, &neg_one, &pass, &nobody, &nobody,
+	&nobody.pw_uid, &neg_one, &pass, &nobody, &nobody,
 		    "After setreuid(nobody, -1),"}, {
 	&neg_one, &neg_one, &pass, &nobody, &nobody, "After setreuid(-1, -1),"},
 	{
-	&neg_one, &root_pw_uid, &fail, &nobody, &nobody,
+	&neg_one, &root.pw_uid, &fail, &nobody, &nobody,
 		    "After setreuid(-1, root),"}, {
-	&root_pw_uid, &neg_one, &fail, &nobody, &nobody,
+	&root.pw_uid, &neg_one, &fail, &nobody, &nobody,
 		    "After setreuid(root, -1),"}, {
-	&root_pw_uid, &root_pw_uid, &fail, &nobody, &nobody,
+	&root.pw_uid, &root.pw_uid, &fail, &nobody, &nobody,
 		    "After setreuid(root, root),"}, {
-	&root_pw_uid, &nobody_pw_uid, &fail, &nobody, &nobody,
+	&root.pw_uid, &nobody.pw_uid, &fail, &nobody, &nobody,
 		    "After setreuid(root, nobody),"}, {
-	&root_pw_uid, &bin_pw_uid, &fail, &nobody, &nobody,
+	&root.pw_uid, &bin.pw_uid, &fail, &nobody, &nobody,
 		    "After setreuid(root, nobody),"}, {
-	&bin_pw_uid, &root_pw_uid, &fail, &nobody, &nobody,
+	&bin.pw_uid, &root.pw_uid, &fail, &nobody, &nobody,
 		    "After setreuid(bin, root),"}, {
-	&bin_pw_uid, &neg_one, &fail, &nobody, &nobody,
+	&bin.pw_uid, &neg_one, &fail, &nobody, &nobody,
 		    "After setreuid(bin, -1),"}, {
-	&bin_pw_uid, &bin_pw_uid, &fail, &nobody, &nobody,
+	&bin.pw_uid, &bin.pw_uid, &fail, &nobody, &nobody,
 		    "After setreuid(bin, bin,),"}, {
-	&bin_pw_uid, &nobody_pw_uid, &fail, &nobody, &nobody,
+	&bin.pw_uid, &nobody.pw_uid, &fail, &nobody, &nobody,
 		    "After setreuid(bin, nobody),"}, {
-&nobody_pw_uid, &bin_pw_uid, &fail, &nobody, &nobody,
+	&nobody.pw_uid, &bin.pw_uid, &fail, &nobody, &nobody,
 		    "After setreuid(nobody, bin),"},};
 
 int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
 
-void setup(void);
-void cleanup(void);
-void uid_verify(struct passwd *, struct passwd *, char *);
+static void setup(void);
+static void cleanup(void);
+static void uid_verify(struct passwd *, struct passwd *, char *);
 
 int main(int ac, char **av)
 {
@@ -147,13 +105,12 @@ int main(int ac, char **av)
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		int i;
 
-		/* reset tst_count in case we are looping */
 		tst_count = 0;
 
 		for (i = 0; i < TST_TOTAL; i++) {
 
 			/* Set the real or effective user id */
-			TEST(setreuid(*test_data[i].real_uid,
+			TEST(SETREUID(cleanup, *test_data[i].real_uid,
 				      *test_data[i].eff_uid));
 
 			if (TEST_RETURN == *test_data[i].exp_ret) {
@@ -187,86 +144,57 @@ int main(int ac, char **av)
 			if (TEST_RETURN == -1) {
 				TEST_ERROR_LOG(TEST_ERRNO);
 			}
-			/*
-			 * Perform functional verification if test
-			 * executed without (-f) option.
-			 */
 			if (STD_FUNCTIONAL_TEST) {
 				uid_verify(test_data[i].exp_real_usr,
 					   test_data[i].exp_eff_usr,
 					   test_data[i].test_msg);
+			} else {
+				tst_resm(TINFO, "Call succeeded.");
 			}
 		}
 	}
 
 	cleanup();
 	tst_exit();
-
 }
 
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
+static void setup(void)
 {
+	tst_require_root(NULL);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
-	if (getpwnam("nobody") == NULL) {
+	if (getpwnam("nobody") == NULL)
 		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
-		tst_exit();
-	}
 
-	if (getpwnam("bin") == NULL) {
+	if (getpwnam("bin") == NULL)
 		tst_brkm(TBROK, NULL, "bin must be a valid user.");
-		tst_exit();
-	}
-
-	/* set the expected errnos... */
-	TEST_EXP_ENOS(exp_enos);
 
 	root = *(getpwnam("root"));
-	root_pw_uid = root.pw_uid;
+	UID16_CHECK(root.pw_uid, setreuid, cleanup);
 
 	nobody = *(getpwnam("nobody"));
-	nobody_pw_uid = nobody.pw_uid;
+	UID16_CHECK(nobody.pw_uid, setreuid, cleanup);
 
 	bin = *(getpwnam("bin"));
-	bin_pw_uid = bin.pw_uid;
+	UID16_CHECK(bin.pw_uid, setreuid, cleanup);
 
-	/* Check that the test process id is nobody */
-	if (geteuid() != nobody.pw_uid) {
-/*		tst_brkm(TBROK, NULL, "Must be nobody for this test!");
-		tst_exit();*/
-		setuid(nobody.pw_uid);
-	}
+	if (setuid(nobody.pw_uid) < 0)
+		tst_brkm(TBROK | TERRNO, NULL, "setuid() to nobody failed");
 
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
 	TEST_PAUSE;
 }
 
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
 
 }
 
-void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
+static void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
 {
 	if ((getuid() != ru->pw_uid) || (geteuid() != eu->pw_uid)) {
-		tst_resm(TINFO, "ERROR: %s real uid = %d; effective uid = %d",
+		tst_resm(TFAIL, "ERROR: %s real uid = %d; effective uid = %d",
 			 when, getuid(), geteuid());
 		tst_resm(TINFO, "Expected: real uid = %d; effective uid = %d",
 			 ru->pw_uid, eu->pw_uid);
diff --git a/testcases/kernel/syscalls/setreuid/setreuid04.c b/testcases/kernel/syscalls/setreuid/setreuid04.c
index 0396f05..d949a4b 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid04.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid04.c
@@ -1,83 +1,45 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Ported by John George
  */
 
 /*
- * NAME
- *	setreuid04.c
- *
- * DESCRIPTION
- *	Test that root can change the real and effective uid to an
- *	unpriviledged user.
- *
- * ALGORITHM
- *
- *	Setup:
- *	  Setup signal handling
- *	  Get user information.
- *	  Pause for SIGUSER1 if option specified.
- *
- *	Setup test values.
- *	Loop if the proper options are given.
- *	For each test set execute the system call
- *	  Check that we received the expected result.
- *	  Verify that the uid and euid values are still correct.
- *	Cleanup:
- *	  Print errno log and/or timing stats if option given.
- *
- * USAGE:  <for command-line>
- *	 setreuid04 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions
- *	This test must be run by root.
- *	nobody must be a valid user.
- *	This test cannot be run with the i/I option.
+ * Test that root can change the real and effective uid to an
+ * unpriviledged user.
  */
 
 #include <errno.h>
 #include <stdlib.h>
 #include <pwd.h>
+#include <sys/wait.h>
+
 #include "test.h"
 #include "usctest.h"
-#include <sys/wait.h>
+#include "compat_16.h"
 
-char *TCID = "setreuid04";
+TCID_DEFINE(setreuid04);
 
-uid_t neg_one = -1;
+static uid_t neg_one = -1;
 
 /* flag to tell parent if child passed or failed. */
-int flag = 0;
+static int flag;
 
-uid_t root_pw_uid, nobody_pw_uid;
-char user1name[] = "nobody";
-char rootname[] = "root";
-
-struct passwd nobody, root;
+static struct passwd nobody, root;
 
 /*
  * The following structure contains all test data.  Each structure in the array
@@ -93,15 +55,15 @@ struct test_data_t {
 } test_data[] = {
 	{
 	&neg_one, &neg_one, &root, &root, "After setreuid(-1, nobody),"}, {
-&nobody_pw_uid, &nobody_pw_uid, &nobody, &nobody,
+&nobody.pw_uid, &nobody.pw_uid, &nobody, &nobody,
 		    "After setreuid(-1, -1),"},};
 
 /*int TST_TOTAL = sizeof(test_data)/sizeof(test_data[0]);*/
 int TST_TOTAL = 2;
 
-void setup(void);
-void cleanup(void);
-void uid_verify(struct passwd *, struct passwd *, char *);
+static void setup(void);
+static void cleanup(void);
+static void uid_verify(struct passwd *, struct passwd *, char *);
 
 int main(int ac, char **av)
 {
@@ -115,10 +77,11 @@ int main(int ac, char **av)
 
 	setup();
 
+	flag = 0;
+
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		int i, pid, status;
 
-		/* reset tst_count in case we are looping */
 		tst_count = 0;
 
 		if ((pid = FORK_OR_VFORK()) == -1) {
@@ -128,7 +91,7 @@ int main(int ac, char **av)
 			for (i = 0; i < TST_TOTAL; i++) {
 
 				/* Set the real or effective user id */
-				TEST(setreuid(*test_data[i].real_uid,
+				TEST(SETREUID(cleanup, *test_data[i].real_uid,
 					      *test_data[i].eff_uid));
 
 				if (TEST_RETURN != -1) {
@@ -144,10 +107,6 @@ int main(int ac, char **av)
 					flag = -1;
 				}
 
-				/*
-				 * Perform functional verification if test
-				 * executed without (-f) option.
-				 */
 				if (STD_FUNCTIONAL_TEST) {
 					uid_verify(test_data[i].exp_real_usr,
 						   test_data[i].exp_eff_usr,
@@ -167,62 +126,36 @@ int main(int ac, char **av)
 	}
 	cleanup();
 	tst_exit();
-
 }
 
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
+static void setup(void)
 {
+	tst_require_root(NULL);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
-	if (getpwnam("nobody") == NULL) {
+	if (getpwnam("nobody") == NULL)
 		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
-		tst_exit();
-	}
-
-	/* Check that the test process id is root */
-	if (geteuid() != 0) {
-		tst_brkm(TBROK, NULL, "Must be root for this test!");
-		tst_exit();
-	}
 
 	root = *(getpwnam("root"));
-	root_pw_uid = root.pw_uid;
+	UID16_CHECK(root.pw_uid, setreuid, cleanup);
 
 	nobody = *(getpwnam("nobody"));
-	nobody_pw_uid = nobody.pw_uid;
+	UID16_CHECK(nobody.pw_uid, setreuid, cleanup);
 
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -i option.
-	 * You want to make sure you do this before you create your temporary
-	 * directory.
-	 */
 	TEST_PAUSE;
 }
 
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
 
 }
 
-void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
+static void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
 {
 	if ((getuid() != ru->pw_uid) || (geteuid() != eu->pw_uid)) {
-		tst_resm(TINFO, "ERROR: %s real uid = %d; effective uid = %d",
+		tst_resm(TFAIL, "ERROR: %s real uid = %d; effective uid = %d",
 			 when, getuid(), geteuid());
 		tst_resm(TINFO, "Expected: real uid = %d; effective uid = %d",
 			 ru->pw_uid, eu->pw_uid);
diff --git a/testcases/kernel/syscalls/setreuid/setreuid05.c b/testcases/kernel/syscalls/setreuid/setreuid05.c
index fe8bd89..c46fcd9 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid05.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid05.c
@@ -1,91 +1,47 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Ported by John George
  */
 
 /*
- * NAME
- *	setreuid05.c
- *
- * DESCRIPTION
- *	Test the setreuid() feature, verifying the role of the saved-set-uid
- *	and setreuid's effect on it.
- *
- * ALGORITHM
- *
-*      Setup:
- *	  Setup signal handling
- *	  Get user information.
- *	  Pause for SIGUSER1 if option specified.
- *
- *	Setup test values.
- *	Loop if the proper options are given.
- *	For each test set execute the system call
- *	  Check that we received the expected result.
- *	  If setreuid failed as expected
- *		check that the correct errno value was set.
- *	otherwise
- *		Issue Pass message.
- *	  Verify that the uid and euid values are still correct.
- *	Cleanup:
- *	  Print errno log and/or timing stats if option given.
- *
- * USAGE:  <for command-line>
- *	setreuid05 [-c n] [-f] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions
- *	This test must be run by root.
- *	nobody must be a valid user.
+ * Test the setreuid() feature, verifying the role of the saved-set-uid
+ * and setreuid's effect on it.
  */
 
 #include <errno.h>
 #include <pwd.h>
 #include <stdlib.h>
+#include <sys/wait.h>
+
 #include "test.h"
 #include "usctest.h"
-#include <sys/wait.h>
+#include "compat_16.h"
 
-char *TCID = "setreuid05";
+TCID_DEFINE(setreuid05);
 
 /* flag to tell parent if child passed or failed. */
 int flag = 0;
 
-int fail = -1;
-int pass = 0;
-uid_t neg_one = -1;
-int exp_enos[] = { EPERM, 0 };
-
-uid_t root_pw_uid, nobody_pw_uid, daemon_pw_uid, bin_pw_uid;
-char user1name[] = "nobody";
-char user2name[] = "daemon";
-char rootname[] = "root";
-char binname[] = "bin";
+static int fail = -1;
+static int pass;
+static uid_t neg_one = -1;
 
-struct passwd nobody, daemonpw, root, bin;
+static struct passwd nobody, daemonpw, root, bin;
 
 struct test_data_t {
 	uid_t *real_uid;
@@ -96,39 +52,39 @@ struct test_data_t {
 	char *test_msg;
 } test_data[] = {
 	{
-	&nobody_pw_uid, &root_pw_uid, &pass, &nobody, &root, "Initially"}, {
-	&neg_one, &nobody_pw_uid, &pass, &nobody, &nobody,
+	&nobody.pw_uid, &root.pw_uid, &pass, &nobody, &root, "Initially"}, {
+	&neg_one, &nobody.pw_uid, &pass, &nobody, &nobody,
 		    "After setreuid(-1, nobody),"}, {
-	&neg_one, &root_pw_uid, &pass, &nobody, &root,
+	&neg_one, &root.pw_uid, &pass, &nobody, &root,
 		    "After setreuid(-1, root),"}, {
-	&daemon_pw_uid, &neg_one, &pass, &daemonpw, &root,
+	&daemonpw.pw_uid, &neg_one, &pass, &daemonpw, &root,
 		    "After setreuid(daemon, -1),"}, {
-	&neg_one, &bin_pw_uid, &pass, &daemonpw, &bin,
+	&neg_one, &bin.pw_uid, &pass, &daemonpw, &bin,
 		    "After setreuid(-1, bin),"}, {
-	&neg_one, &root_pw_uid, &fail, &daemonpw, &bin,
+	&neg_one, &root.pw_uid, &fail, &daemonpw, &bin,
 		    "After setreuid(-1, root),"}, {
-	&neg_one, &nobody_pw_uid, &fail, &daemonpw, &bin,
+	&neg_one, &nobody.pw_uid, &fail, &daemonpw, &bin,
 		    "After setreuid(-1, nobody),"}, {
-	&neg_one, &daemon_pw_uid, &pass, &daemonpw, &daemonpw,
+	&neg_one, &daemonpw.pw_uid, &pass, &daemonpw, &daemonpw,
 		    "After setreuid(-1, daemon),"}, {
-	&neg_one, &bin_pw_uid, &pass, &daemonpw, &bin,
+	&neg_one, &bin.pw_uid, &pass, &daemonpw, &bin,
 		    "After setreuid(-1, bin),"}, {
-	&bin_pw_uid, &daemon_pw_uid, &pass, &bin, &daemonpw,
+	&bin.pw_uid, &daemonpw.pw_uid, &pass, &bin, &daemonpw,
 		    "After setreuid(bin, daemon),"}, {
-	&neg_one, &bin_pw_uid, &pass, &bin, &bin, "After setreuid(-1, bin),"},
+	&neg_one, &bin.pw_uid, &pass, &bin, &bin, "After setreuid(-1, bin),"},
 	{
-	&neg_one, &daemon_pw_uid, &pass, &bin, &daemonpw,
+	&neg_one, &daemonpw.pw_uid, &pass, &bin, &daemonpw,
 		    "After setreuid(-1, daemon),"}, {
-	&daemon_pw_uid, &neg_one, &pass, &daemonpw, &daemonpw,
+	&daemonpw.pw_uid, &neg_one, &pass, &daemonpw, &daemonpw,
 		    "After setreuid(daemon, -1),"}, {
-&neg_one, &bin_pw_uid, &fail, &daemonpw, &daemonpw,
+	&neg_one, &bin.pw_uid, &fail, &daemonpw, &daemonpw,
 		    "After setreuid(-1, bin),"},};
 
 int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
 
-void setup(void);
-void cleanup(void);
-void uid_verify(struct passwd *, struct passwd *, char *);
+static void setup(void);
+static void cleanup(void);
+static void uid_verify(struct passwd *, struct passwd *, char *);
 
 int main(int argc, char **argv)
 {
@@ -142,10 +98,11 @@ int main(int argc, char **argv)
 
 	setup();
 
+	pass = 0;
+
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		int i, pid, status;
 
-		/* reset tst_count in case we are looping */
 		tst_count = 0;
 
 		if ((pid = FORK_OR_VFORK()) == -1) {
@@ -153,7 +110,7 @@ int main(int argc, char **argv)
 		} else if (pid == 0) {	/* child */
 			for (i = 0; i < TST_TOTAL; i++) {
 				/* Set the real or effective user id */
-				TEST(setreuid(*test_data[i].real_uid,
+				TEST(SETREUID(cleanup, *test_data[i].real_uid,
 					      *test_data[i].eff_uid));
 
 				if (TEST_RETURN == *test_data[i].exp_ret) {
@@ -193,14 +150,12 @@ int main(int argc, char **argv)
 				if (TEST_RETURN == -1) {
 					TEST_ERROR_LOG(TEST_ERRNO);
 				}
-				/*
-				 * Perform functional verification if test
-				 * executed without (-f) option.
-				 */
 				if (STD_FUNCTIONAL_TEST) {
 					uid_verify(test_data[i].exp_real_usr,
 						   test_data[i].exp_eff_usr,
 						   test_data[i].test_msg);
+				} else {
+					tst_resm(TINFO, "Call succeeded.");
 				}
 			}
 			exit(flag);
@@ -214,73 +169,48 @@ int main(int argc, char **argv)
 	}
 	cleanup();
 	tst_exit();
-
 }
 
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
+static void setup(void)
 {
+	tst_require_root(NULL);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
-	if (getpwnam("nobody") == NULL) {
+	if (getpwnam("nobody") == NULL)
 		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
-		tst_exit();
-	}
 
-	if (getpwnam("daemon") == NULL) {
+	if (getpwnam("daemon") == NULL)
 		tst_brkm(TBROK, NULL, "daemon must be a valid user.");
-		tst_exit();
-	}
-
-	if (getuid() != 0) {
-		tst_resm(TBROK, "Must be run as root");
-		tst_exit();
-	}
 
-	/* set the expected errnos... */
-	TEST_EXP_ENOS(exp_enos);
+	if (getpwnam("bin") == NULL)
+		tst_brkm(TBROK, NULL, "bin must be a valid user.");
 
 	nobody = *(getpwnam("nobody"));
-	nobody_pw_uid = nobody.pw_uid;
+	UID16_CHECK(nobody.pw_uid, setreuid, cleanup);
 
 	daemonpw = *(getpwnam("daemon"));
-	daemon_pw_uid = daemonpw.pw_uid;
+	UID16_CHECK(daemonpw.pw_uid, setreuid, cleanup);
 
 	root = *(getpwnam("root"));
-	root_pw_uid = root.pw_uid;
+	UID16_CHECK(root.pw_uid, setreuid, cleanup);
 
 	bin = *(getpwnam("bin"));
-	bin_pw_uid = bin.pw_uid;
+	UID16_CHECK(bin.pw_uid, setreuid, cleanup);
 
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
 	TEST_PAUSE;
 }
 
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
 
 }
 
-void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
+static void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
 {
 	if ((getuid() != ru->pw_uid) || (geteuid() != eu->pw_uid)) {
-		tst_resm(TINFO, "ERROR: %s real uid = %d; effective uid = %d",
+		tst_resm(TFAIL, "ERROR: %s real uid = %d; effective uid = %d",
 			 when, getuid(), geteuid());
 		tst_resm(TINFO, "Expected: real uid = %d; effective uid = %d",
 			 ru->pw_uid, eu->pw_uid);
diff --git a/testcases/kernel/syscalls/setreuid/setreuid06.c b/testcases/kernel/syscalls/setreuid/setreuid06.c
index f03ab86..823d10b 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid06.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid06.c
@@ -1,44 +1,25 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Ported by John George
  */
 
 /*
- * NAME
- *	setreuid06.c
- *
- * DESCRIPTION
- *	Test that EPERM is set when setreuid is given an invalid user id.
- *
- * USAGE:  <for command-line>
- *	setreuid06 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- *
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions
- *      Must be ran as non-root user - nobody recommended.
+ * Test that EPERM is set when setreuid is given an invalid user id.
  */
 
 #include <wait.h>
@@ -50,20 +31,20 @@
 #include <sys/param.h>
 #include <sys/types.h>
 #include <sys/stat.h>
+
 #include "test.h"
 #include "usctest.h"
+#include "compat_16.h"
 
 #define INVAL_USER		 (USHRT_MAX-2)
 
-char *TCID = "setreuid06";
+TCID_DEFINE(setreuid06);
 int TST_TOTAL = 1;
-int exp_enos[] = { EPERM, 0 };
 
-char nobody_uid[] = "nobody";
-struct passwd *ltpuser;
+static struct passwd *ltpuser;
 
-void setup(void);
-void cleanup(void);
+static void setup(void);
+static void cleanup(void);
 
 int main(int argc, char **argv)
 {
@@ -75,16 +56,12 @@ int main(int argc, char **argv)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 	}
 
-	/*
-	 * perform global setup for the test
-	 */
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
-		/* reset tst_count in case we are looping */
 		tst_count = 0;
 
-		TEST(setreuid(-1, INVAL_USER));
+		TEST(SETREUID(cleanup, -1, INVAL_USER));
 		if (TEST_RETURN != -1) {
 			tst_resm(TFAIL, "%s did not fail as expected", TCID);
 		} else if (TEST_ERRNO == EPERM) {
@@ -100,49 +77,28 @@ int main(int argc, char **argv)
 	}
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
+static void setup(void)
 {
+	tst_require_root(NULL);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
-	/* set the expected errnos... */
-	TEST_EXP_ENOS(exp_enos);
-
 	umask(0);
 
-	/* Switch to nobody user for correct error code collection */
-	if (geteuid() != 0) {
-		tst_brkm(TBROK, NULL, "Test must be run as root");
-	}
-	ltpuser = getpwnam(nobody_uid);
-	if (setuid(ltpuser->pw_uid) == -1) {
-		tst_resm(TINFO, "setuid failed to "
+	ltpuser = getpwnam("nobody");
+	if (ltpuser == NULL)
+		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
+
+	if (setuid(ltpuser->pw_uid) == -1)
+		tst_brkm(TBROK | TERRNO, NULL, "setuid failed to "
 			 "to set the effective uid to %d", ltpuser->pw_uid);
-		perror("setuid");
-	}
 
 	TEST_PAUSE;
 }
 
-/*
- * cleanup()
- *	performs all the ONE TIME cleanup for this test at completion
- *	or premature exit
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/*
-	 * print timing status if that option was specified
-	 * print errno log if that option was specified
-	 */
 	TEST_CLEANUP;
-
 }
diff --git a/testcases/kernel/syscalls/setreuid/setreuid07.c b/testcases/kernel/syscalls/setreuid/setreuid07.c
index e64700c..b2bb6fc 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid07.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid07.c
@@ -1,71 +1,55 @@
-/******************************************************************************/
-/* Copyright (c) Kerlabs 2008.                                                */
-/* Copyright (c) International Business Machines  Corp., 2008                 */
-/*                                                                            */
-/* This program is free software;  you can redistribute it and/or modify      */
-/* it under the terms of the GNU General Public License as published by       */
-/* the Free Software Foundation; either version 2 of the License, or          */
-/* (at your option) any later version.                                        */
-/*                                                                            */
-/* This program is distributed in the hope that it will be useful,            */
-/* but WITHOUT ANY WARRANTY;  without even the implied warranty of            */
-/* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See                  */
-/* the GNU General Public License for more details.                           */
-/*                                                                            */
-/* You should have received a copy of the GNU General Public License          */
-/* along with this program;  if not, write to the Free Software               */
-/* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA    */
-/*                                                                            */
-/******************************************************************************/
 /*
- * NAME
- *	setreuid07.c
+ * Copyright (c) Kerlabs 2008.
+ * Copyright (c) International Business Machines  Corp., 2008
  *
- * DESCRIPTION
- *	Check if setreuid behaves correctly with file permissions.
- *      The test creates a file as ROOT with permissions 0644, does a setreuid
- *      and then tries to open the file with RDWR permissions.
- *      The same test is done in a fork to check if new UIDs are correctly
- *      passed to the son.
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- * USAGE:  <for command-line>
- *  setreuid07 [-c n] [-e] [-i n] [-I x] [-P x] [-t]
- *     where,  -c n : Run n copies concurrently.
- *             -e   : Turn on errno logging.
- *             -i n : Execute test n times.
- *             -I x : Execute test for x seconds.
- *             -P x : Pause for x seconds between iterations.
- *             -t   : Turn on syscall timing.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- * HISTORY
- *	07/2001 Created by Renaud Lottiaux
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
- * RESTRICTIONS
- *	Must be run as root.
+ * Created by Renaud Lottiaux
  */
+
+/*
+ * Check if setreuid behaves correctly with file permissions.
+ * The test creates a file as ROOT with permissions 0644, does a setreuid
+ * and then tries to open the file with RDWR permissions.
+ * The same test is done in a fork to check if new UIDs are correctly
+ * passed to the son.
+ */
+
 #include <errno.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
 #include <fcntl.h>
 #include <unistd.h>
+#include <pwd.h>
+
 #include "test.h"
 #include "usctest.h"
-#include <pwd.h>
+#include "compat_16.h"
 
-char *TCID = "setreuid07";
+TCID_DEFINE(setreuid07);
 int TST_TOTAL = 1;
-char nobody_uid[] = "nobody";
-char testfile[256] = "";
-struct passwd *ltpuser;
 
-int exp_enos[] = { EACCES, 0 };
+static char testfile[256] = "";
+static struct passwd *ltpuser;
 
-int fd = -1;
+static int fd = -1;
 
-void setup(void);
-void cleanup(void);
-void do_master_child();
+static void setup(void);
+static void cleanup(void);
+static void do_master_child(void);
 
 int main(int ac, char **av)
 {
@@ -74,10 +58,9 @@ int main(int ac, char **av)
 	int status;
 
 	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
-		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-	setup();
+		tst_brkm(TBROK, cleanup, "OPTION PARSING ERROR - %s", msg);
 
-	TEST_EXP_ENOS(exp_enos);
+	setup();
 
 	pid = FORK_OR_VFORK();
 	if (pid < 0)
@@ -95,10 +78,7 @@ int main(int ac, char **av)
 	tst_exit();
 }
 
-/*
- * do_master_child()
- */
-void do_master_child()
+static void do_master_child(void)
 {
 	int lc;
 	int pid;
@@ -107,11 +87,10 @@ void do_master_child()
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		int tst_fd;
 
-		/* Reset tst_count in case we are looping */
 		tst_count = 0;
 
-		if (setreuid(0, ltpuser->pw_uid) == -1) {
-			perror("setfsuid failed");
+		if (SETREUID(NULL, 0, ltpuser->pw_uid) == -1) {
+			perror("setreuid failed");
 			exit(1);
 		}
 
@@ -175,8 +154,8 @@ void do_master_child()
 		 *         the file with RDWR permissions.
 		 */
 		tst_count++;
-		if (setreuid(0, 0) == -1) {
-			perror("setfsuid failed");
+		if (SETREUID(NULL, 0, 0) == -1) {
+			perror("setreuid failed");
 			exit(1);
 		}
 
@@ -193,14 +172,13 @@ void do_master_child()
 	exit(0);
 }
 
-/*
- * setup() - performs all ONE TIME setup for this test
- */
-void setup(void)
+static void setup(void)
 {
 	tst_require_root(NULL);
 
-	ltpuser = getpwnam(nobody_uid);
+	ltpuser = getpwnam("nobody");
+	if (ltpuser == NULL)
+		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
 
 	tst_tmpdir();
 
@@ -209,27 +187,19 @@ void setup(void)
 	/* Create test file */
 	fd = open(testfile, O_CREAT | O_RDWR, 0644);
 	if (fd < 0)
-		tst_brkm(TBROK, cleanup, "cannot creat test file");
+		tst_brkm(TBROK | TERRNO,
+			cleanup, "cannot create test file");
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
 	TEST_PAUSE;
 }
 
-/*
- * cleanup() - performs all the ONE TIME cleanup for this test at completion
- *	       or premature exit
- */
-void cleanup(void)
+static void cleanup(void)
 {
 	close(fd);
 
-	/*
-	 * print timing status if that option was specified
-	 * print errno log if that option was specified
-	 */
 	TEST_CLEANUP;
 
 	tst_rmdir();
-
 }
diff --git a/testcases/kernel/syscalls/utils/compat_16.h b/testcases/kernel/syscalls/utils/compat_16.h
index fa1217d..b1da7d7 100644
--- a/testcases/kernel/syscalls/utils/compat_16.h
+++ b/testcases/kernel/syscalls/utils/compat_16.h
@@ -116,4 +116,9 @@ int SETFSGID(void (cleanup)(void), GID_T gid)
 {
 	LTP_CREATE_SYSCALL(setfsgid, cleanup, gid);
 }
+
+int SETREUID(void (cleanup)(void), UID_T ruid, UID_T euid)
+{
+	LTP_CREATE_SYSCALL(setreuid, cleanup, ruid, euid);
+}
 #endif /* __LTP_COMPAT_16_H__ */
-- 
1.7.1


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 2/3] syscalls/setregid{01, 03, 04}: 16-bit fixes and minor cleanup
  2013-10-21  7:25 [LTP] 16-bit fixes for setreuid, setregid Stanislav Kholmanskikh
  2013-10-21  7:25 ` [LTP] [PATCH 1/3] syscalls/setreuid: 16-bit fixes and minor cleanup Stanislav Kholmanskikh
@ 2013-10-21  7:25 ` Stanislav Kholmanskikh
  2013-10-21  7:25 ` [LTP] [PATCH 3/3] syscalls/setregid02: fixes Stanislav Kholmanskikh
  2013-10-22 17:08 ` [LTP] 16-bit fixes for setreuid, setregid chrubis
  3 siblings, 0 replies; 5+ messages in thread
From: Stanislav Kholmanskikh @ 2013-10-21  7:25 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 testcases/kernel/syscalls/setregid/setregid01.c |  146 +++---------------
 testcases/kernel/syscalls/setregid/setregid03.c |  184 ++++++++---------------
 testcases/kernel/syscalls/setregid/setregid04.c |  142 +++++-------------
 testcases/kernel/syscalls/utils/compat_16.h     |    4 +
 4 files changed, 124 insertions(+), 352 deletions(-)

diff --git a/testcases/kernel/syscalls/setregid/setregid01.c b/testcases/kernel/syscalls/setregid/setregid01.c
index a24177d..dae17bf 100644
--- a/testcases/kernel/syscalls/setregid/setregid01.c
+++ b/testcases/kernel/syscalls/setregid/setregid01.c
@@ -29,104 +29,30 @@
  *
  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
  *
+ * Author: William Roske
+ * Co-pilot: Dave Fenner
+ */
+
+/*
+ * Testcase to test the basic functionality of setregid(2) systemm call.
  */
-/* $Id: setregid01.c,v 1.6 2009/11/02 13:57:18 subrata_modak Exp $ */
-/**********************************************************
- *
- *    OS Test - Silicon Graphics, Inc.
- *
- *    TEST IDENTIFIER	: setregid01
- *
- *    EXECUTED BY	: anyone
- *
- *    TEST TITLE	: Basic test for setregid(2)
- *
- *    PARENT DOCUMENT	: usctpl01
- *
- *    TEST CASE TOTAL	: 5
- *
- *    WALL CLOCK TIME	: 1
- *
- *    CPU TYPES		: ALL
- *
- *    AUTHOR		: William Roske
- *
- *    CO-PILOT		: Dave Fenner
- *
- *    DATE STARTED	: 05/13/92
- *
- *    INITIAL RELEASE	: UNICOS 7.0
- *
- *    TEST CASES
- *
- * 	1.) setregid(2) returns...(See Description)
- *
- *    INPUT SPECIFICATIONS
- * 	The standard options for system call tests are accepted.
- *	(See the parse_opts(3) man page).
- *
- *    OUTPUT SPECIFICATIONS
- *
- *    DURATION
- * 	Terminates - with frequency and infinite modes.
- *
- *    SIGNALS
- * 	Uses SIGUSR1 to pause before test if option set.
- * 	(See the parse_opts(3) man page).
- *
- *    RESOURCES
- * 	None
- *
- *    ENVIRONMENTAL NEEDS
- *      No run-time environmental needs.
- *
- *    SPECIAL PROCEDURAL REQUIREMENTS
- * 	None
- *
- *    INTERCASE DEPENDENCIES
- * 	None
- *
- *    DETAILED DESCRIPTION
- *	This is a Phase I test for the setregid(2) system call.  It is intended
- *	to provide a limited exposure of the system call, for now.  It
- *	should/will be extended when full functional tests are written for
- *	setregid(2).
- *
- * 	Setup:
- * 	  Setup signal handling.
- *	  Pause for SIGUSR1 if option specified.
- *
- * 	Test:
- *	 Loop if the proper options are given.
- * 	  Execute system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise, Issue a PASS message.
- *
- * 	Cleanup:
- * 	  Print errno log and/or timing stats if options given
- *
- *
- *#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#*#**/
 
 #include <errno.h>
 #include <string.h>
 #include <signal.h>
-
 #include <sys/types.h>
 
 #include "test.h"
 #include "usctest.h"
+#include "compat_16.h"
 
-void setup();
-void cleanup();
+static void setup(void);
+static void cleanup(void);
 
-char *TCID = "setregid01";
+TCID_DEFINE(setregid01);
 int TST_TOTAL = 5;
 
-int exp_enos[] = { 0, 0 };
-
-int gid, egid;			/* current real and effective group id */
+static gid_t gid, egid;	/* current real and effective group id */
 
 int main(int ac, char **av)
 {
@@ -138,9 +64,6 @@ int main(int ac, char **av)
 
 	setup();
 
-	/* set the expected errnos... */
-	TEST_EXP_ENOS(exp_enos);
-
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 
 		tst_count = 0;
@@ -150,12 +73,13 @@ int main(int ac, char **av)
 		 *  Dont change either real or effective gid
 		 */
 		gid = getgid();
+		GID16_CHECK(gid, setregid, cleanup);
+
 		egid = getegid();
+		GID16_CHECK(egid, setregid, cleanup);
 
-		/* Call setregid(2) */
-		TEST(setregid(-1, -1));
+		TEST(SETREGID(cleanup, -1, -1));
 
-		/* check return code */
 		if (TEST_RETURN == -1) {
 			TEST_ERROR_LOG(TEST_ERRNO);
 			tst_resm(TFAIL,
@@ -163,7 +87,6 @@ int main(int ac, char **av)
 				 TEST_ERRNO, strerror(TEST_ERRNO));
 		} else {
 			if (STD_FUNCTIONAL_TEST) {
-				/* No Verification test, yet... */
 				tst_resm(TPASS,
 					 "setregid -  Dont change either real or effective gid returned %ld",
 					 TEST_RETURN);
@@ -175,10 +98,8 @@ int main(int ac, char **av)
 		 *  change effective to effective gid
 		 */
 
-		/* Call setregid(2) */
-		TEST(setregid(-1, egid));
+		TEST(SETREGID(cleanup, -1, egid));
 
-		/* check return code */
 		if (TEST_RETURN == -1) {
 			TEST_ERROR_LOG(TEST_ERRNO);
 			tst_resm(TFAIL,
@@ -186,7 +107,6 @@ int main(int ac, char **av)
 				 TEST_ERRNO, strerror(TEST_ERRNO));
 		} else {
 			if (STD_FUNCTIONAL_TEST) {
-				/* No Verification test, yet... */
 				tst_resm(TPASS,
 					 "setregid -  change effective to effective gid returned %ld",
 					 TEST_RETURN);
@@ -198,10 +118,8 @@ int main(int ac, char **av)
 		 *  change real to real gid
 		 */
 
-		/* Call setregid(2) */
-		TEST(setregid(gid, -1));
+		TEST(SETREGID(cleanup, gid, -1));
 
-		/* check return code */
 		if (TEST_RETURN == -1) {
 			TEST_ERROR_LOG(TEST_ERRNO);
 			tst_resm(TFAIL,
@@ -209,7 +127,6 @@ int main(int ac, char **av)
 				 TEST_ERRNO, strerror(TEST_ERRNO));
 		} else {
 			if (STD_FUNCTIONAL_TEST) {
-				/* No Verification test, yet... */
 				tst_resm(TPASS,
 					 "setregid -  change real to real gid returned %ld",
 					 TEST_RETURN);
@@ -221,10 +138,8 @@ int main(int ac, char **av)
 		 *  change effective to real gid
 		 */
 
-		/* Call setregid(2) */
-		TEST(setregid(-1, gid));
+		TEST(SETREGID(cleanup, -1, gid));
 
-		/* check return code */
 		if (TEST_RETURN == -1) {
 			TEST_ERROR_LOG(TEST_ERRNO);
 			tst_resm(TFAIL,
@@ -232,7 +147,6 @@ int main(int ac, char **av)
 				 TEST_ERRNO, strerror(TEST_ERRNO));
 		} else {
 			if (STD_FUNCTIONAL_TEST) {
-				/* No Verification test, yet... */
 				tst_resm(TPASS,
 					 "setregid -  change effective to real gid returned %ld",
 					 TEST_RETURN);
@@ -244,16 +158,13 @@ int main(int ac, char **av)
 		 *  try to change real to current real
 		 */
 
-		/* Call setregid(2) */
-		TEST(setregid(gid, gid));
+		TEST(SETREGID(cleanup, gid, gid));
 
-		/* check return code */
 		if (TEST_RETURN == -1) {
 			TEST_ERROR_LOG(TEST_ERRNO);
 			tst_resm(TFAIL | TTERRNO, "setregid failed");
 		} else {
 			if (STD_FUNCTIONAL_TEST) {
-				/* No Verification test, yet... */
 				tst_resm(TPASS, "setregid return %ld",
 					 TEST_RETURN);
 			}
@@ -263,34 +174,19 @@ int main(int ac, char **av)
 
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
-/***************************************************************
- * setup() - performs all ONE TIME setup for this test.
- ***************************************************************/
-void setup()
+static void setup(void)
 {
-
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
 	TEST_PAUSE;
 
-	/* make a temp dir and cd to it */
 	tst_tmpdir();
 }
 
-/***************************************************************
- * cleanup() - performs all ONE TIME cleanup for this test at
- *		completion or premature exit.
- ***************************************************************/
-void cleanup()
+static void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
 
 	tst_rmdir();
diff --git a/testcases/kernel/syscalls/setregid/setregid03.c b/testcases/kernel/syscalls/setregid/setregid03.c
index b9a5311..932371b 100644
--- a/testcases/kernel/syscalls/setregid/setregid03.c
+++ b/testcases/kernel/syscalls/setregid/setregid03.c
@@ -1,65 +1,25 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Ported by John George
  */
 
 /*
- * NAME
- * 	setregid03.c
- *
- * DESCRIPTION
- * 	Test setregid() when executed by a non-root user.
- *
- * ALGORITHM
- *
- *	Setup:
- *	  Setup signal handling
- *	  Get user information.
- *	  Pause for SIGUSER1 if option specified.
- *	Setup test values.
- *	Loop if the proper options are given.
- *	For each test set execute the system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise,
- *		Verify the Functionality of system call
- *		if successful,
- *			Issue Functionality-Pass message.
- *		Otherwise,
- *			Issue Functionality-Fail message.
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given.
- *
- * USAGE:  <for command-line>
- *	setregid03 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions
- * 	This test must be ran as root.
- *	users, sys and bin must be valid groups.
+ * Test setregid() when executed by a non-root user.
  */
 
 #include <errno.h>
@@ -67,21 +27,19 @@
 #include <stdlib.h>
 #include <pwd.h>
 #include <string.h>
-#include "test.h"
-#include "usctest.h"
 #include <sys/wait.h>
 
-char *TCID = "setregid03";
-int fail = -1;
-int pass = 0;
-gid_t neg_one = -1;
-int exp_enos[] = { 0 };
+#include "test.h"
+#include "usctest.h"
+#include "compat_16.h"
 
-gid_t users_gr_gid, root_gr_gid, sys_gr_gid, bin_gr_gid;
-uid_t nobody_pw_uid;
+TCID_DEFINE(setregid03);
+static int fail = -1;
+static int pass;
+static gid_t neg_one = -1;
 
 /* flag to tell parent if child passed or failed. */
-int flag = 0;
+static int flag;
 
 struct group users, sys, root, bin;
 struct passwd nobody;
@@ -99,33 +57,33 @@ struct test_data_t {
 	char *test_msg;
 } test_data[] = {
 	{
-	&sys_gr_gid, &bin_gr_gid, &pass, &sys, &bin,
+	&sys.gr_gid, &bin.gr_gid, &pass, &sys, &bin,
 		    "After setregid(sys, bin),"}, {
-	&neg_one, &sys_gr_gid, &pass, &sys, &sys, "After setregid(-1, sys)"},
+	&neg_one, &sys.gr_gid, &pass, &sys, &sys, "After setregid(-1, sys)"},
 	{
-	&neg_one, &bin_gr_gid, &pass, &sys, &bin, "After setregid(-1, bin),"},
+	&neg_one, &bin.gr_gid, &pass, &sys, &bin, "After setregid(-1, bin),"},
 	{
-	&bin_gr_gid, &neg_one, &pass, &bin, &bin, "After setregid(bin, -1),"},
+	&bin.gr_gid, &neg_one, &pass, &bin, &bin, "After setregid(bin, -1),"},
 	{
 	&neg_one, &neg_one, &pass, &bin, &bin, "After setregid(-1, -1),"}, {
-	&neg_one, &bin_gr_gid, &pass, &bin, &bin, "After setregid(-1, bin),"},
+	&neg_one, &bin.gr_gid, &pass, &bin, &bin, "After setregid(-1, bin),"},
 	{
-	&bin_gr_gid, &neg_one, &pass, &bin, &bin, "After setregid(bin, -1),"},
+	&bin.gr_gid, &neg_one, &pass, &bin, &bin, "After setregid(bin, -1),"},
 	{
-	&bin_gr_gid, &bin_gr_gid, &pass, &bin, &bin,
+	&bin.gr_gid, &bin.gr_gid, &pass, &bin, &bin,
 		    "After setregid(bin, bin),"}, {
-	&sys_gr_gid, &neg_one, &fail, &bin, &bin, "After setregid(sys, -1)"},
+	&sys.gr_gid, &neg_one, &fail, &bin, &bin, "After setregid(sys, -1)"},
 	{
-	&neg_one, &sys_gr_gid, &fail, &bin, &bin, "After setregid(-1, sys)"},
+	&neg_one, &sys.gr_gid, &fail, &bin, &bin, "After setregid(-1, sys)"},
 	{
-&sys_gr_gid, &sys_gr_gid, &fail, &bin, &bin,
+	&sys.gr_gid, &sys.gr_gid, &fail, &bin, &bin,
 		    "After setregid(sys, sys)"},};
 
 int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
 
-void setup(void);
-void cleanup(void);
-void gid_verify(struct group *ru, struct group *eu, char *when);
+static void setup(void);
+static void cleanup(void);
+static void gid_verify(struct group *ru, struct group *eu, char *when);
 
 int main(int ac, char **av)
 {
@@ -141,15 +99,16 @@ int main(int ac, char **av)
 		pid_t pid;
 		int status, i;
 
-		/* reset tst_count in case we are looping */
+		pass = 0;
+		flag = 0;
+
 		tst_count = 0;
 
 		/* set the appropriate ownership values */
-		if (setregid(sys_gr_gid, bin_gr_gid) == -1) {
+		if (SETREGID(cleanup, sys.gr_gid, bin.gr_gid) == -1)
 			tst_brkm(TBROK, NULL, "Initial setregid failed");
-		}
 
-		if (seteuid(nobody_pw_uid) == -1) {
+		if (seteuid(nobody.pw_uid) == -1) {
 			tst_brkm(TBROK, NULL, "Initial seteuid failed");
 		}
 		if ((pid = FORK_OR_VFORK()) == -1) {
@@ -158,7 +117,7 @@ int main(int ac, char **av)
 			for (i = 0; i < TST_TOTAL; i++) {
 				gid_t test_ret;
 				/* Set the real or effective group id */
-				TEST(setregid(*test_data[i].real_gid,
+				TEST(SETREGID(NULL, *test_data[i].real_gid,
 					      *test_data[i].eff_gid));
 				test_ret = TEST_RETURN;
 
@@ -202,10 +161,6 @@ int main(int ac, char **av)
 					TEST_ERROR_LOG(TEST_ERRNO);
 				}
 
-				/*
-				 * Perform functional verification if test
-				 * executed without (-f) option.
-				 */
 				if (STD_FUNCTIONAL_TEST) {
 					gid_verify(test_data[i].exp_real_usr,
 						   test_data[i].exp_eff_usr,
@@ -225,65 +180,50 @@ int main(int ac, char **av)
 	}
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
+static void setup(void)
 {
+	struct group *junk;
+
 	tst_require_root(NULL);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
-	/* set the expected errnos... */
-	TEST_EXP_ENOS(exp_enos);
-
+	if (getpwnam("nobody") == NULL)
+		tst_brkm(TBROK, NULL, "nobody must be a valid user.");
 	nobody = *(getpwnam("nobody"));
-	nobody_pw_uid = nobody.pw_uid;
-
-	root = *(getgrnam("root"));
-	root_gr_gid = root.gr_gid;
-
-	users = *(getgrnam("users"));
-	users_gr_gid = users.gr_gid;
 
-	sys = *(getgrnam("sys"));
-	sys_gr_gid = sys.gr_gid;
+#define GET_GID(group) do { \
+	junk = getgrnam(#group); \
+	if (junk == NULL) { \
+		tst_brkm(TBROK, NULL, "%s must be a valid group", #group); \
+	} \
+	GID16_CHECK(junk->gr_gid, setregid, NULL); \
+	group = *(junk); \
+} while (0)
 
-	bin = *(getgrnam("bin"));
-	bin_gr_gid = bin.gr_gid;
+	GET_GID(users);
+	GET_GID(sys);
+	GET_GID(bin);
 
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
 	TEST_PAUSE;
 }
 
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
 }
 
-void gid_verify(struct group *rg, struct group *eg, char *when)
+static void gid_verify(struct group *rg, struct group *eg, char *when)
 {
 	if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) {
-		tst_resm(TINFO, "ERROR: %s real gid = %d; effective gid = %d",
+		tst_resm(TFAIL, "ERROR: %s real gid = %d; effective gid = %d",
 			 when, getgid(), getegid());
 		tst_resm(TINFO, "Expected: real gid = %d; effective gid = %d",
 			 rg->gr_gid, eg->gr_gid);
 		flag = -1;
+	} else {
+		tst_resm(TPASS, "real or effective gid was modified as expected");
 	}
 }
diff --git a/testcases/kernel/syscalls/setregid/setregid04.c b/testcases/kernel/syscalls/setregid/setregid04.c
index ee1348c..7b343e2 100644
--- a/testcases/kernel/syscalls/setregid/setregid04.c
+++ b/testcases/kernel/syscalls/setregid/setregid04.c
@@ -1,81 +1,42 @@
 /*
+ * Copyright (c) International Business Machines  Corp., 2001
  *
- *   Copyright (c) International Business Machines  Corp., 2001
+ * This program is free software;  you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
  *
- *   This program is free software;  you can redistribute it and/or modify
- *   it under the terms of the GNU General Public License as published by
- *   the Free Software Foundation; either version 2 of the License, or
- *   (at your option) any later version.
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY;  without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
+ * the GNU General Public License for more details.
  *
- *   This program is distributed in the hope that it will be useful,
- *   but WITHOUT ANY WARRANTY;  without even the implied warranty of
- *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See
- *   the GNU General Public License for more details.
+ * You should have received a copy of the GNU General Public License
+ * along with this program;  if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  *
- *   You should have received a copy of the GNU General Public License
- *   along with this program;  if not, write to the Free Software
- *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ * Ported by John George
  */
 
 /*
- * NAME
- * 	setregid04.c
- *
- * DESCRIPTION
- * 	Test setregid() when executed by root.
- *
- * ALGORITHM
- *
- *	Setup:
- *	  Setup signal handling
- *	  Get user information.
- *	  Pause for SIGUSER1 if option specified.
- *	Setup test values.
- *	Loop if the proper options are given.
- *	For each test set execute the system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise,
- *		Verify the Functionality of system call
- *		if successful,
- *			Issue Functionality-Pass message.
- *		Otherwise,
- *			Issue Functionality-Fail message.
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given.
- *
- * USAGE:  <for command-line>
- *	setregid04 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions
- * 	This test must be ran as root.
+ * Test setregid() when executed by root.
  */
 
+#include <errno.h>
 #include <pwd.h>
 #include <grp.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include "test.h"
 #include "usctest.h"
-#include <errno.h>
+#include "compat_16.h"
+
+TCID_DEFINE(setregid04);
 
-char *TCID = "setregid04";
-gid_t users_gr_gid, root_gr_gid, daemon_gr_gid, bin_gr_gid;
-gid_t neg_one = -1;
-int exp_enos[] = { 0 };
+static gid_t neg_one = -1;
 
-/* Avoid clashing with daemon in unistd.h. */
-struct group users_gr, daemon_gr, root_gr, bin_gr;
+static struct group users_gr, daemon_gr, root_gr, bin_gr;
 
 /*
  * The following structure contains all test data.  Each structure in the array
@@ -90,31 +51,31 @@ struct test_data_t {
 	const char *test_msg;
 } test_data[] = {
 	{
-	&root_gr_gid, &root_gr_gid, &root_gr, &root_gr,
+	&root_gr.gr_gid, &root_gr.gr_gid, &root_gr, &root_gr,
 		    "After setregid(root, root),"}, {
-	&users_gr_gid, &neg_one, &users_gr, &root_gr,
+	&users_gr.gr_gid, &neg_one, &users_gr, &root_gr,
 		    "After setregid(users, -1)"}, {
-	&root_gr_gid, &neg_one, &root_gr, &root_gr,
+	&root_gr.gr_gid, &neg_one, &root_gr, &root_gr,
 		    "After setregid(root,-1),"}, {
 	&neg_one, &neg_one, &root_gr, &root_gr,
 		    "After setregid(-1, -1),"}, {
-	&neg_one, &root_gr_gid, &root_gr, &root_gr,
+	&neg_one, &root_gr.gr_gid, &root_gr, &root_gr,
 		    "After setregid(-1, root)"}, {
-	&root_gr_gid, &neg_one, &root_gr, &root_gr,
+	&root_gr.gr_gid, &neg_one, &root_gr, &root_gr,
 		    "After setregid(root, -1),"}, {
-	&daemon_gr_gid, &users_gr_gid, &daemon_gr, &users_gr,
+	&daemon_gr.gr_gid, &users_gr.gr_gid, &daemon_gr, &users_gr,
 		    "After setregid(daemon, users)"}, {
 	&neg_one, &neg_one, &daemon_gr, &users_gr,
 		    "After setregid(-1, -1)"}, {
-	&neg_one, &users_gr_gid, &daemon_gr, &users_gr,
+	&neg_one, &users_gr.gr_gid, &daemon_gr, &users_gr,
 		    "After setregid(-1, users)"}
 };
 
 int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
 
-void setup(void);
-void cleanup(void);
-void gid_verify(struct group *ru, struct group *eu, const char *when);
+static void setup(void);
+static void cleanup(void);
+static void gid_verify(struct group *ru, struct group *eu, const char *when);
 
 int main(int ac, char **av)
 {
@@ -129,12 +90,11 @@ int main(int ac, char **av)
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		int i;
 
-		/* reset tst_count in case we are looping */
 		tst_count = 0;
 
 		for (i = 0; i < TST_TOTAL; i++) {
 			/* Set the real or effective group id */
-			TEST(setregid(*test_data[i].real_gid,
+			TEST(SETREGID(cleanup, *test_data[i].real_gid,
 				      *test_data[i].eff_gid));
 
 			if (TEST_RETURN == -1) {
@@ -143,10 +103,6 @@ int main(int ac, char **av)
 					 *test_data[i].real_gid,
 					 *test_data[i].eff_gid);
 			} else {
-				/*
-				 * Perform functional verification if test
-				 * executed without (-f) option.
-				 */
 				if (STD_FUNCTIONAL_TEST) {
 					gid_verify(test_data[i].exp_real_usr,
 						   test_data[i].exp_eff_usr,
@@ -160,58 +116,34 @@ int main(int ac, char **av)
 
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
 #define SAFE_GETGROUP(GROUPNAME)	\
-	if ((junk = getgrnam(#GROUPNAME)) == NULL) { \
+	if (getgrnam(#GROUPNAME) == NULL) { \
 		tst_brkm(TBROK, NULL, "Couldn't find the `" #GROUPNAME "' group"); \
 	} \
-	memcpy((void*) &GROUPNAME ## _gr, (const void*) junk, sizeof(struct group)); \
-	GROUPNAME ## _gr_gid = GROUPNAME ## _gr.gr_gid
+	GROUPNAME ## _gr = *(getgrnam(#GROUPNAME));
 
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
+static void setup(void)
 {
-	struct group *junk;
-
 	tst_require_root(NULL);
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
-	/* set the expected errnos... */
-	TEST_EXP_ENOS(exp_enos);
-
 	SAFE_GETGROUP(root);
 	SAFE_GETGROUP(users);
 	SAFE_GETGROUP(daemon);
 	SAFE_GETGROUP(bin);
 
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
 	TEST_PAUSE;
 }
 
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
 }
 
-void gid_verify(struct group *rg, struct group *eg, const char *when)
+static void gid_verify(struct group *rg, struct group *eg, const char *when)
 {
 	if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) {
 		tst_resm(TFAIL, "ERROR: %s real gid = %d; effective gid = %d",
diff --git a/testcases/kernel/syscalls/utils/compat_16.h b/testcases/kernel/syscalls/utils/compat_16.h
index b1da7d7..47f9912 100644
--- a/testcases/kernel/syscalls/utils/compat_16.h
+++ b/testcases/kernel/syscalls/utils/compat_16.h
@@ -121,4 +121,8 @@ int SETREUID(void (cleanup)(void), UID_T ruid, UID_T euid)
 {
 	LTP_CREATE_SYSCALL(setreuid, cleanup, ruid, euid);
 }
+int SETREGID(void (cleanup)(void), GID_T rgid, GID_T egid)
+{
+	LTP_CREATE_SYSCALL(setregid, cleanup, rgid, egid);
+}
 #endif /* __LTP_COMPAT_16_H__ */
-- 
1.7.1


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* [LTP] [PATCH 3/3] syscalls/setregid02: fixes
  2013-10-21  7:25 [LTP] 16-bit fixes for setreuid, setregid Stanislav Kholmanskikh
  2013-10-21  7:25 ` [LTP] [PATCH 1/3] syscalls/setreuid: 16-bit fixes and minor cleanup Stanislav Kholmanskikh
  2013-10-21  7:25 ` [LTP] [PATCH 2/3] syscalls/setregid{01, 03, 04}: " Stanislav Kholmanskikh
@ 2013-10-21  7:25 ` Stanislav Kholmanskikh
  2013-10-22 17:08 ` [LTP] 16-bit fixes for setreuid, setregid chrubis
  3 siblings, 0 replies; 5+ messages in thread
From: Stanislav Kholmanskikh @ 2013-10-21  7:25 UTC (permalink / raw)
  To: ltp-list; +Cc: vasily.isaenko

It was a bug that the testcase initially changed its uid/gid
to 'nobody' user but after performing setregid() It waited for
'users' gid. Fixed this.

Also added 16-bit version check and performed minor cleanup.

Signed-off-by: Stanislav Kholmanskikh <stanislav.kholmanskikh@oracle.com>
---
 testcases/kernel/syscalls/setregid/setregid02.c |  144 +++++++----------------
 1 files changed, 41 insertions(+), 103 deletions(-)

diff --git a/testcases/kernel/syscalls/setregid/setregid02.c b/testcases/kernel/syscalls/setregid/setregid02.c
index 349a494..5674070 100644
--- a/testcases/kernel/syscalls/setregid/setregid02.c
+++ b/testcases/kernel/syscalls/setregid/setregid02.c
@@ -15,74 +15,34 @@
  *   You should have received a copy of the GNU General Public License
  *   along with this program;  if not, write to the Free Software
  *   Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ *   Ported by John George
  */
 
 /*
- * NAME
- * 	setregid02.c
- *
- * DESCRIPTION
- * 	Test that setregid() fails and sets the proper errno values when a
- *	non-root user attemps to change the real or effective group id to a
- *	value other than the current gid or the current effective gid.
- *
- * ALGORITHM
- *
- *	Setup:
- *	  Setup signal handling
- *	  Get user information.
- *	  Pause for SIGUSER1 if option specified.
- *	Setup test values.
- *	Loop if the proper options are given.
- *	For each test set execute the system call
- *	  Check return code, if system call failed (return=-1)
- *		Log the errno and Issue a FAIL message.
- *	  Otherwise,
- *		Verify the Functionality of system call
- *		if successful,
- *			Issue Functionality-Pass message.
- *		Otherwise,
- *			Issue Functionality-Fail message.
- *	Cleanup:
- *	  Print errno log and/or timing stats if options given.
- *
- * USAGE:  <for command-line>
- *	setregid02 [-c n] [-e] [-f] [-i n] [-I x] [-P x] [-t]
- *	where,  -c n : Run n copies concurrently.
- *		-e   : Turn on errno logging.
- *		-f   : Turn off functionality Testing.
- *		-i n : Execute test n times.
- *		-I x : Execute test for x seconds.
- *		-P x : Pause for x seconds between iterations.
- *		-t   : Turn on syscall timing.
- * History
- *	07/2001 John George
- *		-Ported
- *
- * Restrictions
- * 	This test must be ran as root.
- *	users must be a valid group.
+ * Test that setregid() fails and sets the proper errno values when a
+ * non-root user attemps to change the real or effective group id to a
+ * value other than the current gid or the current effective gid.
  */
 
+#include <errno.h>
 #include <pwd.h>
 #include <grp.h>
 #include <stdlib.h>
 #include <string.h>
+
 #include "test.h"
 #include "usctest.h"
-#include <errno.h>
+#include "compat_16.h"
+
+TCID_DEFINE(setregid02);
 
-char *TCID = "setregid02";
-gid_t users_gr_gid, root_gr_gid, bin_gr_gid;
-gid_t neg_one = -1;
-int exp_enos[] = { EPERM, 0 };
+static gid_t neg_one = -1;
 
-gid_t inval_user = (USHRT_MAX);
-char nobody_uid[] = "nobody";
-struct passwd *nobody;
+static gid_t inval_user = (USHRT_MAX);
+static struct passwd *ltpuser;
 
-struct group users, root, bin;
-struct passwd *nobody;
+static struct group nobody, root, bin;
 
 /*
  * The following structure contains all test data.  Each structure in the array
@@ -98,28 +58,28 @@ struct test_data_t {
 	char *test_msg;
 } test_data[] = {
 	{
-	&neg_one, &root_gr_gid, EPERM, &users, &users,
+	&neg_one, &root.gr_gid, EPERM, &nobody, &nobody,
 		    "After setregid(-1, root),"}, {
-	&neg_one, &bin_gr_gid, EPERM, &users, &users,
+	&neg_one, &bin.gr_gid, EPERM, &nobody, &nobody,
 		    "After setregid(-1, bin)"}, {
-	&root_gr_gid, &neg_one, EPERM, &users, &users,
+	&root.gr_gid, &neg_one, EPERM, &nobody, &nobody,
 		    "After setregid(root,-1),"}, {
-	&bin_gr_gid, &neg_one, EPERM, &users, &users,
+	&bin.gr_gid, &neg_one, EPERM, &nobody, &nobody,
 		    "After setregid(bin, -1),"}, {
-	&root_gr_gid, &bin_gr_gid, EPERM, &users, &users,
+	&root.gr_gid, &bin.gr_gid, EPERM, &nobody, &nobody,
 		    "After setregid(root, bin)"}, {
-	&bin_gr_gid, &root_gr_gid, EPERM, &users, &users,
+	&bin.gr_gid, &root.gr_gid, EPERM, &nobody, &nobody,
 		    "After setregid(bin, root),"}, {
-	&inval_user, &neg_one, EINVAL, &users, &users,
+	&inval_user, &neg_one, EINVAL, &nobody, &nobody,
 		    "After setregid(invalid group, -1),"}, {
-&neg_one, &inval_user, EINVAL, &users, &users,
+&neg_one, &inval_user, EINVAL, &nobody, &nobody,
 		    "After setregid(-1, invalid group),"},};
 
 int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
 
-void setup(void);
-void cleanup(void);
-void gid_verify(struct group *ru, struct group *eu, char *when);
+static void setup(void);
+static void cleanup(void);
+static void gid_verify(struct group *ru, struct group *eu, char *when);
 
 int main(int ac, char **av)
 {
@@ -134,12 +94,11 @@ int main(int ac, char **av)
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
 		int i;
 
-		/* reset tst_count in case we are looping */
 		tst_count = 0;
 
 		for (i = 0; i < TST_TOTAL; i++) {
 			/* Set the real or effective group id */
-			TEST(setregid(*test_data[i].real_gid,
+			TEST(SETREGID(cleanup, *test_data[i].real_gid,
 				      *test_data[i].eff_gid));
 
 			if (TEST_RETURN == -1) {
@@ -169,10 +128,6 @@ int main(int ac, char **av)
 					 *test_data[i].real_gid,
 					 *test_data[i].eff_gid, TEST_RETURN);
 			}
-			/*
-			 * Perform functional verification if test
-			 * executed without (-f) option.
-			 */
 			if (STD_FUNCTIONAL_TEST) {
 				gid_verify(test_data[i].exp_real_usr,
 					   test_data[i].exp_eff_usr,
@@ -184,15 +139,9 @@ int main(int ac, char **av)
 	}
 	cleanup();
 	tst_exit();
-	tst_exit();
-
 }
 
-/*
- * setup()
- *	performs all ONE TIME setup for this test
- */
-void setup(void)
+static void setup(void)
 {
 	struct group *junk;
 
@@ -200,62 +149,51 @@ void setup(void)
 
 	tst_sig(FORK, DEF_HANDLER, cleanup);
 
-	if ((nobody = getpwnam("nobody")) == NULL) {
+	ltpuser = getpwnam("nobody");
+	if (ltpuser == NULL)
 		tst_brkm(TBROK, NULL, "getpwnam(\"nobody\") failed");
-	}
 
-	if (setgid(nobody->pw_gid) == -1) {
+	if (setgid(ltpuser->pw_gid) == -1) {
 		tst_brkm(TBROK | TERRNO, NULL,
 			 "setgid failed to set the effective gid to %d",
-			 nobody->pw_gid);
+			 ltpuser->pw_gid);
 	}
-	if (setuid(nobody->pw_uid) == -1) {
+	if (setuid(ltpuser->pw_uid) == -1) {
 		tst_brkm(TBROK | TERRNO, NULL,
 			 "setuid failed to to set the effective uid to %d",
-			 nobody->pw_uid);
+			 ltpuser->pw_uid);
 	}
 
-	/* set the expected errnos... */
-	TEST_EXP_ENOS(exp_enos);
-
 #define GET_GID(group)	do {		\
 	junk = getgrnam(#group);	\
 	if (junk == NULL) {		\
 		tst_brkm(TBROK|TERRNO, NULL, "getgrnam(\"%s\") failed", #group); \
 	}				\
-	group ## _gr_gid = junk->gr_gid;\
+	GID16_CHECK(junk->gr_gid, setregid, NULL); \
+	group = *(junk); \
 } while (0)
 
 	GET_GID(root);
-	GET_GID(users);
+	GET_GID(nobody);
 	GET_GID(bin);
 
-	/* Pause if that option was specified
-	 * TEST_PAUSE contains the code to fork the test with the -c option.
-	 */
 	TEST_PAUSE;
 }
 
-/*
- * cleanup()
- *	performs all ONE TIME cleanup for this test at
- *	completion or premature exit
- */
-void cleanup(void)
+static void cleanup(void)
 {
-	/*
-	 * print timing stats if that option was specified.
-	 * print errno log if that option was specified.
-	 */
 	TEST_CLEANUP;
 }
 
 void gid_verify(struct group *rg, struct group *eg, char *when)
 {
 	if ((getgid() != rg->gr_gid) || (getegid() != eg->gr_gid)) {
-		tst_resm(TINFO, "ERROR: %s real gid = %d; effective gid = %d",
+		tst_resm(TFAIL, "ERROR: %s real gid = %d; effective gid = %d",
 			 when, getgid(), getegid());
 		tst_resm(TINFO, "Expected: real gid = %d; effective gid = %d",
 			 rg->gr_gid, eg->gr_gid);
+	} else {
+		tst_resm(TPASS, "real or effective gid was modified as expected");
+
 	}
 }
-- 
1.7.1


------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135031&iu=/4140/ostg.clktrk
_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

* Re: [LTP] 16-bit fixes for setreuid, setregid
  2013-10-21  7:25 [LTP] 16-bit fixes for setreuid, setregid Stanislav Kholmanskikh
                   ` (2 preceding siblings ...)
  2013-10-21  7:25 ` [LTP] [PATCH 3/3] syscalls/setregid02: fixes Stanislav Kholmanskikh
@ 2013-10-22 17:08 ` chrubis
  3 siblings, 0 replies; 5+ messages in thread
From: chrubis @ 2013-10-22 17:08 UTC (permalink / raw)
  To: Stanislav Kholmanskikh; +Cc: vasily.isaenko, ltp-list

[-- Attachment #1: Type: text/plain, Size: 237 bytes --]

Hi!
> This series contains fixes for 16-bit version of syscalls for
> setreuid, setregid system calls.
> 
> And some cleanup also.

Pushed (with a few minor fixes by myself, see attached patch), thanks.

-- 
Cyril Hrubis
chrubis@suse.cz

[-- Attachment #2: setere.diff --]
[-- Type: text/plain, Size: 5343 bytes --]

diff --git a/testcases/kernel/syscalls/setregid/setregid02.c b/testcases/kernel/syscalls/setregid/setregid02.c
index 5674070..e67a7df 100644
--- a/testcases/kernel/syscalls/setregid/setregid02.c
+++ b/testcases/kernel/syscalls/setregid/setregid02.c
@@ -72,7 +72,7 @@ struct test_data_t {
 		    "After setregid(bin, root),"}, {
 	&inval_user, &neg_one, EINVAL, &nobody, &nobody,
 		    "After setregid(invalid group, -1),"}, {
-&neg_one, &inval_user, EINVAL, &nobody, &nobody,
+	&neg_one, &inval_user, EINVAL, &nobody, &nobody,
 		    "After setregid(-1, invalid group),"},};
 
 int TST_TOTAL = sizeof(test_data) / sizeof(test_data[0]);
@@ -194,6 +194,5 @@ void gid_verify(struct group *rg, struct group *eg, char *when)
 			 rg->gr_gid, eg->gr_gid);
 	} else {
 		tst_resm(TPASS, "real or effective gid was modified as expected");
-
 	}
 }
diff --git a/testcases/kernel/syscalls/setregid/setregid03.c b/testcases/kernel/syscalls/setregid/setregid03.c
index 932371b..1cbdd52 100644
--- a/testcases/kernel/syscalls/setregid/setregid03.c
+++ b/testcases/kernel/syscalls/setregid/setregid03.c
@@ -108,9 +108,9 @@ int main(int ac, char **av)
 		if (SETREGID(cleanup, sys.gr_gid, bin.gr_gid) == -1)
 			tst_brkm(TBROK, NULL, "Initial setregid failed");
 
-		if (seteuid(nobody.pw_uid) == -1) {
+		if (seteuid(nobody.pw_uid) == -1)
 			tst_brkm(TBROK, NULL, "Initial seteuid failed");
-		}
+
 		if ((pid = FORK_OR_VFORK()) == -1) {
 			tst_brkm(TBROK, NULL, "fork failed");
 		} else if (pid == 0) {	/* child */
diff --git a/testcases/kernel/syscalls/setreuid/setreuid01.c b/testcases/kernel/syscalls/setreuid/setreuid01.c
index 45d38cb..18b5ed0 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid01.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid01.c
@@ -46,8 +46,8 @@
 #include "usctest.h"
 #include "compat_16.h"
 
-static void setup();
-static void cleanup();
+static void setup(void);
+static void cleanup(void);
 
 TCID_DEFINE(setreuid01);
 int TST_TOTAL = 5;
@@ -182,7 +182,6 @@ int main(int ac, char **av)
 
 static void setup(void)
 {
-
 	tst_sig(NOFORK, DEF_HANDLER, cleanup);
 
 	TEST_PAUSE;
diff --git a/testcases/kernel/syscalls/setreuid/setreuid02.c b/testcases/kernel/syscalls/setreuid/setreuid02.c
index 050df17..1263996 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid02.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid02.c
@@ -70,11 +70,9 @@ int main(int ac, char **av)
 	int lc;
 	char *msg;
 
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-	}
-
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
@@ -140,7 +138,6 @@ static void setup(void)
 static void cleanup(void)
 {
 	TEST_CLEANUP;
-
 }
 
 static void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
diff --git a/testcases/kernel/syscalls/setreuid/setreuid03.c b/testcases/kernel/syscalls/setreuid/setreuid03.c
index 24e52d5..1074e79 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid03.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid03.c
@@ -95,11 +95,9 @@ int main(int ac, char **av)
 	int lc;
 	char *msg;
 
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-	}
-
 	setup();
 
 	for (lc = 0; TEST_LOOPING(lc); lc++) {
@@ -188,7 +186,6 @@ static void setup(void)
 static void cleanup(void)
 {
 	TEST_CLEANUP;
-
 }
 
 static void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
diff --git a/testcases/kernel/syscalls/setreuid/setreuid04.c b/testcases/kernel/syscalls/setreuid/setreuid04.c
index d949a4b..3010fc5 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid04.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid04.c
@@ -70,11 +70,9 @@ int main(int ac, char **av)
 	int lc;
 	char *msg;
 
-	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL) {
+	if ((msg = parse_opts(ac, av, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-	}
-
 	setup();
 
 	flag = 0;
diff --git a/testcases/kernel/syscalls/setreuid/setreuid05.c b/testcases/kernel/syscalls/setreuid/setreuid05.c
index c46fcd9..a379ab7 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid05.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid05.c
@@ -91,11 +91,9 @@ int main(int argc, char **argv)
 	int lc;
 	char *msg;
 
-	if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) {
+	if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
 
-	}
-
 	setup();
 
 	pass = 0;
@@ -204,7 +202,6 @@ static void setup(void)
 static void cleanup(void)
 {
 	TEST_CLEANUP;
-
 }
 
 static void uid_verify(struct passwd *ru, struct passwd *eu, char *when)
diff --git a/testcases/kernel/syscalls/setreuid/setreuid06.c b/testcases/kernel/syscalls/setreuid/setreuid06.c
index 823d10b..e4bc207 100644
--- a/testcases/kernel/syscalls/setreuid/setreuid06.c
+++ b/testcases/kernel/syscalls/setreuid/setreuid06.c
@@ -48,13 +48,11 @@ static void cleanup(void);
 
 int main(int argc, char **argv)
 {
-
 	int lc;
 	char *msg;
 
-	if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL) {
+	if ((msg = parse_opts(argc, argv, NULL, NULL)) != NULL)
 		tst_brkm(TBROK, NULL, "OPTION PARSING ERROR - %s", msg);
-	}
 
 	setup();
 

[-- Attachment #3: Type: text/plain, Size: 416 bytes --]

------------------------------------------------------------------------------
October Webinars: Code for Performance
Free Intel webinars can help you accelerate application performance.
Explore tips for MPI, OpenMP, advanced profiling, and more. Get the most from 
the latest Intel processors and coprocessors. See abstracts and register >
http://pubads.g.doubleclick.net/gampad/clk?id=60135991&iu=/4140/ostg.clktrk

[-- Attachment #4: Type: text/plain, Size: 155 bytes --]

_______________________________________________
Ltp-list mailing list
Ltp-list@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/ltp-list

^ permalink raw reply related	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2013-10-22 17:09 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-10-21  7:25 [LTP] 16-bit fixes for setreuid, setregid Stanislav Kholmanskikh
2013-10-21  7:25 ` [LTP] [PATCH 1/3] syscalls/setreuid: 16-bit fixes and minor cleanup Stanislav Kholmanskikh
2013-10-21  7:25 ` [LTP] [PATCH 2/3] syscalls/setregid{01, 03, 04}: " Stanislav Kholmanskikh
2013-10-21  7:25 ` [LTP] [PATCH 3/3] syscalls/setregid02: fixes Stanislav Kholmanskikh
2013-10-22 17:08 ` [LTP] 16-bit fixes for setreuid, setregid chrubis

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox