| 1 | # | ||||||||||||||||||||||||||||||
| 2 | # Copyright (c) 2004,2005 Alexander Taler (dissent@0--0.org) | ||||||||||||||||||||||||||||||
| 3 | # | ||||||||||||||||||||||||||||||
| 4 | # All rights reserved. This program is free software; you can redistribute it | ||||||||||||||||||||||||||||||
| 5 | # and/or modify it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||
| 6 | # | ||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | package VCS::LibCVS::Client::Connection::CvsPass; | ||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||
| 13 | =head1 NAME | ||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||
| 15 | VCS::LibCVS::Client::Connection::CvsPass - A ~/.cvspass file. | ||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | my $cvspass = VCS::LibCVS::Client::Connection::CvsPass->new(); | ||||||||||||||||||||||||||||||
| 20 | my $password = $cvspass->get_password($root); | ||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||
| 24 | A ~/.cvspass file. This file contains the trivially encoded passwords used by | ||||||||||||||||||||||||||||||
| 25 | the CVS pserver authentication system. This interface provides access to the | ||||||||||||||||||||||||||||||
| 26 | passwords. | ||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | =cut | ||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||
| 30 | ############################################################################### | ||||||||||||||||||||||||||||||
| 31 | # Class constants | ||||||||||||||||||||||||||||||
| 32 | ############################################################################### | ||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||
| 34 | 1 | ▶ | use constant REVISION => '$Header: /cvsroot/libcvs-perl/libcvs-perl/VCS/LibCVS/Client/Connection/CvsPass.pm,v 1.6 2005/10/10 12:52:11 dissent Exp $ '; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||
| 36 | ############################################################################### | ||||||||||||||||||||||||||||||
| 37 | # Private variables | ||||||||||||||||||||||||||||||
| 38 | ############################################################################### | ||||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||||
| 40 | # CvsPass is a hash, and uses the following private entries. | ||||||||||||||||||||||||||||||
| 41 | # | ||||||||||||||||||||||||||||||
| 42 | # $self->{Passwords} is a hash ref, whose keys are Root specifications in the | ||||||||||||||||||||||||||||||
| 43 | # format of the password file (eg :pserver:dissent@fire.0--0.org:2401/cvs), and | ||||||||||||||||||||||||||||||
| 44 | # whose values are the encoded password for that root. | ||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||
| 46 | ############################################################################### | ||||||||||||||||||||||||||||||
| 47 | # Class routines | ||||||||||||||||||||||||||||||
| 48 | ############################################################################### | ||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||
| 50 | =head1 CLASS ROUTINES | ||||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||||
| 52 | =head2 B<new()> | ||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | $cvspass = VCS::LibCVS::Client::Connection::CvsPass->new(); | ||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | =over 4 | ||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||
| 58 | =item return type: VCS::LibCVS::Client::CvsPass | ||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | =back | ||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||
| 62 | Return a new CvsPass object, for the current user, found in their home | ||||||||||||||||||||||||||||||
| 63 | directory. | ||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||
| 65 | =cut | ||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | 0 | ▶ | sub new { | ||||||||||||||||||||||||||||
|
Subroutine
new: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 68 | 0 | my $class = shift; | |||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||
| 70 | 0 | my $that = bless {}, $class; | |||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||
| 72 | 0 | $that->{Passwords} = {}; | |||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( -e _get_passfilename()) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 75 | 0 | my $pass_file = IO::File->new(_get_passfilename()); | |||||||||||||||||||||||||||||
| 76 | 0 | ▶ | confess "Couldn't read: ". _get_passfilename() unless defined $pass_file; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 77 | 0 | foreach my $pass_line ($pass_file->getlines()) { | |||||||||||||||||||||||||||||
| 78 | 0 | ▶ | if ($pass_line =~ m#^/1 (:pserver:.*) (.*)$#) { | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 79 | 0 | $that->{Passwords}->{$1} = $2; | |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||
| 82 | 0 | $pass_file->close(); | |||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||
| 85 | 0 | return $that; | |||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||
| 88 | ############################################################################### | ||||||||||||||||||||||||||||||
| 89 | # Instance routines | ||||||||||||||||||||||||||||||
| 90 | ############################################################################### | ||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | =head1 INSTANCE ROUTINES | ||||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||||
| 94 | =head2 B<get_password()> | ||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | $password = $cvspass$->get_password($root) | ||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||
| 98 | =over 4 | ||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||
| 100 | =item return type: scalar string | ||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||
| 102 | =item argument 1 type: VCS::LibCVS::Datum::Root | ||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||
| 104 | =back | ||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||
| 106 | Retrieve the password for the indicated repository. | ||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub get_password { | ||||||||||||||||||||||||||||
|
Subroutine
get_password: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 111 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 112 | 0 | my $root = shift; | |||||||||||||||||||||||||||||
| 113 | 0 | return $self->{Passwords}->{_format_cvsroot($root)}; | |||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||
| 116 | =head2 B<store_password()> | ||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | $cvspass$->store_password($root, $password) | ||||||||||||||||||||||||||||||
| 119 | |||||||||||||||||||||||||||||||
| 120 | =over 4 | ||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||
| 122 | =item return type: undef | ||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||
| 124 | =item argument 1 type: VCS::LibCVS::Datum::Root | ||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||
| 126 | =item argument 2 type: scalar string | ||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||
| 128 | The scrambled password. | ||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||
| 130 | =back | ||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||
| 132 | Store a password for the repository. The password must be scrambled using the | ||||||||||||||||||||||||||||||
| 133 | pserver scrambling technique. See | ||||||||||||||||||||||||||||||
| 134 | VCS::LibCVS::Client::Connection::Pserver::pserver_scramble() for details. | ||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||
| 136 | =cut | ||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||
| 138 | 0 | ▶ | sub store_password { | ||||||||||||||||||||||||||||
|
Subroutine
store_password: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 139 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 140 | 0 | my ($root, $password) = @_; | |||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||
| 142 | 0 | my $rootString = _format_cvsroot($root); | |||||||||||||||||||||||||||||
| 143 | 0 | $self->{Passwords}->{$rootString} = $password; | |||||||||||||||||||||||||||||
| 144 | 0 | $self->_append($rootString, $password); | |||||||||||||||||||||||||||||
| 145 | 0 | return; | |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||
| 149 | ############################################################################### | ||||||||||||||||||||||||||||||
| 150 | # Private routines | ||||||||||||||||||||||||||||||
| 151 | ############################################################################### | ||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||
| 153 | # Append a password to .cvspass | ||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||
| 155 | 0 | ▶ | sub _append { | ||||||||||||||||||||||||||||
|
Subroutine
_append: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 156 | 0 | my $self = shift; | |||||||||||||||||||||||||||||
| 157 | 0 | my ($root, $password) = @_; | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||
| 159 | 0 | my $pass_file = IO::File->new(_get_passfilename(), "a"); | |||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||
| 161 | 0 | ▶ | confess "Couldn't append to: ". _get_passfilename() unless defined $pass_file; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||
| 163 | 0 | $pass_file->print("/1 $root $password\n"); | |||||||||||||||||||||||||||||
| 164 | 0 | $pass_file->close(); | |||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||
| 166 | 0 | return; | |||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||
| 169 | # Get the name of the cvs pass file: | ||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||
| 171 | 0 | ▶ | sub _get_passfilename { | ||||||||||||||||||||||||||||
|
Subroutine
_get_passfilename: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 172 | 0 | my $pass_filename = File::Spec->catpath('', $ENV{HOME}, ".cvspass"); | |||||||||||||||||||||||||||||
| 173 | 0 | return $pass_filename; | |||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||
| 176 | # Create a cvsroot string for the .cvspass file from a Root | ||||||||||||||||||||||||||||||
| 177 | 0 | ▶ | sub _format_cvsroot { | ||||||||||||||||||||||||||||
|
Subroutine
_format_cvsroot: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||
| 178 | 0 | my $root = shift; | |||||||||||||||||||||||||||||
| 179 | return (":pserver" | ||||||||||||||||||||||||||||||
| 180 | . ":" . ($root->{UserName} || getlogin()) | ||||||||||||||||||||||||||||||
| 181 | . "@" . $root->{HostName} | ||||||||||||||||||||||||||||||
| 182 | . ":" . ($root->{Port} || "2401") | ||||||||||||||||||||||||||||||
| 183 | 0 | ▶ | . $root->{RootDir}); | ||||||||||||||||||||||||||||
|
Condition0%0/5
$root->{'UserName'} || getlogin
$root->{'Port'} || '2401'
MC/DC0%0/2
$root->{'UserName'} || getlogin
$root->{'UserName'}
getlogin
MC/DC0%0/1
$root->{'Port'} || '2401'
$root->{'Port'}
Truth table0%0/3
A || B
A= $root->{'UserName'}B= getlogin
Truth table0%0/2
A
A= $root->{'Port'}
| |||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||
| 186 | =pod | ||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||
| 188 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||
| 190 | VCS::LibCVS::Client::Connection::Pserver | ||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||
| 192 | =cut | ||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||
| 194 | 1 | 1; | |||||||||||||||||||||||||||||