106 lines
2.4 KiB
Diff
106 lines
2.4 KiB
Diff
|
commit 08e7fbbfec644406b5f6f3ce787444bc5e2c4b3d
|
||
|
Author: Gary Ching-Pang Lin <glin@suse.com>
|
||
|
Date: Fri Mar 29 12:12:00 2013 +0800
|
||
|
|
||
|
Make the error message more understandable
|
||
|
|
||
|
diff --git a/src/efilib.c b/src/efilib.c
|
||
|
index cb1aca6..1b72cd9 100644
|
||
|
--- a/src/efilib.c
|
||
|
+++ b/src/efilib.c
|
||
|
@@ -5,6 +5,7 @@
|
||
|
#include <string.h>
|
||
|
#include <stdio.h>
|
||
|
#include <stdlib.h>
|
||
|
+#include <errno.h>
|
||
|
#include "efi.h"
|
||
|
|
||
|
#define SYSFS_DIR_EFI_VARS "/sys/firmware/efi/efivars"
|
||
|
@@ -95,7 +96,9 @@ read_variable (efi_variable_t *var)
|
||
|
snprintf (filename, PATH_MAX-1, "%s/%s", SYSFS_DIR_EFI_VARS, name);
|
||
|
fd = open (filename, O_RDONLY);
|
||
|
if (fd == -1) {
|
||
|
- return EFI_NOT_FOUND;
|
||
|
+ if (errno == ENOENT)
|
||
|
+ return EFI_NOT_FOUND;
|
||
|
+ return EFI_INVALID_PARAMETER;
|
||
|
}
|
||
|
|
||
|
if (fstat (fd, &buf) != 0) {
|
||
|
diff --git a/src/mokutil.c b/src/mokutil.c
|
||
|
index 27ebf09..3f89db2 100644
|
||
|
--- a/src/mokutil.c
|
||
|
+++ b/src/mokutil.c
|
||
|
@@ -236,14 +236,20 @@ static int
|
||
|
list_enrolled_keys ()
|
||
|
{
|
||
|
efi_variable_t var;
|
||
|
+ efi_status_t status;
|
||
|
int ret;
|
||
|
|
||
|
memset (&var, 0, sizeof(var));
|
||
|
var.VariableName = "MokListRT";
|
||
|
-
|
||
|
var.VendorGuid = SHIM_LOCK_GUID;
|
||
|
|
||
|
- if (read_variable (&var) != EFI_SUCCESS) {
|
||
|
+ status = read_variable (&var);
|
||
|
+ if (status != EFI_SUCCESS) {
|
||
|
+ if (status == EFI_NOT_FOUND) {
|
||
|
+ printf ("MokListRT is empty\n");
|
||
|
+ return 0;
|
||
|
+ }
|
||
|
+
|
||
|
fprintf (stderr, "Failed to read MokListRT\n");
|
||
|
return -1;
|
||
|
}
|
||
|
@@ -258,14 +264,20 @@ static int
|
||
|
list_new_keys ()
|
||
|
{
|
||
|
efi_variable_t var;
|
||
|
+ efi_status_t status;
|
||
|
int ret;
|
||
|
|
||
|
memset (&var, 0, sizeof(var));
|
||
|
var.VariableName = "MokNew";
|
||
|
-
|
||
|
var.VendorGuid = SHIM_LOCK_GUID;
|
||
|
|
||
|
- if (read_variable (&var) != EFI_SUCCESS) {
|
||
|
+ status = read_variable (&var);
|
||
|
+ if (status != EFI_SUCCESS) {
|
||
|
+ if (status == EFI_NOT_FOUND) {
|
||
|
+ printf ("No MOK new key request\n");
|
||
|
+ return 0;
|
||
|
+ }
|
||
|
+
|
||
|
fprintf (stderr, "Failed to read MokNew\n");
|
||
|
return -1;
|
||
|
}
|
||
|
@@ -812,6 +824,7 @@ static int
|
||
|
export_moks ()
|
||
|
{
|
||
|
efi_variable_t var;
|
||
|
+ efi_status_t status;
|
||
|
char filename[PATH_MAX];
|
||
|
uint32_t mok_num;
|
||
|
MokListNode *list;
|
||
|
@@ -822,10 +835,15 @@ export_moks ()
|
||
|
|
||
|
memset (&var, 0, sizeof(var));
|
||
|
var.VariableName = "MokListRT";
|
||
|
-
|
||
|
var.VendorGuid = SHIM_LOCK_GUID;
|
||
|
|
||
|
- if (read_variable (&var) != EFI_SUCCESS) {
|
||
|
+ status = read_variable (&var);
|
||
|
+ if (status != EFI_SUCCESS) {
|
||
|
+ if (status == EFI_NOT_FOUND) {
|
||
|
+ printf ("MokListRT is empty\n");
|
||
|
+ return 0;
|
||
|
+ }
|
||
|
+
|
||
|
fprintf (stderr, "Failed to read MokListRT\n");
|
||
|
return -1;
|
||
|
}
|