Skip to content

Commit e52845a

Browse files
sxulbenpye
authored andcommitted
fix error on windows server
1 parent 03781b4 commit e52845a

File tree

3 files changed

+33
-2
lines changed

3 files changed

+33
-2
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,5 +17,5 @@ require (
1717
github.com/lxn/win v0.0.0-20181015143721-a7f87360b10e
1818
github.com/oxtoacart/bpool v0.0.0-20190227141107-8c4636f812cc // indirect
1919
github.com/stretchr/testify v1.3.0 // indirect
20-
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67
20+
golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d
2121
)

go.sum

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,3 +35,5 @@ github.com/stretchr/testify v1.3.0 h1:TivCn/peBQ7UY8ooIcPgZFpTNSz0Q2U6UrFlUfqbe0
3535
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
3636
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67 h1:1Fzlr8kkDLQwqMP8GxrhptBLqZG/EDpiATneiZHY998=
3737
golang.org/x/sys v0.0.0-20190405154228-4b34438f7a67/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
38+
golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d h1:62ap6LNOjDU6uGmKXHJbSfciMoV+FeI1sRXx/pLDL44=
39+
golang.org/x/sys v0.0.0-20200317113312-5766fd39f98d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=

main.go

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import (
1313
"net"
1414
"os"
1515
"os/signal"
16+
"os/user"
1617
"reflect"
1718
"sync"
1819
"syscall"
@@ -53,8 +54,34 @@ type copyDataStruct struct {
5354
lpData uintptr
5455
}
5556

57+
type SecurityAttributes struct {
58+
Length uint32
59+
SecurityDescriptor uintptr
60+
InheritHandle uint32
61+
}
62+
5663
var queryPageantMutex sync.Mutex
5764

65+
func makeInheritSaWithSid() *windows.SecurityAttributes {
66+
var sa windows.SecurityAttributes
67+
68+
u, err := user.Current()
69+
70+
if err == nil {
71+
sd, err := windows.SecurityDescriptorFromString("O:" + u.Uid)
72+
if err == nil {
73+
sa.SecurityDescriptor = sd
74+
}
75+
}
76+
77+
sa.Length = uint32(unsafe.Sizeof(sa))
78+
79+
sa.InheritHandle = 1
80+
81+
return &sa
82+
83+
}
84+
5885
func queryPageant(buf []byte) (result []byte, err error) {
5986
if len(buf) > agentMaxMessageLength {
6087
err = errors.New("Message too long")
@@ -75,7 +102,9 @@ func queryPageant(buf []byte) (result []byte, err error) {
75102
mapName := fmt.Sprintf("WSLPageantRequest")
76103
queryPageantMutex.Lock()
77104

78-
fileMap, err := windows.CreateFileMapping(invalidHandleValue, nil, pageReadWrite, 0, agentMaxMessageLength, syscall.StringToUTF16Ptr(mapName))
105+
var sa = makeInheritSaWithSid()
106+
107+
fileMap, err := windows.CreateFileMapping(invalidHandleValue, sa, pageReadWrite, 0, agentMaxMessageLength, syscall.StringToUTF16Ptr(mapName))
79108
if err != nil {
80109
queryPageantMutex.Unlock()
81110
return

0 commit comments

Comments
 (0)