Passwd-DB

 view release on metacpan or  search on metacpan

DB.pm  view on Meta::CPAN

use Carp;
use vars qw($VERSION @ISA @EXPORT @EXPORT_OK);

require Exporter;
require AutoLoader;

@ISA = qw(Exporter AutoLoader);
# Items to export into callers namespace by default. Note: do not export
# names by default without a very good reason. Use EXPORT_OK instead.
# Do not simply export all your public functions/methods/constants.
@EXPORT = qw(getpwnam getpwuid);

@EXPORT_OK = qw(mgetpwnam setpwinfo rmpwnam init_db modpwinfo);

$VERSION = '1.05';

my %_DB_Global = ();
$_DB_Global{'Database'} = $ENV{'PWDDatabase'};
$_DB_Global{'CFlags'} = O_CREAT;  # found in Fcntl

# Preloaded methods go here.

DB.pm  view on Meta::CPAN

    if (scalar(@info) == 7) {
        splice (@info,4,0, "");
        splice (@info,4,0, "");
        untie %dbm;
        return @info;
    }
    untie %dbm;
    return;
}

sub getpwuid ($) {
    my ($self, $uid) = @_;
    my (%dbm, @info, $key, $db);

    if (ref($self)) {
	$db = $self->{'Database'};
    } else {
	$uid = $self;
	$db = $_DB_Global{'Database'};
    }

DB.pm  view on Meta::CPAN


Passwd::DB - Perl module for manipulating a password file stored in a BerkeleyDB hash

=head1 SYNOPSIS

  use Passwd::DB;

  $db = Passwd::DB->new("/usr/local/databases/db_ftp_users");
  $db = Passwd::DB->new("/usr/local/databases/db_ftp_users", 'create');
  @info = $db->getpwnam('bob');
  @info = $db->getpwuid('100');
  @minfo = $db->mgetpwnam('bob');
  $err = $db->modpwinfo(@minfo);
  $err = $db->setpwinfo(@minfo);
  $err = $db->rmpwnam('bob');

  use Passwd::DB qw(init_db getpwnam getpwuid mgetpwnam modpwinfo setpwinfo rmpwnam);

  Passwd::DB->init_db("/usr/local/databases/db_ftp_users");
  Passwd::DB->init_db("/usr/local/databases/db_ftp_users", 1);
  init_db("/usr/local/db_bob",1);
  @info = getpwnam('bob');
  @info = getpwuid('100');
  @minfo = mgetpwnam('bob');
  $err = modpwinfo(@minfo);
  $err = setpwinfo(@minfo);
  $err = rmpwnam('bob');


=head1 DESCRIPTION

Passwd::DB provides basic password routines.  It augments getpwnam and getpwuid functions with setpwinfo, modpwinfo, rmpwnam, mgetpwnam.  The routines can be used both in object context or straight.  When used in non-object context a call to init_db ...

new and init_db can be called with an optional second argument.  If it is set to 1 or 'create' the database will be created if it doesn't already exist.

getpwnam and getpwuid are the same as their respective core counterparts.

setpwinfo and modpwinfo are called with arrays containing (in order):
 name, crypted_password, uid, gid, gecos, home_directory, shell

rmpwnam is called with a scalar containing the login name.

mgetpwnam returns the same array that getpwnam returns without the 'unused' age or comment fields.

setpwinfo does a create/modify of the user.
modpwinfo only does a modify, it will return an error if the user doesn't exist.

DB.pm  view on Meta::CPAN

Error return values:
  < 0   system error occurred, error value should be in $!
    0   no error
    1   operation failed
    2   operation failed because user does not exist


=head1 Exported functions on the OK basis

    getpwnam
    getpwuid
    mgetpwnam
    modpwinfo
    setpwinfo
    rmpwnam
    init_db

=head1 AUTHOR

Eric Estabrooks, eric@urbanrage.com



( run in 0.379 second using v1.01-cache-2.11-cpan-8d75d55dd25 )