Skip to content

Commit 398ef76

Browse files
authored
object: error returned when uid or gid cannot be found (#5995)
1 parent f0a8c3a commit 398ef76

File tree

4 files changed

+13
-0
lines changed

4 files changed

+13
-0
lines changed

cmd/object.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,9 @@ func (j *juiceFS) Chmod(key string, mode os.FileMode) error {
355355
func (j *juiceFS) Chown(key string, owner, group string) error {
356356
uid := utils.LookupUser(owner)
357357
gid := utils.LookupGroup(group)
358+
if uid == -1 || gid == -1 {
359+
return fmt.Errorf("user(%s):group(%s) not found", owner, group)
360+
}
358361
f, err := j.jfs.Lopen(ctx, j.path(key), 0)
359362
if err != 0 {
360363
return err

pkg/object/file.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ package object
1818

1919
import (
2020
"bytes"
21+
"fmt"
2122
"io"
2223
"io/fs"
2324
"math/rand"
@@ -340,6 +341,9 @@ func (d *filestore) Chown(key string, owner, group string) error {
340341
p := d.path(key)
341342
uid := utils.LookupUser(owner)
342343
gid := utils.LookupGroup(group)
344+
if uid == -1 || gid == -1 {
345+
return fmt.Errorf("user(%s):group(%s) not found", owner, group)
346+
}
343347
return os.Lchown(p, uid, gid)
344348
}
345349

pkg/object/nfs.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -389,6 +389,9 @@ func (n *nfsStore) Chmod(path string, mode os.FileMode) error {
389389
func (n *nfsStore) Chown(path string, owner, group string) error {
390390
uid := utils.LookupUser(owner)
391391
gid := utils.LookupGroup(group)
392+
if uid == -1 || gid == -1 {
393+
return fmt.Errorf("user(%s):group(%s) not found", owner, group)
394+
}
392395
return n.setAttr(path, func(attr *nfs.Fattr) nfs.Sattr3 {
393396
return nfs.Sattr3{
394397
UID: nfs.SetUID{

pkg/object/sftp.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,9 @@ func (f *sftpStore) Chown(key string, owner, group string) error {
290290
defer f.putSftpConnection(&c, err)
291291
uid := utils.LookupUser(owner)
292292
gid := utils.LookupGroup(group)
293+
if uid == -1 || gid == -1 {
294+
return fmt.Errorf("user(%s):group(%s) not found", owner, group)
295+
}
293296
return c.sftpClient.Chown(f.path(key), uid, gid)
294297
}
295298

0 commit comments

Comments
 (0)