161ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron/* 2e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin * Check decoding of fchmod syscall. 3e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin * 461ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * Copyright (c) 2016 Fabien Siron <fabien.siron@epita.fr> 5e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin * Copyright (c) 2016 Dmitry V. Levin <ldv@altlinux.org> 661ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * All rights reserved. 761ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * 861ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * Redistribution and use in source and binary forms, with or without 961ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * modification, are permitted provided that the following conditions 1061ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * are met: 1161ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * 1. Redistributions of source code must retain the above copyright 1261ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * notice, this list of conditions and the following disclaimer. 1361ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * 2. Redistributions in binary form must reproduce the above copyright 1461ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * notice, this list of conditions and the following disclaimer in the 1561ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * documentation and/or other materials provided with the distribution. 1661ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * 3. The name of the author may not be used to endorse or promote products 1761ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * derived from this software without specific prior written permission. 1861ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * 1961ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 2061ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 2161ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 2261ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 2361ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 2461ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2561ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2661ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2761ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 2861ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2961ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron */ 3061ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 3161ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron#include "tests.h" 326a2f43ce6469c06d0244a07cea3d04f3740a66ceDmitry V. Levin#include <asm/unistd.h> 3361ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 34e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin#ifdef __NR_fchmod 3561ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 36e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin# include <fcntl.h> 37e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin# include <sys/stat.h> 38e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin# include <stdio.h> 39e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin# include <unistd.h> 4061ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 4161ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Sironint 4261ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Sironmain(void) 4361ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron{ 4461ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron static const char fname[] = "fchmod_test_file"; 4561ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 4661ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron int fd = open(fname, O_CREAT|O_RDONLY, 0400); 47e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin if (fd < 0) 4861ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron perror_msg_and_fail("open"); 4961ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 50e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin if (unlink(fname)) 5161ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron perror_msg_and_fail("unlink"); 5261ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 53e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin long rc = syscall(__NR_fchmod, fd, 0600); 54e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin printf("fchmod(%d, 0600) = %s\n", fd, sprintrc(rc)); 55e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin 56e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin close(fd); 5761ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 58e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin rc = syscall(__NR_fchmod, fd, 051); 59e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin printf("fchmod(%d, 051) = %s\n", fd, sprintrc(rc)); 6061ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 61e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin rc = syscall(__NR_fchmod, fd, 004); 62e9bfa4e4066924966809d67c88ecbca0bf5424c7Dmitry V. Levin printf("fchmod(%d, 004) = %s\n", fd, sprintrc(rc)); 6361ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 6461ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron puts("+++ exited with 0 +++"); 6561ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron return 0; 6661ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron} 6761ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 6861ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron#else 6961ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 7061ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien SironSKIP_MAIN_UNDEFINED("__NR_fchmod") 7161ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron 7261ac8ee9b2abe1be777af8e1ba91175fd58f3e7dFabien Siron#endif 73