1

我正在使用PEAR/VersionControl_SVN库使用颠覆。这个库的优点是它是 subversion 命令行客户端的包装器。因此,我不需要安装任何绑定/模块/扩展(例如svn extension)就可以直接使用嵌入式函数(例如svn_lsor svn_commit)使用 subversion。我所有的应用程序都需要安装 subversion 命令行客户端。不好的是,如果使用 subversion 命令行客户端无法完成某些事情,那么使用这个库是不可能的。

/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