You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

63 lines
1009 B

  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. }