Here's a Perl program that checks for changes to the direct setuid:
#! / usr / bin / perl
sub callingUser () {
my ($ login, $ pass, $ uid, $ gid) = getpwuid ($ <);
return $ login;
}
sub effectiveUser () {
my ($ login, $ pass, $ uid, $ gid) = getpwuid ($>);
return $ login;
}
printf ("Real user name:% s \ n", effectiveUser ());
printf ("Calling user name:% s \ n", callingUser ());
But since you mentioned that a change to setuid could happen anytime sooner, you probably have to parse the output of ps : I would do this using the following command. This command uses only the functions defined in POSIX , so I hope that it is portable for all kinds of systems:
ps -e -o pid, ppid, user, ruser
source share