-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathsetuid.c
42 lines (35 loc) · 961 Bytes
/
setuid.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
#include <sys/types.h>
#include <unistd.h>
#include <stdio.h>
#include <fcntl.h>
#include <stdlib.h>
#include <grp.h>
#include <pwd.h>
#include <err.h>
int
main(void)
{
printf("real ID:\t%s\n", getpwuid(getuid())->pw_name);
printf("effective ID:\t%s\n", getpwuid(geteuid())->pw_name);
printf("real GID:\t%s\n", getgrgid(getgid())->gr_name);
printf("effective GID:\t%s\n\n", getgrgid(getegid())->gr_name);
if (open("test", O_RDONLY) == -1) {
warn("test");
} else {
printf("ok, open() succeeded\n");
}
printf("\nafter setuid()...\n\n");
if (setuid(1062) == -1) {
err(1, "setuid");
}
printf("real ID:\t%s\n", getpwuid(getuid())->pw_name);
printf("effective ID:\t%s\n", getpwuid(geteuid())->pw_name);
printf("real GID:\t%s\n", getgrgid(getgid())->gr_name);
printf("effective GID:\t%s\n\n", getgrgid(getegid())->gr_name);
if (open("test", O_RDONLY) == -1) {
warn("test");
} else {
printf("ok, open() succeeded\n");
}
return (0);
}