title: Function seteuid() called from set-root-id program works but shows error msg
body: <p>I compiled this sample set-root-id program:  </p>
  
  <pre><code>  #define _GNU_SOURCE
  
    #include &lt;stdio.h&gt;
    #include &lt;string.h&gt;
    #include &lt;stdlib.h&gt;
    #include &lt;sys/types.h&gt;
    #include &lt;unistd.h&gt;
    #include &lt;errno.h&gt;
  
  
    void print_ids()
       {
       uid_t ruid, euid, suid, rgid, egid, sgid;
  
       getresuid(&amp;ruid, &amp;euid, &amp;suid);
       printf("\nruid=%d, euid=%d, suid=%d\n", ruid, euid, suid);
  
       getresgid(&amp;rgid, &amp;egid, &amp;sgid);
       printf("rgid=%d, egid=%d, sgid=%d\n\n", rgid, egid, sgid);
       }
  
  
    void main(int argc, char *argv[])
       {
       print_ids();
       seteuid(1000); printf("seteuid(1000): %s\n", strerror(errno));
       print_ids();
       seteuid(1001); printf("seteuid(1001): %s\n", strerror(errno));
       print_ids();
       seteuid(0);    printf("seteuid(0): %s\n",    strerror(errno));   
       print_ids();
       }
  </code></pre>
  
  <p>Call to seteuid(0) works, but dislays an error message: "Operation not permitted":   </p>
  
  <pre><code>$ gcc -Wall ./p3.c -o p3
  ./p3.c:32: warning: return type of ‘main’ is not ‘int’
  $ su -c "chown root:root ./p3 ; chmod 4755 ./p3"
  Password: ****
  $ ls -l ./p3
  -rwsr-xr-x 1 root root 7697  2 gen 19.21 ./p3
  $ ./p3
  
  ruid=1000, euid=0, suid=0
  rgid=1000, egid=1000, sgid=1000
  
  seteuid(1000): Success
  
  ruid=1000, euid=1000, suid=0
  rgid=1000, egid=1000, sgid=1000
  
  seteuid(1001): Operation not permitted
  
  ruid=1000, euid=1000, suid=0
  rgid=1000, egid=1000, sgid=1000
  
  seteuid(0): Operation not permitted
  
  ruid=1000, euid=0, suid=0
  rgid=1000, egid=1000, sgid=1000
  
  $
  </code></pre>
  
  <p>Why seteuid(0) works but displays the error message?
  I noticed that omitting call to seteuid(1001) or call to seteuid(1000) no error messages appear.</p>
  
  <p>Thank you   </p>
  
  <p>(I work on Debian 6, gcc version 4.4.5)</p>