@@ -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+
5663var 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+
5885func 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