Skip to content

Commit

Permalink
tpm2: Implement RuntimeAttributesGet to print out attributes
Browse files Browse the repository at this point in the history
Signed-off-by: Stefan Berger <[email protected]>
  • Loading branch information
stefanberger committed Sep 3, 2024
1 parent e197df6 commit 38a2ad9
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
53 changes: 53 additions & 0 deletions src/tpm2/RuntimeAttributes.c
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
#include "tpm_library_intern.h"

#define ATTR_SEPARATOR_C ','
#define ATTR_SEPARATOR_STR ","

static const struct {
const char *name;
Expand Down Expand Up @@ -177,6 +178,58 @@ RuntimeAttributesSwitchProfile(struct RuntimeAttributes *RuntimeAttributes,
return retVal;
}

LIB_EXPORT char *
RuntimeAttributesGet(struct RuntimeAttributes *RuntimeAttributes,
enum RuntimeAttributeType rat)
{
char *buffer, *nbuffer = NULL;
bool first = true;
size_t idx;
int n;

buffer = strdup("\"");
if (!buffer)
return NULL;

for (idx = 0; idx < ARRAY_SIZE(s_AttributeProperties); idx++) {
switch (rat) {
case RUNTIME_ATTR_IMPLEMENTED:
// no filter
break;
case RUNTIME_ATTR_CAN_BE_DISABLED:
// all of them can be disabled
break;
case RUNTIME_ATTR_ENABLED:
// skip over disabled ones
if (!TEST_BIT(idx, RuntimeAttributes->enabledAttributesPrint))
continue;
break;
case RUNTIME_ATTR_DISABLED:
// skip over enabled ones
if (TEST_BIT(idx, RuntimeAttributes->enabledAttributesPrint))
continue;
break;
default:
continue;
}
n = asprintf(&nbuffer, "%s%s%s",
buffer ? buffer : "",
first ? "" : ATTR_SEPARATOR_STR,
s_AttributeProperties[idx].name);
free(buffer);
if (n < 0)
return NULL;

buffer = nbuffer;
first = false;
}

n = asprintf(&nbuffer, "%s\"", buffer);
free(buffer);

return nbuffer;
}

LIB_EXPORT BOOL
RuntimeAttributeCheckRequired(struct RuntimeAttributes *RuntimeAttributes,
unsigned int attributeFlags)
Expand Down
13 changes: 13 additions & 0 deletions src/tpm2/RuntimeAttributes_fp.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,19 @@ RuntimeAttributesSwitchProfile(struct RuntimeAttributes *RuntimeAttributes,
unsigned int maxStateFormatLevel,
char **oldProfile);

enum RuntimeAttributeType {
RUNTIME_ATTR_IMPLEMENTED,
RUNTIME_ATTR_ENABLED,
RUNTIME_ATTR_DISABLED,
RUNTIME_ATTR_CAN_BE_DISABLED,

RUNTIME_ATTR_NUM, /* keep last */
};

char *
RuntimeAttributesGet(struct RuntimeAttributes *RuntimeAttribute,
enum RuntimeAttributeType rat);

BOOL
RuntimeAttributeCheckRequired(struct RuntimeAttributes *RuntimeAttributes,
unsigned int attributeFlags);
Expand Down

0 comments on commit 38a2ad9

Please sign in to comment.