[cs631apue] setuid

Keyur Ved kved at stevens.edu
Fri Oct 12 17:55:07 EDT 2018


You should be able to access the group name/username using
getgrgid(3) and getpwuid(3), those functions do not require root.

On Fri, Oct 12, 2018 at 5:43 PM Aubhik Mazumdar <amazumda at stevens.edu>
wrote:

> Hello,
>
> Initially I was facing segfaults while printing the username and group
> name retrieved using getpwuid and getgruid. This was because the
> /etc/passwd and shadow files cannot be accessed if you are not root.
>
> To overcome this, I started using the setuid program to set the effective
> userId to 0 (super user) and reverting back to the original uid after
> reading the file.
>
> Has anybody found a better way of getting the username and the groupname
> without using setuid?
>
> Thanks,
> Aubhik Mazumdar
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.stevens.edu/pipermail/cs631apue/attachments/20181012/310ef2d1/attachment.html>


More information about the cs631apue mailing list