summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--session-helper/flatpak-session-helper.c117
1 files changed, 64 insertions, 53 deletions
diff --git a/session-helper/flatpak-session-helper.c b/session-helper/flatpak-session-helper.c
index 52d2829d..5c1b12d0 100644
--- a/session-helper/flatpak-session-helper.c
+++ b/session-helper/flatpak-session-helper.c
@@ -607,6 +607,67 @@ message_handler (const gchar *log_domain,
g_printerr ("%s: %s\n", g_get_prgname (), message);
}
+static void
+start_p11_kit_server (const char *flatpak_dir)
+{
+ g_autofree char *socket_basename = g_strdup_printf ("pkcs11-flatpak-%d", getpid ());
+ g_autofree char *socket_path = g_build_filename (flatpak_dir, socket_basename, NULL);
+ g_autofree char *p11_kit_stdout = NULL;
+ gint exit_status;
+ g_autoptr(GError) local_error = NULL;
+ g_auto(GStrv) stdout_lines = NULL;
+ int i;
+ char *p11_argv[] =
+ {
+ "p11-kit", "server",
+ "-n", socket_path,
+ "--provider", "p11-kit-trust.so",
+ "pkcs11:model=p11-kit-trust?write-protected=yes",
+ NULL
+ };
+
+ g_debug ("starting p11-kit server");
+
+ if (!g_spawn_sync (NULL,
+ p11_argv, NULL, G_SPAWN_SEARCH_PATH,
+ NULL, NULL,
+ &p11_kit_stdout, NULL,
+ &exit_status, &local_error))
+ {
+ g_warning ("Unable to start p11-kit server: %s\n", local_error->message);
+ return;
+ }
+
+ if (exit_status != 0)
+ {
+ g_warning ("Unable to start p11-kit server, exited with status %d\n", exit_status);
+ return;
+ }
+
+ stdout_lines = g_strsplit (p11_kit_stdout, "\n", 0);
+ /* Output is something like:
+ P11_KIT_SERVER_ADDRESS=unix:path=/run/user/1000/p11-kit/pkcs11-2603742; export P11_KIT_SERVER_ADDRESS;
+ P11_KIT_SERVER_PID=2603743; export P11_KIT_SERVER_PID;
+ */
+ for (i = 0; stdout_lines[i] != NULL; i++)
+ {
+ char *line = stdout_lines[i];
+
+ if (g_str_has_prefix (line, "P11_KIT_SERVER_PID="))
+ {
+ char *pid = line + strlen ("P11_KIT_SERVER_PID=");
+ char *p = pid;
+ while (g_ascii_isdigit (*p))
+ p++;
+
+ *p = 0;
+ p11_kit_server_pid = atol (pid);
+ }
+ }
+
+ p11_kit_server_socket_path = g_steal_pointer (&socket_path);
+}
+
int
main (int argc,
char **argv)
@@ -693,59 +754,9 @@ main (int argc,
}
if (g_find_program_in_path ("p11-kit"))
- {
- g_autofree char *socket_basename = g_strdup_printf ("pkcs11-flatpak-%d", getpid ());
- g_autofree char *socket_path = g_build_filename (flatpak_dir, socket_basename, NULL);
- g_autofree char *p11_kit_stdout = NULL;
- gint exit_status;
- g_autoptr(GError) local_error = NULL;
- char *p11_argv[] = {
- "p11-kit", "server",
- "-n", socket_path,
- "--provider", "p11-kit-trust.so",
- "pkcs11:model=p11-kit-trust?write-protected=yes",
- NULL
- };
- if (!g_spawn_sync (NULL,
- p11_argv, NULL, G_SPAWN_SEARCH_PATH,
- NULL, NULL,
- &p11_kit_stdout, NULL,
- &exit_status, &local_error))
- {
- g_warning ("Unable to start p11-kit server: %s\n", local_error->message);
- }
- else if (exit_status != 0)
- {
- g_warning ("Unable to start p11-kit server, exited with status %d\n", exit_status);
- }
- else
- {
- g_auto(GStrv) stdout_lines = g_strsplit (p11_kit_stdout, "\n", 0);
- int i;
-
- /* Output is something like:
- P11_KIT_SERVER_ADDRESS=unix:path=/run/user/1000/p11-kit/pkcs11-2603742; export P11_KIT_SERVER_ADDRESS;
- P11_KIT_SERVER_PID=2603743; export P11_KIT_SERVER_PID;
- */
- for (i = 0; stdout_lines[i] != NULL; i++)
- {
- char *line = stdout_lines[i];
-
- if (g_str_has_prefix (line, "P11_KIT_SERVER_PID="))
- {
- char *pid = line + strlen ("P11_KIT_SERVER_PID=");
- char *p = pid;
- while (g_ascii_isdigit (*p))
- p++;
-
- *p = 0;
- p11_kit_server_pid = atol (pid);
- }
- }
-
- p11_kit_server_socket_path = g_steal_pointer (&socket_path);
- }
- }
+ start_p11_kit_server (flatpak_dir);
+ else
+ g_debug ("p11-kit not found");
monitor_dir = g_build_filename (flatpak_dir, "monitor", NULL);
if (g_mkdir_with_parents (monitor_dir, 0700) != 0)