Last change
on this file since 1888 was
1755,
checked in by nanardon, 8 years ago
|
deny to set wrong password unless with --force
|
-
Property svn:executable set to
*
|
File size:
2.0 KB
|
Rev | Line | |
---|
[189] | 1 | #!/usr/bin/perl |
---|
| 2 | |
---|
| 3 | use strict; |
---|
| 4 | use warnings; |
---|
| 5 | use LATMOS::Accounts; |
---|
| 6 | use Getopt::Long; |
---|
| 7 | use Pod::Usage; |
---|
[312] | 8 | use Term::ReadKey; |
---|
[189] | 9 | |
---|
[312] | 10 | =head1 NAME |
---|
| 11 | |
---|
[715] | 12 | la-passwd - set user password |
---|
| 13 | |
---|
| 14 | =head1 SYNOPSIS |
---|
| 15 | |
---|
| 16 | la-passwd [options] userid |
---|
[312] | 17 | |
---|
[584] | 18 | =head1 OPTIONS |
---|
| 19 | |
---|
| 20 | =over 4 |
---|
| 21 | |
---|
[861] | 22 | =item -c|--config configdir |
---|
[584] | 23 | |
---|
[861] | 24 | Use this configuration directory instead of the default one. |
---|
[584] | 25 | |
---|
[594] | 26 | =item -b|--base basename |
---|
| 27 | |
---|
| 28 | Query this specific base instead of the default one. |
---|
| 29 | |
---|
[715] | 30 | =item -s|--sync syncname |
---|
| 31 | |
---|
| 32 | Use this synchronisation |
---|
| 33 | |
---|
[594] | 34 | =item -t|--test |
---|
| 35 | |
---|
| 36 | Don't change the password but check its validity using CrackLib. |
---|
| 37 | |
---|
[584] | 38 | =back |
---|
| 39 | |
---|
[312] | 40 | =cut |
---|
| 41 | |
---|
[189] | 42 | GetOptions( |
---|
| 43 | 'c|config=s' => \my $config, |
---|
| 44 | 'b|base=s' => \my $base, |
---|
[584] | 45 | 't|test' => \my $test, |
---|
[715] | 46 | 's|sync=s' => \my $sync, |
---|
[1755] | 47 | 'f|force' => \my $force, |
---|
[189] | 48 | 'help' => sub { pod2usage(0) }, |
---|
| 49 | ) or pod2usage(); |
---|
| 50 | |
---|
[656] | 51 | if (!$ARGV[0]) {warn "You must specify 'userid', aborting\n"; pod2usage(); } |
---|
[655] | 52 | |
---|
[189] | 53 | my $otype = 'user'; |
---|
| 54 | |
---|
[457] | 55 | my $LA = LATMOS::Accounts->new($config, noacl => 1); |
---|
[715] | 56 | my $labase = $base ? $LA->base($base) : $LA->sync_access($sync); |
---|
[189] | 57 | $labase && $labase->load or die "Cannot load base"; |
---|
| 58 | |
---|
[664] | 59 | $labase->wexported(1); |
---|
| 60 | |
---|
[189] | 61 | my $obj = $labase->get_object($otype, $ARGV[0]) or do { |
---|
| 62 | die "Object $otype $ARGV[0] not found\n"; |
---|
| 63 | }; |
---|
[312] | 64 | |
---|
| 65 | ReadMode('noecho'); |
---|
| 66 | print "Enter password: "; |
---|
| 67 | my $password = ReadLine(0); |
---|
| 68 | ReadMode 0; |
---|
| 69 | print "\n"; |
---|
[772] | 70 | chomp($password); |
---|
[312] | 71 | |
---|
[1755] | 72 | my $res = $obj->check_password($password); |
---|
[584] | 73 | |
---|
[1755] | 74 | if ($res !~ /^ok$/) { |
---|
| 75 | print "Password quality: " . $res . "\n"; |
---|
| 76 | die "Cannot set bad password, use --force to bypass security\n" unless($force); |
---|
| 77 | } |
---|
| 78 | |
---|
[584] | 79 | exit(0) if($test); |
---|
| 80 | |
---|
[312] | 81 | if ($obj->set_password($password)) { |
---|
[207] | 82 | print "Password succefully changed\n"; |
---|
[412] | 83 | $labase->commit; |
---|
[207] | 84 | exit 0; |
---|
| 85 | } else { |
---|
| 86 | warn "Error when trying to change password\n"; |
---|
| 87 | exit 1; |
---|
| 88 | } |
---|
Note: See
TracBrowser
for help on using the repository browser.