summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorBjörn Schießle <schiessle@owncloud.com>2014-05-16 12:23:01 -0400
committerBjörn Schießle <schiessle@owncloud.com>2014-05-16 12:23:01 -0400
commitb52cb8f5570f4ec0e73aa5b2e1a5dbd178135382 (patch)
tree8e622b686a60a49bbe6cf21469a232dcb72e6eea /lib
parentd5f60a8eb0b3521ba0d85e9191468f09ea37803e (diff)
parentb6e14af861481d0b2ebf6ca752d994c5adfce866 (diff)
downloadnextcloud-server-b52cb8f5570f4ec0e73aa5b2e1a5dbd178135382.tar.gz
nextcloud-server-b52cb8f5570f4ec0e73aa5b2e1a5dbd178135382.zip
Merge pull request #8604 from owncloud/sharing_encforce_password
allow admin to enforce passwords for public link shares
Diffstat (limited to 'lib')
-rw-r--r--lib/private/share/share.php11
-rwxr-xr-xlib/private/util.php10
-rw-r--r--lib/public/util.php8
3 files changed, 28 insertions, 1 deletions
diff --git a/lib/private/share/share.php b/lib/private/share/share.php
index a8537a916fb..440889ea6dc 100644
--- a/lib/private/share/share.php
+++ b/lib/private/share/share.php
@@ -588,7 +588,9 @@ class Share extends \OC\Share\Constants {
$shareWith['users'] = array_diff(\OC_Group::usersInGroup($group), array($uidOwner));
} else if ($shareType === self::SHARE_TYPE_LINK) {
if (\OC_Appconfig::getValue('core', 'shareapi_allow_links', 'yes') == 'yes') {
+
// when updating a link share
+ // FIXME Don't delete link if we update it
if ($checkExists = self::getItems($itemType, $itemSource, self::SHARE_TYPE_LINK, null,
$uidOwner, self::FORMAT_NONE, null, 1)) {
// remember old token
@@ -599,7 +601,7 @@ class Share extends \OC\Share\Constants {
}
// Generate hash of password - same method as user passwords
- if (isset($shareWith)) {
+ if (!empty($shareWith)) {
$forcePortable = (CRYPT_BLOWFISH != 1);
$hasher = new \PasswordHash(8, $forcePortable);
$shareWith = $hasher->HashPassword($shareWith.\OC_Config::getValue('passwordsalt', ''));
@@ -611,6 +613,13 @@ class Share extends \OC\Share\Constants {
}
}
+ if (\OCP\Util::isPublicLinkPasswordRequired() && empty($shareWith)) {
+ $message = 'You need to provide a password to create a public link, only protected links are allowed';
+ $message_t = $l->t('You need to provide a password to create a public link, only protected links are allowed');
+ \OC_Log::write('OCP\Share', $message, \OC_Log::ERROR);
+ throw new \Exception($message_t);
+ }
+
// Generate token
if (isset($oldToken)) {
$token = $oldToken;
diff --git a/lib/private/util.php b/lib/private/util.php
index f76ee7b338a..107dc6b9a9f 100755
--- a/lib/private/util.php
+++ b/lib/private/util.php
@@ -87,6 +87,16 @@ class OC_Util {
}
/**
+ * @brief check if a password is required for each public link
+ * @return boolean
+ */
+ public static function isPublicLinkPasswordRequired() {
+ $appConfig = \OC::$server->getAppConfig();
+ $enforcePassword = $appConfig->getValue('core', 'shareapi_enforce_links_password', 'no');
+ return ($enforcePassword === 'yes') ? true : false;
+ }
+
+ /**
* Get the quota of a user
* @param string $user
* @return int Quota bytes
diff --git a/lib/public/util.php b/lib/public/util.php
index 8aeb03aef8e..929d86859a1 100644
--- a/lib/public/util.php
+++ b/lib/public/util.php
@@ -499,4 +499,12 @@ class Util {
public static function generateRandomBytes($length = 30) {
return \OC_Util::generateRandomBytes($length);
}
+
+ /**
+ * @brief check if a password is required for each public link
+ * @return boolean
+ */
+ public static function isPublicLinkPasswordRequired() {
+ return \OC_Util::isPublicLinkPasswordRequired();
+ }
}