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
b99f8085
Unverified
Commit
b99f8085
authored
Nov 07, 2016
by
Vincent Petry
Browse files
Add repair step to fix file share permissions
parent
d1c84409
Changes
3
Show whitespace changes
Inline
Side-by-side
lib/private/Repair/RepairInvalidShares.php
View file @
b99f8085
...
...
@@ -26,6 +26,7 @@ namespace OC\Repair;
use
OCP\Migration\IOutput
;
use
OCP\Migration\IRepairStep
;
use
Doctrine\DBAL\Platforms\OraclePlatform
;
/**
* Repairs shares with invalid data
...
...
@@ -90,6 +91,35 @@ class RepairInvalidShares implements IRepairStep {
}
}
/**
* Adjust file share permissions
*/
private
function
adjustFileSharePermissions
(
IOutput
$out
)
{
$mask
=
\
OCP\Constants
::
PERMISSION_READ
|
\
OCP\Constants
::
PERMISSION_UPDATE
|
\
OCP\Constants
::
PERMISSION_SHARE
;
$builder
=
$this
->
connection
->
getQueryBuilder
();
if
(
$this
->
connection
->
getDatabasePlatform
()
instanceof
OraclePlatform
)
{
$permsFunc
=
$builder
->
createFunction
(
'bitand('
.
$builder
->
getColumnName
(
'permissions'
)
.
', '
.
$mask
.
')'
);
}
else
{
$permsFunc
=
$builder
->
createFunction
(
'('
.
$builder
->
getColumnName
(
'permissions'
)
.
' & '
.
$mask
.
')'
);
}
$builder
->
update
(
'share'
)
->
set
(
'permissions'
,
$permsFunc
)
->
where
(
$builder
->
expr
()
->
eq
(
'item_type'
,
$builder
->
expr
()
->
literal
(
'file'
)))
->
andWhere
(
$builder
->
expr
()
->
neq
(
'permissions'
,
$permsFunc
));
$updatedEntries
=
$builder
->
execute
();
if
(
$updatedEntries
>
0
)
{
$out
->
info
(
'Fixed file share permissions for '
.
$updatedEntries
.
' shares'
);
}
}
/**
* Remove shares where the parent share does not exist anymore
*/
...
...
@@ -136,6 +166,9 @@ class RepairInvalidShares implements IRepairStep {
// this situation was only possible before 9.1
$this
->
addShareLinkDeletePermission
(
$out
);
}
if
(
version_compare
(
$ocVersionFromBeforeUpdate
,
'9.2.0.2'
,
'<'
))
{
$this
->
adjustFileSharePermissions
(
$out
);
}
$this
->
removeSharesNonExistingParent
(
$out
);
}
...
...
tests/lib/Repair/RepairInvalidSharesTest.php
View file @
b99f8085
...
...
@@ -278,6 +278,73 @@ class RepairInvalidSharesTest extends TestCase {
$result
->
closeCursor
();
}
public
function
fileSharePermissionsProvider
()
{
return
[
// unchanged for folder
[
'folder'
,
31
,
31
,
],
// unchanged for read-write + share
[
'file'
,
\
OCP\Constants
::
PERMISSION_READ
|
\
OCP\Constants
::
PERMISSION_UPDATE
|
\
OCP\Constants
::
PERMISSION_SHARE
,
\
OCP\Constants
::
PERMISSION_READ
|
\
OCP\Constants
::
PERMISSION_UPDATE
|
\
OCP\Constants
::
PERMISSION_SHARE
,
],
// fixed for all perms
[
'file'
,
\
OCP\Constants
::
PERMISSION_READ
|
\
OCP\Constants
::
PERMISSION_CREATE
|
\
OCP\Constants
::
PERMISSION_UPDATE
|
\
OCP\Constants
::
PERMISSION_DELETE
|
\
OCP\Constants
::
PERMISSION_SHARE
,
\
OCP\Constants
::
PERMISSION_READ
|
\
OCP\Constants
::
PERMISSION_UPDATE
|
\
OCP\Constants
::
PERMISSION_SHARE
,
],
];
}
/**
* Test adjusting file share permissions
*
* @dataProvider fileSharePermissionsProvider
*/
public
function
testFileSharePermissions
(
$itemType
,
$testPerms
,
$expectedPerms
)
{
$qb
=
$this
->
connection
->
getQueryBuilder
();
$qb
->
insert
(
'share'
)
->
values
([
'share_type'
=>
$qb
->
expr
()
->
literal
(
Constants
::
SHARE_TYPE_LINK
),
'uid_owner'
=>
$qb
->
expr
()
->
literal
(
'user1'
),
'item_type'
=>
$qb
->
expr
()
->
literal
(
$itemType
),
'item_source'
=>
$qb
->
expr
()
->
literal
(
123
),
'item_target'
=>
$qb
->
expr
()
->
literal
(
'/123'
),
'file_source'
=>
$qb
->
expr
()
->
literal
(
123
),
'file_target'
=>
$qb
->
expr
()
->
literal
(
'/test'
),
'permissions'
=>
$qb
->
expr
()
->
literal
(
$testPerms
),
'stime'
=>
$qb
->
expr
()
->
literal
(
time
()),
])
->
execute
();
$shareId
=
$this
->
getLastShareId
();
/** @var IOutput | \PHPUnit_Framework_MockObject_MockObject $outputMock */
$outputMock
=
$this
->
getMockBuilder
(
'\OCP\Migration\IOutput'
)
->
disableOriginalConstructor
()
->
getMock
();
$this
->
repair
->
run
(
$outputMock
);
$results
=
$this
->
connection
->
getQueryBuilder
()
->
select
(
'*'
)
->
from
(
'share'
)
->
orderBy
(
'permissions'
,
'ASC'
)
->
execute
()
->
fetchAll
();
$this
->
assertCount
(
1
,
$results
);
$updatedShare
=
$results
[
0
];
$this
->
assertEquals
(
$expectedPerms
,
$updatedShare
[
'permissions'
]);
}
/**
* @return int
*/
...
...
version.php
View file @
b99f8085
...
...
@@ -23,7 +23,7 @@
// We only can count up. The 4. digit is only for the internal patchlevel to trigger DB upgrades
// between betas, final and RCs. This is _not_ the public version number. Reset minor/patchlevel
// when updating major/minor version number.
$OC_Version
=
array
(
9
,
2
,
0
,
2
);
$OC_Version
=
array
(
9
,
2
,
0
,
3
);
// The human readable string
$OC_VersionString
=
'9.2.0 pre alpha'
;
...
...
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