2022-01-13 15:58:11 +08:00
|
|
|
package filesys
|
|
|
|
|
|
|
|
import (
|
|
|
|
"github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
|
|
|
|
"github.com/seaweedfs/fuse"
|
|
|
|
)
|
|
|
|
|
|
|
|
func checkPermission(entry *filer_pb.Entry, uid, gid uint32, isWrite bool) error {
|
2022-01-13 18:07:39 +08:00
|
|
|
if uid == 0 || gid == 0 {
|
|
|
|
return nil
|
|
|
|
}
|
2022-01-13 15:58:11 +08:00
|
|
|
if entry == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
if entry.Attributes == nil {
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
attr := entry.Attributes
|
|
|
|
if attr.Uid == uid {
|
|
|
|
if isWrite {
|
2022-01-13 18:07:39 +08:00
|
|
|
if attr.FileMode&0200 > 0 {
|
2022-01-13 15:58:11 +08:00
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return fuse.EPERM
|
|
|
|
}
|
|
|
|
} else {
|
2022-01-13 18:07:39 +08:00
|
|
|
if attr.FileMode&0400 > 0 {
|
2022-01-13 15:58:11 +08:00
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return fuse.EPERM
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else if attr.Gid == gid {
|
|
|
|
if isWrite {
|
|
|
|
if attr.FileMode&0020 > 0 {
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return fuse.EPERM
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if attr.FileMode&0040 > 0 {
|
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return fuse.EPERM
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if isWrite {
|
2022-01-13 18:07:39 +08:00
|
|
|
if attr.FileMode&0002 > 0 {
|
2022-01-13 15:58:11 +08:00
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return fuse.EPERM
|
|
|
|
}
|
|
|
|
} else {
|
2022-01-13 18:07:39 +08:00
|
|
|
if attr.FileMode&0004 > 0 {
|
2022-01-13 15:58:11 +08:00
|
|
|
return nil
|
|
|
|
} else {
|
|
|
|
return fuse.EPERM
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|