Under RedHat 7.2 I need to be able to stat /dev/hda as a typical user, this is part of a larger program. Since /dev/hda has permissions of 660 I think I need to use setuid. I have tried with just a simple program
but can not get setuid to work. After I compile the program I chmod 4755 the program and when I run it setuid always fails. What am I doing wrong.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
int main(int argc, char **argv)
{
int status;
status = setuid(0);
if(status < 0)
{
fprintf("setuid failed.\n");
exit(status);
}
}
but can not get setuid to work. After I compile the program I chmod 4755 the program and when I run it setuid always fails. What am I doing wrong.
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
int main(int argc, char **argv)
{
int status;
status = setuid(0);
if(status < 0)
{
fprintf("setuid failed.\n");
exit(status);
}
}
