summaryrefslogtreecommitdiff
path: root/daemon/gkd-glue.c
blob: 44ee21365e785bac6aec89e22ce0a6c4a0fa1617 (plain)
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
/*
 * gnome-keyring
 *
 * Copyright (C) 2010 Stefan Walter
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful, but
 * WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this program; if not, see
 * <http://www.gnu.org/licenses/>.
 */

#include "config.h"

#include "gkd-glue.h"
#include "gkd-util.h"

#include "ssh-agent/gkd-ssh-agent-service.h"
#include "ssh-agent/gkd-ssh-agent-interaction.h"

#include "egg/egg-cleanup.h"

static void
pkcs11_ssh_cleanup (gpointer data)
{
	GkdSshAgentService *service = GKD_SSH_AGENT_SERVICE (data);
	gkd_ssh_agent_service_stop (service);
	g_object_unref (service);
}

gboolean
gkd_daemon_startup_ssh (void)
{
	const gchar *base_dir;
	GTlsInteraction *interaction;
	GkdSshAgentPreload *preload;
	GkdSshAgentService *service;

	base_dir = gkd_util_get_master_directory ();
	g_return_val_if_fail (base_dir, FALSE);

	interaction = gkd_ssh_agent_interaction_new (NULL);
	preload = gkd_ssh_agent_preload_new ("~/.ssh");

	service = gkd_ssh_agent_service_new (base_dir, interaction, preload);
	g_object_unref (interaction);
	g_object_unref (preload);

	if (!gkd_ssh_agent_service_start (service))
		return FALSE;

	/* ssh-agent sets the environment variable */
	gkd_util_push_environment ("SSH_AUTH_SOCK", g_getenv ("SSH_AUTH_SOCK"));

	egg_cleanup_register (pkcs11_ssh_cleanup, service);

	return TRUE;
}