SYNOPSIS

  use Unix::GroupFile;

  $grp = new Unix::GroupFile "/etc/group";
  $grp->group("bozos", "*", $grp->maxgid + 1, @members);
  $grp->remove_user("coolgrp", "bgates", "badguy");
  $grp->add_user("coolgrp", "joecool", "goodguy");
  $grp->remove_user("*", "deadguy");
  $grp->passwd("bozos", $grp->encpass("newpass"));
  $grp->commit();
  undef $grp;

DESCRIPTION

The Unix::GroupFile module provides an abstract interface to /etc/group format files. It automatically handles file locking, getting colons and commas in the right places, and all the other niggling details.

This module also handles the annoying problem (at least on some systems) of trying to create a group line longer than 512 characters. Typically this is done by creating multiple lines of groups with the same \s-1GID\s0. When a new GroupFile object is created, all members of groups with the same \s-1GID\s0 are merged into a single group with a name corresponding to the first name found in the file for that \s-1GID\s0. When the file is committed, long groups are written out as multiple lines of no more than 512 characters, with numbers appended to the group name for the extra lines.

METHODS

This method will add the list of users to an existing group. Users that are already members of the group are silently ignored. The special group name * will add the users to every group. Returns 1 on success or 0 on failure.

commit( [\s-1BACKUPEXT\s0] )

See the Unix::ConfigFile documentation for a description of this method.

delete( \s-1GROUP\s0 )

This method will delete the named group. It has no effect if the supplied group does not exist.

encpass( \s-1PASSWORD\s0 )

See the Unix::ConfigFile documentation for a description of this method.

gid( \s-1GROUP\s0 [,GID] )

Read or modify a group's \s-1GID\s0. Returns the \s-1GID\s0 in either case. Note that it is illegal to change a group's \s-1GID\s0 to a \s-1GID\s0 that is already in use by another group. In this case, the method returns undef. This method can add, modify, or return information about a group. Supplied with a single group parameter, it will return a list consisting of (\s-1PASSWORD\s0, \s-1GID\s0, @MEMBERS), or undef if no such group exists. If you supply at least three parameters, the named group will be created or modified if it already exists. The list is also returned to you in this case. Note that it is illegal to specify a \s-1GID\s0 that is already in use by another group. In this case, the method returns undef.

groups( [\s-1SORTBY\s0] )

This method returns a list of all existing groups. By default the list will be sorted in order of the GIDs of the groups. You may also supply \*(L"name\*(R" as a parameter to the method to get the list sorted by group name. In scalar context, this method returns the total number of groups.

maxgid( )

This method returns the maximum \s-1GID\s0 in use by all groups.

members( \s-1GROUP\s0 [,@USERS] )

Read or modify the list of members associated with a group. If you specify any users when you call the method, all existing members of the group are removed and your list becomes the new set of members. In scalar context, this method returns the total number of members in the group.

new( \s-1FILENAME\s0 [,OPTIONS] )

See the Unix::ConfigFile documentation for a description of this method.

passwd( \s-1GROUP\s0 [,PASSWD] )

Read or modify a group's password. Returns the encrypted password in either case. If you have a plaintext password, use the encpass method to encrypt it before passing it to this method. This method will remove the list of users from an existing group. Users that are not members of the group are silently ignored. The special group name * will remove the users from every group. Returns 1 on success or 0 on failure.

rename_user( \s-1OLDNAME\s0, \s-1NEWNAME\s0 )

This method will change one username to another in every group. Returns the number of groups affected.

AUTHOR

Steve Snodgrass, [email protected]

RELATED TO Unix::GroupFile…

Unix::AliasFile, Unix::AutomountFile, Unix::ConfigFile, Unix::PasswdFile