Groups

NAME

Unix::Groups - access to details from /etc/group

SYNOPSIS

use Unix::Groups;

my $groups = Unix::Groups.new;

say "The logged in user is member of these groups:";

for $groups.groups-for-user($*USER.Str) -> $group {
    say $group.name;
}

DESCRIPTION

This module provides access to the group details from /etc/group, with similar to getgrent(), getgrnam and getgrgid in the Unix standard C library.

The methods either return a Unix::Groups::Group object or an array of those objects.

Because this module goes directly to the group file, if your system is configured to retrieve its group information from e.g. NIS or LDAP it may not necessarily reflect all the groups present, just the local ones.

METHODS

method groups

method groups() returns Array[User::Groups::Group]

Returns the full list of groups, sorted in order of group id.

method group-by-name

method group-by-name(Str $name) returns User::Groups::Group

Returns the group specified by $name or the type object if none exists.

method group-by-id

method group-by-id(Int $id) returns User::Groups::Group

Returns the group specified by the integer group id of the type object if none exists.

method groups-for-user

method groups-for-user(Str() $user) returns Array[User::Groups::Group]

This returns a list of the groups that the specified user is a member of or an empty list if the user isn't in any groups.

Unix::Groups::Group

This is the class that represents the groups returned by the above methods. It stringifies to the group name and numifies to the group id.

It has attributes that reflect the fields in /etc/group

gid

The Int id of the group.

name

The name of the group.

password

The password for the group if set, most modern systems place this in a shadow file so this may be empty or some other meaningless value.

users

This is a list of the names of the users that are members of the group.

Unix::Groups v0.0.6

Access to the Unix group file in Raku

Authors

  • Jonathan Stowe

License

Artistic-2.0

Dependencies

Test Dependencies

Provides

  • Unix::Groups

Documentation

The Camelia image is copyright 2009 by Larry Wall. "Raku" is trademark of the Yet Another Society. All rights reserved.