mirror of
https://gitlab.com/cryptsetup/cryptsetup.git
synced 2025-12-13 03:40:05 +01:00
Add token handler version function prototype.
Dynamicaly loaded token handlers should provide version string for debug purposes.
This commit is contained in:
@@ -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;
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user