2023-07-17 04:23:26 +03:00
|
|
|
package cmd
|
|
|
|
|
|
|
|
import (
|
2024-02-04 03:58:04 +03:00
|
|
|
"fmt"
|
|
|
|
"syscall"
|
2023-07-17 04:23:26 +03:00
|
|
|
|
|
|
|
"github.com/awnumar/memguard"
|
|
|
|
"github.com/quexten/goldwarden/agent"
|
|
|
|
"github.com/spf13/cobra"
|
|
|
|
)
|
|
|
|
|
|
|
|
var daemonizeCmd = &cobra.Command{
|
|
|
|
Use: "daemonize",
|
|
|
|
Short: "Starts the agent as a daemon",
|
|
|
|
Long: `Starts the agent as a daemon. The agent will run in the background and will
|
|
|
|
run in the background until it is stopped.`,
|
|
|
|
Run: func(cmd *cobra.Command, args []string) {
|
2023-08-21 19:37:34 +03:00
|
|
|
websocketDisabled := runtimeConfig.WebsocketDisabled
|
|
|
|
sshDisabled := runtimeConfig.DisableSSHAgent
|
|
|
|
|
2023-08-21 14:52:06 +03:00
|
|
|
if websocketDisabled {
|
2024-02-08 18:35:07 +03:00
|
|
|
fmt.Println("Websocket disabled")
|
2023-08-21 14:52:06 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
if sshDisabled {
|
2024-02-08 18:35:07 +03:00
|
|
|
fmt.Println("SSH agent disabled")
|
2023-08-21 14:52:06 +03:00
|
|
|
}
|
|
|
|
|
2024-02-04 03:58:04 +03:00
|
|
|
cleanup := func() {
|
|
|
|
fmt.Println("removing sockets and exiting")
|
|
|
|
fmt.Println("unlinking", runtimeConfig.GoldwardenSocketPath)
|
|
|
|
err := syscall.Unlink(runtimeConfig.GoldwardenSocketPath)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
fmt.Println("unlinking", runtimeConfig.SSHAgentSocketPath)
|
|
|
|
err = syscall.Unlink(runtimeConfig.SSHAgentSocketPath)
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
fmt.Println("memguard wiping memory and exiting")
|
2023-07-17 04:23:26 +03:00
|
|
|
memguard.SafeExit(0)
|
2024-02-04 03:58:04 +03:00
|
|
|
}
|
|
|
|
|
2023-12-30 20:53:01 +03:00
|
|
|
err := agent.StartUnixAgent(runtimeConfig.GoldwardenSocketPath, runtimeConfig)
|
2023-07-17 04:23:26 +03:00
|
|
|
if err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2024-02-04 03:58:04 +03:00
|
|
|
cleanup()
|
2023-07-17 04:23:26 +03:00
|
|
|
},
|
|
|
|
}
|
|
|
|
|
|
|
|
func init() {
|
|
|
|
rootCmd.AddCommand(daemonizeCmd)
|
|
|
|
}
|