composefs: Hard error except on ENOENT even in "optional" case

Since we enabled composefs at build time, the default (non-composefs)
case now always prints
`composefs: Optional support failed: No such file or directory`
But that's normal and expected.

Rework things here so that in the very special case where
we are in "maybe/optional" mode and we get ENOENT, then we
output a much more normal-looking message that doesn't include
the string "failed".

Now on the flip side - if I have explicitly enabled signature
checking, I think we *do* want to make that fatal even if
composefs is in "maybe" mode.

(This part is more debatable; perhaps we should just disallow
 the case of "maybe" + signatures at all; but I think this is
 an improvement in that direction)
This commit is contained in:
Colin Walters 2023-08-21 17:19:35 -04:00
parent e952b1bf14
commit 38880bff01

View File

@ -264,6 +264,24 @@ validate_signature (GBytes *data, GVariant *signatures, GPtrArray *pubkeys)
return FALSE;
}
// Output a friendly message based on an errno for common cases
static const char *
composefs_error_message (int errsv)
{
switch (errsv)
{
case ENOVERITY:
return "fsverity not enabled on composefs image";
case EWRONGVERITY:
return "Wrong fsverity digest in composefs image";
case ENOSIGNATURE:
return "Missing signature for fsverity in composefs image";
default:
return strerror (errsv);
}
}
#endif
typedef struct
@ -495,29 +513,14 @@ main (int argc, char *argv[])
else
{
int errsv = errno;
const char *errmsg;
switch (errsv)
g_assert (composefs_config->enabled != OT_TRISTATE_NO);
if (composefs_config->enabled == OT_TRISTATE_MAYBE && errsv == ENOENT)
{
case ENOVERITY:
errmsg = "fsverity not enabled on composefs image";
break;
case EWRONGVERITY:
errmsg = "Wrong fsverity digest in composefs image";
break;
case ENOSIGNATURE:
errmsg = "Missing signature for fsverity in composefs image";
break;
default:
errmsg = strerror (errno);
break;
}
if (composefs_config->enabled == OT_TRISTATE_MAYBE)
{
g_print ("composefs: optional support failed: %s\n", errmsg);
g_print ("composefs: No image present\n");
}
else
{
g_assert (composefs_config->enabled == OT_TRISTATE_YES);
const char *errmsg = composefs_error_message (errsv);
errx (EXIT_FAILURE, "composefs: failed to mount: %s", errmsg);
}
}