diff options
| author | fukachan <fukachan> | 2003-02-02 10:59:19 +0000 |
|---|---|---|
| committer | fukachan <fukachan> | 2003-02-02 10:59:19 +0000 |
| commit | 19afce81a05f1345815b8074cf438f438dce9bc4 (patch) | |
| tree | 6162de3f0c7db010e48bbc61bb6a1eba6990920c /fml/lib | |
| parent | d20aa75bcdd2766c1df8c54545553fb45e7871f1 (diff) | |
| download | fml8-19afce81a05f1345815b8074cf438f438dce9bc4.tar.gz fml8-19afce81a05f1345815b8074cf438f438dce9bc4.tar.bz2 fml8-19afce81a05f1345815b8074cf438f438dce9bc4.zip | |
add utilities to change admin password: changepassword, chpass,
initpass and passwd.
"initpass" and "passwd" are prepared for fml 4 compatibility.
Diffstat (limited to 'fml/lib')
| -rw-r--r-- | fml/lib/FML/Command/Admin/changepassword.pm | 201 | ||||
| -rw-r--r-- | fml/lib/FML/Command/Admin/chpass.pm | 66 | ||||
| -rw-r--r-- | fml/lib/FML/Command/Admin/initpass.pm | 79 | ||||
| -rw-r--r-- | fml/lib/FML/Command/Admin/passwd.pm | 68 |
4 files changed, 414 insertions, 0 deletions
diff --git a/fml/lib/FML/Command/Admin/changepassword.pm b/fml/lib/FML/Command/Admin/changepassword.pm new file mode 100644 index 00000000..8233d62d --- /dev/null +++ b/fml/lib/FML/Command/Admin/changepassword.pm @@ -0,0 +1,201 @@ +#-*- perl -*- +# +# Copyright (C) 2003 Ken'ichi Fukamachi +# All rights reserved. This program is free software; you can +# redistribute it and/or modify it under the same terms as Perl itself. +# +# $FML$ +# + +package FML::Command::Admin::changepassword; +use strict; +use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); +use Carp; +use FML::Log qw(Log LogWarn LogError); + + +=head1 NAME + +FML::Command::Admin::changepassword - change admin password + +=head1 SYNOPSIS + +See C<FML::Command> for more details. + +=head1 DESCRIPTION + +password a new address. + +=head1 METHODS + +=head2 C<process($curproc, $command_args)> + +=cut + + +# Descriptions: constructor. +# Arguments: OBJ($self) +# Side Effects: none +# Return Value: OBJ +sub new +{ + my ($self) = @_; + my ($type) = ref($self) || $self; + my $me = {}; + return bless $me, $type; +} + + +# Descriptions: need lock or not +# Arguments: none +# Side Effects: none +# Return Value: NUM( 1 or 0) +sub need_lock { 1;} + + +# Descriptions: change the admin password. +# Arguments: OBJ($self) OBJ($curproc) HASH_REF($command_args) +# Side Effects: update $member_map $recipient_map +# Return Value: NUM +sub process +{ + my ($self, $curproc, $command_args) = @_; + my $config = $curproc->config(); + my $maps = $config->get_as_array_ref('admin_member_password_maps'); + my $pri_map = $config->{ primary_admin_member_password_map }; + my $myname = $curproc->myname(); + my $options = $command_args->{ options }; + + # XXX The arguments differ for the cases. + # 1. command mail: admin changepassword [$USER] $PASSWORD + # 2. command line: makefml changepassword $ML $ADDR $PASSWORD + # fml $ML changepassword $ADDR $PASSWORD + if ($myname eq 'makefml' || $myname eq 'fml' || + $myname eq 'loader' || + $myname eq 'command' || $myname eq 'fml.pl') { + my ($address, $password); + + if ($options->[2]) { + croak("wrong arguments"); + } + elsif ($options->[0] && $options->[1]) { + $address = $options->[ 0 ]; + $password = $options->[ 1 ]; + } + elsif ($options->[0]) { + # XXX special treatment only for command mails. + if ($myname eq 'command' || $myname eq 'fml.pl') { + my $cred = $curproc->{ credential }; + $address = $cred->sender(); # From: in the header + $password = $options->[ 0 ]; + } + else { + croak("wrong arguments"); + } + } + else { + croak("wrong arguments"); + } + + $self->_change_password($curproc, $command_args, $address, $password); + } + else { + LogError("myname=$myname unknown program"); + } +} + + +# Descriptions: change the admin password. +# Arguments: OBJ($self) OBJ($curproc) HASH_REF($command_args) +# STR($address) STR($password) +# Side Effects: update *admin_member_password_maps +# Return Value: NUM +sub _change_password +{ + my ($self, $curproc, $command_args, $address, $password) = @_; + my $config = $curproc->config(); + my $maps = $config->get_as_array_ref('admin_member_password_maps'); + my $pri_map = $config->{ primary_admin_member_password_map }; + my $status = 0; + + # crypt-fy password. + use FML::Crypt; + my $crypt = new FML::Crypt; + my $cp = $crypt->unix_crypt($password, $$); + + # XXX delete entries for address among ALL MAPS. + use IO::Adapter; + for my $map (@$maps) { + my $obj = new IO::Adapter $map; + if (defined $obj) { + $obj->open(); + if ($obj->find( $address )) { + $obj->delete( $address ); + if ($obj->error()) { + LogError("cannot delete $address from=$map"); + } + else { + Log("delete $address from=$map"); + } + } + $obj->close(); + } + } + + # XXX add password entry to ONLY primary map. o.k. ? + my $obj = new IO::Adapter $pri_map; + if (defined $obj) { + $obj->open(); + $obj->add( $address, [ $cp, "UNIX_CRYPT" ] ) && $status++; + if ($obj->error()) { + LogError("cannot add $address to=$pri_map"); + } + else { + Log("add password for $address to=$pri_map"); + } + $obj->close(); + } + + return $status; +} + + +# Descriptions: rewrite buffer to hide the password phrase in $rbuf +# Arguments: OBJ($self) OBJ($curproc) HASH_REF($command_args) STR_REF($rbuf) +# Side Effects: none +# Return Value: none +sub rewrite_prompt +{ + my ($self, $curproc, $command_args, $rbuf) = @_; + + if (defined $rbuf) { + $$rbuf =~ s/^(.*(password|pass)\s+).*/$1 ********/; + } +} + + +=head1 CODING STYLE + +See C<http://www.fml.org/software/FNF/> on fml coding style guide. + +=head1 AUTHOR + +Ken'ichi Fukamachi + +=head1 COPYRIGHT + +Copyright (C) 2003 Ken'ichi Fukamachi + +All rights reserved. This program is free software; you can +redistribute it and/or modify it under the same terms as Perl itself. + +=head1 HISTORY + +FML::Command::Admin::changepassword +first appeared in fml8 mailing list driver package. +See C<http://www.fml.org/> for more details. + +=cut + + +1; diff --git a/fml/lib/FML/Command/Admin/chpass.pm b/fml/lib/FML/Command/Admin/chpass.pm new file mode 100644 index 00000000..903c4555 --- /dev/null +++ b/fml/lib/FML/Command/Admin/chpass.pm @@ -0,0 +1,66 @@ +#-*- perl -*- +# +# Copyright (C) 2003 Ken'ichi Fukamachi +# All rights reserved. This program is free software; you can +# redistribute it and/or modify it under the same terms as Perl itself. +# +# $FML$ +# + +package FML::Command::Admin::chpass; +use strict; +use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); +use Carp; + + +use FML::Command::Admin::changepassword; +@ISA = qw(FML::Command::Admin::changepassword); + + +# Descriptions: change admin password +# Arguments: OBJ($self) OBJ($curproc) HASH_REF($command_args) +# Side Effects: forward request to password module +# Return Value: none +sub process +{ + my ($self, $curproc, $command_args) = @_; + $self->SUPER::process($curproc, $command_args); +} + + +=head1 NAME + +FML::Command::Admin::chpass - change admin password + +=head1 SYNOPSIS + +See C<FML::Command> for more details. + +=head1 DESCRIPTION + +an alias of C<FML::Command::Admin::changepassword>. + +=head1 CODING STYLE + +See C<http://www.fml.org/software/FNF/> on fml coding style guide. + +=head1 AUTHOR + +Ken'ichi Fukamachi + +=head1 COPYRIGHT + +Copyright (C) 2003 Ken'ichi Fukamachi + +All rights reserved. This program is free software; you can +redistribute it and/or modify it under the same terms as Perl itself. + +=head1 HISTORY + +FML::Command::Admin::chpass first appeared in fml8 mailing list driver package. +See C<http://www.fml.org/> for more details. + +=cut + + +1; diff --git a/fml/lib/FML/Command/Admin/initpass.pm b/fml/lib/FML/Command/Admin/initpass.pm new file mode 100644 index 00000000..5e5ab25c --- /dev/null +++ b/fml/lib/FML/Command/Admin/initpass.pm @@ -0,0 +1,79 @@ +#-*- perl -*- +# +# Copyright (C) 2003 Ken'ichi Fukamachi +# All rights reserved. This program is free software; you can +# redistribute it and/or modify it under the same terms as Perl itself. +# +# $FML$ +# + +package FML::Command::Admin::initpass; +use strict; +use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); +use Carp; + + +use FML::Command::Admin::changepassword; +@ISA = qw(FML::Command::Admin::changepassword); + + +# Descriptions: initialize admin password of a new user. +# Arguments: OBJ($self) OBJ($curproc) HASH_REF($command_args) +# Side Effects: forward request to password module +# Return Value: none +sub process +{ + my ($self, $curproc, $command_args) = @_; + my $options = $command_args->{ options }; + + if ($options->[ 2 ]) { + croak("wrong arguments"); + } + elsif ($options->[ 1 ] && $options->[ 0 ]) { + # [0] = username + # [1] = password(plaintext) + $self->SUPER::process($curproc, $command_args); + } + else { + croak("wrong arguments"); + } +} + + +=head1 NAME + +FML::Command::Admin::initpass - initialize admin password (fml4 compatible) + +=head1 SYNOPSIS + +See C<FML::Command> for more details. + +=head1 DESCRIPTION + +an alias of C<FML::Command::Admin::changepassword>. + +=head1 CODING STYLE + +See C<http://www.fml.org/software/FNF/> on fml coding style guide. + +=head1 AUTHOR + +Ken'ichi Fukamachi + +=head1 COPYRIGHT + +Copyright (C) 2003 Ken'ichi Fukamachi + +All rights reserved. This program is free software; you can +redistribute it and/or modify it under the same terms as Perl itself. + +=head1 HISTORY + +FML::Command::Admin::initpass +first appeared in fml8 mailing list driver package. +See C<http://www.fml.org/> for more details. + +=cut + + +1; diff --git a/fml/lib/FML/Command/Admin/passwd.pm b/fml/lib/FML/Command/Admin/passwd.pm new file mode 100644 index 00000000..42692015 --- /dev/null +++ b/fml/lib/FML/Command/Admin/passwd.pm @@ -0,0 +1,68 @@ +#-*- perl -*- +# +# Copyright (C) 2003 Ken'ichi Fukamachi +# All rights reserved. This program is free software; you can +# redistribute it and/or modify it under the same terms as Perl itself. +# +# $FML$ +# + +package FML::Command::Admin::passwd; +use strict; +use vars qw(@ISA @EXPORT @EXPORT_OK $AUTOLOAD); +use Carp; + + +use FML::Command::Admin::changepassword; +@ISA = qw(FML::Command::Admin::changepassword); + + +# Descriptions: change admin password +# Arguments: OBJ($self) OBJ($curproc) HASH_REF($command_args) +# Side Effects: forward request to password module +# Return Value: none +sub process +{ + my ($self, $curproc, $command_args) = @_; + my $options = $command_args->{ options }; + + $self->SUPER::process($curproc, $command_args); +} + + +=head1 NAME + +FML::Command::Admin::passwd - change admin password (fml4 compatible) + +=head1 SYNOPSIS + +See C<FML::Command> for more details. + +=head1 DESCRIPTION + +an alias of C<FML::Command::Admin::changepassword>. + +=head1 CODING STYLE + +See C<http://www.fml.org/software/FNF/> on fml coding style guide. + +=head1 AUTHOR + +Ken'ichi Fukamachi + +=head1 COPYRIGHT + +Copyright (C) 2003 Ken'ichi Fukamachi + +All rights reserved. This program is free software; you can +redistribute it and/or modify it under the same terms as Perl itself. + +=head1 HISTORY + +FML::Command::Admin::passwd first appeared in fml8 mailing list driver package. +See C<http://www.fml.org/> for more details. + +=cut + + +1; |
