You are not logged in.

#1 2012-05-19 11:00:10

ghost
Member
Registered: 2011-11-10
Posts: 44

Setuid Problem

Hi,
I'm trying to write a small programm using setuid, but I don't get it to work.


Here I'm trying out the example from wikipedia http://en.wikipedia.org/wiki/Setuid#Demonstration

I set the setuid bit, but the programm will still be executed as the same user.

What am I doing wrong?

markus@markus-laptop /tmp % cat > printid.c
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
int main(void) {
    printf(
        "         UID           GID  \n"
        "Real      %d  Real      %d  \n"
        "Effective %d  Effective %d  \n",
             getuid (),     getgid (),
             geteuid(),     getegid()
    );
    return 0;       /* always good to return something */
}
markus@markus-laptop /tmp % cc printid.c -o printid
markus@markus-laptop /tmp % ./printid
         UID           GID  
Real      1000  Real      100  
Effective 1000  Effective 100  
markus@markus-laptop /tmp % sudo chown root printid
markus@markus-laptop /tmp % sudo chmod ug+s printid
markus@markus-laptop /tmp % sudo chmod o-rx printid
markus@markus-laptop /tmp % ll printid
-rwsr-s--- 1 root users 5436 19. Mai 12:51 printid*
markus@markus-laptop /tmp % ./printid
         UID           GID  
Real      1000  Real      100  
Effective 1000  Effective 100  
markus@markus-laptop /tmp %                                                     

Offline

#2 2012-05-19 12:21:12

Vain
Member
Registered: 2008-10-19
Posts: 179
Website

Re: Setuid Problem

Hi,

you’re doing this in /tmp. Check the output of “mount”, maybe /tmp is mounted with the option “nosuid”.

(I don’t have /tmp mounted as tmpfs and your code works for me.)

Offline

#3 2012-05-19 13:21:00

ghost
Member
Registered: 2011-11-10
Posts: 44

Re: Setuid Problem

Vain wrote:

you’re doing this in /tmp. Check the output of “mount”, maybe /tmp is mounted with the option “nosuid”.

Thanks, I wouldn't have thought of that.

It was mounted with 'nosuid'.

Offline

Board footer

Powered by FluxBB