correct authentication
This commit is contained in:
@@ -3,4 +3,4 @@
|
|||||||
Name = "TurtleSilicon"
|
Name = "TurtleSilicon"
|
||||||
ID = "com.tairasu.turtlesilicon"
|
ID = "com.tairasu.turtlesilicon"
|
||||||
Version = "1.1.0"
|
Version = "1.1.0"
|
||||||
Build = 13
|
Build = 17
|
||||||
|
@@ -1,10 +1,12 @@
|
|||||||
package service
|
package service
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"bytes"
|
||||||
"fmt"
|
"fmt"
|
||||||
"log"
|
"log"
|
||||||
"os/exec"
|
"os/exec"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
"syscall"
|
"syscall"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
@@ -121,7 +123,41 @@ func StartRosettaX87Service(myWindow fyne.Window, updateAllStatuses func()) {
|
|||||||
|
|
||||||
// startServiceWithPassword starts the service using sudo with the provided password
|
// startServiceWithPassword starts the service using sudo with the provided password
|
||||||
func startServiceWithPassword(workingDir, executable, password string) error {
|
func startServiceWithPassword(workingDir, executable, password string) error {
|
||||||
// Use sudo with the password
|
// First test if the password is correct with a simple sudo command
|
||||||
|
testCmd := exec.Command("sudo", "-S", "-v")
|
||||||
|
testStdin, err := testCmd.StdinPipe()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to create test stdin pipe: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Capture stderr to check for authentication errors
|
||||||
|
var stderr bytes.Buffer
|
||||||
|
testCmd.Stderr = &stderr
|
||||||
|
|
||||||
|
err = testCmd.Start()
|
||||||
|
if err != nil {
|
||||||
|
return fmt.Errorf("failed to start test command: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// Send the password for testing
|
||||||
|
_, err = testStdin.Write([]byte(password + "\n"))
|
||||||
|
if err != nil {
|
||||||
|
testCmd.Process.Kill()
|
||||||
|
return fmt.Errorf("failed to send test password: %v", err)
|
||||||
|
}
|
||||||
|
testStdin.Close()
|
||||||
|
|
||||||
|
// Wait for the test command to complete
|
||||||
|
err = testCmd.Wait()
|
||||||
|
if err != nil {
|
||||||
|
stderrOutput := stderr.String()
|
||||||
|
if strings.Contains(stderrOutput, "Sorry, try again") || strings.Contains(stderrOutput, "incorrect password") {
|
||||||
|
return fmt.Errorf("incorrect password")
|
||||||
|
}
|
||||||
|
return fmt.Errorf("sudo authentication failed: %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
// If we get here, the password is correct, now start the actual service
|
||||||
cmd := exec.Command("sudo", "-S", executable)
|
cmd := exec.Command("sudo", "-S", executable)
|
||||||
cmd.Dir = workingDir
|
cmd.Dir = workingDir
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user