permission.go 1009 B

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. package filesys
  2. import (
  3. "github.com/chrislusf/seaweedfs/weed/pb/filer_pb"
  4. "github.com/seaweedfs/fuse"
  5. )
  6. func checkPermission(entry *filer_pb.Entry, uid, gid uint32, isWrite bool) error {
  7. if uid == 0 || gid == 0 {
  8. return nil
  9. }
  10. if entry == nil {
  11. return nil
  12. }
  13. if entry.Attributes == nil {
  14. return nil
  15. }
  16. attr := entry.Attributes
  17. if attr.Uid == uid {
  18. if isWrite {
  19. if attr.FileMode&0200 > 0 {
  20. return nil
  21. } else {
  22. return fuse.EPERM
  23. }
  24. } else {
  25. if attr.FileMode&0400 > 0 {
  26. return nil
  27. } else {
  28. return fuse.EPERM
  29. }
  30. }
  31. } else if attr.Gid == gid {
  32. if isWrite {
  33. if attr.FileMode&0020 > 0 {
  34. return nil
  35. } else {
  36. return fuse.EPERM
  37. }
  38. } else {
  39. if attr.FileMode&0040 > 0 {
  40. return nil
  41. } else {
  42. return fuse.EPERM
  43. }
  44. }
  45. } else {
  46. if isWrite {
  47. if attr.FileMode&0002 > 0 {
  48. return nil
  49. } else {
  50. return fuse.EPERM
  51. }
  52. } else {
  53. if attr.FileMode&0004 > 0 {
  54. return nil
  55. } else {
  56. return fuse.EPERM
  57. }
  58. }
  59. }
  60. }