Solved

Retrieving group info on Unix

Posted on 2000-02-29
8
280 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
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
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

ScreenConnect 6.0 Free Trial

Discover new time-saving features in one game-changing release, ScreenConnect 6.0, based on partner feedback. New features include a redesigned UI, app configurations and chat acknowledgement to improve customer engagement!

Question has a verified solution.

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

Summary: This tutorial covers some basics of pointer, pointer arithmetic and function pointer. What is a pointer: A pointer is a variable which holds an address. This address might be address of another variable/address of devices/address of fu…
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 opening and writing to files in the C programming language.
The goal of this video is to provide viewers with basic examples to understand how to create, access, and change arrays in the C programming language.

809 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