add windows support (#193)

* add windows support

* build for win

* fix win build
This commit is contained in:
Boshi Lian 2023-08-16 17:35:03 -07:00 committed by GitHub
parent 2482fd67c7
commit d2b002000e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 74 additions and 16 deletions

View file

@ -10,7 +10,7 @@ builds:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:
- linux - linux
# - windows - windows
# - darwin # - darwin
goarch: goarch:
- amd64 - amd64
@ -36,11 +36,11 @@ builds:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:
- linux - linux
- windows
# - darwin
goarch: goarch:
- amd64 - amd64
- arm64 - arm64
# - windows
# - darwin
main: ./plugin/workingdir main: ./plugin/workingdir
binary: plugins/workingdir binary: plugins/workingdir
tags: tags:
@ -50,10 +50,11 @@ builds:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:
- linux - linux
- windows
# - darwin
goarch: goarch:
- amd64 - amd64
- arm64 - arm64
# - windows
# - darwin # - darwin
main: ./plugin/yaml main: ./plugin/yaml
binary: plugins/yaml binary: plugins/yaml
@ -64,11 +65,11 @@ builds:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:
- linux - linux
# - windows
# - darwin
goarch: goarch:
- amd64 - amd64
- arm64 - arm64
# - windows
# - darwin
main: ./plugin/docker main: ./plugin/docker
binary: plugins/docker binary: plugins/docker
tags: tags:
@ -78,11 +79,11 @@ builds:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:
- linux - linux
# - windows
# - darwin
goarch: goarch:
- amd64 - amd64
- arm64 - arm64
# - windows
# - darwin
main: ./plugin/kubernetes main: ./plugin/kubernetes
binary: plugins/kubernetes binary: plugins/kubernetes
tags: tags:
@ -92,11 +93,11 @@ builds:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:
- linux - linux
- windows
# - darwin
goarch: goarch:
- amd64 - amd64
- arm64 - arm64
# - windows
# - darwin
main: ./plugin/fixed main: ./plugin/fixed
binary: plugins/fixed binary: plugins/fixed
tags: tags:
@ -106,11 +107,11 @@ builds:
- CGO_ENABLED=0 - CGO_ENABLED=0
goos: goos:
- linux - linux
- windows
# - darwin
goarch: goarch:
- amd64 - amd64
- arm64 - arm64
# - windows
# - darwin
main: ./plugin/failtoban main: ./plugin/failtoban
binary: plugins/failtoban binary: plugins/failtoban
tags: tags:
@ -118,6 +119,7 @@ builds:
archives: archives:
- format: tar.gz - format: tar.gz
allow_different_binary_count: true
# this name template makes the OS and Arch compatible with the results of uname. # this name template makes the OS and Arch compatible with the results of uname.
name_template: >- name_template: >-
sshpiperd_with_plugins_ sshpiperd_with_plugins_
@ -130,9 +132,14 @@ archives:
format_overrides: format_overrides:
- goos: windows - goos: windows
format: zip format: zip
# builds: builds:
# - sshpiperd - sshpiperd
# - plugin_workingdir - plugin_workingdir
- plugin_yaml
- plugin_fixed
- plugin_failtoban
- plugin_docker
- plugin_kubernetes
dockers: dockers:
- image_templates: - image_templates:
- "farmer1992/sshpiperd:{{ .Version }}-amd64" - "farmer1992/sshpiperd:{{ .Version }}-amd64"

View file

@ -1,4 +1,4 @@
//go:build !linux //go:build !linux && !windows
package main package main
@ -6,3 +6,7 @@ import "os/exec"
func setPdeathsig(cmd *exec.Cmd) { func setPdeathsig(cmd *exec.Cmd) {
} }
func addProcessToJob(cmd *exec.Cmd) error {
return nil
}

View file

@ -10,3 +10,7 @@ import (
func setPdeathsig(cmd *exec.Cmd) { func setPdeathsig(cmd *exec.Cmd) {
cmd.SysProcAttr = &syscall.SysProcAttr{Pdeathsig: syscall.SIGTERM} cmd.SysProcAttr = &syscall.SysProcAttr{Pdeathsig: syscall.SIGTERM}
} }
func addProcessToJob(cmd *exec.Cmd) error {
return nil
}

View file

@ -0,0 +1,35 @@
//go:build windows
package main
import (
"os/exec"
log "github.com/sirupsen/logrus"
"github.com/tg123/jobobject"
)
func setPdeathsig(cmd *exec.Cmd) {
}
func addProcessToJob(cmd *exec.Cmd) error {
if jobObject == nil {
return nil
}
if cmd.Process == nil {
return nil
}
return jobObject.AddProcess(cmd.Process)
}
var jobObject *jobobject.JobObject
func init() {
var err error
jobObject, err = jobobject.Create()
if err != nil {
log.Warnf("failed to create job object: %v", err)
}
}

View file

@ -62,6 +62,10 @@ func createCmdPlugin(args []string) (*plugin.CmdPlugin, error) {
return nil, err return nil, err
} }
if err := addProcessToJob(cmd); err != nil {
return nil, err
}
p.Name = exe p.Name = exe
return p, nil return p, nil

1
go.mod
View file

@ -15,6 +15,7 @@ require (
github.com/patrickmn/go-cache v2.1.0+incompatible github.com/patrickmn/go-cache v2.1.0+incompatible
github.com/pires/go-proxyproto v0.6.2 github.com/pires/go-proxyproto v0.6.2
github.com/sirupsen/logrus v1.9.3 github.com/sirupsen/logrus v1.9.3
github.com/tg123/jobobject v0.1.0
github.com/tg123/remotesigner v0.0.1 github.com/tg123/remotesigner v0.0.1
github.com/urfave/cli/v2 v2.25.7 github.com/urfave/cli/v2 v2.25.7
golang.org/x/crypto v0.12.0 golang.org/x/crypto v0.12.0

3
go.sum
View file

@ -157,6 +157,8 @@ github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO
github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4=
github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk=
github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo=
github.com/tg123/jobobject v0.1.0 h1:deOWVH+SvsnFtT/M+HFhtZ7t9GMYPzYMvvF25IIMRRE=
github.com/tg123/jobobject v0.1.0/go.mod h1:TtbMLKdmTPY6eMo4aqDXiQWv0yTfAgDt1mxv6J9pM8o=
github.com/tg123/remotesigner v0.0.1 h1:fFCKgpBOv0nfpWOuuWMke9vECKQu6PTrm4iktDwwMMM= github.com/tg123/remotesigner v0.0.1 h1:fFCKgpBOv0nfpWOuuWMke9vECKQu6PTrm4iktDwwMMM=
github.com/tg123/remotesigner v0.0.1/go.mod h1:leliuGRH9ayYYwRo6JO8yg+KyWcltK69XJdLv1x7slM= github.com/tg123/remotesigner v0.0.1/go.mod h1:leliuGRH9ayYYwRo6JO8yg+KyWcltK69XJdLv1x7slM=
github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs= github.com/urfave/cli/v2 v2.25.7 h1:VAzn5oq403l5pHjc4OhD54+XGO9cdKVL/7lDjF+iKUs=
@ -202,6 +204,7 @@ golang.org/x/sys v0.0.0-20191026070338-33540a1f6037/go.mod h1:h1NjWce9XRLGQEsW7w
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210119212857-b64e53b001e4/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= golang.org/x/sys v0.0.0-20210124154548-22da62e12c0c/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
golang.org/x/sys v0.0.0-20210611083646-a4fc73990273/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616045830-e2b7044e8c71/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=
golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20210616094352-59db8d763f22/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg=