/** * Decode a given string * * @param string str * @return string */ public static function decode($str) { return CvsPassword::encode($str); }
/** * Authenticate ourselves * * @param string cvsroot * @param string user * @param string pass default '' * @return bool success * @throws peer.ProtocolException in case of a protocol error * @throws peer.AuthenticationException in case login fails * @see http://www.loria.fr/~molli/cvs/doc/cvsclient_3.html */ public function login($cvsroot, $user, $pass = '') { $this->_sendcmd('BEGIN AUTH REQUEST'); $this->_sendcmd($cvsroot); $this->_sendcmd($user); $this->_sendcmd('A%s', CvsPassword::encode($pass)); $this->_sendcmd('END AUTH REQUEST'); // Read server response // // Example #1 (success) // <<< I LOVE YOU // // Example #2 (user does not exist) // <<< E Fatal error, aborting. // <<< error 0 foo: no such user // Example #3 (repository does not exist) // <<< error 0 /home/cvs/repositories/xp: no such repository // <<< I HATE YOU $error = $message = $code = NULL; while ($line = $this->_sock->readLine()) { $this->cat && $this->cat->debug('<<<', $line); if (0 == strcasecmp('I LOVE YOU', $line)) { // Authentication succeeded, we should now negotiate $this->root = $cvsroot; return $this->negotiate(); } elseif (0 == strcasecmp('I HATE YOU', $line)) { // Terminal, break out of loop break; } elseif ('E' == $line[0]) { // Error message, read, remember and continue $error = substr($line, 2); continue; } elseif (sscanf($line, "error %d %[^]", $code, $message)) { // Error code and detail, read, remember and continue continue; } throw new ProtocolException('Unexpected response "' . $line . '"'); } // Authentication failed throw new AuthenticationException(sprintf('%d: %s (%s)', $code, $message, $error), $user, $pass); }