0

I wrote a C program, expecting to see the difference between uid and euid with setuid bit enabled:

#include <unistd.h>
#include <stdio.h>

int main(void) { printf("euid: %d\n", geteuid()); printf("uid: %d\n", getuid()); return 0; }

Then I compiled them in my home directory and /tmp directory respectively but got different results. The script I used to compile and run the two programs:

#!/bin/bash

echo in current directory sudo gcc -o a.out a.c sudo chmod u+s a.out ./a.out

echo echo in /tmp sudo gcc -o /tmp/a.out a.c sudo chmod u+s /tmp/a.out /tmp/a.out

The result of the executation:

in current directory
euid: 0
uid: 1000

in /tmp euid: 1000 uid: 1000

The setuid bit didn't work in /tmp! I wonder why.

I mv the /tmp/a.out to my home directory and the setuid bit worked, so I guess there is something to do with the /tmp directory?

z.h.
  • 994

0 Answers0