Skip to content

Commit

Permalink
permcheck: fix nil entries
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Dec 3, 2024
1 parent e1d21c5 commit 47040a1
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions internal/permcheck/security_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,16 +72,23 @@ func rangeACEs(dacl *windows.ACL, f aceFunc) (err error) {
}

// setSecurityInfo sets the security information on the specified file, using
// ents to create a discretionary access control list. Both owner and ents can
// be nil, in which case the corresponding information is not set.
// ents to create a discretionary access control list. Either owner or ents can
// be nil, in which case the corresponding information is not set, but at least
// one of them should be specified.
func setSecurityInfo(fname string, owner *windows.SID, ents []windows.EXPLICIT_ACCESS) (err error) {
var secInfo windows.SECURITY_INFORMATION

var acl *windows.ACL
if len(ents) > 0 {
// TODO(e.burkov): Investigate if this whole set is necessary.
secInfo |= windows.DACL_SECURITY_INFORMATION |
windows.PROTECTED_DACL_SECURITY_INFORMATION |
windows.UNPROTECTED_DACL_SECURITY_INFORMATION

acl, err = windows.ACLFromEntries(ents, nil)
if err != nil {
return fmt.Errorf("creating access control list: %w", err)
}
}

if owner != nil {
Expand All @@ -92,11 +99,6 @@ func setSecurityInfo(fname string, owner *windows.SID, ents []windows.EXPLICIT_A
return errors.Error("no security information to set")
}

acl, err := windows.ACLFromEntries(ents, nil)
if err != nil {
return fmt.Errorf("creating access control list: %w", err)
}

err = windows.SetNamedSecurityInfo(fname, objectType, secInfo, owner, nil, acl, nil)
if err != nil {
return fmt.Errorf("setting security info: %w", err)
Expand Down

0 comments on commit 47040a1

Please sign in to comment.