int
main(int argc, char *argv[])
{
	GckModule *module;
	GError *error = NULL;
	GIOChannel *channel;
	GMainLoop *loop;
	gboolean ret;
	int sock;

	g_type_init ();

	if (!g_thread_supported ())
		g_thread_init (NULL);

	if (argc <= 1) {
		g_message ("specify pkcs11 module on the command line");
		return 1;
	}

	module = gck_module_initialize (argv[1], argc > 2 ? argv[2] : NULL, 0, &error);
	if (!module) {
		g_message ("couldn't load pkcs11 module: %s", egg_error_message (error));
		g_clear_error (&error);
		return 1;
	}


	g_signal_connect (module, "authenticate-slot", G_CALLBACK (authenticate_slot), NULL);
	g_signal_connect (module, "authenticate-object", G_CALLBACK (authenticate_object), NULL);

	ret = gkd_ssh_agent_initialize_with_module (module);
	g_object_unref (module);

	if (ret == FALSE)
		return 1;

	sock = gkd_ssh_agent_startup ("/tmp");
	if (sock == -1)
		return 1;

	channel = g_io_channel_unix_new (sock);
	g_io_add_watch (channel, G_IO_IN | G_IO_HUP, accept_client, NULL);
	g_io_channel_unref (channel);

	g_print ("SSH_AUTH_SOCK=%s\n", g_getenv ("SSH_AUTH_SOCK"));

	/* Run a main loop */
	loop = g_main_loop_new (NULL, FALSE);
	g_main_loop_run (loop);
	g_main_loop_unref (loop);

	gkd_ssh_agent_shutdown ();
	gkd_ssh_agent_uninitialize ();

	return 0;
}
Esempio n. 2
0
static void
test_invalid_modules (Test *test, gconstpointer unused)
{
	GckModule *invalid;
	GError *error = NULL;

	/* Shouldn't be able to load modules */
	invalid = gck_module_initialize ("blah-blah-non-existant", NULL, &error);
	g_assert_error (error, GCK_ERROR, (int)CKR_GCK_MODULE_PROBLEM);
	g_assert (invalid == NULL);

	g_clear_error (&error);

	/* Shouldn't be able to load any file successfully */
	invalid = gck_module_initialize ("/usr/lib/libm.so", NULL, &error);
	g_assert_error (error, GCK_ERROR, (int)CKR_GCK_MODULE_PROBLEM);
	g_assert (invalid == NULL);

	g_clear_error (&error);
}
Esempio n. 3
0
static void
setup (Test *test, gconstpointer unused)
{
	GError *err = NULL;

	/* Successful load */
	test->module = gck_module_initialize (BUILDDIR "/.libs/libmock-test-module.so", NULL, &err);
	g_assert_no_error (err);
	g_assert (test->module);
	g_object_add_weak_pointer (G_OBJECT (test->module), (gpointer *)&test->module);
}