summaryrefslogtreecommitdiff
path: root/p11-kit/p11-kit.c
diff options
context:
space:
mode:
Diffstat (limited to 'p11-kit/p11-kit.c')
-rw-r--r--p11-kit/p11-kit.c58
1 files changed, 30 insertions, 28 deletions
diff --git a/p11-kit/p11-kit.c b/p11-kit/p11-kit.c
index 34b9476..da9d400 100644
--- a/p11-kit/p11-kit.c
+++ b/p11-kit/p11-kit.c
@@ -41,6 +41,7 @@
#include <assert.h>
#include <ctype.h>
+#include <errno.h>
#include <getopt.h>
#include <string.h>
#include <stdio.h>
@@ -52,7 +53,7 @@
int p11_kit_list_modules (int argc,
char *argv[]);
-int p11_kit_extract (int argc,
+int p11_kit_trust (int argc,
char *argv[]);
int p11_kit_external (int argc,
@@ -60,61 +61,62 @@ int p11_kit_external (int argc,
static const p11_tool_command commands[] = {
{ "list-modules", p11_kit_list_modules, "List modules and tokens" },
- { "extract", p11_kit_extract, "Extract certificates and trust" },
- { P11_TOOL_FALLBACK, p11_kit_external, "List modules and tokens" },
+ { P11_TOOL_FALLBACK, p11_kit_external, NULL },
{ 0, }
};
int
-p11_kit_external (int argc,
- char *argv[])
+p11_kit_trust (int argc,
+ char *argv[])
{
- char *filename;
- char *path;
+ char **args;
- if (!asprintf (&filename, "p11-kit-%s", argv[0]) < 0)
- return_val_if_reached (1);
+ args = calloc (argc + 2, sizeof (char *));
+ return_val_if_fail (args != NULL, 1);
- /* Add our libexec directory to the path */
- path = p11_path_build (PRIVATEDIR, filename, NULL);
- return_val_if_fail (path != NULL, 1);
+ args[0] = BINDIR "/trust";
+ memcpy (args + 1, argv, sizeof (char *) * argc);
+ args[argc + 1] = NULL;
- argv[argc] = NULL;
- execv (path, argv);
+ execv (args[0], args);
/* At this point we have no command */
- p11_message ("'%s' is not a valid command. See 'p11-kit --help'", argv[0]);
+ p11_message_err (errno, "couldn't run trust tool");
- free (filename);
- free (path);
+ free (args);
return 2;
}
int
-p11_kit_extract (int argc,
- char *argv[])
+p11_kit_external (int argc,
+ char *argv[])
{
+ char *filename;
char *path;
- char **args;
- args = calloc (argc + 2, sizeof (char *));
- return_val_if_fail (args != NULL, 1);
+ /* These are trust commands, send them to that tool */
+ if (strcmp (argv[0], "extract") == 0) {
+ return p11_kit_trust (argc, argv);
+ } else if (strcmp (argv[0], "extract-trust") == 0) {
+ argv[0] = "extract-compat";
+ return p11_kit_trust (argc, argv);
+ }
- args[0] = "trust";
- memcpy (args + 1, argv, sizeof (char *) * argc);
- args[argc + 1] = NULL;
+ if (!asprintf (&filename, "p11-kit-%s", argv[0]) < 0)
+ return_val_if_reached (1);
/* Add our libexec directory to the path */
- path = p11_path_build (BINDIR, args[0], NULL);
+ path = p11_path_build (PRIVATEDIR, filename, NULL);
return_val_if_fail (path != NULL, 1);
- execv (path, args);
+ argv[argc] = NULL;
+ execv (path, argv);
/* At this point we have no command */
p11_message ("'%s' is not a valid command. See 'p11-kit --help'", argv[0]);
+ free (filename);
free (path);
- free (args);
return 2;
}