source: trunk/LATMOS-Accounts/bin/la-ban-passwd @ 1806

Last change on this file since 1806 was 1756, checked in by nanardon, 8 years ago

Add some messages

  • Property svn:executable set to *
File size: 1.8 KB
Line 
1#!/usr/bin/perl
2
3use strict;
4use warnings;
5use LATMOS::Accounts;
6use Getopt::Long;
7use Pod::Usage;
8
9=head1 NAME
10
11    la-ban-passwd - Deny password for user
12
13=head1 SYNOPSIS
14
15    la-passwd [options] user password
16    la-passwd --current user
17
18=head1 OPTIONS
19
20=over 4
21
22=item -c|--config configdir
23
24Use this configuration directory instead of the default one.
25
26=item -b|--base basename
27
28Query this specific base instead of the default one.
29
30=item --current
31
32Ban the current password for this user
33
34=item -l|--lock
35
36Lock the account
37
38=item -e|--encrypted
39
40The password given is already encrypted and must be store without modification
41
42=back
43
44=cut
45
46GetOptions(
47    'c|config=s'  => \my $config,
48    'b|base=s'    => \my $base,
49    'l|lock'      => \my $lock,
50    'e|encrypted' => \my $encrypted,
51    'current'     => \my $current,
52    'help'        => sub { pod2usage(0) },
53) or pod2usage();
54
55my ($user, $password) = @ARGV;
56
57if (!$password && !$current) {
58    warn "You must specify a password or --current\n";
59    pod2usage(1);
60}
61
62my $otype = 'user';
63
64my $LA = LATMOS::Accounts->new($config, noacl => 1);
65my $labase = $LA->base($base);
66$labase && $labase->load or die "Cannot load base";
67
68$labase->wexported(1);
69
70my $obj = $labase->get_object($otype, $user) or do {
71    die "Object $otype $user not found\n";
72};
73
74if ($lock) {
75    $obj->set_c_fields('locked', 1);
76    print "User $user locked\n";
77}
78
79if ($current) {
80    $obj->banCurrentPassword;
81    print "Current password banned\n";
82} else {
83    if ($encrypted) {
84        my @salt_char = (('a' .. 'z'), ('A' .. 'Z'), (0 .. 9), '/', '.');
85        my $salt = join('', map { $salt_char[rand(scalar(@salt_char))] } (1 .. 8));
86        $password = crypt($password, '$1$' . $salt);
87    }
88    $obj->storeBannedPassword($password);
89    print "Given password banned\n";
90}
91
92$labase->commit;
93exit 0;
Note: See TracBrowser for help on using the repository browser.