diff --git a/core/copy.go b/core/copy.go index a763929..a57cf50 100644 --- a/core/copy.go +++ b/core/copy.go @@ -1,7 +1,6 @@ package core import ( - "bufio" "fmt" "os" "strings" @@ -59,14 +58,11 @@ func CopyArgument(targetLocation string, field int, passphrase []byte) { // ClipClearArgument reads the assigned clipboard contents from stdin and passes them to clipClearProcess. func ClipClearArgument() { - // read previous clipboard contents from stdin - clipScanner := bufio.NewScanner(os.Stdin) - if clipScanner.Scan() { - assignedContents := clipScanner.Text() - clipClearProcess(assignedContents) - } else { + assignedContents := readFromStdin() + if assignedContents == "" { os.Exit(0) // use os.Exit instead of core.Exit, as this function runs out of a background subprocess that is invisible to the user (will never appear in GUI/TUI environment) } + clipClearProcess(assignedContents) } // GenTOTP generates a TOTP token from a secret (supports standard and Steam TOTP). diff --git a/core/launchClipClearProcessCLIGeneric.go b/core/launchClipClearProcessCLIGeneric.go index e5fc5eb..5102bac 100644 --- a/core/launchClipClearProcessCLIGeneric.go +++ b/core/launchClipClearProcessCLIGeneric.go @@ -10,8 +10,7 @@ import ( // LaunchClipClearProcess launches the timed clipboard clearing process. // For non-interactive CLI implementations, an entirely separate process is created for this purpose. func LaunchClipClearProcess(copySubject string) { - executableName := os.Args[0] - cmd := exec.Command(executableName, "clipclear") + cmd := exec.Command(os.Args[0], "clipclear") writeToStdin(cmd, copySubject) err := cmd.Start() if err != nil { diff --git a/core/launchClipClearProcessCLIUNIX.go b/core/launchClipClearProcessCLIUNIX.go index 95078f8..a231abe 100644 --- a/core/launchClipClearProcessCLIUNIX.go +++ b/core/launchClipClearProcessCLIUNIX.go @@ -11,8 +11,7 @@ import ( // LaunchClipClearProcess launches the timed clipboard clearing process. // For non-interactive CLI implementations, an entirely separate process is created for this purpose. func LaunchClipClearProcess(copySubject string, isWayland bool) { - executableName := os.Args[0] - cmd := exec.Command(executableName, "clipclear", strconv.FormatBool(isWayland)) + cmd := exec.Command(os.Args[0], "clipclear", strconv.FormatBool(isWayland)) writeToStdin(cmd, copySubject) err := cmd.Start() if err != nil { diff --git a/core/rcw.go b/core/rcw.go index 185e41f..88bd4a4 100644 --- a/core/rcw.go +++ b/core/rcw.go @@ -2,8 +2,10 @@ package core import ( "os" + "os/exec" "strings" + "github.com/rwinkhart/rcw/daemon" "github.com/rwinkhart/rcw/wrappers" ) @@ -25,3 +27,22 @@ func EncryptBytes(decBytes []byte, passphrase []byte) []byte { encBytes := wrappers.Encrypt(decBytes, passphrase) return encBytes } + +// LaunchRCWDProcess launches an RCW daemon to serve the given passphrase. +func LaunchRCWDProcess(passphrase string) { + cmd := exec.Command(os.Args[0], "startrcwd") + writeToStdin(cmd, passphrase) + err := cmd.Start() + if err != nil { + PrintError("Failed to launch RCW daemon - Does this libmutton implementation support the \"startrcwd\" argument?", ErrorOther, true) + } +} + +// RCWDArgument reads the passphrase from stdin and serves it via an RCW daemon. +func RCWDArgument() { + passphrase := readFromStdin() + if passphrase == "" { + os.Exit(0) + } + daemon.Start(string(passphrase)) +} diff --git a/core/utilitiesMisc.go b/core/utilitiesMisc.go index fb93abd..f0e1c03 100644 --- a/core/utilitiesMisc.go +++ b/core/utilitiesMisc.go @@ -1,6 +1,7 @@ package core import ( + "bufio" "crypto/rand" "fmt" "io" @@ -59,6 +60,15 @@ func writeToStdin(cmd *exec.Cmd, input string) { }() } +// readFromStdin is a utility function that reads a string from stdin. +func readFromStdin() string { + scanner := bufio.NewScanner(os.Stdin) + if scanner.Scan() { + return scanner.Text() + } + return "" +} + // CreateTempFile creates a temporary file and returns a pointer to it. func CreateTempFile() *os.File { tempFile, err := os.CreateTemp("", "*.markdown") diff --git a/go.mod b/go.mod index a8ff0dc..bd131e5 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/fortis/go-steam-totp v0.0.0-20171114202746-18e928674727 github.com/pkg/sftp v1.13.9 github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481 - github.com/rwinkhart/rcw v0.0.0-20250504183741-f176d57b6ba5 + github.com/rwinkhart/rcw v0.0.0-20250504233845-9314852f061b golang.design/x/clipboard v0.7.0 // only for Android builds golang.org/x/crypto v0.37.0 gopkg.in/ini.v1 v1.67.0 @@ -21,6 +21,11 @@ require ( golang.org/x/sys v0.32.0 // indirect ) +require ( + github.com/Microsoft/go-winio v0.6.2 // indirect + github.com/rwinkhart/peercred-mini v0.0.0-20250407033241-c09add2eceea // indirect +) + replace golang.org/x/sys => github.com/rwinkhart/sys-freebsd-13-xucred v0.32.0 replace github.com/Microsoft/go-winio => github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410 diff --git a/go.sum b/go.sum index 8329283..411f634 100644 --- a/go.sum +++ b/go.sum @@ -15,8 +15,12 @@ github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZb github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481 h1:FkxbO331O7mS5EJkP+MCi0o2gswh/Aezs+//NmefrR8= github.com/pquerna/otp v1.4.1-0.20231130234153-3357de7c0481/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg= -github.com/rwinkhart/rcw v0.0.0-20250504183741-f176d57b6ba5 h1:BX31d76TLGZqeukYECLFPkLD+SS/CAV12Lkdlc6UuGM= -github.com/rwinkhart/rcw v0.0.0-20250504183741-f176d57b6ba5/go.mod h1:giXrq9o5a7bwMSuMvz+5bb2+qbM+zV4pXaG/SceXfLM= +github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410 h1:NhHwFM3Pgm6zRUfFKvi0p5ndjfFbVWsRwmmhyFlG4PE= +github.com/rwinkhart/go-winio-easy-pipe-handles v0.0.0-20250407031321-96994a0e8410/go.mod h1:yd8OoFMLzJbo9gZq8j5qaps8bJ9aShtEA8Ipt1oGCvU= +github.com/rwinkhart/peercred-mini v0.0.0-20250407033241-c09add2eceea h1:VE2ti/AE4Y3kgnyK+J5c5hpddE+dKHpsFch3K2R6puQ= +github.com/rwinkhart/peercred-mini v0.0.0-20250407033241-c09add2eceea/go.mod h1:t+YkvAdnTKTrg4d469tw3K+GCUzX/Bja4h8yKjSIsGs= +github.com/rwinkhart/rcw v0.0.0-20250504233845-9314852f061b h1:eWN9ogSzNE8KcFcoIBgrdgMCOUhxnV7m+SJ9Z3SCnPU= +github.com/rwinkhart/rcw v0.0.0-20250504233845-9314852f061b/go.mod h1:giXrq9o5a7bwMSuMvz+5bb2+qbM+zV4pXaG/SceXfLM= github.com/rwinkhart/sys-freebsd-13-xucred v0.32.0 h1:KRbqimv9Eexf3VB2FrRAQ4v2fGGu7gt3ayMgdT0FNao= github.com/rwinkhart/sys-freebsd-13-xucred v0.32.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= github.com/stretchr/objx v0.1.0/go.mod h1:HFkY916IF+rwdDfMAkV7OtwuqBVzrE8GR6GFx+wExME=