summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/private/security/certificatemanager.php42
-rw-r--r--lib/private/server.php13
2 files changed, 31 insertions, 24 deletions
diff --git a/lib/private/security/certificatemanager.php b/lib/private/security/certificatemanager.php
index 4a8ea170731..7bc83766365 100644
--- a/lib/private/security/certificatemanager.php
+++ b/lib/private/security/certificatemanager.php
@@ -16,15 +16,22 @@ use OCP\ICertificateManager;
*/
class CertificateManager implements ICertificateManager {
/**
- * @var \OCP\IUser
+ * @var string
*/
- protected $user;
+ protected $uid;
/**
- * @param \OCP\IUser $user
+ * @var \OC\Files\View
*/
- public function __construct($user) {
- $this->user = $user;
+ protected $view;
+
+ /**
+ * @param string $uid
+ * @param \OC\Files\View $view relative zu data/
+ */
+ public function __construct($uid, \OC\Files\View $view) {
+ $this->uid = $uid;
+ $this->view = $view;
}
/**
@@ -34,18 +41,18 @@ class CertificateManager implements ICertificateManager {
*/
public function listCertificates() {
$path = $this->getPathToCertificates() . 'uploads/';
- if (!is_dir($path)) {
+ if (!$this->view->is_dir($path)) {
return array();
}
$result = array();
- $handle = opendir($path);
+ $handle = $this->view->opendir($path);
if (!is_resource($handle)) {
return array();
}
while (false !== ($file = readdir($handle))) {
if ($file != '.' && $file != '..') {
try {
- $result[] = new Certificate(file_get_contents($path . $file), $file);
+ $result[] = new Certificate($this->view->file_get_contents($path . $file), $file);
} catch(\Exception $e) {}
}
}
@@ -60,10 +67,10 @@ class CertificateManager implements ICertificateManager {
$path = $this->getPathToCertificates();
$certs = $this->listCertificates();
- $fh_certs = fopen($path . '/rootcerts.crt', 'w');
+ $fh_certs = $this->view->fopen($path . '/rootcerts.crt', 'w');
foreach ($certs as $cert) {
$file = $path . '/uploads/' . $cert->getName();
- $data = file_get_contents($file);
+ $data = $this->view->file_get_contents($file);
if (strpos($data, 'BEGIN CERTIFICATE')) {
fwrite($fh_certs, $data);
fwrite($fh_certs, "\r\n");
@@ -87,17 +94,14 @@ class CertificateManager implements ICertificateManager {
}
$dir = $this->getPathToCertificates() . 'uploads/';
- if (!file_exists($dir)) {
- //path might not exist (e.g. non-standard OC_User::getHome() value)
- //in this case create full path using 3rd (recursive=true) parameter.
- //note that we use "normal" php filesystem functions here since the certs need to be local
- mkdir($dir, 0700, true);
+ if (!$this->view->file_exists($dir)) {
+ $this->view->mkdir($dir);
}
try {
$file = $dir . $name;
$certificateObject = new Certificate($certificate, $name);
- file_put_contents($file, $certificate);
+ $this->view->file_put_contents($file, $certificate);
$this->createCertificateBundle();
return $certificateObject;
} catch (\Exception $e) {
@@ -117,8 +121,8 @@ class CertificateManager implements ICertificateManager {
return false;
}
$path = $this->getPathToCertificates() . 'uploads/';
- if (file_exists($path . $name)) {
- unlink($path . $name);
+ if ($this->view->file_exists($path . $name)) {
+ $this->view->unlink($path . $name);
$this->createCertificateBundle();
}
return true;
@@ -134,7 +138,7 @@ class CertificateManager implements ICertificateManager {
}
private function getPathToCertificates() {
- $path = $this->user ? $this->user->getHome() . '/files_external/' : '/files_external/';
+ $path = is_null($this->uid) ? '/files_external/' : '/' . $this->uid . '/files_external/';
return $path;
}
diff --git a/lib/private/server.php b/lib/private/server.php
index c98f77c6479..15c33e1905f 100644
--- a/lib/private/server.php
+++ b/lib/private/server.php
@@ -249,7 +249,9 @@ class Server extends SimpleContainer implements IServerContainer {
});
$this->registerService('HTTPHelper', function (Server $c) {
$config = $c->getConfig();
- return new HTTPHelper($config, new \OC\Security\CertificateManager($c->getUserSession()->getUser()));
+ $user = $c->getUserSession()->getUser();
+ $uid = $user ? $user->getUID() : null;
+ return new HTTPHelper($config, new \OC\Security\CertificateManager($uid, new \OC\Files\View()));
});
$this->registerService('EventLogger', function (Server $c) {
if (defined('DEBUG') and DEBUG) {
@@ -631,18 +633,19 @@ class Server extends SimpleContainer implements IServerContainer {
/**
* Get the certificate manager for the user
*
- * @param \OCP\IUser $user (optional) if not specified the current loggedin user is used
+ * @param string $uid (optional) if not specified the current loggedin user is used
* @return \OCP\ICertificateManager
*/
- function getCertificateManager($user = null) {
- if (is_null($user)) {
+ function getCertificateManager($uid = null) {
+ if (is_null($uid)) {
$userSession = $this->getUserSession();
$user = $userSession->getUser();
if (is_null($user)) {
return null;
}
+ $uid = $user->getUID();
}
- return new CertificateManager($user);
+ return new CertificateManager($uid, new \OC\Files\View());
}
/**