mirror of
https://gitee.com/gitea/gitea
synced 2025-12-30 20:26:34 +08:00
49
vendor/golang.org/x/sys/windows/svc/security.go
generated
vendored
49
vendor/golang.org/x/sys/windows/svc/security.go
generated
vendored
@@ -7,6 +7,10 @@
|
||||
package svc
|
||||
|
||||
import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
"unsafe"
|
||||
|
||||
"golang.org/x/sys/windows"
|
||||
)
|
||||
|
||||
@@ -23,6 +27,8 @@ func allocSid(subAuth0 uint32) (*windows.SID, error) {
|
||||
// IsAnInteractiveSession determines if calling process is running interactively.
|
||||
// It queries the process token for membership in the Interactive group.
|
||||
// http://stackoverflow.com/questions/2668851/how-do-i-detect-that-my-application-is-running-as-service-or-in-an-interactive-s
|
||||
//
|
||||
// Deprecated: Use IsWindowsService instead.
|
||||
func IsAnInteractiveSession() (bool, error) {
|
||||
interSid, err := allocSid(windows.SECURITY_INTERACTIVE_RID)
|
||||
if err != nil {
|
||||
@@ -57,3 +63,46 @@ func IsAnInteractiveSession() (bool, error) {
|
||||
}
|
||||
return false, nil
|
||||
}
|
||||
|
||||
// IsWindowsService reports whether the process is currently executing
|
||||
// as a Windows service.
|
||||
func IsWindowsService() (bool, error) {
|
||||
// The below technique looks a bit hairy, but it's actually
|
||||
// exactly what the .NET framework does for the similarly named function:
|
||||
// https://github.com/dotnet/extensions/blob/f4066026ca06984b07e90e61a6390ac38152ba93/src/Hosting/WindowsServices/src/WindowsServiceHelpers.cs#L26-L31
|
||||
// Specifically, it looks up whether the parent process has session ID zero
|
||||
// and is called "services".
|
||||
|
||||
var pbi windows.PROCESS_BASIC_INFORMATION
|
||||
pbiLen := uint32(unsafe.Sizeof(pbi))
|
||||
err := windows.NtQueryInformationProcess(windows.CurrentProcess(), windows.ProcessBasicInformation, unsafe.Pointer(&pbi), pbiLen, &pbiLen)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
var psid uint32
|
||||
err = windows.ProcessIdToSessionId(uint32(pbi.InheritedFromUniqueProcessId), &psid)
|
||||
if err != nil || psid != 0 {
|
||||
return false, nil
|
||||
}
|
||||
pproc, err := windows.OpenProcess(windows.PROCESS_QUERY_LIMITED_INFORMATION, false, uint32(pbi.InheritedFromUniqueProcessId))
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
defer windows.CloseHandle(pproc)
|
||||
var exeNameBuf [261]uint16
|
||||
exeNameLen := uint32(len(exeNameBuf) - 1)
|
||||
err = windows.QueryFullProcessImageName(pproc, 0, &exeNameBuf[0], &exeNameLen)
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
exeName := windows.UTF16ToString(exeNameBuf[:exeNameLen])
|
||||
if !strings.EqualFold(filepath.Base(exeName), "services.exe") {
|
||||
return false, nil
|
||||
}
|
||||
system32, err := windows.GetSystemDirectory()
|
||||
if err != nil {
|
||||
return false, err
|
||||
}
|
||||
targetExeName := filepath.Join(system32, "services.exe")
|
||||
return strings.EqualFold(exeName, targetExeName), nil
|
||||
}
|
||||
|
||||
12
vendor/golang.org/x/sys/windows/svc/service.go
generated
vendored
12
vendor/golang.org/x/sys/windows/svc/service.go
generated
vendored
@@ -71,11 +71,13 @@ const (
|
||||
|
||||
// Status combines State and Accepted commands to fully describe running service.
|
||||
type Status struct {
|
||||
State State
|
||||
Accepts Accepted
|
||||
CheckPoint uint32 // used to report progress during a lengthy operation
|
||||
WaitHint uint32 // estimated time required for a pending operation, in milliseconds
|
||||
ProcessId uint32 // if the service is running, the process identifier of it, and otherwise zero
|
||||
State State
|
||||
Accepts Accepted
|
||||
CheckPoint uint32 // used to report progress during a lengthy operation
|
||||
WaitHint uint32 // estimated time required for a pending operation, in milliseconds
|
||||
ProcessId uint32 // if the service is running, the process identifier of it, and otherwise zero
|
||||
Win32ExitCode uint32 // set if the service has exited with a win32 exit code
|
||||
ServiceSpecificExitCode uint32 // set if the service has exited with a service-specific exit code
|
||||
}
|
||||
|
||||
// ChangeRequest is sent to the service Handler to request service status change.
|
||||
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build windows
|
||||
|
||||
// func servicemain(argc uint32, argv **uint16)
|
||||
TEXT ·servicemain(SB),7,$0
|
||||
MOVL argc+0(FP), AX
|
||||
@@ -2,8 +2,6 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build windows
|
||||
|
||||
// func servicemain(argc uint32, argv **uint16)
|
||||
TEXT ·servicemain(SB),7,$0
|
||||
MOVQ SP, AX
|
||||
@@ -2,15 +2,13 @@
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
// +build windows
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
// func servicemain(argc uint32, argv **uint16)
|
||||
TEXT ·servicemain(SB),NOSPLIT|NOFRAME,$0
|
||||
MOVM.DB.W [R4, R14], (R13) // push {r4, lr}
|
||||
MOVW R13, R4
|
||||
BIC $0x7, R13 // alignment for ABI
|
||||
MOVW R13, R4
|
||||
BIC $0x7, R13 // alignment for ABI
|
||||
|
||||
MOVW R0, ·sArgc(SB)
|
||||
MOVW R1, ·sArgv(SB)
|
||||
@@ -19,19 +17,19 @@ TEXT ·servicemain(SB),NOSPLIT|NOFRAME,$0
|
||||
MOVW ·ctlHandlerExProc(SB), R1
|
||||
MOVW $0, R2
|
||||
MOVW ·cRegisterServiceCtrlHandlerExW(SB), R3
|
||||
BL (R3)
|
||||
CMP $0, R0
|
||||
BEQ exit
|
||||
BL (R3)
|
||||
CMP $0, R0
|
||||
BEQ exit
|
||||
MOVW R0, ·ssHandle(SB)
|
||||
|
||||
MOVW ·goWaitsH(SB), R0
|
||||
MOVW ·cSetEvent(SB), R1
|
||||
BL (R1)
|
||||
BL (R1)
|
||||
|
||||
MOVW ·cWaitsH(SB), R0
|
||||
MOVW $-1, R1
|
||||
MOVW ·cWaitForSingleObject(SB), R2
|
||||
BL (R2)
|
||||
BL (R2)
|
||||
|
||||
exit:
|
||||
MOVW R4, R13 // free extra stack space
|
||||
31
vendor/golang.org/x/sys/windows/svc/sys_windows_arm64.s
generated
vendored
Normal file
31
vendor/golang.org/x/sys/windows/svc/sys_windows_arm64.s
generated
vendored
Normal file
@@ -0,0 +1,31 @@
|
||||
// Copyright 2018 The Go Authors. All rights reserved.
|
||||
// Use of this source code is governed by a BSD-style
|
||||
// license that can be found in the LICENSE file.
|
||||
|
||||
#include "textflag.h"
|
||||
|
||||
// func servicemain(argc uint32, argv **uint16)
|
||||
TEXT ·servicemain(SB),NOSPLIT|NOFRAME,$0
|
||||
MOVD R0, ·sArgc(SB)
|
||||
MOVD R1, ·sArgv(SB)
|
||||
|
||||
MOVD ·sName(SB), R0
|
||||
MOVD ·ctlHandlerExProc(SB), R1
|
||||
MOVD $0, R2
|
||||
MOVD ·cRegisterServiceCtrlHandlerExW(SB), R3
|
||||
BL (R3)
|
||||
CMP $0, R0
|
||||
BEQ exit
|
||||
MOVD R0, ·ssHandle(SB)
|
||||
|
||||
MOVD ·goWaitsH(SB), R0
|
||||
MOVD ·cSetEvent(SB), R1
|
||||
BL (R1)
|
||||
|
||||
MOVD ·cWaitsH(SB), R0
|
||||
MOVD $-1, R1
|
||||
MOVD ·cWaitForSingleObject(SB), R2
|
||||
BL (R2)
|
||||
|
||||
exit:
|
||||
RET
|
||||
Reference in New Issue
Block a user