1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75
|
/* SPDX-License-Identifier: BSD-3-Clause */
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include "tools/fapi/tss2_template.h"
/* Context struct used to store passed command line parameters */
static struct cxt {
char const *path;
char const *description;
bool overwrite;
} ctx;
/* Parse command line parameters */
static bool on_option(char key, char *value) {
switch (key) {
case 'p':
ctx.path = value;
break;
case 'o':
ctx.description = value;
break;
case 'f':
ctx.overwrite = true;
break;
}
return true;
}
/* Define possible command line parameters */
static bool tss2_tool_onstart(tpm2_options **opts) {
struct option topts[] = {
{"path" , required_argument, NULL, 'p'},
{"description" , required_argument, NULL, 'o'},
{"force" , no_argument , NULL, 'f'},
};
return (*opts = tpm2_options_new ("o:fp:", ARRAY_LEN(topts), topts,
on_option, NULL, 0)) != NULL;
}
/* Execute specific tool */
static int tss2_tool_onrun (FAPI_CONTEXT *fctx) {
/* Check availability of required parameters */
if (!ctx.path) {
fprintf (stderr, "path is missing, use --path\n");
return -1;
}
if (!ctx.description) {
fprintf (stderr, "description is missing, use --description\n");
return -1;
}
/* Execute FAPI command with passed arguments */
char *description;
TSS2_RC r = Fapi_GetDescription (fctx, ctx.path, &description);
if (r != TSS2_RC_SUCCESS) {
LOG_PERR ("Fapi_GetDescription", r);
return 1;
}
/* Write returned data to file(s) */
r = open_write_and_close (ctx.description, ctx.overwrite, description,
strlen(description));
if (r){
Fapi_Free (description);
return 1;
}
Fapi_Free (description);
return 0;
}
TSS2_TOOL_REGISTER("getdescription", tss2_tool_onstart, tss2_tool_onrun, NULL)
|