0
0
mirror of https://github.com/go-gitea/gitea.git synced 2026-06-22 18:38:31 +02:00
gitea/modules/ssh/agent_windows.go

40 lines
1.0 KiB
Go

// Copyright 2026 The Gitea Authors. All rights reserved.
// SPDX-License-Identifier: MIT
//go:build windows
package ssh
import (
"fmt"
"net"
"code.gitea.io/gitea/modules/util"
"github.com/Microsoft/go-winio"
)
// createAgentListener creates a Windows named pipe listener for the SSH agent.
// Returns the listener, pipe path, and a cleanup function for early-return error paths.
func createAgentListener() (net.Listener, string, func(), error) {
agentID := util.CryptoRandomString(16)
pipePath := `\\.\pipe\gitea-ssh-agent-` + agentID
listener, err := winio.ListenPipe(pipePath, nil)
if err != nil {
return nil, "", nil, fmt.Errorf("failed to create named pipe: %w", err)
}
cleanup := func() {
listener.Close()
}
return listener, pipePath, cleanup, nil
}
// setListenerAcceptDeadline is a no-op on Windows; named pipes don't support SetDeadline.
func setListenerAcceptDeadline(_ net.Listener) {}
// cleanupAgentSocket is a no-op on Windows; named pipes are automatically cleaned up when closed.
func cleanupAgentSocket(_ string) {}