(root)/
strace-6.5/
tests/
chmod.c
       1  /*
       2   * Copyright (c) 2016 Anchit Jain <anchitjain1234@gmail.com>
       3   * Copyright (c) 2016-2018 Dmitry V. Levin <ldv@strace.io>
       4   * Copyright (c) 2016-2021 The strace developers.
       5   * All rights reserved.
       6   *
       7   * SPDX-License-Identifier: GPL-2.0-or-later
       8   */
       9  
      10  #include "tests.h"
      11  #include "scno.h"
      12  
      13  #if defined __NR_chmod
      14  
      15  # include <fcntl.h>
      16  # include <stdio.h>
      17  # include <unistd.h>
      18  
      19  # include "secontext.h"
      20  
      21  int
      22  main(void)
      23  {
      24  	/*
      25  	 * Make sure the current workdir of the tracee
      26  	 * is different from the current workdir of the tracer.
      27  	 */
      28  	create_and_enter_subdir("chmod_subdir");
      29  
      30  	char *my_secontext = SECONTEXT_PID_MY();
      31  
      32  	static const char sample[] = "chmod_test_file";
      33  	(void) unlink(sample);
      34  	if (open(sample, O_CREAT|O_RDONLY, 0400) < 0)
      35  		perror_msg_and_fail("open: %s", sample);
      36  
      37  	long rc = syscall(__NR_chmod, sample, 0600);
      38  	printf("%s%s(\"%s\"%s, 0600) = %s\n",
      39  	       my_secontext, "chmod",
      40  	       sample, SECONTEXT_FILE(sample),
      41  	       sprintrc(rc));
      42  
      43  	if (unlink(sample))
      44  		perror_msg_and_fail("unlink: %s", sample);
      45  
      46  	rc = syscall(__NR_chmod, sample, 051);
      47  	printf("%s%s(\"%s\", 051) = %s\n",
      48  	       my_secontext, "chmod",
      49  	       sample,
      50  	       sprintrc(rc));
      51  
      52  	rc = syscall(__NR_chmod, sample, 004);
      53  	printf("%s%s(\"%s\", 004) = %s\n",
      54  	       my_secontext, "chmod",
      55  	       sample,
      56  	       sprintrc(rc));
      57  
      58  	leave_and_remove_subdir();
      59  
      60  	puts("+++ exited with 0 +++");
      61  	return 0;
      62  }
      63  
      64  #else
      65  
      66  SKIP_MAIN_UNDEFINED("__NR_chmod")
      67  
      68  #endif