Fix: avoid silent fatalities

demo: https://tcp.ac/i/JMSUc.gif
This commit is contained in:
kayos@tcp.direct 2024-06-17 00:30:24 -07:00
parent 3337efcb8f
commit 395f5ab6bc
No known key found for this signature in database
GPG key ID: 4B841471B4BEE979
13 changed files with 115 additions and 78 deletions

View file

@ -10,8 +10,7 @@ import (
"strings"
"time"
"github.com/HikariKnight/ls-iommu/pkg/errorcheck"
"github.com/HikariKnight/quickpassthrough/internal/common"
"github.com/HikariKnight/quickpassthrough/internal/logger"
)
@ -85,16 +84,16 @@ func Elevate(password string) {
// Open STDIN
stdin, err := cmd.StdinPipe()
errorcheck.ErrorCheck(err, "\nFailed to get sudo STDIN")
common.ErrorCheck(err, "\nFailed to get sudo STDIN")
// Start the authentication
err = cmd.Start()
errorcheck.ErrorCheck(err, "\nFailed to start sudo command")
common.ErrorCheck(err, "\nFailed to start sudo command")
// Get the passed password
pw, _ := base64.StdEncoding.DecodeString(password)
_, err = stdin.Write([]byte(string(pw) + "\n"))
errorcheck.ErrorCheck(err, "\nFailed at typing to STDIN")
common.ErrorCheck(err, "\nFailed at typing to STDIN")
// Clear the password
pw = nil
password = ""
@ -103,7 +102,7 @@ func Elevate(password string) {
// Wait for the sudo prompt (If the correct password was given, it will not stay behind)
err = cmd.Wait()
errorcheck.ErrorCheck(err, "\nError, password given was wrong")
common.ErrorCheck(err, "\nError, password given was wrong")
}
// Clear clears the terminal.