|
PTools::SDF::File::Passwd - Get list of users via "/etc/passwd" or "ypcat passwd" |
PTools::SDF::File::Passwd - Get list of users via ``/etc/passwd'' or ``ypcat passwd''
This document describes version 0.05, released Nov 12, 2002.
use PTools::SDF::File::Passwd;
or use PTools::SDF::File::Passwd qw( passwd ); # default: from /etc/passwd
or use PTools::SDF::File::Passwd qw( NIS ); # alt: via "ypcat passwd"
Note: Only when the NIS format of ``use PTools::SDF::File::Passwd'' is employed is it possible to instantiate from an array of passwd entries. When this is done, the NIS password file is not loaded.
$pwObj = new PTools::SDF::File::Passwd;
or $pwObj = new PTools::SDF::File::Passwd( @arrayOfPasswdEntries );
The list of system users is, at this point, sorted in ``uname'' order. To process each entry, for example, use something like the following. Pick ``$fieldName'' from the ``@PasswdFieldNames'' list, defined below.
foreach $uname ( $pwObj->getUserList ) {
(@passwdEnt) = $pwObj->getPwent( $uname );
(or) $passwdField = $pwObj->getPwent( $uname, $fieldName );
(@gcosEntry) = $pwObj->getGcos( $uname );
$gcosHashRef = $pwObj->parseGcos( @gcosEntry );
(or) $gcosHashRef = $pwObj->parseGcos( $uname );
}
Different installations define the ``gcos'' field in different ways. To redefine how the ``gcos'' field in the passwd entry is parsed, simply subclass this module and override the ``parseGcos'' method.
(@gcosFields) = $pwObj->getGcosFieldNames;
To determine field names currently defined, use the above method.
To re-sort, simply invoke the normal PTools::SDF::SDF ``sort'' method. This is probably not necessary. See the PTools::SDF::SDF module and the modules SDF::Sort::Quick and PTools::SDF::Sort::Shell for further details on sorting. (Note that ``$mode'' may or may not work, depending on the sorter used.) Pick ``$keyFieldName'' from the ``@PasswdFieldNames'' list, defined below.
$pwObj->sort( $mode, $keyFieldName );
Note that even after resorting the ``getUserList'' method will STILL return a list sorted in 'uname' order. To process using the new sort order, walk the list sequentially. For example,
foreach $rec ( 0 .. $pwObj->param ) {
(@passwdEnt) = $pwObj->param($rec);
(@gcosEntry) = $pwObj->param($rec,'gcos');
$gcosHashRef = $pwObj->parseGcos( @gcosEntry );
}
use PTools::SDF::File::Passwd;
or use PTools::SDF::File::Passwd qw( passwd ); # default: from /etc/passwd
or use PTools::SDF::File::Passwd qw( NIS ); # alt: via "ypcat passwd"
Note: Only when the NIS format of ``use PTools::SDF::File::Passwd'' is employed is it possible to instantiate from an array of passwd entries. When this is done, the NIS password file is not loaded.
$pwObj = new PTools::SDF::File::Passwd;
or $pwObj = new PTools::SDF::File::Passwd( @arrayOfPasswdEntries );
foreach $uname ( $pwObj->getUserList ) { . . . }
(@passwdEnt) = $pwObj->getPwent( $uname );
or $passwdField = $pwObj->getPwent( $uname, $fieldName );
$acctStat = $pwObj->getAcctStat( $uname ); # returns "Active" or "Disabled"
if ($pwObj->acctActive( $uname )) { ... }
if ($pwObj->acctDisabled( $uname )) { ... }
WARN: If additional characters are used in the local passwd file to indicate a disabled account, this module must be subclassed and the necessary methods overridden.
(@gcosEntry) = $pwObj->getGcos( $uname );
(@gcosFields) = $pwObj->getGcosFieldNames;
Different installations define the ``gcos'' field in different ways. To redefine how the ``gcos'' field in the passwd entry is parsed, simply subclass this module and override the ``parseGcos'' method.
Examples:
$gcosHashRef = $pwObj->parseGcos( $uname );
(@gcosEntry) = $pwObj->getGcos( $uname ); $gcosHashRef = $pwObj->parseGcos( @gcosEntry );
The Params here will vary, based on the currently loaded sort module.
This class inherits from both PTools::SDF::IDX and PTools::SDF::ARRAY. The PTools::SDF::ARRAY class inherits from PTools::SDF::SDF which, in turn, inherits from PTools::SDF::File.
For additional methods see the PTools::SDF::IDX manpage, the PTools::SDF::ARRAY manpage, the PTools::SDF::SDF manpage and the PTools::SDF::File manpage.
For documentation on the various sorting classes available see the PTools::SDF::Sort::Bubble manpage, the PTools::SDF::Sort::Quick manpage and the PTools::SDF::Sort::Shell manpage.
Chris Cobb, <nospamplease@ccobb.net>
Copyright (c) 2002-2007 by Chris Cobb. All rights reserved. This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
|
PTools::SDF::File::Passwd - Get list of users via "/etc/passwd" or "ypcat passwd" |