diff options
author | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-09-11 23:14:44 -0700 |
---|---|---|
committer | Stephen Hemminger <stephen.hemminger@vyatta.com> | 2009-09-11 23:14:44 -0700 |
commit | 64df88a052e7e1af4c32dc7834304a2f1579ef4f (patch) | |
tree | 9f6150a725bbe0c3737702cca59a1375ce131040 /scripts/show-users.pl | |
parent | 0fdb23d33f7027c7114d741f96cfa0bc97f1f8b8 (diff) | |
download | vyatta-op-64df88a052e7e1af4c32dc7834304a2f1579ef4f.tar.gz vyatta-op-64df88a052e7e1af4c32dc7834304a2f1579ef4f.zip |
Add show system login users
Bug 4828
Add script to show logins and compare vyatta config to current system.
Show only, does not change status.
Diffstat (limited to 'scripts/show-users.pl')
-rw-r--r-- | scripts/show-users.pl | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/scripts/show-users.pl b/scripts/show-users.pl new file mode 100644 index 0000000..d47a535 --- /dev/null +++ b/scripts/show-users.pl @@ -0,0 +1,106 @@ +#! /usr/bin/perl + +# **** License **** +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, but +# WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +# General Public License for more details. +# +# This code was originally developed by Vyatta, Inc. +# Portions created by Vyatta are Copyright (C) 2007 Vyatta, Inc. +# All Rights Reserved. +# +# Author: Stephen Hemminger +# Date: Sept 2009 +# Description: Show password accounts +# +# **** End License **** + +use lib "/opt/vyatta/share/perl5"; +use Term::ANSIColor; +use Vyatta::Config; + +use strict; +use warnings; + +sub usage { + print "Usage: $0 {type}\n"; + print " type := all | vyatta | locked | other | color\n"; + exit 1; +} + +my %pw; +setpwent(); +while ( my ($u, $p) = getpwent()) { + $pw{$u} = $p; +} +endpwent(); + +my $cfg = new Vyatta::Config; +$cfg->setLevel('system login user'); +$cfg->{_active_dir_base} = '/opt/vyatta/config/active/'; +my %vuser = map { $_ => 1 } $cfg->listOrigNodes(); + +sub locked { + return grep { length($pw{$_}) == 1 } @_; +} + +sub nopasswd { + return grep { length($pw{$_}) == 0 } @_; +} + +sub all { + return @_; +} + +sub vyatta { + return grep { $vuser{$_} } @_; +} + +sub other { + return grep { length($pw{$_}) > 1 && ! defined($vuser{$_}) } @_; +} + +sub login_color { + my $u = shift; + my $p = $pw{$u}; + my $c; + + if (length($p) == 0) { + $c = 'blink red'; # open no password! + } elsif ($vuser{$u}) { + $c = 'green'; # vyatta user + } elsif (length($p) == 1) { + $c = 'blue'; # locked account + } else { + $c = 'yellow'; # non vyatta account + } + return color($c) . $u . color('reset'); +} + +# show non-locked accounts in color +sub colorize { + return map { login_color($_) } grep { length($pw{$_}) != 1 } @_; +} + +my %filters = ( + 'all' => \&all, + 'vyatta' => \&vyatta, + 'locked' => \&locked, + 'open' => \&nopasswd, + 'other' => \&other, + 'color' => \&colorize, +); + +for (@ARGV) { + my $func = $filters{$_}; + unless ($func) { + warn "Unknown type $_\n"; + usage(); + } + print join("\n", sort($func->(keys %pw))), "\n"; +} |