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

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

bannedPassword feature (denied password for a user)

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