mirror of
https://github.com/rwinkhart/libmutton.git
synced 2026-08-27 20:36:29 -04:00
Fix ClearProcess
This commit is contained in:
@@ -41,7 +41,7 @@ func ClearProcess(assignedContents []byte) error {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return errors.New("unable to read clipboard contents")
|
return errors.New("unable to read clipboard contents")
|
||||||
}
|
}
|
||||||
if bytes.Equal(assignedContents, newContents) {
|
if bytes.Equal(assignedContents, bytes.TrimRight(newContents, "\r\n")) {
|
||||||
if err = clearClipboard(); err != nil {
|
if err = clearClipboard(); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -7,17 +7,21 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"github.com/rwinkhart/go-boilerplate/back"
|
"github.com/rwinkhart/go-boilerplate/back"
|
||||||
|
"github.com/rwinkhart/go-boilerplate/security"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CopyBytes copies a byte slice to the clipboard.
|
// CopyBytes copies a byte slice to the clipboard.
|
||||||
func CopyBytes(clearClipboardAutomatically bool, copySubject []byte) error {
|
func CopyBytes(clearClipboardAutomatically bool, copySubject []byte) error {
|
||||||
cmd := exec.Command("pbcopy")
|
cmd := exec.Command("pbcopy")
|
||||||
_ = back.WriteToStdinAndZeroizeInput(cmd, copySubject)
|
_ = back.WriteToStdin(cmd, copySubject, false)
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
|
security.ZeroizeBytes(copySubject)
|
||||||
return errors.New("unable to copy to clipboard: " + err.Error())
|
return errors.New("unable to copy to clipboard: " + err.Error())
|
||||||
}
|
}
|
||||||
if clearClipboardAutomatically {
|
if clearClipboardAutomatically {
|
||||||
LaunchClearProcess(copySubject)
|
LaunchClearProcess(copySubject)
|
||||||
|
} else {
|
||||||
|
security.ZeroizeBytes(copySubject)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -25,6 +29,6 @@ func CopyBytes(clearClipboardAutomatically bool, copySubject []byte) error {
|
|||||||
// getClipCommands returns the commands for pasting and clearing the clipboard contents.
|
// getClipCommands returns the commands for pasting and clearing the clipboard contents.
|
||||||
func getClipCommands() (*exec.Cmd, *exec.Cmd, error) {
|
func getClipCommands() (*exec.Cmd, *exec.Cmd, error) {
|
||||||
cmdClear := exec.Command("pbcopy")
|
cmdClear := exec.Command("pbcopy")
|
||||||
_ = back.WriteToStdinAndZeroizeInput(cmdClear, nil)
|
_ = back.WriteToStdin(cmdClear, nil, false)
|
||||||
return exec.Command("pbpaste"), cmdClear, nil
|
return exec.Command("pbpaste"), cmdClear, nil
|
||||||
}
|
}
|
||||||
|
|||||||
+5
-1
@@ -8,6 +8,7 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"github.com/rwinkhart/go-boilerplate/back"
|
"github.com/rwinkhart/go-boilerplate/back"
|
||||||
|
"github.com/rwinkhart/go-boilerplate/security"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CopyBytes copies a byte slice to the clipboard.
|
// CopyBytes copies a byte slice to the clipboard.
|
||||||
@@ -24,12 +25,15 @@ func CopyBytes(clearClipboardAutomatically bool, copySubject []byte) error {
|
|||||||
cmdCopy = exec.Command("xclip", "-sel", "c", "-t", "text/plain")
|
cmdCopy = exec.Command("xclip", "-sel", "c", "-t", "text/plain")
|
||||||
}
|
}
|
||||||
|
|
||||||
_ = back.WriteToStdinAndZeroizeInput(cmdCopy, copySubject)
|
_ = back.WriteToStdin(cmdCopy, copySubject, false)
|
||||||
if err = cmdCopy.Run(); err != nil {
|
if err = cmdCopy.Run(); err != nil {
|
||||||
|
security.ZeroizeBytes(copySubject)
|
||||||
return errors.New("unable to copy to clipboard: " + err.Error())
|
return errors.New("unable to copy to clipboard: " + err.Error())
|
||||||
}
|
}
|
||||||
if clearClipboardAutomatically {
|
if clearClipboardAutomatically {
|
||||||
LaunchClearProcess(copySubject)
|
LaunchClearProcess(copySubject)
|
||||||
|
} else {
|
||||||
|
security.ZeroizeBytes(copySubject)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|||||||
+6
-2
@@ -7,17 +7,21 @@ import (
|
|||||||
"os/exec"
|
"os/exec"
|
||||||
|
|
||||||
"github.com/rwinkhart/go-boilerplate/back"
|
"github.com/rwinkhart/go-boilerplate/back"
|
||||||
|
"github.com/rwinkhart/go-boilerplate/security"
|
||||||
)
|
)
|
||||||
|
|
||||||
// CopyBytes copies a byte slice to the clipboard.
|
// CopyBytes copies a byte slice to the clipboard.
|
||||||
func CopyBytes(clearClipboardAutomatically bool, copySubject []byte) error {
|
func CopyBytes(clearClipboardAutomatically bool, copySubject []byte) error {
|
||||||
cmd := exec.Command("clip.exe")
|
cmd := exec.Command("clip.exe")
|
||||||
_ = back.WriteToStdinAndZeroizeInput(cmd, copySubject)
|
_ = back.WriteToStdin(cmd, copySubject, false)
|
||||||
if err := cmd.Run(); err != nil {
|
if err := cmd.Run(); err != nil {
|
||||||
|
security.ZeroizeBytes(copySubject)
|
||||||
return errors.New("unable to copy to clipboard: " + err.Error())
|
return errors.New("unable to copy to clipboard: " + err.Error())
|
||||||
}
|
}
|
||||||
if clearClipboardAutomatically {
|
if clearClipboardAutomatically {
|
||||||
LaunchClearProcess(copySubject)
|
LaunchClearProcess(copySubject)
|
||||||
|
} else {
|
||||||
|
security.ZeroizeBytes(copySubject)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
@@ -25,6 +29,6 @@ func CopyBytes(clearClipboardAutomatically bool, copySubject []byte) error {
|
|||||||
// getClipCommands returns the commands for pasting and clearing the clipboard contents.
|
// getClipCommands returns the commands for pasting and clearing the clipboard contents.
|
||||||
func getClipCommands() (*exec.Cmd, *exec.Cmd, error) {
|
func getClipCommands() (*exec.Cmd, *exec.Cmd, error) {
|
||||||
clearCMD := exec.Command("clip.exe")
|
clearCMD := exec.Command("clip.exe")
|
||||||
_ = back.WriteToStdinAndZeroizeInput(clearCMD, nil)
|
_ = back.WriteToStdin(clearCMD, nil, false)
|
||||||
return exec.Command("powershell.exe", "-c", "Get-Clipboard"), clearCMD, nil
|
return exec.Command("powershell.exe", "-c", "Get-Clipboard"), clearCMD, nil
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -15,7 +15,7 @@ import (
|
|||||||
func LaunchClearProcess(copySubject []byte) {
|
func LaunchClearProcess(copySubject []byte) {
|
||||||
cmd := exec.Command(os.Args[0], "clipclear")
|
cmd := exec.Command(os.Args[0], "clipclear")
|
||||||
cmd.SysProcAttr = global.GetSysProcAttr()
|
cmd.SysProcAttr = global.GetSysProcAttr()
|
||||||
_ = back.WriteToStdinAndZeroizeInput(cmd, copySubject)
|
_ = back.WriteToStdin(cmd, copySubject, true)
|
||||||
_ = cmd.Start()
|
_ = cmd.Start()
|
||||||
os.Exit(0) // use os.Exit directly since this version of this function is only meant for non-interactive CLI implementations
|
os.Exit(0) // use os.Exit directly since this version of this function is only meant for non-interactive CLI implementations
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -95,7 +95,7 @@ func launchRCWDProcess() []byte {
|
|||||||
|
|
||||||
cmd := exec.Command(os.Args[0], "startrcwd")
|
cmd := exec.Command(os.Args[0], "startrcwd")
|
||||||
cmd.SysProcAttr = global.GetSysProcAttr()
|
cmd.SysProcAttr = global.GetSysProcAttr()
|
||||||
_ = back.WriteToStdinAndZeroizeInput(cmd, append([]byte{}, password...))
|
_ = back.WriteToStdin(cmd, password, false)
|
||||||
_ = cmd.Start()
|
_ = cmd.Start()
|
||||||
|
|
||||||
return password
|
return password
|
||||||
|
|||||||
@@ -45,7 +45,7 @@ This release adds password age-tracking support and features large refactors tha
|
|||||||
- gopkg.in/ini.v1
|
- gopkg.in/ini.v1
|
||||||
- Bumped
|
- Bumped
|
||||||
- Go: v1.25.4 => v1.26.0
|
- Go: v1.25.4 => v1.26.0
|
||||||
- github.com/rwinkhart/go-boilerplate: v0.1.0 => v0.3.0
|
- github.com/rwinkhart/go-boilerplate: v0.1.0 => v0.3.1
|
||||||
- github.com/rwinkhart/rcw: v0.2.4 => v0.3.0
|
- github.com/rwinkhart/rcw: v0.2.4 => v0.3.0
|
||||||
- golang.org/x/crypto: v0.45.0 => v0.48.0
|
- golang.org/x/crypto: v0.45.0 => v0.48.0
|
||||||
- github.com/rwinkhart/sys: v0.38.0 => v0.41.0
|
- github.com/rwinkhart/sys: v0.38.0 => v0.41.0
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ go 1.26.0
|
|||||||
require (
|
require (
|
||||||
github.com/pkg/sftp v1.13.10
|
github.com/pkg/sftp v1.13.10
|
||||||
github.com/pquerna/otp v1.5.0
|
github.com/pquerna/otp v1.5.0
|
||||||
github.com/rwinkhart/go-boilerplate v0.3.0
|
github.com/rwinkhart/go-boilerplate v0.3.1
|
||||||
github.com/rwinkhart/rcw v0.3.0
|
github.com/rwinkhart/rcw v0.3.0
|
||||||
golang.org/x/crypto v0.48.0
|
golang.org/x/crypto v0.48.0
|
||||||
golang.org/x/sys v0.41.0
|
golang.org/x/sys v0.41.0
|
||||||
|
|||||||
@@ -12,8 +12,8 @@ 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/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
|
||||||
github.com/pquerna/otp v1.5.0 h1:NMMR+WrmaqXU4EzdGJEE1aUUI0AMRzsp96fFFWNPwxs=
|
github.com/pquerna/otp v1.5.0 h1:NMMR+WrmaqXU4EzdGJEE1aUUI0AMRzsp96fFFWNPwxs=
|
||||||
github.com/pquerna/otp v1.5.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
|
github.com/pquerna/otp v1.5.0/go.mod h1:dkJfzwRKNiegxyNb54X/3fLwhCynbMspSyWKnvi1AEg=
|
||||||
github.com/rwinkhart/go-boilerplate v0.3.0 h1:dwlm1mZya1xrATkvm2pHbTIFNb5WRjIc7A3a4Ep2aAM=
|
github.com/rwinkhart/go-boilerplate v0.3.1 h1:vkVRuptO2s1yPzzwpvtiiB0c/hPB6yr0p1mzZ2Myb9E=
|
||||||
github.com/rwinkhart/go-boilerplate v0.3.0/go.mod h1:ES13A2r9fnCVfyezwMBgY/RgA4pOIudOUXz3Jk/ikes=
|
github.com/rwinkhart/go-boilerplate v0.3.1/go.mod h1:ES13A2r9fnCVfyezwMBgY/RgA4pOIudOUXz3Jk/ikes=
|
||||||
github.com/rwinkhart/go-winio v0.1.1 h1:kAJKiqneR7cUR01Wn5/doAAV4kOGTEGPug4oinXc5N4=
|
github.com/rwinkhart/go-winio v0.1.1 h1:kAJKiqneR7cUR01Wn5/doAAV4kOGTEGPug4oinXc5N4=
|
||||||
github.com/rwinkhart/go-winio v0.1.1/go.mod h1:ZWa7ssZJT30CCDGJ7fk/2SBTq9BIQrrVjrcss0UW2s0=
|
github.com/rwinkhart/go-winio v0.1.1/go.mod h1:ZWa7ssZJT30CCDGJ7fk/2SBTq9BIQrrVjrcss0UW2s0=
|
||||||
github.com/rwinkhart/peercred-mini v0.1.4 h1:93+phjLknvJadEd2cu/ZPPWdfRSPOwFJzDBEn4ZtWVc=
|
github.com/rwinkhart/peercred-mini v0.1.4 h1:93+phjLknvJadEd2cu/ZPPWdfRSPOwFJzDBEn4ZtWVc=
|
||||||
|
|||||||
Reference in New Issue
Block a user