• We’re currently investigating an issue related to the forum theme and styling that is impacting page layout and visual formatting. The problem has been identified, and we are actively working on a resolution. There is no impact to user data or functionality, this is strictly a front-end display issue. We’ll post an update once the fix has been deployed. Thanks for your patience while we get this sorted.

setuid programming question

denali

Golden Member
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);
}
}
 
If the program is setuid it's already running as the owning uid (make sure root owns it), there's no need to change your euid unless you're dropping privs.

Also if you set the permissions on /dev/hda properly, you shouldn't need uid to be 0. Just add your user to the disk group and make sure the disk group has rwx to /dev/hda.
 
Back
Top