Kaydet (Commit) 3cc57415 authored tarafından Vladimir Glazounov's avatar Vladimir Glazounov

INTEGRATION: CWS cvsprot01 (1.1.2); FILE ADDED

2007/07/09 13:50:56 hr 1.1.2.2: #i63313#: fix pasing of CVS scrambled passwords, they can contain whitespace
2006/03/17 15:39:55 hr 1.1.2.1: #i63313# perl implementation of the CVS client protocol
üst 6cccefe6
#*************************************************************************
#
# OpenOffice.org - a multi-platform office productivity suite
#
# $RCSfile: Credentials.pm,v $
#
# $Revision: 1.2 $
#
# last change: $Author: vg $ $Date: 2007-08-27 13:33:43 $
#
# The Contents of this file are made available subject to
# the terms of GNU Lesser General Public License Version 2.1.
#
#
# GNU Lesser General Public License Version 2.1
# =============================================
# Copyright 2005 by Sun Microsystems, Inc.
# 901 San Antonio Road, Palo Alto, CA 94303, USA
#
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License version 2.1, as published by the Free Software Foundation.
#
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston,
# MA 02111-1307 USA
#
#*************************************************************************
#
# Credentials.pm - package for aquiring the CVS credentials from .cvspass
#
package PCVSLib::Credentials;
use Carp;
use IO::File;
use PCVSLib::Root;
use strict;
use warnings;
#### ctor ####
sub new
{
my $invocant = shift;
my $class = ref($invocant) || $invocant;
my $self = {};
$self->{passfile} = shift;
# private members
$self->{parsed_} = 0;
$self->{passwords_} = {};
bless ($self, $class);
return $self;
}
#### instance accessors #####
for my $datum qw(passfile) {
no strict "refs";
*$datum = sub {
my $self = shift;
$self->{$datum} = shift if @_;
return $self->{$datum};
}
}
#### public methods ####
sub get_password
{
my $self = shift;
my $root = shift;
if ( !$self->{parsed_} ) {
$self->parse_passfile();
}
my $root_string = $root->to_string();
my $password = $self->{passwords_}->{$root_string};
if ( !defined($password) ) {
# try again with port number
my $root_string_with_port = $root->to_string_with_port();
$password = $self->{passwords_}->{$root_string_with_port};
}
if ( !defined($password) ) {
my $passfile = $self->{passfile};
croak("PCVSLIB::Credentials::get_password(): missing entry in '$passfile': '$root_string'");
}
return $password;
}
#### private methods ####
sub parse_passfile
{
my $self = shift;
my $passfile = $self->{passfile};
if ( !defined($passfile) ) {
my $home = $ENV{HOME};
if ( !defined($home) ) {
croak("PCVSLIB::Credentials::parse_passfile(): environment variable HOME not set");
}
$self->{passfile} = $passfile = "$home/.cvspass";
}
my $fh = IO::File->new("<$passfile");
if ( !defined($fh) ) {
croak("PCVSLIB::Credentials::parse_passfile(): can't open CVS password file: '$passfile': $!");
}
while(<$fh>) {
if ( /^\/1 (:pserver:\S+) (\S.*)$/ ) {
# new style .cvspass entries
$self->{passwords_}->{$1} = $2;
}
elsif ( /(:pserver:\S+) (\S+.*)$/ ) {
# old style .cvspass entries
$self->{passwords_}->{$1} = $2;
}
}
$fh->close();
$self->{parsed_}++;
}
1;
# vim: set ts=4 shiftwidth=4 expandtab syntax=perl:
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment