tpm2_policyrestart.c 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. #include "log.h"
  3. #include "tpm2_tool.h"
  4. #include "tpm2_options.h"
  5. typedef struct tpm2_policyreset_ctx tpm2_policyreset_ctx;
  6. struct tpm2_policyreset_ctx {
  7. char *path;
  8. tpm2_session *session;
  9. };
  10. static tpm2_policyreset_ctx ctx;
  11. static bool on_option(char key, char *value) {
  12. switch (key) {
  13. case 'S':
  14. ctx.path = value;
  15. break;
  16. }
  17. return true;
  18. }
  19. static bool tpm2_tool_onstart(tpm2_options **opts) {
  20. static struct option topts[] = {
  21. { "session", required_argument, NULL, 'S' },
  22. };
  23. *opts = tpm2_options_new("S:", ARRAY_LEN(topts), topts, on_option,
  24. NULL, 0);
  25. return *opts != NULL;
  26. }
  27. static tool_rc tpm2_tool_onrun(ESYS_CONTEXT *ectx, tpm2_option_flags flags) {
  28. UNUSED(flags);
  29. tool_rc rc = tpm2_session_restore(ectx, ctx.path, false, &ctx.session);
  30. if (rc != tool_rc_success) {
  31. return rc;
  32. }
  33. return tpm2_session_restart(ectx, ctx.session);
  34. }
  35. static tool_rc tpm2_tool_onstop(ESYS_CONTEXT *ectx) {
  36. UNUSED(ectx);
  37. return tpm2_session_close(&ctx.session);
  38. }
  39. // Register this tool with tpm2_tool.c
  40. TPM2_TOOL_REGISTER("policyrestart", tpm2_tool_onstart, tpm2_tool_onrun, tpm2_tool_onstop, NULL)