Compare commits

..

No commits in common. "dev" and "main" have entirely different histories.
dev ... main

5 changed files with 30 additions and 26 deletions

View file

@ -5,4 +5,4 @@ build:
go build -o build/ go build -o build/
push-client: push-client:
scp build/config root@192.168.122.76:/usr/bin/efi-http-config scp build/config root@192.168.122.2:/usr/bin/efi-http-config

View file

@ -154,7 +154,7 @@ func displayAppList(l *logger.SimpleLogger) {
if a.Active { if a.Active {
prefix = "*" prefix = "*"
} }
l.Infof("\t- %s[%d] %s: %s", prefix, a.ID, a.Name, a.DevicePath) l.Infof("\t- %s[%d] %s: %s (disk id %s)", prefix, a.ID, a.Name, a.Path, a.DiskID)
} }
} }

View file

@ -10,8 +10,7 @@ import (
"strings" "strings"
) )
// var efiBootmgrRegexp = regexp.MustCompile(`Boot(?P<id>[0-9A-F]+)\* (?P<name>.+)\t(.+\(.+,.+,(?P<disk_id>[0-9a-f-]+),.+,.+\))/File\((?P<filepath>.+)\)`) var efiBootmgrRegexp = regexp.MustCompile(`Boot(?P<id>[0-9A-F]+)\* (?P<name>.+)\t(.+\(.+,.+,(?P<disk_id>[0-9a-f-]+),.+,.+\))/File\((?P<filepath>.+)\)`)
var efiBootmgrRegexp = regexp.MustCompile(`Boot(?P<id>[0-9A-F]+)\* (?P<name>.+)\t(?P<device_path>.+\))`)
var activeRegexp = regexp.MustCompile(`BootCurrent: (\d+)`) var activeRegexp = regexp.MustCompile(`BootCurrent: (\d+)`)
var bootOrderRegexp = regexp.MustCompile(`BootOrder: ((?:[0-9A-F]{4},?)+)`) var bootOrderRegexp = regexp.MustCompile(`BootOrder: ((?:[0-9A-F]{4},?)+)`)
@ -22,7 +21,8 @@ const execPath = "/usr/bin/efibootmgr"
type EfiApp struct { type EfiApp struct {
ID int ID int
Name string Name string
DevicePath string Path string
DiskID string
Active bool Active bool
} }
@ -49,15 +49,20 @@ func efiAppFromBootMgrOutput(rawVal string, activeId int) (app EfiApp, ok bool)
if !ok { if !ok {
return return
} }
devicePath, ok := result["device_path"] filepath, ok := result["filepath"]
if !ok {
return
}
disk_id, ok := result["disk_id"]
if !ok { if !ok {
return return
} }
return EfiApp{ return EfiApp{
ID: int(idInt), ID: int(idInt),
Name: strings.TrimSpace(name), Name: strings.TrimSpace(name),
DevicePath: strings.TrimSpace(devicePath), Path: strings.TrimSpace(filepath),
Active: int(idInt) == activeId, Active: int(idInt) == activeId,
DiskID: disk_id,
}, true }, true
} }

View file

