gboolean gkd_pkcs11_startup_ssh (void) { GIOChannel *channel; const gchar *base_dir; int sock; base_dir = gkd_util_get_master_directory (); g_return_val_if_fail (base_dir, FALSE); sock = gkd_ssh_agent_startup (base_dir); if (sock == -1) return FALSE; channel = g_io_channel_unix_new (sock); g_io_add_watch (channel, G_IO_IN | G_IO_HUP, accept_ssh_client, NULL); g_io_channel_unref (channel); /* gkm-ssh-agent sets the environment variable */ gkd_util_push_environment ("SSH_AUTH_SOCK", g_getenv ("SSH_AUTH_SOCK")); egg_cleanup_register (pkcs11_ssh_cleanup, NULL); return TRUE; }
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; }