17 char *envp
[3] = {"spring", "summer", 0};
18 char *passwd_file
= "/etc/passwd";
22 int main(int argc
, char *argv
[]);
34 if (argc
== 2) m
= atoi(argv
[1]);
38 system("cp ../t11a .");
39 system("cp ../t11b .");
42 printf("must be setuid root; test aborted\n");
46 printf("must be setuid root logged in as someone else; test aborted\n");
50 for (i
= 0; i
< ITERATIONS
; i
++) {
51 if (m
& 0001) test11a();
52 if (m
& 0002) test11b();
53 if (m
& 0004) test11c();
54 if (m
& 0010) test11d();
74 if (chown("t11a", 10, 20) < 0) e(2);
77 /* The following call should fail because the mode has no X
78 * bits on. If a bug lets it unexpectedly succeed, the child
79 * will print an error message since the arguments are wrong.
81 execl("t11a", "t11a", (char *) 0); /* should fail -- no X bits */
83 /* Control should come here after the failed execl(). */
85 if ((fd
= creat("t1", 0600)) != 3) e(3);
86 if (close(fd
) < 0) e(4);
87 if (open("t1", O_RDWR
) != 3) e(5);
88 if (chown("t1", 10, 99) < 0) e(6);
89 if ((fd
= creat("t2", 0060)) != 4) e(7);
90 if (close(fd
) < 0) e(8);
91 if (open("t2", O_RDWR
) != 4) e(9);
92 if (chown("t2", 99, 20) < 0) e(10);
93 if (setgid(6) < 0) e(11);
94 if (setuid(5) < 0) e(12);
95 if (getuid() != 5) e(13);
96 if (geteuid() != 5) e(14);
97 if (getgid() != 6) e(15);
98 if (getegid() != 6) e(16);
103 if (write(3, aa
, 4) != 4) e(17);
105 execle("t11a", "t11a", "arg0", "arg1", "arg2", (char *) 0, envp
);
107 printf("Can't exec t11a\n");
120 if (n
!= (75 << 8)) e(20);
122 /* Child tests execv. */
135 /* Test getlogin(). This test MUST run setuid root. */
140 #define MAXLINELEN 200
141 char array
[MAXLINELEN
], save
[L_cuserid
];
145 errno
= -2000; /* None of these calls set errno. */
151 strcpy(save
, lnamep
);
153 /* Because we are setuid, login != 'root' */
156 if ( (n
= strlen(save
)) == 0) e(5);
158 /* Check login against passwd file. First lookup login in /etc/passwd. */
159 if (n
== 0) return; /* if login not found, don't look it up */
160 if ( (stream
= fopen(passwd_file
, "r")) == NULL
) e(8);
161 while (fgets(array
, sizeof(array
), stream
) != NULL
) {
162 if (strncmp(array
, save
, n
) == 0) {
163 p
= &array
[0]; /* hunt for uid */
164 while (*p
!= ':') p
++;
166 while (*p
!= ':') p
++;
167 p
++; /* p now points to uid */
169 if (etc_uid
!= ruid
) e(9);
170 break; /* 1 entry per login please */
182 fd
= creat("T11.1", 0750);
184 if (chown("T11.1", 8, 1) != 0) e(2);
185 if (chmod("T11.1", 0666) != 0) e(3);
186 if (stat("T11.1", &statbuf
) != 0) e(4);
187 if ((statbuf
.st_mode
& (S_IRWXU
| S_IRWXG
| S_IRWXO
)) != 0666) e(5);
188 if (close(fd
) != 0) e(6);
189 if (unlink("T11.1") != 0) e(7);