@ -10,7 +10,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - Windows", func(t *testing.T) { t.Run("OK - Windows", func(t *testing.T) {
rawVal := (`Boot0000* Windows Boot Manager HD(1,GPT,4ad714ba-6a01-4f76-90e3-1bb93a59b67e,0x800,0x32000)/File(\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI)` + rawVal := (`Boot0000* Windows Boot Manager HD(1,GPT,4ad714ba-6a01-4f76-90e3-1bb93a59b67e,0x800,0x32000)/File(\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI)` +
`57494e444f5753000100000088000000780000004200430044004f0042004a004500430054003d007b00390064006500610038003600320063002d0035006300640064002d00`) `57494e444f5753000100000088000000780000004200430044004f0042004a004500430054003d007b00390064006500610038003600320063002d0035006300640064002d00`)
expected := EfiApp{ID: 0, Name: "Windows Boot Manager", DevicePath: `HD(1,GPT,4ad714ba-6a01-4f76-90e3-1bb93a59b67e,0x800,0x32000)/File(\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI)`, Active: true} expected := EfiApp{ID: 0, Name: "Windows Boot Manager", Path: `\EFI\MICROSOFT\BOOT\BOOTMGFW.EFI`, Active: true, DiskID: "4ad714ba-6a01-4f76-90e3-1bb93a59b67e"}
app, ok := efiAppFromBootMgrOutput(rawVal, 0) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) assert.Equal(t, expected, app)
@ -18,7 +18,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - Manjaro", func(t *testing.T) { t.Run("OK - Manjaro", func(t *testing.T) {
rawVal := `Boot0001* Manjaro HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\MANJARO\GRUBX64.EFI)` rawVal := `Boot0001* Manjaro HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\MANJARO\GRUBX64.EFI)`
expected := EfiApp{ID: 1, Name: "Manjaro", DevicePath: `HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\MANJARO\GRUBX64.EFI)`, Active: false} expected := EfiApp{ID: 1, Name: "Manjaro", Path: `\EFI\MANJARO\GRUBX64.EFI`, Active: false, DiskID: "16f06d01-50da-6544-86bd-f3457f980086"}
app, ok := efiAppFromBootMgrOutput(rawVal, 0) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) assert.Equal(t, expected, app)
@ -26,7 +26,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - SystemdBoot VM", func(t *testing.T) { t.Run("OK - SystemdBoot VM", func(t *testing.T) {
rawVal := `Boot0001* SYSTEMD_BOOT PciRoot(0x0)/Pci(0x1f,0x2)/Sata(0,65535,0)/HD(1,GPT,c4540877-4592-494f-bd8a-2a23abb22c3f,0x800,0x100000)/File(\EFI\systemd\systemd-bootx64.efi)` rawVal := `Boot0001* SYSTEMD_BOOT PciRoot(0x0)/Pci(0x1f,0x2)/Sata(0,65535,0)/HD(1,GPT,c4540877-4592-494f-bd8a-2a23abb22c3f,0x800,0x100000)/File(\EFI\systemd\systemd-bootx64.efi)`
expected := EfiApp{ID: 1, Name: "SYSTEMD_BOOT", DevicePath: `PciRoot(0x0)/Pci(0x1f,0x2)/Sata(0,65535,0)/HD(1,GPT,c4540877-4592-494f-bd8a-2a23abb22c3f,0x800,0x100000)/File(\EFI\systemd\systemd-bootx64.efi)`, Active: false} expected := EfiApp{ID: 1, Name: "SYSTEMD_BOOT", Path: `\EFI\systemd\systemd-bootx64.efi`, Active: false, DiskID: "c4540877-4592-494f-bd8a-2a23abb22c3f"}
app, ok := efiAppFromBootMgrOutput(rawVal, 0) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) assert.Equal(t, expected, app)
@ -34,7 +34,7 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - HTTP_BOOT hexa", func(t *testing.T) { t.Run("OK - HTTP_BOOT hexa", func(t *testing.T) {
rawVal := `Boot000A* httpboot.efi HD(1,GPT,c4540877-4592-494f-bd8a-2a23abb22c3f,0x800,0x100000)/File(\EFI\httpboot\httpboot.efi)` rawVal := `Boot000A* httpboot.efi HD(1,GPT,c4540877-4592-494f-bd8a-2a23abb22c3f,0x800,0x100000)/File(\EFI\httpboot\httpboot.efi)`
expected := EfiApp{ID: 10, Name: "httpboot.efi", DevicePath: `HD(1,GPT,c4540877-4592-494f-bd8a-2a23abb22c3f,0x800,0x100000)/File(\EFI\httpboot\httpboot.efi)`, Active: false} expected := EfiApp{ID: 10, Name: "httpboot.efi", Path: `\EFI\httpboot\httpboot.efi`, Active: false, DiskID: "c4540877-4592-494f-bd8a-2a23abb22c3f"}
app, ok := efiAppFromBootMgrOutput(rawVal, 0) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) assert.Equal(t, expected, app)
@ -42,18 +42,16 @@ func TestEfiFomBootMgr(t *testing.T) {
t.Run("OK - EFI Base", func(t *testing.T) { t.Run("OK - EFI Base", func(t *testing.T) {
rawVal := `Boot0002* UEFI OS HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\BOOT\BOOTX64.EFI)0000424f` rawVal := `Boot0002* UEFI OS HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\BOOT\BOOTX64.EFI)0000424f`
expected := EfiApp{ID: 2, Name: "UEFI OS", DevicePath: `HD(1,GPT,16f06d01-50da-6544-86bd-f3457f980086,0x1000,0x96000)/File(\EFI\BOOT\BOOTX64.EFI)`, Active: false} expected := EfiApp{ID: 2, Name: "UEFI OS", Path: `\EFI\BOOT\BOOTX64.EFI`, Active: false, DiskID: "16f06d01-50da-6544-86bd-f3457f980086"}
app, ok := efiAppFromBootMgrOutput(rawVal, 0) app, ok := efiAppFromBootMgrOutput(rawVal, 0)
assert.True(t, ok) assert.True(t, ok)
assert.Equal(t, expected, app) assert.Equal(t, expected, app)
}) })
t.Run("OK - CD", func(t *testing.T) { t.Run("NOK - CD", func(t *testing.T) {
rawVal := `Boot0003* UEFI:CD/DVD Drive BBS(129,,0x0)` rawVal := `Boot0003* UEFI:CD/DVD Drive BBS(129,,0x0)`
expected := EfiApp{ID: 3, Name: "UEFI:CD/DVD Drive", DevicePath: `BBS(129,,0x0)`, Active: false} _, ok := efiAppFromBootMgrOutput(rawVal, 0)
app, ok := efiAppFromBootMgrOutput(rawVal, 0) assert.False(t, ok)
assert.True(t, ok)
assert.Equal(t, expected, app)
}) })
t.Run("NOK - Other line", func(t *testing.T) { t.Run("NOK - Other line", func(t *testing.T) {

View file

@ -18,7 +18,8 @@ const enrollURL = "/enroll"
type enrollEFIOption struct { type enrollEFIOption struct {
Name string `json:"name"` Name string `json:"name"`
DevicePath string `json:"device_path"` Path string `json:"path"`
DiskID string `json:"disk_id"`
} }
type enrollPayload struct { type enrollPayload struct {
@ -46,7 +47,7 @@ func enrollToServer(ctx context.Context, host string, name string, apps []prober
} }
for _, a := range apps { for _, a := range apps {
appID := uuid.New() appID := uuid.New()
payload.Options[appID.String()] = enrollEFIOption{Name: a.Name, DevicePath: a.DevicePath} payload.Options[appID.String()] = enrollEFIOption{Name: a.Name, Path: a.Path, DiskID: a.DiskID}
if a.Active { if a.Active {
payload.SelectedOption = appID.String() payload.SelectedOption = appID.String()
} }