Skip to content

Commit

Permalink
fix error on windows server
Browse files Browse the repository at this point in the history
  • Loading branch information
sxul authored and benpye committed Apr 8, 2020
1 parent 03781b4 commit e52845a
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 2 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,5 @@ require (
github.com/lxn/win v0.0.0-20181015143721-a7f87360b10e
github.com/oxtoacart/bpool v0.0.0-20190227141107-8c4636f812cc // indirect
github.com/stretchr/testify v1.3.0 // indirect
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67
golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d
)
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -35,3 +35,5 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 h1:1Fzlr8kkDLQwqMP8GxrhptBLqZG/EDpiATneiZHY998=
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d h1:62ap6LNOjDU6uGmKXHJbSfciMoV+FeI1sRXx/pLDL44=
golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
31 changes: 30 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"net"
"os"
"os/signal"
"os/user"
"reflect"
"sync"
"syscall"
Expand Down Expand Up @@ -53,8 +54,34 @@ type copyDataStruct struct {
lpData uintptr
}

type SecurityAttributes struct {
Length uint32
SecurityDescriptor uintptr
InheritHandle uint32
}

var queryPageantMutex sync.Mutex

func makeInheritSaWithSid() *windows.SecurityAttributes {
var sa windows.SecurityAttributes

u, err := user.Current()

if err == nil {
sd, err := windows.SecurityDescriptorFromString("O:" + u.Uid)
if err == nil {
sa.SecurityDescriptor = sd
}
}

sa.Length = uint32(unsafe.Sizeof(sa))

sa.InheritHandle = 1

return &sa

}

func queryPageant(buf []byte) (result []byte, err error) {
if len(buf) > agentMaxMessageLength {
err = errors.New("Message too long")
Expand All @@ -75,7 +102,9 @@ func queryPageant(buf []byte) (result []byte, err error) {
mapName := fmt.Sprintf("WSLPageantRequest")
queryPageantMutex.Lock()

fileMap, err := windows.CreateFileMapping(invalidHandleValue, nil, pageReadWrite, 0, agentMaxMessageLength, syscall.StringToUTF16Ptr(mapName))
var sa = makeInheritSaWithSid()

fileMap, err := windows.CreateFileMapping(invalidHandleValue, sa, pageReadWrite, 0, agentMaxMessageLength, syscall.StringToUTF16Ptr(mapName))
if err != nil {
queryPageantMutex.Unlock()
return
Expand Down

0 comments on commit e52845a

Please sign in to comment.