-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathget_real_effective_saved_ids.c
46 lines (37 loc) · 1.01 KB
/
get_real_effective_saved_ids.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
43
44
45
46
/*
* Author: NagaChaitanya Vellanki
*
*
* Get real, effective and saved set ID's
*/
#define _GNU_SOURCE
#include <errno.h>
#include <stdarg.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
void err_exit(const char *format, ...) {
va_list args;
va_start(args, format);
vfprintf(stderr, format, args);
va_end(args);
exit(EXIT_FAILURE);
}
int main(int argc, char *argv[]) {
uid_t ruid, euid, suid;
gid_t rgid, egid, sgid;
if(getresuid(&ruid, &euid, &suid) == -1) {
err_exit("Error on getresuid, %s\n", strerror(errno));
}
if(getresgid(&rgid, &egid, &sgid) == -1) {
err_exit("Error on getresuid, %s\n", strerror(errno));
}
if(getresuid(&ruid, &euid, &suid) == -1) {
err_exit("Error on getresuid, %s\n", strerror(errno));
}
printf("Real User ID: %d\nEffective User ID: %d\nSaved Set User ID: %d\n", ruid, euid, suid);
printf("\n");
printf("Real Group ID: %d\nEffective Group ID: %d\nSaved Set Group ID: %d\n", rgid, egid, sgid);
exit(EXIT_SUCCESS);
}