title: How to use setuid bin to access another executable?
body: <p>I have a C program which gets its name, tacks the string ".script" to the end, and  executes the resulting script. My goal is to have the C executable have the setuid bit set, and for the script to be owned by the effective uid. But when I test it, it gives me a permission denied. I added a print for the real and effective uid, and the euid is being set. The two files appear as:</p>
  
  <pre><code>-rwsr-xr-x. 1 ts00001 ts00001     8792 Oct  9 08:54 testing
  -rwxr-x---. 1 ts00001 ts00001       21 Oct  9 08:15 testing.script
  </code></pre>
  
  <p>Executing the program gives me:</p>
  
  <pre><code>ts00086@rofrpna bin:0 $ ./testing
  uid = 223336, euid = 202223
  /bin/bash: /usr/local/bin/testing.script: Permission denied
  ts00086@rofrpna bin:126 $
  </code></pre>
  
  <p>So... What point am I failing to see here?</p>
  
  <p>The C program is as follows:</p>
  
  <pre><code>#include &lt;stdlib.h&gt;
  #include &lt;unistd.h&gt;
  #include &lt;stdio.h&gt;
  #include &lt;string.h&gt;
  #include &lt;errno.h&gt;
  
  char ** duplicateArray(char ** input);
  
  int main(int ac, char **av)
  {
          int i;
          char script[1024];
  
          printf("uid = %d, euid = %d\n", getuid(), geteuid());
  
          realpath(av[0], script);
          strcat(script, ".script");
  
          printf("script result = %d\n", execv(script, av));
          printf("errno = %d\n", errno);
  
          return 0;
  }
  </code></pre>