Commit Graph
76 Commits
Author SHA1 Message Date
Hamza El-Saawy b52bba4773 Updating windows build constraints
pkg/guid is not windows specific, as it can run on Linux.
Build constraints on guid_windows and guid_nonwindows are redundant with
file names, but added for consistency.

Added missing build constraints.

Added Ubuntu to test matrix, along with windows 2022.

Signed-off-by: Hamza El-Saawy <hamzaelsaawy@microsoft.com>
2022-03-29 12:38:23 -04:00
Michael Hofmann c4cf81c481 Replace github.com/pkg/errors with stdlib errors
Since Go version 1.13, the standard library has built-in support for
wrapping and unwrapping of error values.  This commit bumps the minimum
version required by the module from 1.12 to 1.13, replaces all calls to
errors.Wrap/f with fmt.Errorf and removes the now unneeded dependency on
github.com/pkg/errors.

Signed-off-by: Michael Hofmann <michael.hofmann@bitgestalt.com>
2021-12-01 11:09:15 +01:00
Kathryn Baldauf 60c1574cd7 Merge pull request #169 from dcormier/dc/guid
Allow guid package to be used on non-Windows GOOS targets
2021-10-25 17:23:25 -07:00
Kyle Wojtaszek 4c72048b5c FIxing corruption in callbacks
Signed-off-by: Kyle Wojtaszek <kylewo@microsoft.com>
2021-10-12 14:31:04 -07:00
Kyle W 0b148d19cf Fix corruption in x86 callback 2021-06-14 13:44:35 -07:00
Kevin Parsons 9f0ab2cc0a Fix syscall error handling in vhd and pkg/security
These packages had incorrect error handling for their generated syscall
bindings. The functions they were calling returned errors directly, but
the binding was written such that the generated code was calling
GetLastError instead.

Thankfully, this did not affect the detection of whether or not an error
had occurred, it only caused the value returned in the case of an error
to be not the right error code.

Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2021-04-26 15:08:11 -07:00
Kathryn Baldauf 085c1a94ab Add CI github action for testing on push and PR
Signed-off-by: Kathryn Baldauf <kabaldau@microsoft.com>
2021-04-21 15:35:36 -07:00
Kevin Parsons 941861fe1a pkg/etw: Fix to build on windows/arm
We don't support actually using ETW on windows/arm, but to make things
easier for downstream dependencies, we want to still allow the package
to compile and just no-op on this architecture. We do this by returning
a nil Provider, and implementing its methods to no-op when the receiver
is nil.

Previously this was implemented by putting NewProviderWithID in
provider_unsupported.go, but when we refactored the code so that the
actual work was done in NewProviderWithOptions instead, we didn't fix up
provider_unsupported. This change fixes this by putting only
NewProviderWithOptions in provider_unsupported.go, since the other
provider creation functions call into this one.

Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2021-03-24 15:05:25 -07:00
Paul "TBBle" Hampson bc48b61dc9 Make local mksyscall_windows.go forks less forked
At this point points of difference between the three local
mksyscall_windows.go implementations and
golang.org/x/sys/windows/mkwinsyscall v0.0.0-20210104204734-6f8348627aad
are:
- pkg/etw: Deduplicates imported functions due to multiple calling APIs
- pkg/security and vhd: Forced UTF-16 mode, not checking A/W suffix. I
  also removed cosmetic differences between these two implementations.

`go generate` reports no changes with these updates.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2021-02-11 22:50:55 +11:00
Paul "TBBle" Hampson 1390d1a07b Pull sync generated syscalls
This moves all the current users of
$GOROOT/src/syscall/mksyscall_windows.go to instead use
golang.org/x/sys/windows/mkwinsyscall, as directed by the version of the
former in Go 1.15.

It also syncs the local forks of mksyscall_windows.go with the latest
version of golang.org/x/sys/windows/mkwinsyscall/mkwinsyscall.go, so
that the local patches can be easily seen in a side-by-side comparison.
Significant changes compared to the in-tree forked versions:
* *bool parameters are read back through a temp-var, not directly like
  other pointer parameters.
* ?-suffixed function names support testing for function presence before
  calling. This replaces a local implementation of this in
  pkg/security, which was not actually used anyway. The upstream version
  correctly supports functions that don't already have an error return.
* `errnoErr(0)` is now useful, so each call of `errnoErr` doesn't need
  to be protected with a check for 0 first.
