view release on metacpan or search on metacpan
lib/DBD/Sys/CompositeTable.pm view on Meta::CPAN
# calls
# DBD::Sys::CompositeTable( [ 'DBD::Sys::Plugin::Any::Procs',
# 'DBD::Sys::Plugin::Win32::Procs' ],
# $attr );
This will fetch the column names from both embedded tables and get (simplfied):
# %colNames = (
# 'DBD::Sys::Plugin::Any::Procs' => [
# 'pid', 'ppid', 'uid', 'gid', 'cmndline', 'sess', 'priority', 'ttynum', 'start', 'run', 'status',
# ],
# 'DBD::Sys::Plugin::Win32::Procs' => [
# 'pid', 'ppid', 'uid', 'gid', 'cmndline', 'sess', 'priority', 'thread', 'start', 'run', 'status',
# ]
# );
# @colNames = (
# 'pid', 'ppid', 'uid', 'gid', 'cmndline', 'sess', 'priority', 'ttynum', 'start', 'run', 'status', 'threads',
# );
# %mergeCols = (
# 'DBD::Sys::Plugin::Any::Procs' => [
# 0 .. 10,
# ],
# 'DBD::Sys::Plugin::Win32::Procs' => [
# 7,
# ]
# );
# $primaryKey = 'pid';
The merge phase in C<collect_data()> finally does (let's assume running
in a cygwin environment, where Proc::ProcessTable and Win32::Process::Info
both are working):
+-----+------+-----+-----+----------+------+----------+---------+-------+-----+---------+
| pid | ppid | uid | gid | cmndline | sess | priority | ttynum | start | run | status |
+-----+------+-----+-----+----------+------+----------+---------+-------+-----+---------+
| 0 | 0 | 0 | 0 | 'init' | 0 | 4 | <undef> | 0 | 999 | 'ioblk' |
| 100 | 0 | 200 | 20 | 'bash' | 1 | 8 | pty/1 | 10000 | 200 | 'wait' |
+-----+------+-----+-----+----------+------+----------+---------+-------+-----+---------+
+-----+------+-----+-----+----------+------+----------+-------+-----+---------+---------+
| pid | ppid | uid | gid | cmndline | sess | priority | start | run | status | threads |
+-----+------+-----+-----+----------+------+----------+-------+-----+---------+---------+
| 782 | 241 | 501 | 501 | 'cygwin' | 0 | 4 | 0 | 999 | 'ioblk' | 2 |
| 100 | 0 | 501 | 501 | 'bash' | 1 | 8 | 10000 | 200 | 'wait' | 8 |
+-----+------+-----+-----+----------+------+----------+-------+-----+---------+---------+
The resulting table would be:
+-----+------+-----+-----+----------+------+----------+---------+-------+-----+---------+---------+
| pid | ppid | uid | gid | cmndline | sess | priority | ttynum | start | run | status | threads |
+-----+------+-----+-----+----------+------+----------+---------+-------+-----+---------+---------+
| 0 | 0 | 0 | 0 | 'init' | 0 | 4 | <undef> | 0 | 999 | 'ioblk' | <undef> |
| 100 | 0 | 200 | 20 | 'bash' | 1 | 8 | pty/1 | 10000 | 200 | 'wait' | 8 |
| 782 | 241 | 501 | 501 | 'cygwin' | 0 | 4 | <undef> | 0 | 999 | 'ioblk' | 8 |
+-----+------+-----+-----+----------+------+----------+---------+-------+-----+---------+---------+
In the real world, it's a bit more complicated and especially the process
table is a bit larger, but it illustrates the most important points:
=over 4
lib/DBD/Sys/Plugin/Any/Procs.pm view on Meta::CPAN
=head1 ISA
DBD::Sys::Plugin::Any::Procs
ISA DBD::Sys::Table
=cut
$VERSION = "0.102";
@colNames = (
qw(uid gid euid egid pid ppid pgrp sess priority ttynum flags),
qw(fulltime ctime virtsize rss wchan fname start),
qw(pctcpu state pctmem cmndline ttydev)
);
my $haveProcProcessTable;
my %knownCols;
=head1 DESCRIPTION
This module provides the table C<procs> for any operating system (which is
supported by Proc::ProcessTable).
=head2 COLUMNS
=head3 uid
UID of process
=head3 gid
GID of process
=head3 euid
Effective UID of process
=head3 egid
Effective GID of process
=head3 pid
Process ID
=head3 ppid
Parent process ID
lib/DBD/Sys/Plugin/Unix/Groups.pm view on Meta::CPAN
package DBD::Sys::Plugin::Unix::Groups;
use strict;
use warnings;
use vars qw($VERSION @colNames);
use base qw(DBD::Sys::Table);
$VERSION = "0.102";
@colNames = qw(groupname grpass gid members);
=pod
=head1 NAME
DBD::Sys::Plugin::Unix::Groups - provides a table containing operating system user groups
=head1 SYNOPSIS
$groups = $dbh->selectall_hashref("select * from grent", "groupname");
lib/DBD/Sys/Plugin/Unix/Groups.pm view on Meta::CPAN
=head2 COLUMNS
=head3 groupname
Name of the group
=head3 grpass
Encrypted password of the group
=head3 gid
Numerical group id of the users primary group
=head3 members
Numerical count of the members in this group
=head1 METHODS
=head2 get_table_name
lib/DBD/Sys/Plugin/Unix/Groups.pm view on Meta::CPAN
=cut
sub collect_data()
{
my %data;
if ($havegrent)
{
setgrent(); # rewind to ensure we're starting fresh ...
while ( my ( $name, $grpass, $gid, $members ) = getgrent() )
{
if ( defined( $data{$name} ) ) # FBSD seems to have a bug with multiple entries
{
my $row = $data{$name};
unless ( ( $row->[0] eq $name )
and ( $row->[1] eq $grpass )
and ( $row->[2] == $gid )
and ( $row->[3] eq $members ) )
{
warn
"$name is delivered more than once and the group information differs from the first one";
}
}
else
{
$data{$name} = [ $name, $grpass, $gid, $members ];
}
}
setgrent(); # rewind
endgrent();
}
my @data = values %data;
return \@data;
}
lib/DBD/Sys/Plugin/Unix/Users.pm view on Meta::CPAN
package DBD::Sys::Plugin::Unix::Users;
use strict;
use warnings;
use vars qw($VERSION @colNames);
use base qw(DBD::Sys::Table);
$VERSION = "0.102";
@colNames = qw(username passwd uid gid quota comment gcos dir shell expire);
=pod
=head1 NAME
DBD::Sys::Plugin::Unix::Users - provides a table containing a list of operating system users
=head1 SYNOPSIS
$users = $dbh->selectall_hashref("select * from pwent", "username");
lib/DBD/Sys/Plugin/Unix/Users.pm view on Meta::CPAN
the system.
=head3 passwd
Encrypted password of the user - typically accessible by root only.
=head3 uid
Numerical user id
=head3 gid
Numerical group id of the users primary group
=head3 quota
Quota, when supported by this system and set
=head3 comment
Comment, when set
lib/DBD/Sys/Plugin/Unix/Users.pm view on Meta::CPAN
=cut
sub collect_data()
{
my @data;
if ($havepwent)
{
setpwent(); # rewind to ensure we're starting fresh ...
while ( my ( $name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell, $expire ) =
getpwent() )
{
push( @data,
[ $name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell, $expire ] );
}
setpwent();
endpwent();
}
return \@data;
}
=head1 PREREQUISITES
lib/DBD/Sys/Plugin/Win32/Groups.pm view on Meta::CPAN
use vars qw($VERSION @colNames);
use base qw(DBD::Sys::Table);
my $haveWin32pwent = 0;
eval {
require Win32::pwent;
$haveWin32pwent = 1;
};
$VERSION = "0.102";
@colNames = qw(groupname grpass gid members);
=pod
=head1 NAME
DBD::Sys::Plugin::Win32::Groups - provides a table containing the operating system user groups
=head1 SYNOPSIS
$groups = $dbh->selectall_hashref("select * from grent", "groupname");
lib/DBD/Sys/Plugin/Win32/Groups.pm view on Meta::CPAN
=head2 COLUMNS
=head3 groupname
Name of the group
=head3 grpass
Encrypted password of the group - usually empty for current LANMAN functions
=head3 gid
Numerical group id of the users primary group
=head3 members
Numerical count of the members in this group
=head1 METHODS
=head2 get_table_name
lib/DBD/Sys/Plugin/Win32/Groups.pm view on Meta::CPAN
=cut
sub collect_data()
{
my @data;
if ($haveWin32pwent)
{
Win32::pwent::endgrent(); # ensure we're starting fresh ...
while ( my ( $name, $grpass, $gid, $members ) = Win32::pwent::getgrent() )
{
push( @data, [ $name, $grpass, $gid, $members ] );
}
Win32::pwent::endgrent();
}
return \@data;
}
=head1 PREREQUISITES
The module C<Win32::pwent> is required to provide data for the
lib/DBD/Sys/Plugin/Win32/Users.pm view on Meta::CPAN
use vars qw($VERSION @colNames);
use base qw(DBD::Sys::Table);
my $haveWin32pwent = 0;
eval {
require Win32::pwent;
$haveWin32pwent = 1;
};
$VERSION = "0.102";
@colNames = qw(username passwd uid gid quota comment gcos dir shell expire);
=pod
=head1 NAME
DBD::Sys::Plugin::Win32::Users - provides a table containing the operating system users
=head1 SYNOPSIS
$users = $dbh->selectall_hashref("select * from pwent", "username");
lib/DBD/Sys/Plugin/Win32/Users.pm view on Meta::CPAN
the system.
=head3 passwd
Encrypted password of the user - usually empty for current LANMAN functions.
=head3 uid
Numerical user id
=head3 gid
Numerical group id of the users primary group
=head3 quota
Quota, when supported by this system and set
=head3 comment
Comment, when set
lib/DBD/Sys/Plugin/Win32/Users.pm view on Meta::CPAN
=cut
sub collect_data()
{
my @data;
if ($haveWin32pwent)
{
Win32::pwent::endpwent(); # ensure we're starting fresh ...
while ( my ( $name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell, $expire ) =
Win32::pwent::getpwent() )
{
push( @data,
[ $name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell, $expire ] );
}
Win32::pwent::endpwent();
}
return \@data;
}
=head1 PREREQUISITES
The module C<Win32::pwent> is required to provide data for the
t/002_checktbls.t view on Meta::CPAN
}
}
my ( $username, $userid, $groupname, $groupid );
if ( $^O eq 'MSWin32' )
{
$username = getlogin() || Win32::LoginName() || $ENV{USERNAME};
$userid = Win32::pwent::getpwnam($username);
$groupid = ( Win32::pwent::getpwnam($username) )[3];
$groupname = Win32::pwent::getgrgid($groupid);
}
else
{
$userid = $<;
$username = getpwuid($<);
$groupid = $(;
$groupname = getgrgid($();
}
my $foundAllTables = 0;
ok( my $dbh = DBI->connect('DBI:Sys:'), 'connect' ) or diag($DBI::errstr);
ok( my $st = $dbh->prepare('SELECT table_name FROM alltables'), 'prepare alltables' ) or diag( $dbh->errstr );
ok( my $num = $st->execute(), 'execute alltables' ) or diag( $st->errstr );
while ( $row = $st->fetchrow_hashref() )
{
t/002_checktbls.t view on Meta::CPAN
ok( $st = $dbh->prepare('SELECT DISTINCT username, uid FROM pwent WHERE uid=?'), 'prepare pwent' )
or diag( $dbh->errstr );
ok( $num = $st->execute($userid), 'execute pwent' ) or diag( $st->errstr );
while ( $row = $st->fetchrow_hashref() )
{
cmp_ok( $userid, '==', $row->{uid}, 'uid pwent' );
cmp_ok( $username, 'eq', $row->{username}, 'username pwent' );
}
ok( $st = $dbh->prepare('SELECT DISTINCT groupname, gid FROM grent WHERE gid=?'), 'prepare grent' )
or diag( $dbh->errstr );
ok( $num = $st->execute( 0 + $groupid ), 'execute grent' ) or diag( $st->errstr );
while ( $row = $st->fetchrow_hashref() )
{
cmp_ok( $groupid, '==', $row->{gid}, 'gid grent' );
cmp_ok( $groupname, 'eq', $row->{groupname}, 'groupname grent' );
}
ok(
$st = $dbh->prepare(
"SELECT DISTINCT grent.groupname, grent.gid FROM grent, pwent WHERE pwent.uid=? and pwent.gid=grent.gid"),
'prepare join'
) or diag( $dbh->errstr );
ok( $num = $st->execute($userid), 'execute join' ) or diag( $st->errstr );
while ( $row = $st->fetchrow_hashref() )
{
cmp_ok( $groupid, '==', $row->{'grent.gid'}, 'gid join' );
cmp_ok( $groupname, 'eq', $row->{'grent.groupname'}, 'groupname join' );
}
t/004_process.t view on Meta::CPAN
}
}
my ( $username, $userid, $groupname, $groupid );
if ( $^O eq 'MSWin32' )
{
$username = getlogin() || Win32::LoginName() || $ENV{USERNAME};
$userid = Win32::pwent::getpwnam($username);
$groupid = ( Win32::pwent::getpwnam($username) )[3];
$groupname = Win32::pwent::getgrgid($groupid);
}
else
{
$userid = $<;
$username = getpwuid($<);
$groupid = $(;
$groupname = getgrgid($();
}
my $table;
my $found = 0;
ok( my $dbh = DBI->connect('DBI:Sys:'), 'connect 1' ) or diag($DBI::errstr);
if ( $proved_vers[1]->{'Proc::ProcessTable'} )
{
t/007_logonusers.t view on Meta::CPAN
plan( skip_all => "Sys::Utmp required for this test" ) unless ( defined( _HASH( $proved_vers[1] ) ) );
plan( tests => 4 );
my ( $username, $userid, $groupname, $groupid );
if ( $^O eq 'MSWin32' )
{
$username = getlogin() || Win32::LoginName() || $ENV{USERNAME};
$userid = Win32::pwent::getpwnam($username);
$groupid = ( Win32::pwent::getpwnam($username) )[3];
$groupname = Win32::pwent::getgrgid($groupid);
}
else
{
$userid = $<;
$username = getpwuid($<);
$groupid = $(;
$groupname = getgrgid($();
}
ok( my $dbh = DBI->connect('DBI:Sys:'), 'connect 1' ) or diag($DBI::errstr);
ok( $st = $dbh->prepare("SELECT COUNT(*) FROM logins WHERE username=?"), 'prepare logins' ) or diag( $dbh->errstr );
ok( my $num = $st->execute($username), 'execute logins' ) or diag( $st->errstr );
$row = $st->fetchrow_arrayref();
ok( $row->[0], 'login found' );