3 * Copyright (c) International Business Machines Corp., 2000
5 * This program is free software; you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation; either version 2 of the License, or
8 * (at your option) any later version.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See
13 * the GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 * FILE(s) : fs_perms.c simpletest.sh textx.o Makefile README
22 * DESCRIPTION : Regression test for Linux filesystem permissions.
23 * AUTHOR : Jeff Martin (martinjn@us.ibm.com)
25 * (04/12/01)v.99 First attempt at using C for fs-regression test. Only tests read and write bits.
26 * (04/19/01)v1.0 Added test for execute bit.
27 * (05/23/01)v1.1 Added command line parameter to specify test file.
28 * (07/12/01)v1.2 Removed conf file and went to command line parameters.
36 #include <sys/types.h>
41 int testsetup(mode_t mode, int cuserId, int cgroupId);
42 int testfperm(int userId, int groupId, char* fperm);
44 int main( int argc, char *argv[]) {
46 int result, exresult=0, cuserId=0, cgroupId=0, userId=0, groupId=0;
51 mode = strtol(argv[1],(char**)NULL,010);
52 cuserId = atoi(argv[2]);
53 cgroupId = atoi(argv[3]);
54 userId = atoi(argv[4]);
55 groupId = atoi(argv[5]);
57 exresult = atoi(argv[7]);
60 printf("Usage: %s <mode of file> <UID of file> <GID of file> <UID of tester> <GID of tester> <permission to test r|w|x> <expected result as 0|1>\n",argv[0]);
64 testsetup(mode,cuserId,cgroupId);
65 result=testfperm(userId,groupId,fperm);
66 system("rm test.file");
67 printf("%c a %03o file owned by (%d/%d) as user/group(%d/%d) ",fperm[0],mode,cuserId,cgroupId,userId,groupId);
68 if (result == exresult) {
78 int testsetup(mode_t mode, int cuserId, int cgroupId) {
79 system("cp testx.file test.file");
80 chmod("test.file",mode);
81 chown("test.file",cuserId,cgroupId);
85 int testfperm(int userId, int groupId, char* fperm) {
91 /* SET CURRENT USER/GROUP PERMISSIONS */
92 if(setegid(groupId)) {
93 printf("could not setegid to %d.\n",groupId);
99 printf("could not seteuid to %d.\n",userId);
105 switch(tolower(fperm[0])) {
109 execlp("./test.file","test.file",NULL);
113 nuthertmpi=WEXITSTATUS(tmpi);
119 if((testfile=fopen("test.file",fperm))){