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

fix share jail #4134

Merged
merged 1 commit into from
Aug 25, 2023
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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,7 @@ 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 isMountPointForPath(receivedShare.MountPoint.Path, ref.Path) {
return receivedShare, lsRes.Status, nil
}
}
Expand All @@ -1069,6 +1069,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