1 // SPDX-License-Identifier: GPL-2.0+
3 * Copyright (c) International Business Machines Corp., 2000
7 * FILE(s) : fs_perms.c simpletest.sh textx.o Makefile README
8 * DESCRIPTION : Regression test for Linux filesystem permissions.
9 * AUTHOR : Jeff Martin (martinjn@us.ibm.com)
11 * (04/12/01)v.99 First attempt at using C for fs-regression test. Only tests read and write bits.
12 * (04/19/01)v1.0 Added test for execute bit.
13 * (05/23/01)v1.1 Added command line parameter to specify test file.
14 * (07/12/01)v1.2 Removed conf file and went to command line parameters.
22 #include <sys/types.h>
29 int testsetup(mode_t mode, int cuserId, int cgroupId);
30 int testfperm(int userId, int groupId, char* fperm);
32 int main( int argc, char *argv[]) {
34 int result, exresult=0, cuserId=0, cgroupId=0, userId=0, groupId=0;
39 mode = strtol(argv[1],(char**)NULL,010);
40 cuserId = atoi(argv[2]);
41 cgroupId = atoi(argv[3]);
42 userId = atoi(argv[4]);
43 groupId = atoi(argv[5]);
45 exresult = atoi(argv[7]);
48 printf("Usage: %s <mode of file> <UID of file> <GID of file> <UID of tester> <GID of tester> <permission to test r|w|x|t|T> <expected result as 0|1>\n",argv[0]);
52 testsetup(mode,cuserId,cgroupId);
53 result=testfperm(userId,groupId,fperm);
54 system("rm -f test.file");
55 printf("%s a %03o file owned by (%d/%d) as user/group(%d/%d) ",fperm,mode,cuserId,cgroupId,userId,groupId);
56 if (result == exresult) {
66 int testsetup(mode_t mode, int cuserId, int cgroupId) {
67 system("cp testx.file test.file");
68 chmod("test.file",mode);
69 chown("test.file",cuserId,cgroupId);
73 int testfperm(int userId, int groupId, char* fperm) {
77 /* SET CURRENT USER/GROUP PERMISSIONS */
79 if(setegid(groupId)) {
80 printf("could not setegid to %d.\n",groupId);
84 printf("could not seteuid to %d.\n",userId);
88 if (!strcmp("x", fperm)) {
94 execlp("./test.file","test.file",NULL);
98 ret = WEXITSTATUS(status);
99 } else if (!strcmp("t", fperm)) {
100 ret = utime("test.file", NULL) ? 0 : 1;
101 } else if (!strcmp("T", fperm)) {
102 time_t now = time(NULL);
103 struct utimbuf times = {
108 ret = utime("test.file", ×) ? 0 : 1;
112 if((file = fopen("test.file",fperm))){