Skip to content

Commit

Permalink
permcheck: imp code
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Nov 29, 2024
1 parent 7dfbeda commit 0b6a713
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 11 deletions.
8 changes: 4 additions & 4 deletions internal/permcheck/security_unix.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ type entity = container.KeyValue[string, bool]

// entities returns a list of filesystem entities that need to be ranged over.
func entities(workDir, dataDir, statsDir, querylogDir, confFilePath string) (ents []entity) {
ents = container.KeyValues[string, bool]{{
ents = []entity{{
Key: workDir,
Value: true,
}, {
Expand All @@ -47,13 +47,13 @@ func entities(workDir, dataDir, statsDir, querylogDir, confFilePath string) (ent
Value: true,
})
}
ents = append(ents, []entity{{
ents = append(ents, entity{
Key: filepath.Join(querylogDir, "querylog.json"),
Value: false,
}, {
}, entity{
Key: filepath.Join(querylogDir, "querylog.json.1"),
Value: false,
}}...)
})

if dataDir != statsDir {
ents = append(ents, entity{
Expand Down
14 changes: 7 additions & 7 deletions internal/permcheck/security_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ import (
"golang.org/x/sys/windows"
)

// desiredSecInfo defines the parts of a security descriptor to retrieve.
const desiredSecInfo windows.SECURITY_INFORMATION = windows.OWNER_SECURITY_INFORMATION |
windows.DACL_SECURITY_INFORMATION |
windows.PROTECTED_DACL_SECURITY_INFORMATION |
windows.UNPROTECTED_DACL_SECURITY_INFORMATION

// objectType is the type of the object for directories in context of security
// API.
const objectType windows.SE_OBJECT_TYPE = windows.SE_FILE_OBJECT
Expand Down Expand Up @@ -103,7 +97,7 @@ func setSecurityInfo(fname string, owner *windows.SID, ents []windows.EXPLICIT_A
return fmt.Errorf("creating access control list: %w", err)
}

err = windows.SetNamedSecurityInfo(fname, objectType, desiredSecInfo, owner, nil, acl, nil)
err = windows.SetNamedSecurityInfo(fname, objectType, secInfo, owner, nil, acl, nil)
if err != nil {
return fmt.Errorf("setting security info: %w", err)
}
Expand All @@ -113,6 +107,12 @@ func setSecurityInfo(fname string, owner *windows.SID, ents []windows.EXPLICIT_A

// getSecurityInfo retrieves the security information for the specified file.
func getSecurityInfo(fname string) (dacl *windows.ACL, owner *windows.SID, err error) {
// desiredSecInfo defines the parts of a security descriptor to retrieve.
const desiredSecInfo windows.SECURITY_INFORMATION = windows.OWNER_SECURITY_INFORMATION |
windows.DACL_SECURITY_INFORMATION |
windows.PROTECTED_DACL_SECURITY_INFORMATION |
windows.UNPROTECTED_DACL_SECURITY_INFORMATION

sd, err := windows.GetNamedSecurityInfo(fname, objectType, desiredSecInfo)
if err != nil {
return nil, nil, fmt.Errorf("getting security descriptor: %w", err)
Expand Down

0 comments on commit 0b6a713

Please sign in to comment.