Forum: Ruby Secondary user groups

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
gga (Guest)
on 2007-06-24 01:30
(Received via mailing list)
require 'etc'
Etc.getpwnam(user)

or, using Daniel B.'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?
gga (Guest)
on 2007-06-24 01:55
(Received via mailing list)
On Jun 23, 6:27 pm, gga <removed_email_address@domain.invalid> 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.
Gregory B. (Guest)
on 2007-06-24 03:42
(Received via mailing list)
On 6/23/07, gga <removed_email_address@domain.invalid> 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 B. (Guest)
on 2007-06-25 06:42
(Received via mailing list)
Gregory B. wrote:
>> 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
This topic is locked and can not be replied to.