Skip to content

Commit

Permalink
fix share jail
Browse files Browse the repository at this point in the history
Signed-off-by: Jörn Friedrich Dreyer <jfd@butonic.de>
  • Loading branch information
butonic committed Aug 25, 2023
1 parent 1314c34 commit 32790ae
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 3 deletions.
5 changes: 5 additions & 0 deletions changelog/unreleased/fix-share-jail.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
Bugfix: fix share jail

Make matching mountpoints deterministic by comparing whole path segments of mountpoints

https://github.com/cs3org/reva/pull/4134
Original file line number Diff line number Diff line change
Expand Up @@ -1059,7 +1059,8 @@ func (s *service) resolveAcceptedShare(ctx context.Context, ref *provider.Refere
if receivedShare.State != collaboration.ShareState_SHARE_STATE_ACCEPTED {
continue
}
if strings.HasPrefix(strings.TrimPrefix(ref.Path, "./"), receivedShare.MountPoint.Path) {
//if strings.HasPrefix(strings.TrimPrefix(ref.Path, "./"), receivedShare.MountPoint.Path) {

Check failure on line 1062 in internal/grpc/services/sharesstorageprovider/sharesstorageprovider.go

View workflow job for this annotation

GitHub Actions / lint

commentFormatting: put a space between `//` and comment text (gocritic)
if isMountPointForPath(receivedShare.MountPoint.Path, ref.Path) {
return receivedShare, lsRes.Status, nil
}
}
Expand All @@ -1069,6 +1070,17 @@ func (s *service) resolveAcceptedShare(ctx context.Context, ref *provider.Refere
return nil, status.NewNotFound(ctx, "sharesstorageprovider: not found "+ref.String()), nil
}

func isMountPointForPath(mountpoint, path string) bool {
requiredSegments := strings.Split(strings.TrimPrefix(mountpoint, "./"), "/")
pathSegments := strings.Split(strings.TrimPrefix(path, "./"), "/")
for i := range requiredSegments {
if pathSegments[i] != requiredSegments[i] {
return false
}
}
return true
}

func (s *service) rejectReceivedShare(ctx context.Context, receivedShare *collaboration.ReceivedShare) error {
receivedShare.State = collaboration.ShareState_SHARE_STATE_REJECTED
receivedShare.MountPoint = nil
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,7 @@ var _ = Describe("Sharesstorageprovider", func() {
},
},
MountPoint: &sprovider.Reference{
Path: "",
Path: "share1-shareddir",
},
}

Expand Down Expand Up @@ -188,7 +188,7 @@ var _ = Describe("Sharesstorageprovider", func() {
gatewayClient.On("Stat", mock.Anything, mock.AnythingOfType("*providerv1beta1.StatRequest")).Return(
func(_ context.Context, req *sprovider.StatRequest, _ ...grpc.CallOption) *sprovider.StatResponse {
switch req.Ref.GetPath() {
case "./share1-shareddir":
case "./share1-shareddir", "./share1-shareddir (1)":
return &sprovider.StatResponse{
Status: status.NewOK(context.Background()),
Info: &sprovider.ResourceInfo{
Expand Down Expand Up @@ -435,6 +435,21 @@ var _ = Describe("Sharesstorageprovider", func() {
Expect(res.Info.Size).To(Equal(uint64(100)))
})

It("stats the correct share in the share jail", func() {
BaseShare.MountPoint.Path = "share1-shareddir"
BaseShareTwo.MountPoint.Path = "share1-shareddir (1)"
statReq := ShareJailStatRequest
statReq.Ref.Path = "./share1-shareddir (1)"
res, err := s.Stat(ctx, statReq)
Expect(err).ToNot(HaveOccurred())
Expect(res).ToNot(BeNil())
Expect(res.Status.Code).To(Equal(rpc.Code_CODE_OK))
Expect(res.Info).ToNot(BeNil())
Expect(res.Info.Type).To(Equal(sprovider.ResourceType_RESOURCE_TYPE_CONTAINER))
Expect(res.Info.Path).To(Equal("share1-shareddir"))
Expect(res.Info.Size).To(Equal(uint64(100)))
})

It("stats a shares folder", func() {
statReq := BaseStatRequest
res, err := s.Stat(ctx, statReq)
Expand Down

0 comments on commit 32790ae

Please sign in to comment.