21 uid_t uid
, euid
, suid
;
22 gid_t gid
, egid
, sgid
;
24 getresuid(&uid
, &euid
, &suid
);
25 getresgid(&gid
, &egid
, &sgid
);
27 outputstd("initial uid:%d gid:%d euid:%d egid:%d suid:%d sgid:%d\n",
28 uid
, gid
, euid
, egid
, suid
, sgid
);
33 if (setresgid(nobody_gid
, nobody_gid
, nobody_gid
) < 0) {
34 outputerr("Error setting nobody gid (%s)\n", strerror(errno
));
38 if (setgroups(0, NULL
) == -1) {
39 outputerr("Error dropping supplemental groups (%s)\n", strerror(errno
));
43 if (setresuid(nobody_uid
, nobody_uid
, nobody_uid
) < 0) {
44 outputerr("Error setting nobody uid (%s)\n", strerror(errno
));
48 outputstd("set uid to %d and gid to %d (nobody)\n", nobody_uid
, nobody_gid
);
53 struct passwd
*passwd
;
58 passwd
= getpwnam("nobody");
60 outputerr("Error getting nobody pwent (%s)\n", strerror(errno
));
63 nobody_uid
= passwd
->pw_uid
;
64 nobody_gid
= passwd
->pw_gid
;
68 void do_uid0_check(void)
72 /* if we're already unprivileged, then don't worry. */
76 if (dangerous
== TRUE
) {
77 outputstd("DANGER: RUNNING AS ROOT.\n");
78 outputstd("Unless you are running in a virtual machine, this could cause serious problems such as overwriting CMOS\n");
79 outputstd("or similar which could potentially make this machine unbootable without a firmware reset.\n");
80 outputstd("You might want to check out running with --dropprivs (currently experimental).\n\n");
83 if (dropprivs
== FALSE
) {
84 outputstd("Don't run as root (or pass --dangerous, or --dropprivs if you know what you are doing).\n");
87 outputstd("--dropprivs is still in development, and really shouldn't be used unless you're helping development. Expect crashes.\n");
88 outputstd("Going to run as user nobody (uid:%d gid:%d)\n", nobody_uid
, nobody_gid
);
92 outputstd("ctrl-c now unless you really know what you are doing.\n");
93 for (i
= 10; i
> 0; i
--) {
94 outputstd("Continuing in %d seconds.\r", i
);
104 /* If we were root, then obviously setuid() will change us, so don't even check. */
110 /* we should be 'nobody' if we ran with --dropprivs */
111 if (dropprivs
== TRUE
) {
112 if (myuid
== nobody_uid
)
118 if (myuid
!= orig_uid
) {
121 /* unshare() can change us to /proc/sys/kernel/overflowuid */
125 output(0, "uid changed! Was: %d, now %d\n", orig_uid
, myuid
);
127 shm
->exit_reason
= EXIT_UID_CHANGED
;