1f08c3bdfSopenharmony_ci// SPDX-License-Identifier: GPL-2.0-or-later 2f08c3bdfSopenharmony_ci/* 3f08c3bdfSopenharmony_ci * Copyright (c) International Business Machines Corp., 2001 4f08c3bdfSopenharmony_ci * Ported to LTP: Wayne Boyer 5f08c3bdfSopenharmony_ci */ 6f08c3bdfSopenharmony_ci 7f08c3bdfSopenharmony_ci/* 8f08c3bdfSopenharmony_ci * Testcase to check whether the sticky bit cleared. 9f08c3bdfSopenharmony_ci * Creat a new file, fstat.st_mode should have the 01000 bit off 10f08c3bdfSopenharmony_ci */ 11f08c3bdfSopenharmony_ci 12f08c3bdfSopenharmony_ci#include <errno.h> 13f08c3bdfSopenharmony_ci#include <stdio.h> 14f08c3bdfSopenharmony_ci#include <sys/types.h> 15f08c3bdfSopenharmony_ci#include <sys/stat.h> 16f08c3bdfSopenharmony_ci#include <fcntl.h> 17f08c3bdfSopenharmony_ci 18f08c3bdfSopenharmony_ci#include "tst_test.h" 19f08c3bdfSopenharmony_ci 20f08c3bdfSopenharmony_cistatic char pfilname[40]; 21f08c3bdfSopenharmony_cistatic int fd; 22f08c3bdfSopenharmony_ci 23f08c3bdfSopenharmony_cistatic void verify_creat(void) 24f08c3bdfSopenharmony_ci{ 25f08c3bdfSopenharmony_ci struct stat statbuf; 26f08c3bdfSopenharmony_ci 27f08c3bdfSopenharmony_ci fd = creat(pfilname, 444); 28f08c3bdfSopenharmony_ci 29f08c3bdfSopenharmony_ci if (fd == -1) { 30f08c3bdfSopenharmony_ci tst_res(TFAIL | TERRNO, "creat(%s) failed", pfilname); 31f08c3bdfSopenharmony_ci return; 32f08c3bdfSopenharmony_ci } 33f08c3bdfSopenharmony_ci 34f08c3bdfSopenharmony_ci SAFE_FSTAT(fd, &statbuf); 35f08c3bdfSopenharmony_ci 36f08c3bdfSopenharmony_ci tst_res(TINFO, "Created file has mode = 0%o", statbuf.st_mode); 37f08c3bdfSopenharmony_ci 38f08c3bdfSopenharmony_ci if ((statbuf.st_mode & S_ISVTX) != 0) 39f08c3bdfSopenharmony_ci tst_res(TFAIL, "save text bit not cleared"); 40f08c3bdfSopenharmony_ci else 41f08c3bdfSopenharmony_ci tst_res(TPASS, "save text bit cleared"); 42f08c3bdfSopenharmony_ci 43f08c3bdfSopenharmony_ci SAFE_CLOSE(fd); 44f08c3bdfSopenharmony_ci} 45f08c3bdfSopenharmony_ci 46f08c3bdfSopenharmony_cistatic void setup(void) 47f08c3bdfSopenharmony_ci{ 48f08c3bdfSopenharmony_ci sprintf(pfilname, "./creat03.%d", getpid()); 49f08c3bdfSopenharmony_ci} 50f08c3bdfSopenharmony_ci 51f08c3bdfSopenharmony_cistatic void cleanup(void) 52f08c3bdfSopenharmony_ci{ 53f08c3bdfSopenharmony_ci if (fd > 0) 54f08c3bdfSopenharmony_ci SAFE_CLOSE(fd); 55f08c3bdfSopenharmony_ci} 56f08c3bdfSopenharmony_ci 57f08c3bdfSopenharmony_cistatic struct tst_test test = { 58f08c3bdfSopenharmony_ci .test_all = verify_creat, 59f08c3bdfSopenharmony_ci .needs_tmpdir = 1, 60f08c3bdfSopenharmony_ci .setup = setup, 61f08c3bdfSopenharmony_ci .cleanup = cleanup, 62f08c3bdfSopenharmony_ci}; 63