+
+#ifdef SILC_PLUGIN
+ if ((argc < 4) && (strcasecmp(argv[1], "passphrase-change") == 0)) {
+#else
+ if (strcmp(opt->longName, "passphrase-change") == 0) {
+#endif
+ /* Change the passphrase of the private key file */
+#ifdef SILC_PLUGIN
+ CREATE_KEY_REC *rec;
+
+ rec = g_new0(CREATE_KEY_REC, 1);
+ rec->file = g_strdup((argc == 3 ? argv[2] : privkey));
+
+ keyboard_entry_redirect((SIGNAL_FUNC) change_private_key_passphrase,
+ format_get_text("fe-common/silc", NULL, NULL,
+ NULL, SILCTXT_CONFIG_PASS_ASK1),
+ ENTRY_REDIRECT_FLAG_HIDDEN, rec);
+ goto out;
+#else
+ silc_cipher_register_default();
+ silc_pkcs_register_default();
+ silc_hash_register_default();
+ silc_hmac_register_default();
+ silc_change_private_key_passphrase(arg, NULL, NULL);
+ exit(0);
+#endif
+ }
+
+#ifndef SILC_PLUGIN
+ if (strcmp(opt->longName, "show-key") == 0) {
+ /* Dump the key */
+ silc_cipher_register_default();
+ silc_pkcs_register_default();
+ silc_hash_register_default();
+ silc_hmac_register_default();
+ silc_show_public_key_file((char *)arg);
+ exit(0);
+ }
+#endif
+
+#ifdef SILC_PLUGIN
+err:
+ printformat_module("fe-common/silc", NULL, NULL,
+ MSGLEVEL_CRAP, SILCTXT_CONFIG_UNKNOWN,
+ data);
+
+out:
+ for (i=0; i<argc; i++)
+ silc_free(argv[i]);
+
+ silc_free(argv);
+ silc_free(argv_lens);
+ silc_free(argv_types);
+#endif
+}
+#undef FUNCTION_EXIT
+
+/* Called to indicate the client library has stopped. */
+static void
+silc_stopped(SilcClient client, void *context)
+{
+ SILC_LOG_DEBUG(("Client library has stopped"));
+ *(int*)context = -1;
+}
+
+/* Called to indicate the client library is running. */
+
+static void
+silc_running(SilcClient client, void *context)
+{
+ running = 1;
+ SILC_LOG_DEBUG(("Client library is running"));
+}
+
+static void sig_init_finished(void)
+{
+ /* Check ~/.silc directory and public and private keys */
+ if (!silc_client_check_silc_dir()) {
+#ifdef SILC_PLUGIN
+ init_failed = -1;
+#else
+ sleep(1);
+ exit(1);
+#endif
+ return;
+ }
+
+ /* Load public and private key */
+ if (!silc_client_load_keys(silc_client)) {
+#ifdef SILC_PLUGIN
+ init_failed = -1;
+#else
+ sleep(1);
+ exit(1);
+#endif
+ return;
+ }
+
+ /* Initialize the SILC client */
+ opt_hostname = (opt_hostname ? opt_hostname : silc_net_localhost());
+ if (!silc_client_init(silc_client, settings_get_str("user_name"),
+ opt_hostname, settings_get_str("real_name"),
+ silc_running, NULL)) {
+#ifdef SILC_PLUGIN
+ init_failed = -1;
+#else
+ sleep(1);
+ exit(1);
+#endif
+ return;
+ }
+
+ silc_schedule_set_notify(silc_client->schedule, scheduler_notify_cb, NULL);
+
+ silc_log_set_callback(SILC_LOG_INFO, silc_log_misc, NULL);
+ silc_log_set_callback(SILC_LOG_WARNING, silc_log_misc, NULL);
+ silc_log_set_callback(SILC_LOG_ERROR, silc_log_misc, NULL);
+ silc_log_set_callback(SILC_LOG_FATAL, silc_log_misc, NULL);
+
+ silc_hash_alloc("sha1", &sha1hash);
+
+ /* Run SILC scheduler */
+ my_silc_scheduler(NULL);