Add token handler version function prototype.

Dynamicaly loaded token handlers should provide
version string for debug purposes.
This commit is contained in:
Ondrej Kozina
2021-01-26 12:37:31 +01:00
parent 10e4d8fbac
commit 6df3488654
3 changed files with 38 additions and 1 deletions

View File

@@ -184,6 +184,7 @@ struct crypt_token_handler_v2 {
/* here ends v1. Do not touch anything above */
crypt_token_open_pin_func open_pin;
crypt_token_version_func version;
void *dlhandle;
};

View File

@@ -77,6 +77,24 @@ static bool token_validate_v1(struct crypt_device *cd, const crypt_token_handler
return true;
}
#if USE_EXTERNAL_TOKENS
static bool token_validate_v2(struct crypt_device *cd, const struct crypt_token_handler_internal *h)
{
if (!h)
return false;
if (!token_validate_v1(cd, &h->u.v1))
return false;
if (!h->u.v2.version) {
log_dbg(cd, "Token handler does not provide " CRYPT_TOKEN_ABI_VERSION " function.");
return false;
}
return true;
}
#endif
static int
crypt_token_load_external(struct crypt_device *cd, const char *name, struct crypt_token_handler_internal *ret)
{
@@ -114,12 +132,19 @@ crypt_token_load_external(struct crypt_device *cd, const char *name, struct cryp
token->validate = token_dlvsym(cd, h, CRYPT_TOKEN_ABI_VALIDATE, CRYPT_TOKEN_ABI_VERSION1);
token->dump = token_dlvsym(cd, h, CRYPT_TOKEN_ABI_DUMP, CRYPT_TOKEN_ABI_VERSION1);
token->open_pin = token_dlvsym(cd, h, CRYPT_TOKEN_ABI_OPEN_PIN, CRYPT_TOKEN_ABI_VERSION1);
token->version = token_dlvsym(cd, h, CRYPT_TOKEN_ABI_VERSION, CRYPT_TOKEN_ABI_VERSION1);
if (!token_validate_v1(cd, &ret->u.v1)) {
if (!token_validate_v2(cd, ret)) {
r = -EINVAL;
goto err;
}
r = snprintf(buf, sizeof(buf), "%s", token->version() ?: "");
if (r < 0 || (size_t)r >= sizeof(buf))
*buf = '\0';
log_dbg(cd, "Token handler %s-%s loaded sucessfuly.", token->name, buf);
token->dlhandle = h;
ret->version = 2;