This is a set-root-uid program
$ls -l
-rwsr-sr-x 1 root root 7406 2011-12-13 22:37 ./x*
The source code:
int main(void) {
printf(
" UID GID
"
"Real %d Real %d
"
"Effective %d Effective %d
",
getuid (), getgid (),
geteuid(), getegid()
);
seteuid(600);
printf(
" UID GID
"
"Real %d Real %d
"
"Effective %d Effective %d
",
getuid (), getgid (),
geteuid(), getegid()
);
setuid(1000);
printf(
" UID GID
"
"Real %d Real %d
"
"Effective %d Effective %d
",
getuid (), getgid (),
geteuid(), getegid()
);
setuid(0); // HOW DOES THIS SUCCEED IN SETTING THE EUID BACK TO 0
printf(
" UID GID
"
"Real %d Real %d
"
"Effective %d Effective %d
",
getuid (), getgid (),
geteuid(), getegid()
);
return 0 ;
}
OUTPUT
UID GID
Real 1000 Real 1000
Effective 0 Effective 0
UID GID
Real 1000 Real 1000
Effective 600 Effective 0
UID GID
Real 1000 Real 1000
Effective 1000 Effective 1000
UID GID
Real 1000 Real 1000
Effective 0 Effective 1000
My question
The man page states that setuid will change the real,saved and effective uid.
So after the calling setuid(1000)
, all three change to 1000
.
How is that setuid(0)
let's me change euid
to 0
?
question from:
https://stackoverflow.com/questions/8499296/realuid-saved-uid-effective-uid-whats-going-on 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…