File Coverage

blib/lib/DBD/Sys/Plugin/Unix/Users.pm
Criterion Covered Total %
statement 14 22 63.6
branch 0 2 0.0
condition n/a
subroutine 6 7 85.7
pod 3 3 100.0
total 23 34 67.6


line stmt bran cond sub pod time code
1             package DBD::Sys::Plugin::Unix::Users;
2              
3 3     3   2422 use strict;
  3         7  
  3         100  
4 3     3   14 use warnings;
  3         6  
  3         83  
5 3     3   255 use vars qw($VERSION @colNames);
  3         7  
  3         144  
6              
7 3     3   14 use base qw(DBD::Sys::Table);
  3         5  
  3         828  
8              
9             $VERSION = "0.102";
10             @colNames = qw(username passwd uid gid quota comment gcos dir shell expire);
11              
12             =pod
13              
14             =head1 NAME
15              
16             DBD::Sys::Plugin::Unix::Users - provides a table containing a list of operating system users
17              
18             =head1 SYNOPSIS
19              
20             $users = $dbh->selectall_hashref("select * from pwent", "username");
21              
22             =head1 ISA
23              
24             DBD::Sys::Plugin::Unix::Users;
25             ISA DBD::Sys::Table
26              
27             =head1 DESCRIPTION
28              
29             This module provides the table I filled the data from the password
30             database C.
31              
32             =head2 COLUMNS
33              
34             =head3 username
35              
36             Name of the user in this row how he/she authenticates himself/herself to
37             the system.
38              
39             =head3 passwd
40              
41             Encrypted password of the user - typically accessible by root only.
42              
43             =head3 uid
44              
45             Numerical user id
46              
47             =head3 gid
48              
49             Numerical group id of the users primary group
50              
51             =head3 quota
52              
53             Quota, when supported by this system and set
54              
55             =head3 comment
56              
57             Comment, when set
58              
59             =head3 gcos
60              
61             General information about the user
62              
63             =head3 dir
64              
65             Users home directory
66              
67             =head3 shell
68              
69             Users default login shell
70              
71             =head3 expire
72              
73             Account expiration time, when available
74              
75             =head1 METHODS
76              
77             =head2 get_table_name
78              
79             Returns 'pwent'.
80              
81             =cut
82              
83 4     4 1 13 sub get_table_name() { return 'pwent'; }
84              
85             =head2 get_col_names
86              
87             Returns the column names of the table as named in L
88              
89             =cut
90              
91 1     1 1 7 sub get_col_names() { @colNames }
92              
93             my $havepwent = 0;
94              
95             eval { setpwent(); my @pwentry = getpwent(); endpwent(); $havepwent = 1; };
96              
97             =head2 collect_data
98              
99             Retrieves the data from the password database and put it into fetchable rows.
100              
101             =cut
102              
103             sub collect_data()
104             {
105 0     0 1   my @data;
106              
107 0 0         if ($havepwent)
108             {
109 0           setpwent(); # rewind to ensure we're starting fresh ...
110 0           while ( my ( $name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell, $expire ) =
111             getpwent() )
112             {
113 0           push( @data,
114             [ $name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell, $expire ] );
115             }
116 0           setpwent();
117 0           endpwent();
118             }
119              
120 0           return \@data;
121             }
122              
123             =head1 PREREQUISITES
124              
125             Perl support for the functions getpwent, setpwent, endpwent is required
126             to provide data for the table.
127              
128             =head1 AUTHOR
129              
130             Jens Rehsack Alexander Breibach
131             CPAN ID: REHSACK
132             rehsack@cpan.org alexander.breibach@googlemail.com
133             http://www.rehsack.de/
134              
135             =head1 ACKNOWLEDGEMENTS
136              
137             Some advisories how to implement the data collecting safer and more
138             portable was provided by Ashish SHUKLA .
139              
140             =head1 COPYRIGHT
141              
142             This program is free software; you can redistribute
143             it and/or modify it under the same terms as Perl itself.
144              
145             The full text of the license can be found in the
146             LICENSE file included with this module.
147              
148             =head1 SUPPORT
149              
150             Free support can be requested via regular CPAN bug-tracking system. There is
151             no guaranteed reaction time or solution time, but it's always tried to give
152             accept or reject a reported ticket within a week. It depends on business load.
153             That doesn't mean that ticket via rt aren't handles as soon as possible,
154             that means that soon depends on how much I have to do.
155              
156             Business and commercial support should be acquired from the authors via
157             preferred freelancer agencies.
158              
159             =cut
160              
161             1;