tss2_setdescription.c 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. /* SPDX-License-Identifier: BSD-3-Clause */
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include "tools/fapi/tss2_template.h"
  5. /* Context struct used to store passed command line parameters */
  6. static struct cxt {
  7. char const *path;
  8. char const *description;
  9. } ctx;
  10. /* Parse command line parameters */
  11. static bool on_option(char key, char *value) {
  12. switch (key) {
  13. case 'i':
  14. if (value && strlen (value) > 1023) {
  15. fprintf (stderr, "The description can be at most 1023 octets\n");
  16. return false;
  17. }
  18. ctx.description = value;
  19. break;
  20. case 'p':
  21. ctx.path = value;
  22. break;
  23. }
  24. return true;
  25. }
  26. /* Define possible command line parameters */
  27. static bool tss2_tool_onstart(tpm2_options **opts) {
  28. struct option topts[] = {
  29. {"description", required_argument, NULL, 'i'},
  30. {"path" , required_argument, NULL, 'p'}
  31. };
  32. return (*opts = tpm2_options_new ("i:p:", ARRAY_LEN(topts), topts,
  33. on_option, NULL, 0)) != NULL;
  34. }
  35. /* Execute specific tool */
  36. static int tss2_tool_onrun (FAPI_CONTEXT *fctx) {
  37. /* Check availability of required parameters */
  38. if (!ctx.path) {
  39. fprintf (stderr, "path is missing, use --path\n");
  40. return -1;
  41. }
  42. /* Execute FAPI command with passed arguments */
  43. TSS2_RC r = Fapi_SetDescription (fctx, ctx.path, ctx.description);
  44. if (r != TSS2_RC_SUCCESS){
  45. LOG_PERR ("Fapi_SetDescription", r);
  46. return 1;
  47. }
  48. return 0;
  49. }
  50. TSS2_TOOL_REGISTER("setdescription", tss2_tool_onstart, tss2_tool_onrun, NULL)