1

ライブラリを使用してsubversionを使用してPEAR/VersionControl_SVNいます。このライブラリの利点は、Subversionコマンドラインクライアントのラッパーであるということです。したがって、組み込み関数(またはなど)を使用してSubversionを直接操作するために、バインディング/モジュール/拡張機能( svn拡張など)をインストールする必要はありません。私のアプリケーションが機能するために必要なのは、Subversionコマンドラインクライアントがインストールされていることだけです。悪いことは、subversionコマンドラインクライアントを使用して何かを実行できない場合、このライブラリを使用して実行することは不可能であるということです。svn_lssvn_commit

たとえば、/testディレクトリを作成して削除してから出力を分析する以外に、ユーザーがリポジトリへの書き込み可能なアクセス権を持っているかどうかを確認する他の方法を見つけることができませんでした。

require_once 'VersionControl/SVN.php';

class SvnException extends Exception {};

function checkCredentials($url, $user, $password) {
    $switches = array(
        'username' => $user, 
        'password' => $password, 
        'message' => 'check whether user '.$user.' has repository writable access'
    );
    $svnerror = &PEAR_ErrorStack::singleton('VersionControl_SVN');
    $svnoptions = array('fetchmode' => VERSIONCONTROL_SVN_FETCHMODE_ARRAY);
    $action = VersionControl_SVN::factory('mkdir', $svnoptions);
    $url = rtrim($url, '/\ ');
    $action->run(array($url.'/test'), $switches);
    $action = VersionControl_SVN::factory('delete', $svnoptions);
    $action->run(array($url.'/test'), $switches);
    if($errors = $svnerror->getErrors()) {
        $all_errors = '';
        foreach ($errors as $err) {
            $all_errors .= $err['message']."\n";
        }
        throw new SvnException($all_errors);
    }
    return true;
}

$url = 'svn://localhost:3129';
$user = 'username';
$password = 'password';
try {
    if(checkCredentials($url, $user, $password)) {
        print "User $user has writable access to subversion repository $url\n";
    }
} catch (SvnException $e) {
    print "User $user does not have writable access to subversion repository $url\n";
    print $e->getMessage();
}

出力は次のとおりです。

> php checksvnaccess.php

User username does not have writable access to subversion repository svn://localhost:3129

svn: E160013: URL 'svn://localhost:3129/test' does not exist (cmd: "C:\Program F
iles\Subversion Client\svn.EXE" delete --username username --password password -
-message "check whether user username has repository writable access" "svn://loc
alhost:3129/test")

svn: E170001: SASL authentication error: SASL(-1): generic failure: Unable to fi
nd a callback: 2 (cmd: "C:\Program Files\Subversion Client\svn.EXE" mkdir --user
name username --password password --message "check whether user username has rep
ository writable access" "svn://localhost:3129/test")

Username: Password for '': (cmd: "C:\Program Files\Subversion Client\svn.EXE" mk
dir --username username --password password --message "check whether user userna
me has repository writable access" "svn://localhost:3129/test")

Authentication realm: <svn://localhost:3129> 76572ec9-2173-de46-8e99-8db01e97341
a (cmd: "C:\Program Files\Subversion Client\svn.EXE" mkdir --username username -
-password password --message "check whether user username has repository writabl
e access" "svn://localhost:3129/test")

このコードサンプルを実行することは、次のコマンドを実行することと同じです。

svn mkdir --username username --password password --message "check whether user username has repository writable access" "svn://localhost:3129/test"
svn delete --username username --password password --message "check whether user username has repository writable access" "svn://localhost:3129/test"

リポジトリにオブジェクトを作成せずに、このライブラリを使用してリポジトリのアクセス権を確認する方法はありますか?コマンドラインを使用してアクセスを確認する方法があれば素晴らしいと思います。たとえば、svn checkaccess --username username --password password svn://localhost:3129/test。回避策はありますか?

4

0 に答える 0