* The generated functions are now sorted. This of course produced a
  *lot* of churn in the generated files.

vhd\vhd.go was changed to generate syscalls into zvhd_windows.go, since
regeneration removes the build tag added by hand in
9d8277341f.

After all that, I also ran
```
go generate . .\pkg\etw\ .\pkg\process\ .\pkg\security\ .\vhd\
```
to update all the existing generated code.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2021-02-11 22:47:40 +11:00
Kathryn Baldauf 68cdd9bd9d Merge pull request #191 from uhthomas/master
Add build guards for all Windows imports
2021-02-10 17:11:08 -08:00
Thomas e09292102f Add noop mains for non windows builds 2021-02-11 00:05:48 +00:00
Thomas d4c02ad896 Add missing build constraints 2021-02-10 23:54:19 +00:00
Thomas f0d2c76ab3 Fix missing platform/architecture separation 2021-02-10 23:09:41 +00:00
Thomas eb9d8c9346 Separate platform from architecture build constraints 2021-02-10 23:05:19 +00:00
Sebastiaan van Stijn f2a56450f4 Use golang.org/x/sys/execabs instead of os/exec
On Windows, the os/exec.{Command,CommandContext,LookPath} functions resolve command
names that have neither path separators nor file extension (e.g., "git") by first
looking in the current working directory before looking in the PATH environment
variable.
Go maintainers intended to match cmd.exe's historical behavior.

However, this is pretty much never the intended behavior and as an abundance of
precaution this patch prevents that when executing commands.

