aboutsummaryrefslogtreecommitdiff
path: root/weed/filesys/permission.go
blob: 2edfd49dd92009ed26dba29a0e65e6ea8ae5a93a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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 {
	if uid == 0 || gid == 0 {
		return nil
	}
	if entry == nil {
		return nil
	}
	if entry.Attributes == nil {
		return nil
	}
	attr := entry.Attributes
	if attr.Uid == uid {
		if isWrite {
			if attr.FileMode&0200 > 0 {
				return nil
			} else {
				return fuse.EPERM
			}
		} else {
			if attr.FileMode&0400 > 0 {
				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 {
			if attr.FileMode&0002 > 0 {
				return nil
			} else {
				return fuse.EPERM
			}
		} else {
			if attr.FileMode&0004 > 0 {
				return nil
			} else {
				return fuse.EPERM
			}
		}
	}

}