Skip to content
This repository has been archived by the owner on Nov 25, 2020. It is now read-only.

Commit

Permalink
Merge pull request #494 from Ellega/master
Browse files Browse the repository at this point in the history
Command Smbclient and Windows OS
  • Loading branch information
cdujeu committed Mar 17, 2014
2 parents 3c10ad0 + 66e4536 commit cc9be3d
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 2 deletions.
2 changes: 1 addition & 1 deletion core/src/plugins/access.smb/plugin_doc.html
@@ -1,3 +1,3 @@
<p>Connect a Samba share and browse its files and folders. This plugin is based on a php wrapper around the command line tool <b>smbclient</b>. This tool must be installed on the server and accessible in the machine path. If you want to manually set the path to the <b>smbclient</b> program, edit the plugin global configuration. Interestingly, there is a working alternative of smbclient installable on Windows, using Cygwin. See the detailed instructions <a href="http://www.citricity.com/moodlegpl/windowssharewebclient/instructions_for_installing_smbclient32_on_windows.pdf">here</a>. In that case, you may have to enter the full path to the smbclient via the plugin configuration.</p>
<p>Connect a Samba share and browse its files and folders. This plugin is based on a php wrapper around the command line tool <b>smbclient</b>. This tool must be installed on the server and accessible in the machine path. If you want to manually set the path to the <b>smbclient</b> program, edit the plugin global configuration. Interestingly, there is a working alternative of smbclient installable on Windows, using Cygwin. See the detailed instructions <a href="http://www.citricity.com/moodlegpl/windowssharewebclient/instructions_for_installing_smbclient32_on_windows.pdf">here</a>. But for a better result please use smbclient 3.0.23c <a href="http://smithii.com/samba">here</a>. In that case, you may have to enter the full path to the smbclient via the plugin configuration.</p>
<p>For a repository, a typical configuration can be <ul><li>Host : <b>192.168.0.25</b></li><li>Uri : <b>Share</b></li></ul>If you encounter problems with "empty listing", check the ajaxplorer logs, and particularly set the server into debug mode : errors grabbed from the smbclient output are logged to the log file, not to the GUI, as sometimes it contains errors but sometimes it contains just warning or even info.</p>
<p>Like the ftp access driver with the auth.ftp, this smb driver can be used in conjunction with the auth.smb plugin to authenticate users directly against the samba share. </p><p>The SMB wrapper was first developped by Victor M. Varela.</p>
44 changes: 43 additions & 1 deletion core/src/plugins/access.smb/smb.php
Expand Up @@ -179,6 +179,10 @@ public function client ($params, $purl)
//$output = popen (SMB4PHP_SMBCLIENT." -N {$options} {$port} {$options} {$params} 2>/dev/null {$auth}", 'r');
$info = array ();

if (PHP_OS == "WIN32" || PHP_OS == "WINNT" || PHP_OS == "Windows") {
$params = ConvSmbParameterToWinOs($params);
}

$cmd = SMB4PHP_SMBCLIENT." -N {$options} {$port} {$options} {$params} {$auth}";
$descriptorspec = array(
0 => array("pipe", "r"), // stdin is a pipe that the child will read from
Expand Down Expand Up @@ -350,7 +354,7 @@ public function url_stat ($url, $flags = STREAM_URL_STAT_LINK)
return null;
}
$p = explode ("\\", $pu['path']);
$name = $p[count($p)-1];
$name = SystemTextEncoding::toUTF8($p[count($p)-1]);
if (isset ($o['info'][$name])) {
$stat = smb::addstatcache ($url, $o['info'][$name]);
} else {
Expand Down Expand Up @@ -717,6 +721,44 @@ private function getStream()

}

function ConvSmbParameterToWinOs($params)
{

$paramstemp = explode(" ", $params);

// first command '-d' or '-L' ?
if ($paramstemp[0] == "-d") {
$count_params = count($paramstemp);

// index command = 4;
// index start path = 6;
$paramstemp[6] = '""'.$paramstemp[6];
$type_cmd = substr($paramstemp[4], 1);
switch ($type_cmd) {

case get:
case put:
case rename:
$index_end_path = $count_params - 2;
$paramstemp[$index_end_path] = $paramstemp[$index_end_path].'""';
$new_params = implode(" ", $paramstemp);
$new_params = str_replace(' ', '"" ""', $new_params);
break;

//Cmd: dir, del, rmdir, mkdir
default:
$index_end_path = $count_params - 2;
$paramstemp[$index_end_path] = $paramstemp[$index_end_path].'""';
$new_params = implode(" ", $paramstemp);
}

return $new_params;
}
else {
return $params;
}
}

###################################################################
# Register 'smb' protocol !
###################################################################
Expand Down

0 comments on commit cc9be3d

Please sign in to comment.