Solved

Retrieving group info on Unix

Posted on 2000-02-29
8
289 Views
Last Modified: 2012-05-04
Hi,

Could anyone help me to retrieve a users login group as well as all the other groups he is a member of. The problem is that a call like "getgroups" only returns the calling users groups and I have to find the groups of any arbitrary user. I am running cc on SCO Unix.

Thanks
Johan
0
Comment
Question by:johand
8 Comments
 
LVL 2

Expert Comment

by:obg
ID: 2569008
I don't think that is possible unless you have root privs. Is that a problem?
0
 

Author Comment

by:johand
ID: 2569435
Running the program with root priv. isnt a problem :)
0
 
LVL 86

Expert Comment

by:jkr
ID: 2569736
>>The problem is that a call like "getgroups" only returns
>>the calling users groups and I have to find the groups of
>>any arbitrary user

what about using 'setuid()'?
0
PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

 
LVL 3

Expert Comment

by:ufolk123
ID: 2571394
May be one good option left is read the /etc/groups and read group information for each group.

The entry in this file is like this
Bdiosa::101:mvpevt,mvpss,mvpsv

where Bdiosa is a group with identifer(101) and have users mvpevt,mvpss,mvpsv
..
So you can get all information you want.Only thing is info is organised in form of group.You may to write a small code to search a user name for each of these entries and collect data.
Please get back for any clarifications.


0
 

Author Comment

by:johand
ID: 2572503
To ufolk123 : I am going to reject your answer :) purely because I see that as the absolute last option. If there is any way that I can retrieve the groupinfo without having to parse the /etc/group file manually I would prefer that method. If no-one else can offer me such a solution I will ask you to resubmit your solution so that I can accept it.

To jkr : Could you clarify how to use setuid to do this ?
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2573530
ufolk123's suggestion is quite easy if you use
grep user1 /etc/group
you immediately have a list of groups where user1 is a member, just cut first word till ':'  (semicolon), not too hard I think...
0
 
LVL 86

Accepted Solution

by:
jkr earned 200 total points
ID: 2574048
Well, I thought of sth. like

(pseudocode)

#include <unistd.h>
#include <sys/types.h>

/* ...*/

#define MAX_SIZE 256

uid_t myuid;
uid_t uid;
gid_t gids [ MAX_SIZE];

int ngroups = 0;

uid = <id of the user of interest>;

myuid = getuid();

setuid ( uid);

ngroups = getgroups ( MAX_SIZE, gids);

setuid ( myuid);


0
 

Author Comment

by:johand
ID: 2579225
Duh !! <slaps forehead repeatedly> of course ! Thanks a lot  :)
0

Featured Post

Problems using Powershell and Active Directory?

Managing Active Directory does not always have to be complicated.  If you are spending more time trying instead of doing, then it's time to look at something else. For nearly 20 years, AD admins around the world have used one tool for day-to-day AD management: Hyena. Discover why

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

An Outlet in Cocoa is a persistent reference to a GUI control; it connects a property (a variable) to a control.  For example, it is common to create an Outlet for the text field GUI control and change the text that appears in this field via that Ou…
This is a short and sweet, but (hopefully) to the point article. There seems to be some fundamental misunderstanding about the function prototype for the "main" function in C and C++, more specifically what type this function should return. I see so…
The goal of this video is to provide viewers with basic examples to understand and use structures in the C programming language.
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use nested-loops in the C programming language.

828 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question