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