1 | /* t11a */
|
---|
2 |
|
---|
3 | #include <sys/types.h>
|
---|
4 | #include <errno.h>
|
---|
5 | #include <fcntl.h>
|
---|
6 | #include <stdlib.h>
|
---|
7 | #include <unistd.h>
|
---|
8 | #include <stdio.h>
|
---|
9 |
|
---|
10 | #define MAX_ERROR 4
|
---|
11 |
|
---|
12 | int errct, subtest=1;
|
---|
13 |
|
---|
14 | _PROTOTYPE(int main, (int argc, char *argv [], char *envp []));
|
---|
15 | _PROTOTYPE(int diff, (char *s1, char *s2));
|
---|
16 | _PROTOTYPE(void e, (int n));
|
---|
17 |
|
---|
18 | int main(argc, argv, envp)
|
---|
19 | int argc;
|
---|
20 | char *argv[], *envp[];
|
---|
21 | {
|
---|
22 | /* See if arguments passed ok. */
|
---|
23 |
|
---|
24 | char aa[4];
|
---|
25 |
|
---|
26 | if (diff(argv[0], "t11a")) e(21);
|
---|
27 | if (diff(argv[1], "arg0")) e(22);
|
---|
28 | if (diff(argv[2], "arg1")) e(23);
|
---|
29 | if (diff(argv[3], "arg2")) e(24);
|
---|
30 | if (diff(envp[0], "spring")) e(25);
|
---|
31 | if (diff(envp[1], "summer")) e(26);
|
---|
32 | if (argc != 4) e(27);
|
---|
33 |
|
---|
34 | /* Now see if the files are ok. */
|
---|
35 | if (read(3, aa, 4) != 2) e(28);
|
---|
36 | if (aa[0] != 7 || aa[1] != 9) e(29);
|
---|
37 |
|
---|
38 | if (getuid() == 10) e(30);
|
---|
39 | if (geteuid() != 10) e(31);
|
---|
40 | if (getgid() == 20) e(32);
|
---|
41 | if (getegid() != 20) e(33);
|
---|
42 |
|
---|
43 | if (open("t1", 0) < 0) e(34);
|
---|
44 | if (open("t2", 0) < 0) e(35);
|
---|
45 | exit(100);
|
---|
46 | }
|
---|
47 |
|
---|
48 | int diff(s1, s2)
|
---|
49 | char *s1, *s2;
|
---|
50 | {
|
---|
51 | while (1) {
|
---|
52 | if (*s1 == 0 && *s2 == 0) return(0);
|
---|
53 | if (*s1 != *s2) return (1);
|
---|
54 | s1++;
|
---|
55 | s2++;
|
---|
56 | }
|
---|
57 | }
|
---|
58 |
|
---|
59 | void e(n)
|
---|
60 | int n;
|
---|
61 | {
|
---|
62 | printf("Subtest %d, error %d errno=%d ", subtest, n, errno);
|
---|
63 | perror("");
|
---|
64 | if (errct++ > MAX_ERROR) {
|
---|
65 | printf("Too many errors; test aborted\n");
|
---|
66 | chdir("..");
|
---|
67 | system("rm -rf DIR*");
|
---|
68 | exit(1);
|
---|
69 | }
|
---|
70 | }
|
---|