Home | History | Annotate | Download | only in setregid
      1 /*
      2  * Copyright (c) 2000 Silicon Graphics, Inc.  All Rights Reserved.
      3  *
      4  * This program is free software; you can redistribute it and/or modify it
      5  * under the terms of version 2 of the GNU General Public License as
      6  * published by the Free Software Foundation.
      7  *
      8  * This program is distributed in the hope that it would be useful, but
      9  * WITHOUT ANY WARRANTY; without even the implied warranty of
     10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
     11  *
     12  * Further, this software is distributed without any warranty that it is
     13  * free of the rightful claim of any third person regarding infringement
     14  * or the like.  Any license provided herein, whether implied or
     15  * otherwise, applies only to this software file.  Patent licenses, if
     16  * any, provided herein do not apply to combinations of this program with
     17  * other software, or any other product whatsoever.
     18  *
     19  * You should have received a copy of the GNU General Public License along
     20  * with this program; if not, write the Free Software Foundation, Inc.,
     21  * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
     22  *
     23  * Contact information: Silicon Graphics, Inc., 1600 Amphitheatre Pkwy,
     24  * Mountain View, CA  94043, or:
     25  *
     26  * http://www.sgi.com
     27  *
     28  * For further information regarding this notice, see:
     29  *
     30  * http://oss.sgi.com/projects/GenInfo/NoticeExplan/
     31  *
     32  * Author: William Roske
     33  * Co-pilot: Dave Fenner
     34  */
     35 
     36 /*
     37  * Testcase to test the basic functionality of setregid(2) systemm call.
     38  */
     39 
     40 #include <errno.h>
     41 #include <string.h>
     42 #include <signal.h>
     43 #include <sys/types.h>
     44 
     45 #include "test.h"
     46 #include "compat_16.h"
     47 
     48 static void setup(void);
     49 
     50 TCID_DEFINE(setregid01);
     51 int TST_TOTAL = 5;
     52 
     53 static gid_t gid, egid;	/* current real and effective group id */
     54 
     55 int main(int ac, char **av)
     56 {
     57 	int lc;
     58 
     59 	tst_parse_opts(ac, av, NULL, NULL);
     60 
     61 	setup();
     62 
     63 	for (lc = 0; TEST_LOOPING(lc); lc++) {
     64 
     65 		tst_count = 0;
     66 
     67 		/*
     68 		 * TEST CASE:
     69 		 *  Dont change either real or effective gid
     70 		 */
     71 		gid = getgid();
     72 		GID16_CHECK(gid, setregid, NULL);
     73 
     74 		egid = getegid();
     75 		GID16_CHECK(egid, setregid, NULL);
     76 
     77 		TEST(SETREGID(NULL, -1, -1));
     78 
     79 		if (TEST_RETURN == -1) {
     80 			tst_resm(TFAIL,
     81 				 "setregid -  Dont change either real or effective gid failed, errno=%d : %s",
     82 				 TEST_ERRNO, strerror(TEST_ERRNO));
     83 		} else {
     84 			tst_resm(TPASS,
     85 				 "setregid -  Dont change either real or effective gid returned %ld",
     86 				 TEST_RETURN);
     87 		}
     88 
     89 		/*
     90 		 * TEST CASE:
     91 		 *  change effective to effective gid
     92 		 */
     93 
     94 		TEST(SETREGID(NULL, -1, egid));
     95 
     96 		if (TEST_RETURN == -1) {
     97 			tst_resm(TFAIL,
     98 				 "setregid -  change effective to effective gid failed, errno=%d : %s",
     99 				 TEST_ERRNO, strerror(TEST_ERRNO));
    100 		} else {
    101 			tst_resm(TPASS,
    102 				 "setregid -  change effective to effective gid returned %ld",
    103 				 TEST_RETURN);
    104 		}
    105 
    106 		/*
    107 		 * TEST CASE:
    108 		 *  change real to real gid
    109 		 */
    110 
    111 		TEST(SETREGID(NULL, gid, -1));
    112 
    113 		if (TEST_RETURN == -1) {
    114 			tst_resm(TFAIL,
    115 				 "setregid -  change real to real gid failed, errno=%d : %s",
    116 				 TEST_ERRNO, strerror(TEST_ERRNO));
    117 		} else {
    118 			tst_resm(TPASS,
    119 				 "setregid -  change real to real gid returned %ld",
    120 				 TEST_RETURN);
    121 		}
    122 
    123 		/*
    124 		 * TEST CASE:
    125 		 *  change effective to real gid
    126 		 */
    127 
    128 		TEST(SETREGID(NULL, -1, gid));
    129 
    130 		if (TEST_RETURN == -1) {
    131 			tst_resm(TFAIL,
    132 				 "setregid -  change effective to real gid failed, errno=%d : %s",
    133 				 TEST_ERRNO, strerror(TEST_ERRNO));
    134 		} else {
    135 			tst_resm(TPASS,
    136 				 "setregid -  change effective to real gid returned %ld",
    137 				 TEST_RETURN);
    138 		}
    139 
    140 		/*
    141 		 * TEST CASE:
    142 		 *  try to change real to current real
    143 		 */
    144 
    145 		TEST(SETREGID(NULL, gid, gid));
    146 
    147 		if (TEST_RETURN == -1) {
    148 			tst_resm(TFAIL | TTERRNO, "setregid failed");
    149 		} else {
    150 			tst_resm(TPASS, "setregid return %ld",
    151 				 TEST_RETURN);
    152 		}
    153 
    154 	}
    155 
    156 	tst_exit();
    157 }
    158 
    159 static void setup(void)
    160 {
    161 	tst_sig(NOFORK, DEF_HANDLER, NULL);
    162 
    163 	TEST_PAUSE;
    164 }
    165