Skip to content

Commit

Permalink
Enable SMB logging for the Community Edition
Browse files Browse the repository at this point in the history
  • Loading branch information
mmattel committed Jan 18, 2018
1 parent 81153de commit 63988e3
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 14 deletions.
48 changes: 34 additions & 14 deletions apps/files_external/lib/Lib/Storage/SMB.php
Original file line number Diff line number Diff line change
Expand Up @@ -659,50 +659,70 @@ public function test() {
}

/**
* @param string $message
* @param int $level
* Return either 'wnd' or 'smb' if the related config values has been enabled
* Return a an existing string if set by the caller
* @param string $from
* @return string
*/
private function log($message, $level = Util::DEBUG, $from = 'wnd') {
private function getSmbWndLogging($from = '') {
if (!empty($from)) {
return $from;
}
if (\OC::$server->getConfig()->getSystemValue('wnd.logging.enable', false) === true) {
Util::writeLog($from, $message, $level);
return 'wnd';
}
if (\OC::$server->getConfig()->getSystemValue('smb.logging.enable', false) === true) {
return 'smb';
}
}


/**
* if wnd.logging.enable is set to true in the config will log a leave line
* @param string $message
* @param int $level
* @param string $from
*/
private function log($message, $level = Util::DEBUG, $from = '') {
$newfrom = $this->getSmbWndLogging($from);
Util::writeLog($newfrom, $message, $level);
}

/**
* if wnd/smb.logging.enable is set to true in the config will log a leave line
* with the given function, the return value or the exception
*
* @param $function
* @param mixed $result an exception will be logged and then returned
* @return mixed
*/
private function leave($function, $result) {
if (\OC::$server->getConfig()->getSystemValue('wnd.logging.enable', false) === false) {
$from = $this->getSmbWndLogging();
if (empty($from)) {
//don't bother building log strings
return $result;
} else if ($result === true) {
Util::writeLog('wnd', "leave: $function, return true", Util::DEBUG);
Util::writeLog($from, "leave: $function, return true", Util::DEBUG);
} else if ($result === false) {
Util::writeLog('wnd', "leave: $function, return false", Util::DEBUG);
Util::writeLog($from, "leave: $function, return false", Util::DEBUG);
} else if (is_string($result)) {
Util::writeLog('wnd', "leave: $function, return '$result'", Util::DEBUG);
Util::writeLog($from, "leave: $function, return '$result'", Util::DEBUG);
} else if (is_resource($result)) {
Util::writeLog('wnd', "leave: $function, return resource", Util::DEBUG);
Util::writeLog($from, "leave: $function, return resource", Util::DEBUG);
} else if ($result instanceof \Exception) {
Util::writeLog('wnd', "leave: $function, throw ".get_class($result)
Util::writeLog($from, "leave: $function, throw ".get_class($result)
.' - code: '.$result->getCode()
.' message: '.$result->getMessage()
.' trace: '.$result->getTraceAsString(), Util::DEBUG);
} else {
Util::writeLog('wnd', "leave: $function, return ".json_encode($result, true), Util::DEBUG);
Util::writeLog($from, "leave: $function, return ".json_encode($result, true), Util::DEBUG);
}
return $result;
}

private function swallow($function, \Exception $exception) {
if (\OC::$server->getConfig()->getSystemValue('wnd.logging.enable', false) === true) {
Util::writeLog('wnd', "$function swallowing ".get_class($exception)
$from = $this->getSmbWndLogging();
if (!empty($from)) {
Util::writeLog($from, "$function swallowing ".get_class($exception)
.' - code: '.$exception->getCode()
.' message: '.$exception->getMessage()
.' trace: '.$exception->getTraceAsString(), Util::DEBUG);
Expand Down
4 changes: 4 additions & 0 deletions config/config.sample.php
Original file line number Diff line number Diff line change
Expand Up @@ -1416,4 +1416,8 @@
*/
'files_external_allow_create_new_local' => false,

/**
* Set this property to true if you want to enable debug logging for SMB access.
*/
'smb.logging.enable' => false,
);

0 comments on commit 63988e3

Please sign in to comment.