Reputation: 2161
Using my c++ program how can I find out what group the current user running my program belongs to? So my program need to figure out a couple of things :
How can do the above 2 using c++ on a RedHat / Linux machine?
Upvotes: 0
Views: 3547
Reputation: 753675
You can find some of the information via getgid()
(real GID) and getegid()
(effective GID). For the other auxilliary groups, you need to use getgroups()
.
In practice, the real and effective GID are normally the same, but it is the effective GID that is used when creating a file. Usually, the group list returned by getgroups()
includes the real group - though it is not clear that it actually has to do so.
Upvotes: 3
Reputation: 126203
You use getuid(2)
and getgid(2)
to get the numeric user and group ids, then use getpwuid(3)
and getgrgid(3)
to look up those ids in the user/group databases and turn them into text names.
Upvotes: 2
Reputation: 798606
With getuid(2)
and getgid(2)
. See credentials(7)
for more information.
Use getpwuid(3)
and getgrgid(3)
for the names.
Upvotes: 5