| 1 |
lars |
1 |
<?php
|
|
|
2 |
/*
|
|
|
3 |
* $Id: CvsPassTask.php 227 2007-08-28 02:17:00Z hans $
|
|
|
4 |
*
|
|
|
5 |
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
|
|
|
6 |
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
|
|
|
7 |
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
|
|
|
8 |
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
|
|
|
9 |
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
|
|
|
10 |
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
|
|
|
11 |
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
|
|
|
12 |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
|
|
|
13 |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
|
|
|
14 |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
|
|
15 |
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
|
|
16 |
*
|
|
|
17 |
* This software consists of voluntary contributions made by many individuals
|
|
|
18 |
* and is licensed under the LGPL. For more information please see
|
|
|
19 |
* <http://phing.info>.
|
|
|
20 |
*/
|
|
|
21 |
|
|
|
22 |
require_once 'phing/Task.php';
|
|
|
23 |
include_once 'phing/system/io/BufferedReader.php';
|
|
|
24 |
include_once 'phing/system/io/BufferedWriter.php';
|
|
|
25 |
include_once 'phing/util/StringHelper.php';
|
|
|
26 |
|
|
|
27 |
/**
|
|
|
28 |
* Adds an new entry to a CVS password file.
|
|
|
29 |
*
|
|
|
30 |
* @author Hans Lellelid <hans@xmpl.org> (Phing)
|
|
|
31 |
* @author Jeff Martin <jeff@custommonkey.org> (Ant)
|
|
|
32 |
* @version $Revision: 1.7 $
|
|
|
33 |
* @package phing.tasks.system
|
|
|
34 |
*/
|
|
|
35 |
class CVSPassTask extends Task {
|
|
|
36 |
|
|
|
37 |
/** CVS Root */
|
|
|
38 |
private $cvsRoot;
|
|
|
39 |
/** Password file to add password to */
|
|
|
40 |
private $passFile;
|
|
|
41 |
/** Password to add to file */
|
|
|
42 |
private $password;
|
|
|
43 |
|
|
|
44 |
/** Array contain char conversion data */
|
|
|
45 |
private static $shifts = array(
|
|
|
46 |
0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15,
|
|
|
47 |
16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31,
|
|
|
48 |
114, 120, 53, 79, 96, 109, 72, 108, 70, 64, 76, 67, 116, 74, 68, 87,
|
|
|
49 |
111, 52, 75, 119, 49, 34, 82, 81, 95, 65, 112, 86, 118, 110, 122, 105,
|
|
|
50 |
41, 57, 83, 43, 46, 102, 40, 89, 38, 103, 45, 50, 42, 123, 91, 35,
|
|
|
51 |
125, 55, 54, 66, 124, 126, 59, 47, 92, 71, 115, 78, 88, 107, 106, 56,
|
|
|
52 |
36, 121, 117, 104, 101, 100, 69, 73, 99, 63, 94, 93, 39, 37, 61, 48,
|
|
|
53 |
58, 113, 32, 90, 44, 98, 60, 51, 33, 97, 62, 77, 84, 80, 85, 223,
|
|
|
54 |
225, 216, 187, 166, 229, 189, 222, 188, 141, 249, 148, 200, 184, 136, 248, 190,
|
|
|
55 |
199, 170, 181, 204, 138, 232, 218, 183, 255, 234, 220, 247, 213, 203, 226, 193,
|
|
|
56 |
174, 172, 228, 252, 217, 201, 131, 230, 197, 211, 145, 238, 161, 179, 160, 212,
|
|
|
57 |
207, 221, 254, 173, 202, 146, 224, 151, 140, 196, 205, 130, 135, 133, 143, 246,
|
|
|
58 |
192, 159, 244, 239, 185, 168, 215, 144, 139, 165, 180, 157, 147, 186, 214, 176,
|
|
|
59 |
227, 231, 219, 169, 175, 156, 206, 198, 129, 164, 150, 210, 154, 177, 134, 127,
|
|
|
60 |
182, 128, 158, 208, 162, 132, 167, 209, 149, 241, 153, 251, 237, 236, 171, 195,
|
|
|
61 |
243, 233, 253, 240, 194, 250, 191, 155, 142, 137, 245, 235, 163, 242, 178, 152
|
|
|
62 |
);
|
|
|
63 |
|
|
|
64 |
/**
|
|
|
65 |
* Create a CVS task using the default cvspass file location.
|
|
|
66 |
*/
|
|
|
67 |
public function __construct() {
|
|
|
68 |
$this->passFile = new PhingFile(
|
|
|
69 |
Phing::getProperty("cygwin.user.home",
|
|
|
70 |
Phing::getProperty("user.home"))
|
|
|
71 |
. DIRECTORY_SEPARATOR . ".cvspass");
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
/**
|
|
|
75 |
* Does the work.
|
|
|
76 |
*
|
|
|
77 |
* @throws BuildException if someting goes wrong with the build
|
|
|
78 |
*/
|
|
|
79 |
public final function main() {
|
|
|
80 |
if ($this->cvsRoot === null) {
|
|
|
81 |
throw new BuildException("cvsroot is required");
|
|
|
82 |
}
|
|
|
83 |
if ($this->password === null) {
|
|
|
84 |
throw new BuildException("password is required");
|
|
|
85 |
}
|
|
|
86 |
|
|
|
87 |
$this->log("cvsRoot: " . $this->cvsRoot, Project::MSG_DEBUG);
|
|
|
88 |
$this->log("password: " . $this->password, Project::MSG_DEBUG);
|
|
|
89 |
$this->log("passFile: " . $this->passFile->__toString(), Project::MSG_DEBUG);
|
|
|
90 |
|
|
|
91 |
$reader = null;
|
|
|
92 |
$writer = null;
|
|
|
93 |
|
|
|
94 |
try {
|
|
|
95 |
$buf = "";
|
|
|
96 |
|
|
|
97 |
if ($this->passFile->exists()) {
|
|
|
98 |
$reader = new BufferedReader(new FileReader($this->passFile));
|
|
|
99 |
|
|
|
100 |
$line = null;
|
|
|
101 |
while (($line = $reader->readLine()) !== null) {
|
|
|
102 |
if (!StringHelper::startsWith($this->cvsRoot, $line)) {
|
|
|
103 |
$buf .= $line . PHP_EOL;
|
|
|
104 |
}
|
|
|
105 |
}
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
$pwdfile = $buf . $this->cvsRoot . " A" . $this->mangle($this->password);
|
|
|
109 |
|
|
|
110 |
$this->log("Writing -> " . $pwdfile , Project::MSG_DEBUG);
|
|
|
111 |
|
|
|
112 |
$writer = new BufferedWriter(new FileWriter($this->passFile));
|
|
|
113 |
$writer->write($pwdfile);
|
|
|
114 |
$writer->newLine();
|
|
|
115 |
|
|
|
116 |
$writer->close();
|
|
|
117 |
if ($reader) {
|
|
|
118 |
$reader->close();
|
|
|
119 |
}
|
|
|
120 |
|
|
|
121 |
} catch (IOException $e) {
|
|
|
122 |
if ($reader) {
|
|
|
123 |
try {
|
|
|
124 |
$reader->close();
|
|
|
125 |
} catch (Exception $e) {}
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
if ($writer) {
|
|
|
129 |
try {
|
|
|
130 |
$writer->close();
|
|
|
131 |
} catch (Exception $e) {}
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
throw new BuildException($e);
|
|
|
135 |
}
|
|
|
136 |
}
|
|
|
137 |
|
|
|
138 |
/**
|
|
|
139 |
* "Encode" the password.
|
|
|
140 |
*/
|
|
|
141 |
private final function mangle($password){
|
|
|
142 |
$buf = "";
|
|
|
143 |
for ($i = 0, $plen = strlen($password); $i < $plen; $i++) {
|
|
|
144 |
$buf .= chr(self::$shifts[ord($password{$i})]);
|
|
|
145 |
}
|
|
|
146 |
return $buf;
|
|
|
147 |
}
|
|
|
148 |
|
|
|
149 |
/**
|
|
|
150 |
* The CVS repository to add an entry for.
|
|
|
151 |
* @param string $cvsRoot
|
|
|
152 |
*/
|
|
|
153 |
public function setCvsroot($cvsRoot) {
|
|
|
154 |
$this->cvsRoot = $cvsRoot;
|
|
|
155 |
}
|
|
|
156 |
|
|
|
157 |
/**
|
|
|
158 |
* Password file to add the entry to.
|
|
|
159 |
* @param PhingFile $passFile
|
|
|
160 |
*/
|
|
|
161 |
public function setPassfile(PhingFile $passFile) {
|
|
|
162 |
$this->passFile = $passFile;
|
|
|
163 |
}
|
|
|
164 |
|
|
|
165 |
/**
|
|
|
166 |
* Password to be added to the password file.
|
|
|
167 |
* @param string $password
|
|
|
168 |
*/
|
|
|
169 |
public function setPassword($password) {
|
|
|
170 |
$this->password = $password;
|
|
|
171 |
}
|
|
|
172 |
|
|
|
173 |
}
|