4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License (the "License").
6 * You may not use this file except in compliance with the License.
8 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
9 * or https://opensource.org/licenses/CDDL-1.0.
10 * See the License for the specific language governing permissions
11 * and limitations under the License.
13 * When distributing Covered Code, include this CDDL HEADER in each
14 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
15 * If applicable, add the following below this CDDL HEADER, with the
16 * fields enclosed by brackets "[]" replaced with your own identifying
17 * information: Portions Copyright [yyyy] [name of copyright owner]
22 * Copyright (c) 2019 by Tomohiro Kusumi. All rights reserved.
28 #include <sys/types.h>
35 main(int argc
, char *argv
[])
37 const char *name
, *phase
;
42 fprintf(stderr
, "Invalid argc\n");
47 if (strcmp(name
, "SUID") == 0) {
49 } else if (strcmp(name
, "SGID") == 0) {
51 } else if (strcmp(name
, "SUID_SGID") == 0) {
52 extra
= S_ISUID
| S_ISGID
;
53 } else if (strcmp(name
, "NONE") == 0) {
56 fprintf(stderr
, "Invalid name %s\n", name
);
60 const char *testdir
= getenv("TESTDIR");
62 fprintf(stderr
, "getenv(TESTDIR)\n");
67 if (stat(testdir
, &st
) == -1 && mkdir(testdir
, 0777) == -1) {
73 snprintf(fpath
, sizeof (fpath
), "%s/%s", testdir
, name
);
77 if (strcmp(phase
, "PRECRASH") == 0) {
79 /* clean up last run */
81 if (stat(fpath
, &st
) == 0) {
82 fprintf(stderr
, "%s exists\n", fpath
);
88 fd
= creat(fpath
, 0777 | extra
);
95 if (setuid(65534) == -1) {
100 fd
= open(fpath
, O_RDWR
);
106 const char buf
[] = "test";
107 if (write(fd
, buf
, sizeof (buf
)) == -1) {
113 } else if (strcmp(phase
, "REPLAY") == 0) {
114 /* created in PRECRASH run */
116 fprintf(stderr
, "Invalid phase %s\n", phase
);
120 if (stat(fpath
, &st
) == -1) {
125 /* Verify SUID/SGID are dropped */
126 mode_t res
= st
.st_mode
& (0777 | S_ISUID
| S_ISGID
);
128 fprintf(stderr
, "stat(2) %o\n", res
);