[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Secondary user groups

gga

6/23/2007 9:28:00 PM


require 'etc'
Etc.getpwnam(user)

or, using Daniel Berger's std-admin library_

require 'sys/admin'
Sys::Admin.get_user(user)

allows me to get a struct with the user's primary group.

However, I need to obtain the list of ALL groups that a user belongs
to (primary and secondary).
Other than doing the unportable:

groups = `groups #{user}`.split

is there a method in the ruby std library to get the secondary groups?

3 Answers

gga

6/23/2007 9:54:00 PM

0

On Jun 23, 6:27 pm, gga <GGarram...@aol.com> wrote:
> require 'etc'
> Etc.getpwnam(user)
>
> or, using Daniel Berger's std-admin library_
>
> require 'sys/admin'
> Sys::Admin.get_user(user)
>
> allows me to get a struct with the user's primary group.
>
> However, I need to obtain the list of ALL groups that a user belongs
> to (primary and secondary).
> Other than doing the unportable:
>
> groups = `groups #{user}`.split
>
> is there a method in the ruby std library to get the secondary groups?

Never mind. Found how to do it.

Gregory Brown

6/23/2007 11:41:00 PM

0

On 6/23/07, gga <GGarramuno@aol.com> wrote:

> > However, I need to obtain the list of ALL groups that a user belongs
> > to (primary and secondary).
> > Other than doing the unportable:
> >
> > groups = `groups #{user}`.split
> >
> > is there a method in the ruby std library to get the secondary groups?
>
> Never mind. Found how to do it.

Well how did you do it? ;)

Daniel Berger

6/25/2007 2:42:00 AM

0

Gregory Brown wrote:
> On 6/23/07, gga <GGarramuno@aol.com> wrote:
>
>> > However, I need to obtain the list of ALL groups that a user belongs
>> > to (primary and secondary).
>> > Other than doing the unportable:
>> >
>> > groups = `groups #{user}`.split
>> >
>> > is there a method in the ruby std library to get the secondary groups?
>>
>> Never mind. Found how to do it.
>
> Well how did you do it? ;)

Here's one way you could do it with sys-admin:

groups = []
Admin.groups{ |g|
groups << g.name if g.members.include?('you')
}

Regards,

Dan