diff options
author | Bjoern Schiessle <schiessle@owncloud.com> | 2014-05-12 12:19:07 +0200 |
---|---|---|
committer | Bjoern Schiessle <schiessle@owncloud.com> | 2014-05-16 17:41:09 +0200 |
commit | b6e14af861481d0b2ebf6ca752d994c5adfce866 (patch) | |
tree | 522434e1a85c90b7212a0c9ebed0174e24a11e8e /lib | |
parent | dab3cb65cf16d78796ce8dc23fa1f72aa9846b7e (diff) | |
download | nextcloud-server-b6e14af861481d0b2ebf6ca752d994c5adfce866.tar.gz nextcloud-server-b6e14af861481d0b2ebf6ca752d994c5adfce866.zip |
allow admin to enforce passwords for public link shares
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/share/share.php | 11 | ||||
-rwxr-xr-x | lib/private/util.php | 10 | ||||
-rw-r--r-- | lib/public/util.php | 8 |
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(); + } } |