Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
die_coolen_jungs
our_own_cloud_project
Commits
bd888748
Commit
bd888748
authored
Jan 26, 2015
by
Vincent Petry
Browse files
Merge pull request #13490 from owncloud/fix_reshare_s2s_share
use uid provided by setupfs hook to mount server2server shares
parents
44d69d71
5ba19ba7
Changes
10
Hide whitespace changes
Inline
Side-by-side
apps/files_sharing/ajax/external.php
View file @
bd888748
...
...
@@ -34,8 +34,8 @@ $externalManager = new \OCA\Files_Sharing\External\Manager(
\
OC
::
$server
->
getDatabaseConnection
(),
\
OC\Files\Filesystem
::
getMountManager
(),
\
OC\Files\Filesystem
::
getLoader
(),
\
OC
::
$server
->
get
UserSession
(),
\
OC
::
$server
->
get
HTTPHelper
()
\
OC
::
$server
->
get
HTTPHelper
(),
\
OC
::
$server
->
get
UserSession
()
->
getUser
()
->
getUID
()
);
$name
=
OCP\Files
::
buildNotExistingFileName
(
'/'
,
$name
);
...
...
apps/files_sharing/api/server2server.php
View file @
bd888748
...
...
@@ -60,8 +60,9 @@ class Server2Server {
\
OC
::
$server
->
getDatabaseConnection
(),
\
OC\Files\Filesystem
::
getMountManager
(),
\
OC\Files\Filesystem
::
getLoader
(),
\
OC
::
$server
->
getUserSession
(),
\
OC
::
$server
->
getHTTPHelper
());
\
OC
::
$server
->
getHTTPHelper
(),
$shareWith
);
$name
=
\
OCP\Files
::
buildNotExistingFileName
(
'/'
,
$name
);
...
...
apps/files_sharing/application.php
View file @
bd888748
...
...
@@ -69,12 +69,14 @@ class Application extends App {
return
Helper
::
isIncomingServer2serverShareEnabled
();
});
$container
->
registerService
(
'ExternalManager'
,
function
(
SimpleContainer
$c
)
use
(
$server
){
$user
=
$server
->
getUserSession
()
->
getUser
();
$uid
=
$user
?
$user
->
getUID
()
:
null
;
return
new
\
OCA\Files_Sharing\External\Manager
(
$server
->
getDatabaseConnection
(),
\
OC\Files\Filesystem
::
getMountManager
(),
\
OC\Files\Filesystem
::
getLoader
(),
$server
->
get
UserSession
(),
$
server
->
getHTTPHelper
()
$server
->
get
HTTPHelper
(),
$
uid
);
});
...
...
apps/files_sharing/lib/controllers/sharecontroller.php
View file @
bd888748
...
...
@@ -142,7 +142,6 @@ class ShareController extends Controller {
return
new
TemplateResponse
(
'core'
,
'404'
,
array
(),
'guest'
);
}
$linkItem
=
OCP\Share
::
getShareByToken
(
$token
,
false
);
$shareOwner
=
$linkItem
[
'uid_owner'
];
$originalSharePath
=
null
;
$rootLinkItem
=
OCP\Share
::
resolveReShare
(
$linkItem
);
...
...
apps/files_sharing/lib/external/manager.php
View file @
bd888748
...
...
@@ -13,6 +13,11 @@ use OC\Files\Filesystem;
class
Manager
{
const
STORAGE
=
'\OCA\Files_Sharing\External\Storage'
;
/**
* @var string
*/
private
$uid
;
/**
* @var \OCP\IDBConnection
*/
...
...
@@ -28,11 +33,6 @@ class Manager {
*/
private
$storageLoader
;
/**
* @var \OC\User\Session
*/
private
$userSession
;
/**
* @var \OC\HTTPHelper
*/
...
...
@@ -41,21 +41,35 @@ class Manager {
/**
* @param \OCP\IDBConnection $connection
* @param \OC\Files\Mount\Manager $mountManager
* @param \OC\User\Session $userSession
* @param \OC\Files\Storage\StorageFactory $storageLoader
* @param \OC\HTTPHelper $httpHelper
* @param string $uid
*/
public
function
__construct
(
\
OCP\IDBConnection
$connection
,
\
OC\Files\Mount\Manager
$mountManager
,
\
OC\Files\Storage\StorageFactory
$storageLoader
,
\
OC\User\Session
$userSession
,
\
OC\HTTPHelper
$httpHelper
)
{
\
OC\Files\Storage\StorageFactory
$storageLoader
,
\
OC\HTTPHelper
$httpHelper
,
$uid
)
{
$this
->
connection
=
$connection
;
$this
->
mountManager
=
$mountManager
;
$this
->
userSession
=
$userSession
;
$this
->
storageLoader
=
$storageLoader
;
$this
->
httpHelper
=
$httpHelper
;
$this
->
uid
=
$uid
;
}
/**
* add new server-to-server share
*
* @param string $remote
* @param string $token
* @param string $password
* @param string $name
* @param string $owner
* @param boolean $accepted
* @param string $user
* @param int $remoteId
* @return mixed
*/
public
function
addShare
(
$remote
,
$token
,
$password
,
$name
,
$owner
,
$accepted
=
false
,
$user
=
null
,
$remoteId
=
-
1
)
{
$user
=
$user
?
$user
:
$this
->
u
serSession
->
getUser
()
->
getUID
()
;
$user
=
$user
?
$user
:
$this
->
u
id
;
$accepted
=
$accepted
?
1
:
0
;
$mountPoint
=
Filesystem
::
normalizePath
(
'/'
.
$name
);
...
...
@@ -86,14 +100,13 @@ class Manager {
return
false
;
}
$user
=
$this
->
userSession
->
getUser
();
if
(
$user
)
{
if
(
!
is_null
(
$this
->
uid
))
{
$query
=
$this
->
connection
->
prepare
(
'
SELECT `remote`, `share_token`, `password`, `mountpoint`, `owner`
FROM `*PREFIX*share_external`
WHERE `user` = ? AND `accepted` = ?
'
);
$query
->
execute
(
array
(
$
user
->
getUID
()
,
1
));
$query
->
execute
(
array
(
$
this
->
uid
,
1
));
while
(
$row
=
$query
->
fetch
())
{
$row
[
'manager'
]
=
$this
;
...
...
@@ -114,7 +127,7 @@ class Manager {
SELECT `remote`, `share_token`
FROM `*PREFIX*share_external`
WHERE `id` = ? AND `user` = ?'
);
$result
=
$getShare
->
execute
(
array
(
$id
,
$this
->
u
serSession
->
getUser
()
->
getUID
()
));
$result
=
$getShare
->
execute
(
array
(
$id
,
$this
->
u
id
));
return
$result
?
$getShare
->
fetch
()
:
false
;
}
...
...
@@ -133,7 +146,7 @@ class Manager {
UPDATE `*PREFIX*share_external`
SET `accepted` = ?
WHERE `id` = ? AND `user` = ?'
);
$acceptShare
->
execute
(
array
(
1
,
$id
,
$this
->
u
serSession
->
getUser
()
->
getUID
()
));
$acceptShare
->
execute
(
array
(
1
,
$id
,
$this
->
u
id
));
$this
->
sendFeedbackToRemote
(
$share
[
'remote'
],
$share
[
'share_token'
],
$id
,
'accept'
);
}
}
...
...
@@ -150,7 +163,7 @@ class Manager {
if
(
$share
)
{
$removeShare
=
$this
->
connection
->
prepare
(
'
DELETE FROM `*PREFIX*share_external` WHERE `id` = ? AND `user` = ?'
);
$removeShare
->
execute
(
array
(
$id
,
$this
->
u
serSession
->
getUser
()
->
getUID
()
));
$removeShare
->
execute
(
array
(
$id
,
$this
->
u
id
));
$this
->
sendFeedbackToRemote
(
$share
[
'remote'
],
$share
[
'share_token'
],
$id
,
'decline'
);
}
}
...
...
@@ -175,19 +188,31 @@ class Manager {
return
(
$result
[
'success'
]
&&
$status
[
'ocs'
][
'meta'
][
'statuscode'
]
===
100
);
}
public
static
function
setup
()
{
/**
* setup the server-to-server mounts
*
* @param array $params
*/
public
static
function
setup
(
array
$params
)
{
$externalManager
=
new
\
OCA\Files_Sharing\External\Manager
(
\
OC
::
$server
->
getDatabaseConnection
(),
\
OC\Files\Filesystem
::
getMountManager
(),
\
OC\Files\Filesystem
::
getLoader
(),
\
OC
::
$server
->
get
UserSession
(),
\
OC
::
$server
->
getHTTPHelper
()
\
OC
::
$server
->
get
HTTPHelper
(),
$params
[
'user'
]
);
$externalManager
->
setupMounts
();
}
/**
* remove '/user/files' from the path and trailing slashes
*
* @param string $path
* @return string
*/
protected
function
stripPath
(
$path
)
{
$prefix
=
'/'
.
$this
->
u
serSession
->
getUser
()
->
getUID
()
.
'/files'
;
$prefix
=
'/'
.
$this
->
u
id
.
'/files'
;
return
rtrim
(
substr
(
$path
,
strlen
(
$prefix
)),
'/'
);
}
...
...
@@ -196,11 +221,10 @@ class Manager {
* @return Mount
*/
protected
function
mountShare
(
$data
)
{
$user
=
$this
->
userSession
->
getUser
();
$data
[
'manager'
]
=
$this
;
$mountPoint
=
'/'
.
$
user
->
getUID
()
.
'/files'
.
$data
[
'mountpoint'
];
$mountPoint
=
'/'
.
$
this
->
uid
.
'/files'
.
$data
[
'mountpoint'
];
$data
[
'mountpoint'
]
=
$mountPoint
;
$data
[
'certificateManager'
]
=
\
OC
::
$server
->
getCertificateManager
(
$
user
);
$data
[
'certificateManager'
]
=
\
OC
::
$server
->
getCertificateManager
(
$
this
->
uid
);
$mount
=
new
Mount
(
self
::
STORAGE
,
$mountPoint
,
$data
,
$this
,
$this
->
storageLoader
);
$this
->
mountManager
->
addMount
(
$mount
);
return
$mount
;
...
...
@@ -219,7 +243,6 @@ class Manager {
* @return bool
*/
public
function
setMountPoint
(
$source
,
$target
)
{
$user
=
$this
->
userSession
->
getUser
();
$source
=
$this
->
stripPath
(
$source
);
$target
=
$this
->
stripPath
(
$target
);
$sourceHash
=
md5
(
$source
);
...
...
@@ -231,13 +254,12 @@ class Manager {
WHERE `mountpoint_hash` = ?
AND `user` = ?
'
);
$result
=
(
bool
)
$query
->
execute
(
array
(
$target
,
$targetHash
,
$sourceHash
,
$
user
->
getUID
()
));
$result
=
(
bool
)
$query
->
execute
(
array
(
$target
,
$targetHash
,
$sourceHash
,
$
this
->
uid
));
return
$result
;
}
public
function
removeShare
(
$mountPoint
)
{
$user
=
$this
->
userSession
->
getUser
();
$mountPoint
=
$this
->
stripPath
(
$mountPoint
);
$hash
=
md5
(
$mountPoint
);
...
...
@@ -245,7 +267,7 @@ class Manager {
SELECT `remote`, `share_token`, `remote_id`
FROM `*PREFIX*share_external`
WHERE `mountpoint_hash` = ? AND `user` = ?'
);
$result
=
$getShare
->
execute
(
array
(
$hash
,
$
user
->
getUID
()
));
$result
=
$getShare
->
execute
(
array
(
$hash
,
$
this
->
uid
));
if
(
$result
)
{
$share
=
$getShare
->
fetch
();
...
...
@@ -257,7 +279,7 @@ class Manager {
WHERE `mountpoint_hash` = ?
AND `user` = ?
'
);
return
(
bool
)
$query
->
execute
(
array
(
$hash
,
$
user
->
getUID
()
));
return
(
bool
)
$query
->
execute
(
array
(
$hash
,
$
this
->
uid
));
}
/**
...
...
@@ -294,7 +316,7 @@ class Manager {
*/
public
function
getOpenShares
()
{
$openShares
=
$this
->
connection
->
prepare
(
'SELECT * FROM `*PREFIX*share_external` WHERE `accepted` = ? AND `user` = ?'
);
$result
=
$openShares
->
execute
(
array
(
0
,
$this
->
u
serSession
->
getUser
()
->
getUID
()
));
$result
=
$openShares
->
execute
(
array
(
0
,
$this
->
u
id
));
return
$result
?
$openShares
->
fetchAll
()
:
array
();
...
...
apps/files_sharing/lib/hooks.php
View file @
bd888748
...
...
@@ -30,8 +30,8 @@ class Hooks {
\
OC
::
$server
->
getDatabaseConnection
(),
\
OC\Files\Filesystem
::
getMountManager
(),
\
OC\Files\Filesystem
::
getLoader
(),
\
OC
::
$server
->
get
UserSession
(),
\
OC
::
$server
->
getHTTPHelper
()
);
\
OC
::
$server
->
get
HTTPHelper
(),
$params
[
'uid'
]
);
$manager
->
removeUserShares
(
$params
[
'uid'
]);
}
...
...
apps/files_sharing/tests/server2server.php
View file @
bd888748
...
...
@@ -153,8 +153,9 @@ class Test_Files_Sharing_S2S_OCS_API extends TestCase {
\
OC
::
$server
->
getDatabaseConnection
(),
\
OC\Files\Filesystem
::
getMountManager
(),
\
OC\Files\Filesystem
::
getLoader
(),
\
OC
::
$server
->
getUserSession
(),
\
OC
::
$server
->
getHTTPHelper
());
\
OC
::
$server
->
getHTTPHelper
(),
$toDelete
);
$manager
->
removeUserShares
(
$toDelete
);
...
...
lib/private/security/certificatemanager.php
View file @
bd888748
...
...
@@ -16,15 +16,22 @@ use OCP\ICertificateManager;
*/
class
CertificateManager
implements
ICertificateManager
{
/**
* @var
\OCP\IUser
* @var
string
*/
protected
$u
ser
;
protected
$u
id
;
/**
* @
p
ar
am
\OC
P\IUser $user
* @
v
ar \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
;
}
...
...
lib/private/server.php
View file @
bd888748
...
...
@@ -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
(
$u
ser
=
null
)
{
if
(
is_null
(
$u
ser
))
{
function
getCertificateManager
(
$u
id
=
null
)
{
if
(
is_null
(
$u
id
))
{
$userSession
=
$this
->
getUserSession
();
$user
=
$userSession
->
getUser
();
if
(
is_null
(
$user
))
{
return
null
;
}
$uid
=
$user
->
getUID
();
}
return
new
CertificateManager
(
$u
ser
);
return
new
CertificateManager
(
$u
id
,
new
\
OC\Files\View
()
);
}
/**
...
...
tests/lib/security/certificatemanager.php
View file @
bd888748
...
...
@@ -28,9 +28,7 @@ class CertificateManagerTest extends \Test\TestCase {
\
OC\Files\Filesystem
::
tearDown
();
\
OC_Util
::
setupFS
(
$this
->
username
);
$this
->
user
=
\
OC
::
$server
->
getUserManager
()
->
get
(
$this
->
username
);
$this
->
certificateManager
=
new
CertificateManager
(
$this
->
user
);
$this
->
certificateManager
=
new
CertificateManager
(
$this
->
username
,
new
\
OC\Files\View
());
}
protected
function
tearDown
()
{
...
...
@@ -84,7 +82,7 @@ class CertificateManagerTest extends \Test\TestCase {
}
function
testGetCertificateBundle
()
{
$this
->
assertSame
(
$this
->
user
->
getHome
()
.
'/files_external/rootcerts.crt'
,
$this
->
certificateManager
->
getCertificateBundle
());
$this
->
assertSame
(
'/'
.
$this
->
user
name
.
'/files_external/rootcerts.crt'
,
$this
->
certificateManager
->
getCertificateBundle
());
}
}
\ No newline at end of file
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment