]> git.proxmox.com Git - swtpm.git/commitdiff
swtpm: Add --print-capabilities option to command line
authorStefan Berger <stefanb@linux.vnet.ibm.com>
Mon, 24 Jun 2019 17:41:02 +0000 (13:41 -0400)
committerStefan Berger <stefanb@us.ibm.com>
Fri, 12 Jul 2019 18:18:20 +0000 (14:18 -0400)
Signed-off-by: Stefan Berger <stefanb@linux.ibm.com>
src/swtpm/cuse_tpm.c
src/swtpm/swtpm.c
src/swtpm/swtpm_chardev.c

index 3aae40fff4873bab437087c96cd75cd1199ffa64..379386b3d0892b2ccbd78b4083a6de0aca9a4c91 100644 (file)
@@ -80,6 +80,8 @@
 #include "utils.h"
 #include "threadpool.h"
 #include "seccomp_profile.h"
+#include "options.h"
+#include "capabilities.h"
 
 /* maximum size of request buffer */
 #define TPM_REQ_MAX 4096
@@ -233,6 +235,7 @@ static const char *usage =
 "                    :  Choose the action of the seccomp profile when a\n"
 "                       blacklisted syscall is executed; default is kill\n"
 #endif
+"--print-capabilites : print capabilities and terminate\n"
 "-h|--help           :  display this help screen and terminate\n"
 "\n";
 
@@ -1401,6 +1404,8 @@ int swtpm_cuse_main(int argc, char **argv, const char *prgname, const char *ifac
 #ifdef WITH_SECCOMP
         {"seccomp"       , required_argument, 0, 'S'},
 #endif
+        {"print-capabilities"
+                         ,       no_argument, 0, 'a'},
         {NULL            , 0                , 0, 0  },
     };
     struct cuse_info cinfo;
@@ -1503,6 +1508,9 @@ int swtpm_cuse_main(int argc, char **argv, const char *prgname, const char *ifac
         case 'h': /* help */
             fprintf(stdout, usage, prgname, iface);
             goto exit;
+        case 'a':
+            ret = capabilities_print_json(true);
+            goto exit;
         case 'v': /* version */
             fprintf(stdout, "TPM emulator CUSE interface version %d.%d.%d, "
                     "Copyright (c) 2014-2015 IBM Corp.\n",
index ea63ebffe282f4b3d472fb9b4d3b3d550ea74d57..3ecbb7b2f91cbbd56afd6f736b73eaa0993ec1a8 100644 (file)
@@ -74,6 +74,8 @@
 #include "sys_dependencies.h"
 #include "osx.h"
 #include "seccomp_profile.h"
+#include "options.h"
+#include "capabilities.h"
 
 /* local variables */
 static int notify_fd[2] = {-1, -1};
@@ -184,6 +186,8 @@ static void usage(FILE *file, const char *prgname, const char *iface)
     "                 : Choose the action of the seccomp profile when a\n"
     "                   blacklisted syscall is executed; default is kill\n"
 #endif
+    "--print-capabilites\n"
+    "                 : print capabilities and terminate\n"
     "-h|--help        : display this help screen and terminate\n"
     "\n",
     prgname, iface);
@@ -202,7 +206,7 @@ int swtpm_main(int argc, char **argv, const char *prgname, const char *iface)
 {
     TPM_RESULT rc = 0;
     int daemonize = FALSE;
-    int opt, longindex;
+    int opt, longindex, ret;
     struct stat statbuf;
     struct mainLoopParams mlp = {
         .cc = NULL,
@@ -251,6 +255,8 @@ int swtpm_main(int argc, char **argv, const char *prgname, const char *iface)
 #ifdef WITH_SECCOMP
         {"seccomp"   , required_argument, 0, 'S'},
 #endif
+        {"print-capabilities"
+                     ,       no_argument, 0, 'a'},
         {NULL        , 0                , 0, 0  },
     };
 
@@ -368,6 +374,10 @@ int swtpm_main(int argc, char **argv, const char *prgname, const char *iface)
             usage(stdout, prgname, iface);
             exit(EXIT_SUCCESS);
 
+        case 'a':
+            ret = capabilities_print_json(false);
+            exit(ret ? EXIT_FAILURE : EXIT_SUCCESS);
+
         case 'r':
             runas = optarg;
             break;
index d0c70e3adc62ba3843e3fbcb6c901db680576411..62786210ccbd3d756c44288f71759210b5cc18b9 100644 (file)
@@ -76,6 +76,8 @@
 #include "tpmstate.h"
 #include "osx.h"
 #include "seccomp_profile.h"
+#include "options.h"
+#include "capabilities.h"
 
 /* local variables */
 static int notify_fd[2] = {-1, -1};
@@ -222,7 +224,7 @@ int swtpm_chardev_main(int argc, char **argv, const char *prgname, const char *i
 {
     TPM_RESULT rc = 0;
     int daemonize = FALSE;
-    int opt, longindex;
+    int opt, longindex, ret;
     struct stat statbuf;
     struct mainLoopParams mlp = {
         .cc = NULL,
@@ -272,6 +274,8 @@ int swtpm_chardev_main(int argc, char **argv, const char *prgname, const char *i
 #ifdef WITH_SECCOMP
         {"seccomp"   , required_argument, 0, 'S'},
 #endif
+        {"print-capabilities"
+                     ,       no_argument, 0, 'a'},
         {NULL        , 0                , 0, 0  },
     };
 
@@ -374,6 +378,10 @@ int swtpm_chardev_main(int argc, char **argv, const char *prgname, const char *i
             usage(stdout, prgname, iface);
             exit(EXIT_SUCCESS);
 
+        case 'a':
+            ret = capabilities_print_json(false);
+            exit(ret ? EXIT_FAILURE : EXIT_SUCCESS);
+
         case 'r':
             runas = optarg;
             break;