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

ocdav: handle redirection prefixes when extracting destination from URL #1111

Merged
merged 5 commits into from
Aug 24, 2020
Merged
Show file tree
Hide file tree
Changes from 4 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
1 change: 0 additions & 1 deletion changelog/unreleased/eosfs-recycle-purge.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Bugfix: do not restore recycle entry on purge


This PR fixes a bug in the EOSFS driver that was restoring a deleted entry
when asking for its permanent purge.
EOS does not have the functionality to purge individual files, but the whole recycle of the user.
Expand Down
8 changes: 8 additions & 0 deletions changelog/unreleased/webdav-move-prefix.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
Bugfix: Handle redirection prefixes when extracting destination from URL

The move function handler in ocdav extracts the destination path from the URL by
removing the base URL prefix from the URL path. This would fail in case there is
a redirection prefix. This PR takes care of that and it also allows zero-size
uploads for localfs.

https://github.com/cs3org/reva/pull/1111
2 changes: 0 additions & 2 deletions cmd/reva/ocm-share-create.go
Original file line number Diff line number Diff line change
Expand Up @@ -117,8 +117,6 @@ func ocmShareCreateCommand() *command {
},
}

fmt.Println("res.Info.Path" + res.Info.Path)

opaqueObj := &types.Opaque{
Map: map[string]*types.OpaqueEntry{
"permissions": &types.OpaqueEntry{
Expand Down
8 changes: 7 additions & 1 deletion internal/http/services/owncloud/ocdav/copy.go
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,14 @@ func (s *svc) handleCopy(w http.ResponseWriter, r *http.Request, ns string) {
}

// TODO check if path is on same storage, return 502 on problems, see https://tools.ietf.org/html/rfc4918#section-9.9.4
// The base URI might contain redirection prefixes which need to be handled
urlSplit := strings.Split(urlPath, baseURI)
ishank011 marked this conversation as resolved.
Show resolved Hide resolved
if len(urlSplit) != 2 {
w.WriteHeader(http.StatusBadRequest)
return
}
// prefix to namespace
dst := path.Join(ns, urlPath[len(baseURI):])
dst := path.Join(ns, urlSplit[1])

// check dst exists
ref = &provider.Reference{
Expand Down
8 changes: 7 additions & 1 deletion internal/http/services/owncloud/ocdav/move.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,14 @@ func (s *svc) handleMove(w http.ResponseWriter, r *http.Request, ns string) {
}

// TODO check if path is on same storage, return 502 on problems, see https://tools.ietf.org/html/rfc4918#section-9.9.4
// The base URI might contain redirection prefixes which need to be handled
urlSplit := strings.Split(urlPath, baseURI)
if len(urlSplit) != 2 {
w.WriteHeader(http.StatusBadRequest)
return
}
// prefix to namespace
dst := path.Join(ns, urlPath[len(baseURI):])
dst := path.Join(ns, urlSplit[1])

// check dst exists
dstStatRef := &provider.Reference{
Expand Down
9 changes: 8 additions & 1 deletion internal/http/services/owncloud/ocdav/trashbin.go
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,14 @@ func (h *TrashbinHandler) Handler(s *svc) http.Handler {
w.WriteHeader(http.StatusBadRequest)
return
}
dst := path.Clean(urlPath[len(baseURI):])

urlSplit := strings.Split(urlPath, baseURI)
if len(urlSplit) != 2 {
w.WriteHeader(http.StatusBadRequest)
return
}

dst := path.Clean(urlSplit[1])

h.restore(w, r, s, u, dst, key)
return
Expand Down
13 changes: 9 additions & 4 deletions pkg/ocm/invite/manager/json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,19 @@ func (m *manager) AcceptInvite(ctx context.Context, invite *invitepb.InviteToken
return err
}

// Add to the list of accepted users
userKey := inviteToken.GetUserId().GetOpaqueId()
for _, acceptedUser := range m.model.AcceptedUsers[userKey] {
currUser := inviteToken.GetUserId()

// do not allow the user who created the token to accept it
if remoteUser.Id.Idp == currUser.Idp && remoteUser.Id.OpaqueId == currUser.OpaqueId {
return errors.New("json: token creator and recipient are the same")
}

for _, acceptedUser := range m.model.AcceptedUsers[currUser.GetOpaqueId()] {
if acceptedUser.Id.GetOpaqueId() == remoteUser.Id.OpaqueId && acceptedUser.Id.GetIdp() == remoteUser.Id.Idp {
return errors.New("json: user already added to accepted users")
}
}
m.model.AcceptedUsers[userKey] = append(m.model.AcceptedUsers[userKey], remoteUser)
m.model.AcceptedUsers[currUser.GetOpaqueId()] = append(m.model.AcceptedUsers[currUser.GetOpaqueId()], remoteUser)
if err := m.model.Save(); err != nil {
err = errors.Wrap(err, "json: error saving model")
return err
Expand Down
14 changes: 10 additions & 4 deletions pkg/ocm/invite/manager/memory/memory.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,21 +143,27 @@ func (m *manager) AcceptInvite(ctx context.Context, invite *invitepb.InviteToken
return err
}

currUser := inviteToken.GetUserId().GetOpaqueId()
currUser := inviteToken.GetUserId()

// do not allow the user who created the token to accept it
if remoteUser.Id.Idp == currUser.Idp && remoteUser.Id.OpaqueId == currUser.OpaqueId {
return errors.New("memory: token creator and recipient are the same")
}

usersList, ok := m.AcceptedUsers.Load(currUser)
acceptedUsers := usersList.([]*userpb.User)
if ok {
acceptedUsers := usersList.([]*userpb.User)
for _, acceptedUser := range acceptedUsers {
if acceptedUser.Id.GetOpaqueId() == remoteUser.Id.OpaqueId && acceptedUser.Id.GetIdp() == remoteUser.Id.Idp {
return errors.New("memory: user already added to accepted users")
}
}

acceptedUsers = append(acceptedUsers, remoteUser)
m.AcceptedUsers.Store(currUser, acceptedUsers)
m.AcceptedUsers.Store(currUser.GetOpaqueId(), acceptedUsers)
} else {
acceptedUsers := []*userpb.User{remoteUser}
m.AcceptedUsers.Store(currUser, acceptedUsers)
m.AcceptedUsers.Store(currUser.GetOpaqueId(), acceptedUsers)
}
return nil
}
Expand Down
14 changes: 12 additions & 2 deletions pkg/storage/utils/localfs/upload.go
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,16 @@ func (fs *localfs) NewUpload(ctx context.Context, info tusd.FileInfo) (upload tu
fs: fs,
}

if !info.SizeIsDeferred && info.Size == 0 {
log.Debug().Interface("info", info).Msg("localfs: finishing upload for empty file")
// no need to create info file and finish directly
err := u.FinishUpload(ctx)
if err != nil {
return nil, err
}
return u, nil
}

// writeInfo creates the file by itself if necessary
err = u.writeInfo()
if err != nil {
Expand Down Expand Up @@ -307,10 +317,10 @@ func (upload *fileUpload) FinishUpload(ctx context.Context) error {

err := os.Rename(upload.binPath, np)

// only delete the upload if it was successfully written to eos
// only delete the upload if it was successfully written to the fs
if err := os.Remove(upload.infoPath); err != nil {
log := appctx.GetLogger(ctx)
log.Err(err).Interface("info", upload.info).Msg("eos: could not delete upload info")
log.Err(err).Interface("info", upload.info).Msg("localfs: could not delete upload info")
}

// TODO: set mtime if specified in metadata
Expand Down
4 changes: 4 additions & 0 deletions pkg/user/manager/rest/rest.go
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,10 @@ func (m *manager) getUserByParam(ctx context.Context, param, val string) (map[st
if err != nil {
return nil, err
}
if len(responseData) == 0 {
return nil, errors.New("rest: no user found")
}

userData, ok := responseData[0].(map[string]interface{})
if !ok {
return nil, errors.New("rest: error in type assertion")
Expand Down