File: pwdInfo

package info (click to toggle)
libcdk-perl 20130816-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 1,284 kB
  • ctags: 430
  • sloc: perl: 6,151; sh: 2,997; makefile: 24
file content (81 lines) | stat: -rwxr-xr-x 1,903 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
#!/usr/bin/perl -w
# $Id: pwdInfo,v 1.4 2013/07/17 19:34:07 tom Exp $

#
# This reads the passwd file and creates an interface to browse the
# information.
#

use strict;
use Cdk;
Cdk::init();

#
# This function loads up the passwd file and returns a reference to the
# data structure.
#
sub loadPasswd {
    my %passwd = ();
    my @logins = ();
    my ( $name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell );

    # Start reading through the passwd file.
    while (
        ( $name, $passwd, $uid, $gid, $quota, $comment, $gcos, $dir, $shell ) =
        getpwent )
    {

        # Store the information.
        $passwd{$name} = "$uid$gid$comment$gcos$dir$shell";
        push( @logins, $name );
    }

    return ( \@logins, \%passwd );
}

# Load up the passwd file.
my ( $logins, $passwdObject ) = loadPasswd();

# Create a scrolling list of all the names.
my $mainScroll = new Cdk::Scroll(
    'Title'   => '<C></U>Pick An Account',
    'Numbers' => "TRUE",
    'List'    => $logins,
    'Height'  => 13,
    'Width'   => 45
);

# Do this forever.
for ( ; ; ) {

    # Let the user select the login to view.
    my $selected = $mainScroll->activate();

    # Did the user just hit escape?
    if ( !defined $selected ) {
        Cdk::end();
        exit 0;
    }

    # Get the name and display the info.
    my $name = $logins->[$selected];

    # Display the info.
    my ( $uid, $gid, $comment, $gcos, $dir, $shell ) =
      split( //, $passwdObject->{$name} );
    my $info = [
        "Account Name   : </R>$name",
        "UID/GID        : ($uid/$gid)",
        "Comment        : </R>$comment",
        "GCOS Value     : </R>$gcos",
        "Home Directory : </R>$dir",
        "Shell          : </R>$shell"
    ];

    my $title = new Cdk::Label( 'Message' => $info );

    # Draw the label.
    $title->draw( 'Box' => "TRUE" );
    $title->wait();
    undef $title;
}