This patch was prompted by the [Go 1.15.7 security fixes](https://blog.golang.org/path-security).

Signed-off-by: Sebastiaan van Stijn <github@gone.nl>
2021-02-10 09:21:40 +01:00
Kathryn Baldauf a38e1dc8bb Merge pull request #188 from TBBle/correct-GetVolumeInformation-return-handling
Correct GetVolumeInformation return type handling
2021-02-09 18:46:35 -08:00
Kyle Wojtaszek 652abba813 Removing unneeded NewProviderWithGroup function 2021-01-27 14:43:00 -08:00
Kyle Wojtaszek 30844eed75 Add ability to set provider group 2021-01-27 13:12:37 -08:00
Thomas Way 9d8277341f Add build guards for all Windows imports 2021-01-21 23:24:01 +00:00
Paul "TBBle" Hampson 0966e1ad56 Correct GetVolumeInformation return type handling
The _docs_ say it returns 0 for failure, non-zero for success.

This implementation is looking for <0 as HRESULT failure, and deriving
an Errno from that.

The new tests fail with GetFileSystemType as it was defined, e.g.,
```
--- FAIL: TestGetFSTypeOfValidButAbsentDrive (0.00s)
    fs_windows_test.go:41: GetFileSystemType a:\ unexpectedly succeeded
```
when I definitely do not have an A:\ drive.

Signed-off-by: Paul "TBBle" Hampson <Paul.Hampson@Pobox.com>
2021-01-16 17:11:37 +11:00
Daniel Cormier 892f7849c3 Allow guid package to be used on non-Windows GOOS targets
`golang.org/x/sys/windows.GUID` is currently only available to builds
targeting `GOOS=windows` (see golang/go#36485). This change makes it
so `windows` builds continue to use `golang.org/x/sys/windows.GUID`,
while non-`windows` builds get a different structure that has all
the same fields and methods.
2020-03-04 09:29:26 -05:00
Kevin Parsons f272bf30b3 Add new process package
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-09-18 18:03:14 -07:00
Kevin Parsons c20fb68775 etw: Add test for provider name to GUID conversion
Also simplified the name to GUID conversion code, and improved the
comments.

Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-07-10 15:12:20 -07:00
Kevin Parsons 177d2ec7ea guid: Add V5 GUID support
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-07-10 15:08:22 -07:00
Kevin Parsons c5294c98c0 guid: Improve version and variant handling
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-07-10 15:03:44 -07:00
Eric Hotinger 28396ed851 Updates the error message in GetFileSystemType to match the function's
casing and exports the error.

Signed-off-by: Eric Hotinger <ehotinger@gmail.com>
2019-07-01 14:25:30 -07:00
Eric Hotinger 9fe4f5c769 Adds a file system helper file for determining the file system type.
Signed-off-by: Eric Hotinger <ehotinger@gmail.com>
2019-06-25 13:42:09 -07:00
Justin d2ef9cfdac Merge pull request #149 from microsoft/etw-logrus-time
etwlogrus: Pass through entry time as ETW field
2019-06-25 10:40:15 -07:00
Kevin Parsons 09baa54393 etwlogrus: Pass through entry time as ETW field
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-06-25 10:36:45 -07:00
Kevin Parsons 2ae559ad19 Replace ETW Logrus hook levels with AllLevels
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-06-25 10:32:12 -07:00
Kevin Parsons 3dac69f6ea pkg/guid: Switch from json.Marshaler to encoding.TextMarshaler
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-13 14:31:21 -07:00
Kevin Parsons b940a6f7ae pkg/guid: Improve error messages
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-13 14:30:09 -07:00
Kevin Parsons 2dc6637e2c pkg/guid: Support big-endian and Windows encodings
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-13 14:28:49 -07:00
Kevin Parsons 6dd84a2574 pkg/guid: Add helper functions to tests
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-13 14:25:53 -07:00
Kevin Parsons 1197d54849 pkg/guid: Add variant and version support
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-13 14:22:42 -07:00
Kevin Parsons a2a7cd6b7d Fix errors introduced with guid-by-value change
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-08 16:43:22 -07:00
Kevin Parsons 7185c03f75 pkg/guid: Prefer passing GUID by value
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-08 15:52:52 -07:00
John Starks 2be8053e58 Merge pull request #138 from microsoft/etw-write-error
etwlogrus: Ignore error from ETW WriteEvent
2019-05-08 08:21:23 -07:00
John Starks 1bcf844dd4 Merge pull request #140 from microsoft/etwlogrus-tests
etwlogrus: Improve tests to actually go through logrus hook
2019-05-08 08:20:37 -07:00
Kevin Parsons afa8dc2e8d etwlogrus: Improve tests to actually go through logrus hook
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-08 00:01:40 -07:00
Kevin Parsons ed00d9afc1 etwlogrus: Fix event logging not including fields
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-07 23:51:39 -07:00
Kevin Parsons 2093f10e12 etwlogrus: Ignore error from ETW WriteEvent
Signed-off-by: Kevin Parsons <kevpar@microsoft.com>
2019-05-07 23:41:01 -07:00
John Starks e90d8317de Merge pull request #133 from jstarks/sort_keys
pkg/etwlogrus: Ensure stable event field order
2019-05-07 13:40:08 -07:00
John Starks 664840fcdb pkg/etwlogrus: Ensure stable event field order
This change updates the logrus hook to sort the incoming logrus data
before passing it to the tracelogging code. This is useful because it
ensures that two instances of the same event have the fields in the same
order, which is necessary to get WPA to line the fields up.
2019-05-07 19:27:13 +00:00
Justin f4260581c2 Merge pull request #132 from jstarks/etwtime
pkg/etw: Add support for time.Time
2019-05-07 10:25:08 -07:00
John Starks 89c1d0e19d pkg/etw: Add support for time.Time
This change adds support for encoding time.Time values as FILETIME
values in tracelogging events. FILETIME has slightly less precision than
time.Time (100ns vs 1ns), but it is the closest availble match.
2019-05-05 00:02:18 +00:00
Kevin Parsons 0112307ab4 Fix ETW package to work on 386
The ETW registration handle is defined to be 64-bits on all platforms. The Go
type previously used a uintptr which created problems on 32-bit systems. This
change adds a new wrapper file which receives a 64-bit handle for the functions
defined in it, and correctly passes it to the native ETW functions either as-is
(on 64-bit) or as two 32-bit values (on 32-bit).

This required a minor change in mksyscall_windows.go, to allow multiple syscalls
that map to the same underlying function without causing a duplicate definition
error in the generated file.
2019-04-22 10:28:49 -07:00
Kevin Parsons 1af701744e Add stock mksyscall_windows.go to ETW package
This is just so we can see the alterations we make to this file as a diff in
the next commit.
2019-04-22 10:24:50 -07:00
Kevin Parsons a4918f0a0f Make ETW no-op on ARM
Proper support for ETW on ARM will require additional changes in Go to support
more than 16 bytes of arguments to a syscall callback. Until this work is done,
the ETW package is being changed to no-op on ARM.
2019-04-20 19:23:37 -07:00