|
@@ -58,3 +58,29 @@ func mkdirAs(path string, mode os.FileMode, ownerUID, ownerGID int, mkAll, chown
|
|
|
}
|
|
|
return nil
|
|
|
}
|
|
|
+
|
|
|
+// CanAccess takes a valid (existing) directory and a uid, gid pair and determines
|
|
|
+// if that uid, gid pair has access (execute bit) to the directory
|
|
|
+func CanAccess(path string, uid, gid int) bool {
|
|
|
+ statInfo, err := system.Stat(path)
|
|
|
+ if err != nil {
|
|
|
+ return false
|
|
|
+ }
|
|
|
+ fileMode := os.FileMode(statInfo.Mode())
|
|
|
+ permBits := fileMode.Perm()
|
|
|
+ return accessible(statInfo.UID() == uint32(uid),
|
|
|
+ statInfo.GID() == uint32(gid), permBits)
|
|
|
+}
|
|
|
+
|
|
|
+func accessible(isOwner, isGroup bool, perms os.FileMode) bool {
|
|
|
+ if isOwner && (perms&0100 == 0100) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if isGroup && (perms&0010 == 0010) {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ if perms&0001 == 0001 {
|
|
|
+ return true
|
|
|
+ }
|
|
|
+ return false
|
|
|
+}
|