Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Retrieving group info on Unix

Posted on 2000-02-29
8
Medium Priority
?
319 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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 800 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

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

Question has a verified solution.

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

This tutorial is posted by Aaron Wojnowski, administrator at SDKExpert.net.  To view more iPhone tutorials, visit www.sdkexpert.net. This is a very simple tutorial on finding the user's current location easily. In this tutorial, you will learn ho…
Examines three attack vectors, specifically, the different types of malware used in malicious attacks, web application attacks, and finally, network based attacks.  Concludes by examining the means of securing and protecting critical systems and inf…
Video by: Grant
The goal of this video is to provide viewers with basic examples to understand and use while-loops 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.

610 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