Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow updating to internal link #3436

Merged
merged 3 commits into from
Nov 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions changelog/unreleased/allow-updating-to-private-link.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: Allow updating to internal link

We now allow updating any link to an internal link when the user has UpdateGrant permissions

https://github.com/cs3org/reva/pull/3436
Original file line number Diff line number Diff line change
Expand Up @@ -949,7 +949,7 @@ func mdToPropResponse(ctx context.Context, pf *XML, md *provider.ResourceInfo, p
shareTypes = utils.ReadPlainFromOpaque(md.Opaque, "share-types")
}

role := conversions.RoleFromResourcePermissions(md.PermissionSet)
role := conversions.RoleFromResourcePermissions(md.PermissionSet, ls != nil)

if md.Space != nil && md.Space.SpaceType != "grant" && utils.ResourceIDEqual(md.Space.Root, md.Id) {
// a space root is never shared
Expand Down
2 changes: 1 addition & 1 deletion internal/http/services/owncloud/ocdav/tus.go
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ func (s *svc) handleTusPost(ctx context.Context, w http.ResponseWriter, r *http.
}
}
isShared := !net.IsCurrentUserOwner(ctx, info.Owner)
role := conversions.RoleFromResourcePermissions(info.PermissionSet)
role := conversions.RoleFromResourcePermissions(info.PermissionSet, isPublic)
permissions := role.WebDAVPermissions(
info.Type == provider.ResourceType_RESOURCE_TYPE_CONTAINER,
isShared,
Expand Down
10 changes: 6 additions & 4 deletions internal/http/services/owncloud/ocs/conversions/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -236,8 +236,8 @@ func CS3Share2ShareData(ctx context.Context, share *collaboration.Share) (*Share
if share.Id != nil {
sd.ID = share.Id.OpaqueId
}
if share.GetPermissions() != nil && share.GetPermissions().GetPermissions() != nil {
sd.Permissions = RoleFromResourcePermissions(share.GetPermissions().GetPermissions()).OCSPermissions()
if share.GetPermissions().GetPermissions() != nil {
sd.Permissions = RoleFromResourcePermissions(share.GetPermissions().GetPermissions(), false).OCSPermissions()
}
if share.Ctime != nil {
sd.STime = share.Ctime.Seconds // TODO CS3 api birth time = btime
Expand All @@ -262,9 +262,11 @@ func PublicShare2ShareData(share *link.PublicShare, r *http.Request, publicURL s
if share.Id != nil {
sd.ID = share.Id.OpaqueId
}
if share.GetPermissions() != nil && share.GetPermissions().GetPermissions() != nil {
sd.Permissions = RoleFromResourcePermissions(share.GetPermissions().GetPermissions()).OCSPermissions()

if s := share.GetPermissions().GetPermissions(); s != nil {
sd.Permissions = RoleFromResourcePermissions(share.GetPermissions().GetPermissions(), true).OCSPermissions()
}

if share.Expiration != nil {
sd.Expiration = timestampToExpiration(share.Expiration)
}
Expand Down
10 changes: 7 additions & 3 deletions internal/http/services/owncloud/ocs/conversions/role.go
Original file line number Diff line number Diff line change
Expand Up @@ -410,7 +410,9 @@ func NewLegacyRoleFromOCSPermissions(p Permissions) *Role {
}

// RoleFromResourcePermissions tries to map cs3 resource permissions to a role
func RoleFromResourcePermissions(rp *provider.ResourcePermissions) *Role {
// It needs to know whether this is a link or not, because empty permissions on links mean "INTERNAL LINK"
// while empty permissions on other resources mean "DENIAL". Obviously this is not optimal.
func RoleFromResourcePermissions(rp *provider.ResourcePermissions, islink bool) *Role {
r := &Role{
Name: RoleUnknown,
ocsPermissions: PermissionInvalid,
Expand All @@ -420,8 +422,10 @@ func RoleFromResourcePermissions(rp *provider.ResourcePermissions) *Role {
return r
}
if grants.PermissionsEqual(rp, &provider.ResourcePermissions{}) {
r.ocsPermissions = PermissionsNone
r.Name = RoleDenied
if !islink {
r.ocsPermissions = PermissionsNone
r.Name = RoleDenied
}
return r
}
if rp.ListContainer &&
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ func buildTokenInfo(owner *user.User, tkn string, token string, passProtected bo
t.SpaceID = sRes.Share.ResourceId.GetSpaceId()
t.OpaqueID = sRes.Share.ResourceId.GetOpaqueId()

role := conversions.RoleFromResourcePermissions(sRes.Share.Permissions.GetPermissions())
role := conversions.RoleFromResourcePermissions(sRes.Share.Permissions.GetPermissions(), true)
t.Aliaslink = role.OCSPermissions() == 0

return t, nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -112,14 +112,15 @@ func (h *Handler) createPublicLinkShare(w http.ResponseWriter, r *http.Request,

if statInfo != nil && statInfo.Type == provider.ResourceType_RESOURCE_TYPE_FILE {
// Single file shares should never have delete or create permissions
role := conversions.RoleFromResourcePermissions(newPermissions)
role := conversions.RoleFromResourcePermissions(newPermissions, true)
permissions := role.OCSPermissions()
permissions &^= conversions.PermissionCreate
permissions &^= conversions.PermissionDelete
newPermissions = conversions.RoleFromOCSPermissions(permissions).CS3ResourcePermissions()
}

if !sufficientPermissions(statInfo.PermissionSet, newPermissions) {
if !sufficientPermissions(statInfo.PermissionSet, newPermissions, true) {
response.WriteOCSError(w, r, http.StatusNotFound, "no share permission", nil)
return nil, &ocsError{
Code: http.StatusNotFound,
Message: "Cannot set the requested share permissions",
Expand Down Expand Up @@ -355,7 +356,8 @@ func (h *Handler) updatePublicShare(w http.ResponseWriter, r *http.Request, shar
return
}

if !sufficientPermissions(statRes.Info.PermissionSet, newPermissions) {
// empty permissions mean internal link here - NOT denial. Hence we need an extra check
if !sufficientPermissions(statRes.Info.PermissionSet, newPermissions, true) {
response.WriteOCSError(w, r, http.StatusNotFound, "no share permission", nil)
return
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ func (h *Handler) CreateShare(w http.ResponseWriter, r *http.Request) {
}

// check user has share permissions
if !conversions.RoleFromResourcePermissions(statRes.Info.PermissionSet).OCSPermissions().Contain(conversions.PermissionShare) {
if !conversions.RoleFromResourcePermissions(statRes.Info.PermissionSet, false).OCSPermissions().Contain(conversions.PermissionShare) {
response.WriteOCSError(w, r, http.StatusNotFound, "No share permission", nil)
return
}
Expand Down Expand Up @@ -447,7 +447,7 @@ func (h *Handler) extractPermissions(reqRole string, reqPermissions string, ri *
role = conversions.RoleFromOCSPermissions(permissions)
}

if !sufficientPermissions(ri.PermissionSet, role.CS3ResourcePermissions()) && role.Name != conversions.RoleDenied {
if !sufficientPermissions(ri.PermissionSet, role.CS3ResourcePermissions(), false) && role.Name != conversions.RoleDenied {
return nil, nil, &ocsError{
Code: http.StatusNotFound,
Message: "Cannot set the requested share permissions",
Expand Down Expand Up @@ -1521,8 +1521,8 @@ func (h *Handler) granteeExists(ctx context.Context, g *provider.Grantee, rid *p
}

// sufficientPermissions returns true if the `existing` permissions contain the `requested` permissions
func sufficientPermissions(existing, requested *provider.ResourcePermissions) bool {
ep := conversions.RoleFromResourcePermissions(existing).OCSPermissions()
rp := conversions.RoleFromResourcePermissions(requested).OCSPermissions()
func sufficientPermissions(existing, requested *provider.ResourcePermissions, islink bool) bool {
ep := conversions.RoleFromResourcePermissions(existing, islink).OCSPermissions()
rp := conversions.RoleFromResourcePermissions(requested, islink).OCSPermissions()
return ep.Contain(rp)
}
2 changes: 1 addition & 1 deletion pkg/share/manager/owncloudsql/conversions.go
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,7 @@ func resourceTypeToItem(r provider.ResourceType) string {
}

func sharePermToInt(p *provider.ResourcePermissions) int {
return int(conversions.RoleFromResourcePermissions(p).OCSPermissions())
return int(conversions.RoleFromResourcePermissions(p, false).OCSPermissions())
}

func intTosharePerm(p int) (*provider.ResourcePermissions, error) {
Expand Down
4 changes: 2 additions & 2 deletions pkg/storage/fs/owncloudsql/owncloudsql.go
Original file line number Diff line number Diff line change
Expand Up @@ -768,7 +768,7 @@ func (fs *owncloudsqlfs) CreateDir(ctx context.Context, ref *provider.Reference)

permissions := 31 // 1: READ, 2: UPDATE, 4: CREATE, 8: DELETE, 16: SHARE
if perm, err := fs.readPermissions(ctx, filepath.Dir(ip)); err == nil {
permissions = int(conversions.RoleFromResourcePermissions(perm).OCSPermissions()) // inherit permissions of parent
permissions = int(conversions.RoleFromResourcePermissions(perm, false).OCSPermissions()) // inherit permissions of parent
}
data := map[string]interface{}{
"path": fs.toDatabasePath(ip),
Expand Down Expand Up @@ -835,7 +835,7 @@ func (fs *owncloudsqlfs) TouchFile(ctx context.Context, ref *provider.Reference)
"path": fs.toDatabasePath(ip),
"etag": calcEtag(ctx, fi),
"mimetype": mime.Detect(false, ip),
"permissions": int(conversions.RoleFromResourcePermissions(parentPerms).OCSPermissions()), // inherit permissions of parent
"permissions": int(conversions.RoleFromResourcePermissions(parentPerms, false).OCSPermissions()), // inherit permissions of parent
"mtime": mtime,
"storage_mtime": mtime,
}
Expand Down
2 changes: 1 addition & 1 deletion pkg/storage/fs/owncloudsql/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ func (fs *owncloudsqlfs) NewUpload(ctx context.Context, info tusd.FileInfo) (upl
"Type": "OwnCloudStore",
"BinPath": binPath,
"InternalDestination": ip,
"Permissions": strconv.Itoa((int)(conversions.RoleFromResourcePermissions(perm).OCSPermissions())),
"Permissions": strconv.Itoa((int)(conversions.RoleFromResourcePermissions(perm, false).OCSPermissions())),

"Idp": usr.Id.Idp,
"UserId": usr.Id.OpaqueId,
Expand Down