Skip to content

Commit 0632871

Browse files
Return nil error instead of syscall.Errno(0) (#5317)
Return a nil error instead of syscall.Errno(0) which indicates a successful operation on windows.
1 parent 6b591eb commit 0632871

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
# Kind can be one of:
2+
# - breaking-change: a change to previously-documented behavior
3+
# - deprecation: functionality that is being removed in a later release
4+
# - bug-fix: fixes a problem in a previous version
5+
# - enhancement: extends functionality but does not break or fix existing behavior
6+
# - feature: new functionality
7+
# - known-issue: problems that we are aware of in a given version
8+
# - security: impacts on the security of a product or a user’s deployment.
9+
# - upgrade: important information for someone upgrading from a prior version
10+
# - other: does not fit into any of the other categories
11+
kind: bug-fix
12+
13+
# Change summary; a 80ish characters long description of the change.
14+
summary: Check windows permissions for false-positive return
15+
16+
# Long description; in case the summary is not enough to describe the change
17+
# this field accommodate a description without length limits.
18+
# NOTE: This field will be rendered only for breaking-change and known-issue kinds at the moment.
19+
description: |
20+
Check the errors returned when handling the ACL on windows systems to stop emmitting an error that states "The operation completed successfully".
21+
22+
# Affected component; a word indicating the component this changeset affects.
23+
component:
24+
25+
# PR URL; optional; the PR number that added the changeset.
26+
# If not present is automatically filled by the tooling finding the PR where this changelog fragment has been added.
27+
# NOTE: the tooling supports backports, so it's able to fill the original PR number instead of the backport PR number.
28+
# Please provide it if you are adding a fragment for a different PR.
29+
pr: https://github.com/elastic/elastic-agent/pull/5317
30+
31+
# Issue URL; optional; the GitHub issue related to this changeset (either closes or is part of).
32+
# If not present is automatically filled by the tooling with the issue linked to the PR number.
33+
issue: https://github.com/elastic/elastic-agent/issues/4496

internal/pkg/agent/perms/windows.go

+13-1
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"fmt"
1212
"io/fs"
1313
"path/filepath"
14+
"syscall"
1415

1516
"github.com/Microsoft/go-winio"
1617
"github.com/hectane/go-acl"
@@ -91,6 +92,11 @@ func FixPermissions(topPath string, opts ...OptFunc) error {
9192

9293
err = acl.Apply(name, true, inherit, grants...)
9394
if err != nil {
95+
// Check for Errno = 0 which indicates success
96+
// https://pkg.go.dev/golang.org/x/sys/windows#Errno
97+
if errors.Is(err, syscall.Errno(0)) {
98+
return nil
99+
}
94100
return err
95101
}
96102
if userSID != nil && groupSID != nil {
@@ -112,7 +118,13 @@ func FixPermissions(topPath string, opts ...OptFunc) error {
112118
if topPath == name {
113119
inherit = false
114120
}
115-
return acl.Apply(name, true, inherit, grants...)
121+
err = acl.Apply(name, true, inherit, grants...)
122+
// Check for Errno = 0 which indicates success
123+
// https://pkg.go.dev/golang.org/x/sys/windows#Errno
124+
if errors.Is(err, syscall.Errno(0)) {
125+
return nil
126+
}
127+
return err
116128
} else if errors.Is(err, fs.ErrNotExist) {
117129
return nil
118130
}

0 commit comments

Comments
 (0)