forked from aquasecurity/trivy
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Fix Windows support (aquasecurity#481)
* fix: Fix Windows support Signed-off-by: Liam Galvin <liam.galvin@aquasec.com> * Update writable.go * Update writable_windows.go
- Loading branch information
Showing
3 changed files
with
61 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
//go:build !windows | ||
// +build !windows | ||
|
||
package resolvers | ||
|
||
import ( | ||
"os" | ||
"syscall" | ||
) | ||
|
||
func isWritable(path string) bool { | ||
info, err := os.Stat(path) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
if !info.IsDir() { | ||
return false | ||
} | ||
|
||
// Check if the user bit is enabled in file permission | ||
if info.Mode().Perm()&(1<<(uint(7))) == 0 { | ||
return false | ||
} | ||
|
||
var stat syscall.Stat_t | ||
if err = syscall.Stat(path, &stat); err != nil { | ||
return false | ||
} | ||
|
||
if uint32(os.Geteuid()) != stat.Uid { | ||
return false | ||
} | ||
|
||
return true | ||
} |
24 changes: 24 additions & 0 deletions
24
pkg/scanners/terraform/parser/resolvers/writable_windows.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package resolvers | ||
|
||
import ( | ||
"os" | ||
) | ||
|
||
func isWritable(path string) bool { | ||
|
||
info, err := os.Stat(path) | ||
if err != nil { | ||
return false | ||
} | ||
|
||
if !info.IsDir() { | ||
return false | ||
} | ||
|
||
// Check if the user bit is enabled in file permission | ||
if info.Mode().Perm()&(1<<(uint(7))) == 0 { | ||
return false | ||
} | ||
|
||
return true | ||
} |