Commit Graph

15 Commits

Author SHA1 Message Date
Morten Linderud ac8723dacd
util: Ensure we ignore when files do not exist in efivarfs
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-02 21:55:37 +02:00
Morten Linderud 0781f6bb98
sbctl/create-keys: Move up the GUID logic
We also make a helper for creating directories in a proper way

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-06-02 21:55:37 +02:00
Morten Linderud 57a1c93eb9
Remove last of the log.* stuff
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:47:45 +02:00
Morten Linderud 8b4fc40724
Added internal functions for checked paths, and CheckMSDos
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:08 +02:00
Morten Linderud 97435cc48e
More internal restructuring
Move more logic top-level, move prints to top-level

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:46:07 +02:00
Morten Linderud bb78cf9c01
Remove previous logging, improve error bubling
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-30 14:43:04 +02:00
igo95862 d3feae2791
Remove ioutil
Deprecated in GO 1.16
2021-05-16 21:14:42 +03:00
Morten Linderud f53632ebd2
util: Expand array in print generator
Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-05-13 12:34:19 +02:00
Morten Linderud 59ec7a813f
sbctl: IsImmutable should return false if the file does not exist
Weird efivarfs quirk is that sometimes empty vars have no file. This
means they are not immutable and we can write to them.

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-04-18 03:29:29 +02:00
Morten Linderud 2572b38a8e
sbctl: Check for immutable files before sbkeysync
This allows us to give a sensible error for `enroll-keys` if the files
are set as immutable.

    $ sbctl enroll-keys
    ==> ERROR: File is immutable: /sys/firmware/efi/efivars/PK-8be4df61-93ca-11d2-aa0d-00e098032b8c
    ==> ERROR: File is immutable: /sys/firmware/efi/efivars/KEK-8be4df61-93ca-11d2-aa0d-00e098032b8c
    ==> ERROR: File is immutable: /sys/firmware/efi/efivars/db-d719b2cb-3d3a-4596-a3bc-dad00e67656f
    ==> ERROR: You need to chattr -i files in efivarfs

Signed-off-by: Morten Linderud <morten@linderud.pw>
2021-04-03 12:27:44 +02:00
Érico Rolim cc55d6e443 Add ReadOrCreateFile utility function.
This function will try to read a file into a byte buffer, and, if the
file doesn't exist, create its containing directory and the file itself.
If any of those actions fail due to permissions, the function will print
a warning about running the tool as root.

Reading from the file and bundle databases works like this, so the error
checking should be implemented in a single place.

Also, use the new function in ReadFileDatabase().

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
2021-01-11 00:49:45 -03:00
Érico Rolim 0a7c6e8bc5 Fix potential seg fault in ChecksumFile.
If ReadFile errors out, the error would only be checked after the
function attempts to read the buffer into the hasher. This commit fixes
that, checking the error as soon as possible.

Signed-off-by: Érico Rolim <erico.erc@gmail.com>
2021-01-11 00:43:21 -03:00
Érico Rolim 2b09a8e645
Change PrintGenerateError signature.
This avoid boilerplate calls to fmt.Sprintf in the main code.
2020-07-25 18:12:42 +02:00
Érico Rolim ed103661f0
Create PrintGenerateError and use it where possible.
It's a function for generating an error from a message and still
printing it. Helps in avoiding duplication.
2020-07-25 18:12:41 +02:00
Morten Linderud 82a0bcaf88
sbctl: forgot ChecksumFile
Signed-off-by: Morten Linderud <morten@linderud.pw>
2020-07-10 00:52:58 +02:00