Implement Set_Kernelstub and attempt to elevate to sudo using STDIN and then attempt to remove the password from the program memory
This commit is contained in:
parent
ca992bf864
commit
7081bfa8d7
5 changed files with 81 additions and 13 deletions
|
@ -4,6 +4,7 @@ import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
"github.com/HikariKnight/quickpassthrough/internal/logger"
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/command"
|
"github.com/HikariKnight/quickpassthrough/pkg/command"
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||||
"github.com/klauspost/cpuid/v2"
|
"github.com/klauspost/cpuid/v2"
|
||||||
|
@ -63,5 +64,15 @@ func Set_Cmdline(gpu_IDs []string) {
|
||||||
// TODO2: look into grubby
|
// TODO2: look into grubby
|
||||||
// TODO3: if unknown bootloader, tell user what to add a kernel arguments
|
// TODO3: if unknown bootloader, tell user what to add a kernel arguments
|
||||||
func Set_KernelStub() {
|
func Set_KernelStub() {
|
||||||
|
// Get the config
|
||||||
|
config := GetConfig()
|
||||||
|
|
||||||
|
// Get the kernel args
|
||||||
|
kernel_args := fileio.ReadFile(config.Path.CMDLINE)
|
||||||
|
|
||||||
|
// Write to logger
|
||||||
|
logger.Printf("Running command:\nsudo kernelstub -a \"%s\"", kernel_args)
|
||||||
|
|
||||||
|
// Run the command
|
||||||
|
command.Run("sudo", "kernelstub", "-a", kernel_args)
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,10 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import tea "github.com/charmbracelet/bubbletea"
|
import (
|
||||||
|
"encoding/base64"
|
||||||
|
|
||||||
|
tea "github.com/charmbracelet/bubbletea"
|
||||||
|
)
|
||||||
|
|
||||||
func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
var cmd tea.Cmd
|
var cmd tea.Cmd
|
||||||
|
@ -8,7 +12,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
case tea.KeyMsg:
|
case tea.KeyMsg:
|
||||||
|
|
||||||
// If we are not done
|
// If we are not done
|
||||||
if m.focused != DONE {
|
if m.focused != INSTALL {
|
||||||
// Setup keybindings
|
// Setup keybindings
|
||||||
switch msg.String() {
|
switch msg.String() {
|
||||||
case "ctrl+c", "q":
|
case "ctrl+c", "q":
|
||||||
|
@ -19,7 +23,7 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
if m.width != 0 {
|
if m.width != 0 {
|
||||||
// Process the selected item, if the return value is true then exit the application
|
// Process the selected item, if the return value is true then exit the application
|
||||||
if m.processSelection() {
|
if m.processSelection() {
|
||||||
return m, tea.Quit
|
return m, tea.ExitAltScreen
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
case "ctrl+z", "backspace":
|
case "ctrl+z", "backspace":
|
||||||
|
@ -45,13 +49,20 @@ func (m *model) Update(msg tea.Msg) (tea.Model, tea.Cmd) {
|
||||||
return m, tea.Quit
|
return m, tea.Quit
|
||||||
|
|
||||||
case "enter":
|
case "enter":
|
||||||
if m.width != 0 {
|
// Start installation and send the password to the command
|
||||||
// Process the selected item, if the return value is true then exit the application
|
m.install(
|
||||||
if m.processSelection() {
|
base64.StdEncoding.EncodeToString(
|
||||||
return m, tea.Quit
|
[]byte(
|
||||||
}
|
m.authDialog.Value(),
|
||||||
}
|
),
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
// Blank the password field
|
||||||
|
m.authDialog.SetValue("")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Issue an UI update
|
||||||
m.authDialog, cmd = m.authDialog.Update(msg)
|
m.authDialog, cmd = m.authDialog.Update(msg)
|
||||||
return m, cmd
|
return m, cmd
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,10 +1,13 @@
|
||||||
package internal
|
package internal
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"regexp"
|
"regexp"
|
||||||
|
|
||||||
"github.com/HikariKnight/quickpassthrough/internal/configs"
|
"github.com/HikariKnight/quickpassthrough/internal/configs"
|
||||||
|
"github.com/HikariKnight/quickpassthrough/internal/logger"
|
||||||
|
"github.com/HikariKnight/quickpassthrough/pkg/command"
|
||||||
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
"github.com/HikariKnight/quickpassthrough/pkg/fileio"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -115,7 +118,8 @@ func (m *model) processSelection() bool {
|
||||||
//m.focused++
|
//m.focused++
|
||||||
|
|
||||||
// Because we have no QuickEmu support yet, just skip USB Controller configuration
|
// Because we have no QuickEmu support yet, just skip USB Controller configuration
|
||||||
m.focused = DONE
|
m.focused = INSTALL
|
||||||
|
return true
|
||||||
|
|
||||||
case INTRO:
|
case INTRO:
|
||||||
// This is an OK Dialog
|
// This is an OK Dialog
|
||||||
|
@ -133,3 +137,34 @@ func (m *model) processSelection() bool {
|
||||||
// Return false as we are not done
|
// Return false as we are not done
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// This function starts the install process
|
||||||
|
// It takes 1 auth string as variable
|
||||||
|
func (m *model) install(auth string) {
|
||||||
|
// Get the config
|
||||||
|
config := configs.GetConfig()
|
||||||
|
|
||||||
|
// Write to logger
|
||||||
|
logger.Printf("Getting authentication token by elevating with sudo once")
|
||||||
|
|
||||||
|
// Elevate to sudo
|
||||||
|
command.Elevate(auth)
|
||||||
|
|
||||||
|
// Write to logger
|
||||||
|
logger.Printf("Attempting to free hash from memory")
|
||||||
|
|
||||||
|
// Blank out the variable
|
||||||
|
auth = ""
|
||||||
|
|
||||||
|
// Based on the bootloader, setup the configuration
|
||||||
|
if config.Bootloader == "kernelstub" {
|
||||||
|
// Write to logger
|
||||||
|
logger.Printf("Configuring systemd-boot using kernelstub")
|
||||||
|
|
||||||
|
// Configure kernelstub
|
||||||
|
configs.Set_KernelStub()
|
||||||
|
} else if config.Bootloader == "unknown" {
|
||||||
|
kernel_args := fileio.ReadFile(config.Path.CMDLINE)
|
||||||
|
fmt.Printf("Unsupported bootloader, please add the below line to your bootloaders kernel arguments\n%s", kernel_args)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
|
@ -115,7 +115,7 @@ func (m model) View() string {
|
||||||
|
|
||||||
view = listStyle.Render(m.lists[m.focused].View())
|
view = listStyle.Render(m.lists[m.focused].View())
|
||||||
|
|
||||||
case DONE:
|
case INSTALL:
|
||||||
title = dialogStyle.Render(
|
title = dialogStyle.Render(
|
||||||
fmt.Sprint(
|
fmt.Sprint(
|
||||||
"The configuration files have been generated and are\n",
|
"The configuration files have been generated and are\n",
|
||||||
|
|
|
@ -46,6 +46,8 @@ const (
|
||||||
VIDEO
|
VIDEO
|
||||||
USB
|
USB
|
||||||
USB_GROUP
|
USB_GROUP
|
||||||
|
INSTALL
|
||||||
|
UNKNOWN_BOOTLOADER
|
||||||
DONE
|
DONE
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -95,14 +97,16 @@ func (m *model) initLists(width, height int) {
|
||||||
defaultList,
|
defaultList,
|
||||||
defaultList,
|
defaultList,
|
||||||
choiceList,
|
choiceList,
|
||||||
|
choiceList,
|
||||||
|
choiceList,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Configure offsets for sizing
|
// Configure offsets for sizing
|
||||||
m.offsetx = []int{
|
m.offsetx = []int{
|
||||||
0, 0, 0, 0, 0, 0, 0, 0,
|
0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
|
||||||
}
|
}
|
||||||
m.offsety = []int{
|
m.offsety = []int{
|
||||||
18, 2, 3, 13, 5, 2, 3, 12,
|
18, 2, 3, 13, 5, 2, 3, 12, 0, 0,
|
||||||
}
|
}
|
||||||
|
|
||||||
// Update the styles with the correct width
|
// Update the styles with the correct width
|
||||||
|
@ -169,4 +173,11 @@ func (m *model) initLists(width, height int) {
|
||||||
}
|
}
|
||||||
m.lists[DONE].SetItems(items)
|
m.lists[DONE].SetItems(items)
|
||||||
m.lists[DONE].SetSize(m.width-m.offsetx[DONE], m.height-m.offsety[DONE])
|
m.lists[DONE].SetSize(m.width-m.offsetx[DONE], m.height-m.offsety[DONE])
|
||||||
|
|
||||||
|
// Init DONE choises
|
||||||
|
items = []list.Item{
|
||||||
|
item{title: "FINISH"},
|
||||||
|
}
|
||||||
|
m.lists[UNKNOWN_BOOTLOADER].SetItems(items)
|
||||||
|
m.lists[UNKNOWN_BOOTLOADER].SetSize(m.width-m.offsetx[UNKNOWN_BOOTLOADER], m.height-m.offsety[UNKNOWN_BOOTLOADER])
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue