Sat Mar 17 19:07:15 CET 2007 Jochen Eisinger <coffee@silcnet.org>
authorJochen Eisinger <coffee@silcnet.org>
Sat, 17 Mar 2007 18:11:19 +0000 (18:11 +0000)
committerJochen Eisinger <coffee@silcnet.org>
Sat, 17 Mar 2007 18:11:19 +0000 (18:11 +0000)
* Incorporate SILC Plugin patches.  Affected files are
  apps/irssi/src/fe-common/silc/module-formats.{c,h},
  apps/irssi/src/silc/core/clientutil.{c,h},
  apps/irssi/src/silc/core/silc-core.c,
  apps/irssi/src/silc/core/silc-chatnets.{c,h},
  apps/irssi/src/fe-common/silc/fe-silcnet.c, and
  apps/irssi/src/fe-common/silc/module.h

CHANGES
apps/irssi/src/fe-common/silc/fe-silcnet.c
apps/irssi/src/fe-common/silc/module-formats.c
apps/irssi/src/fe-common/silc/module-formats.h
apps/irssi/src/fe-common/silc/module.h
apps/irssi/src/silc/core/clientutil.c
apps/irssi/src/silc/core/clientutil.h
apps/irssi/src/silc/core/silc-chatnets.c
apps/irssi/src/silc/core/silc-chatnets.h
apps/irssi/src/silc/core/silc-core.c

diff --git a/CHANGES b/CHANGES
index ec497b033d2a166756a47dcbde36cd1ed0de4559..79aaa5c35858169ea53e754ec29b6953de488bf1 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,3 +1,13 @@
+Sat Mar 17 19:07:15 CET 2007  Jochen Eisinger <coffee@silcnet.org>
+
+       * Incorporate SILC Plugin patches.  Affected files are
+         apps/irssi/src/fe-common/silc/module-formats.{c,h},
+         apps/irssi/src/silc/core/clientutil.{c,h},
+         apps/irssi/src/silc/core/silc-core.c,
+         apps/irssi/src/silc/core/silc-chatnets.{c,h},
+         apps/irssi/src/fe-common/silc/fe-silcnet.c, and
+         apps/irssi/src/fe-common/silc/module.h
+
 Wed Mar 14 17:31:28 EET 2007  Pekka Riikonen <priikone@silcnet.org>
 
        * In notify handling resolve user entries many times if the
index 2ab14d3278dbbf39a14dfb33a8f4965cf0658e26..4efeca54ade80fa4f9e74393b5d00d03ad673b07 100644 (file)
 #include "silc-chatnets.h"
 #include "printtext.h"
 
+void silcnet_create(SILC_CHATNET_REC *rec)
+{
+       g_return_if_fail(rec != NULL);
+
+       rec->chat_type = SILC_PROTOCOL;
+        chatnet_create((CHATNET_REC *) rec);
+}
+
 static void cmd_silcnet_list(void)
 {
        GString *str;
index 422e7c2979f1ef98caa1396bd40ee37e61c2bdae..4bfe1d270ff727f8a7011ab20d17a8a3b6e5c581 100644 (file)
@@ -272,5 +272,25 @@ FORMAT_REC fecommon_silc_formats[] = {
        { "silcnet_line", "%#$0: $1", 2, { 0, 0 } },
        { "silcnet_footer", "", 0 },
 
+#ifdef SILC_PLUGIN
+       /* command line option handling */
+       { NULL, "Command Line Option Handling", 0 },
+
+       { "config_debug", "Run-time debugging is {hilight $0}", 1, { 0 } },
+       { "config_nodebug", "Run-time debugging is {hilight disabled}. To enable it recompile the client with {hilight --enable-debug} configuration option.", 0 },
+       { "config_unknown", "Unknown option: $0", 1, { 0 } },
+       { "config_list", " - $0", 1, { 0 } },
+       { "config_algos", "Supported {hilight $0} algorithms:", 1, { 0 } },
+       { "config_nexttime", "{hilight NOTE:} You need to reload the plugin for these changes to take effect!", 0 },
+       { "config_pass_ask1", "Current Passphrase:", 0 },
+       { "config_pass_ask2", "New Passphrase:", 0 },
+       { "config_pass_ask3", "Retype new Passphrasse:", 0 },
+       { "config_passmismatch", "The passphrases do not match!", 0 },
+       { "config_passchange", "Changed the private key passphrase sucessfully", 0, { 0 } },
+       { "config_passchange_fail", "Failed to change the passphrase!", 0, { 0 } },
+       { "config_create", "Created a new key pair successfully", 0, { 0 } },
+       { "config_create_fail", "Failed to create a new key pair", 0, { 0 } },
+#endif
+
        { NULL, NULL, 0 }
 };
index b7a0fc93e4a863fef1b3f8e17d783e38add0f7ba..8f174be1e7a0a6fdec6f64a9aa6369b2e1fdaa97 100644 (file)
@@ -260,7 +260,26 @@ enum {
   SILCTXT_SILCNET_NOT_FOUND,
   SILCTXT_SILCNET_HEADER,
   SILCTXT_SILCNET_LINE,
-  SILCTXT_SILCNET_FOOTER
+  SILCTXT_SILCNET_FOOTER,
+
+#ifdef SILC_PLUGIN
+  SILCTXT_FILL_9,
+
+  SILCTXT_CONFIG_DEBUG,
+  SILCTXT_CONFIG_NODEBUG,
+  SILCTXT_CONFIG_UNKNOWN,
+  SILCTXT_CONFIG_LIST,
+  SILCTXT_CONFIG_ALGOS,
+  SILCTXT_CONFIG_NEXTTIME,
+  SILCTXT_CONFIG_PASS_ASK1,
+  SILCTXT_CONFIG_PASS_ASK2,
+  SILCTXT_CONFIG_PASS_ASK3,
+  SILCTXT_CONFIG_PASSMISMATCH,
+  SILCTXT_CONFIG_PASSCHANGE,
+  SILCTXT_CONFIG_PASSCHANGE_FAIL,
+  SILCTXT_CONFIG_CREATE,
+  SILCTXT_CONFIG_CREATE_FAIL,
+#endif
 
 };
 
index 0a06d9c5bf1789d74f4cf57120e8967b5e1811f1..b9293006684d128e72ff1f2302c9152222bae62a 100644 (file)
@@ -1,6 +1,7 @@
 #include "common.h"
 
 #define MODULE_NAME "fe-common/silc"
+#define SILC_PROTOCOL (chat_protocol_lookup("SILC"))
 
 #undef PACKAGE
 #undef VERSION
index c3bcd3287d8367a64ecb7f067ada1bb27a3c1e6b..9130779f70d232e47f11f596d5414c8808de3c35 100644 (file)
 
 #include "fe-common/core/printtext.h"
 #include "fe-common/core/keyboard.h"
+#include "fe-common/silc/module-formats.h"
 
 #include "core.h"
 
+#ifdef SILC_PLUGIN
+void silc_client_print_list(char *list)
+{
+  char **items;
+  int i=0;
+
+  items = g_strsplit(list, ",", -1);
+  
+  while (items[i] != NULL)
+    printformat_module("fe-common/silc", NULL, NULL,
+                      MSGLEVEL_CRAP, SILCTXT_CONFIG_LIST,
+                      items[i++]);
+
+  g_strfreev(items);
+}
+#endif
+
 /* Lists supported ciphers */
 
 void silc_client_list_ciphers()
 {
   char *ciphers = silc_cipher_get_supported();
+#ifdef SILC_PLUGIN
+  printformat_module("fe-common/silc", NULL, NULL,
+                    MSGLEVEL_CRAP, SILCTXT_CONFIG_ALGOS,
+                    "cipher");
+  silc_client_print_list(ciphers);
+#else
   fprintf(stdout, "%s\n", ciphers);
+#endif
   silc_free(ciphers);
 }
 
@@ -58,7 +83,14 @@ void silc_client_list_ciphers()
 void silc_client_list_hash_funcs()
 {
   char *hash = silc_hash_get_supported();
+#ifdef SILC_PLUGIN
+  printformat_module("fe-common/silc", NULL, NULL,
+                    MSGLEVEL_CRAP, SILCTXT_CONFIG_ALGOS,
+                    "hash");
+  silc_client_print_list(hash);
+#else
   fprintf(stdout, "%s\n", hash);
+#endif
   silc_free(hash);
 }
 
@@ -67,7 +99,14 @@ void silc_client_list_hash_funcs()
 void silc_client_list_hmacs()
 {
   char *hash = silc_hmac_get_supported();
+#ifdef SILC_PLUGIN
+  printformat_module("fe-common/silc", NULL, NULL,
+                    MSGLEVEL_CRAP, SILCTXT_CONFIG_ALGOS,
+                    "hmac");
+  silc_client_print_list(hash);
+#else
   fprintf(stdout, "%s\n", hash);
+#endif
   silc_free(hash);
 }
 
@@ -76,7 +115,14 @@ void silc_client_list_hmacs()
 void silc_client_list_pkcs()
 {
   char *pkcs = silc_pkcs_get_supported();
+#ifdef SILC_PLUGIN
+  printformat_module("fe-common/silc", NULL, NULL,
+                    MSGLEVEL_CRAP, SILCTXT_CONFIG_ALGOS,
+                    "pkcs");
+  silc_client_print_list(pkcs);
+#else
   fprintf(stdout, "%s\n", pkcs);
+#endif
   silc_free(pkcs);
 }
 
@@ -323,3 +369,104 @@ int silc_client_load_keys(SilcClient client)
 
   return ret;
 }
+
+#ifdef SILC_PLUGIN
+void create_key_passphrase(const char *answer, CREATE_KEY_REC *rec)
+{
+  char priv_key_file[128], pub_key_file[128];
+
+  signal_stop();
+
+  if ((rec->passphrase == NULL) && (answer) && (*answer != '\0')) {
+    rec->passphrase = g_strdup(answer);
+    keyboard_entry_redirect((SIGNAL_FUNC) create_key_passphrase,
+                           format_get_text("fe-common/silc", NULL, NULL,
+                                           NULL, SILCTXT_CONFIG_PASS_ASK2),
+                           ENTRY_REDIRECT_FLAG_HIDDEN, rec);
+    return;
+  }
+
+  if ((answer) && (*answer != '\0') && (rec->passphrase != NULL)) {
+    if (strcmp(answer, rec->passphrase)) {
+      printformat_module("fe-common/silc", NULL, NULL,
+                        MSGLEVEL_CRAP, SILCTXT_CONFIG_PASSMISMATCH);
+      g_free(rec->pkcs);
+      g_free(rec->passphrase);
+      g_free(rec);
+      return;
+    }
+  }
+
+  memset(priv_key_file, 0, sizeof(priv_key_file));
+  memset(pub_key_file, 0, sizeof(pub_key_file));
+  snprintf(priv_key_file, sizeof(priv_key_file) - 1, "%s/%s",
+          get_irssi_dir(), SILC_CLIENT_PRIVATE_KEY_NAME);
+  snprintf(pub_key_file, sizeof(pub_key_file) - 1, "%s/%s",
+          get_irssi_dir(), SILC_CLIENT_PUBLIC_KEY_NAME);
+
+  if (silc_create_key_pair(rec->pkcs, rec->bits, pub_key_file, priv_key_file,
+                      NULL, (rec->passphrase == NULL ? "" : rec->passphrase),
+                      NULL, NULL, NULL, FALSE) == TRUE)
+    printformat_module("fe-common/silc", NULL, NULL,
+                      MSGLEVEL_CRAP, SILCTXT_CONFIG_CREATE);
+  else
+    printformat_module("fe-common/silc", NULL, NULL,
+                      MSGLEVEL_CRAP, SILCTXT_CONFIG_CREATE_FAIL);
+
+  g_free(rec->passphrase);
+  g_free(rec->pkcs);
+  g_free(rec);
+  
+}
+
+void change_private_key_passphrase(const char *answer, CREATE_KEY_REC *rec)
+{
+  signal_stop();
+
+  if (rec->old == NULL) {
+    rec->old = g_strdup((answer == NULL ? "" : answer));
+    keyboard_entry_redirect((SIGNAL_FUNC) change_private_key_passphrase,
+                           format_get_text("fe-common/silc", NULL, NULL,
+                                           NULL, SILCTXT_CONFIG_PASS_ASK2),
+                           ENTRY_REDIRECT_FLAG_HIDDEN, rec);
+    return;
+  }
+  
+  if ((rec->passphrase == NULL) && (answer) && (*answer != '\0')) {
+    rec->passphrase = g_strdup(answer);
+    keyboard_entry_redirect((SIGNAL_FUNC) change_private_key_passphrase,
+                           format_get_text("fe-common/silc", NULL, NULL,
+                                           NULL, SILCTXT_CONFIG_PASS_ASK3),
+                           ENTRY_REDIRECT_FLAG_HIDDEN, rec);
+    return;
+  }
+
+  if ((answer) && (*answer != '\0') && (rec->passphrase != NULL)) {
+    if (strcmp(answer, rec->passphrase)) {
+      printformat_module("fe-common/silc", NULL, NULL,
+                        MSGLEVEL_CRAP, SILCTXT_CONFIG_PASSMISMATCH);
+      g_free(rec->old);
+      g_free(rec->file);
+      g_free(rec->pkcs);
+      g_free(rec->passphrase);
+      g_free(rec);
+      return;
+    }
+  }
+
+  if (silc_change_private_key_passphrase(rec->file, rec->old,
+                                    (rec->passphrase == NULL ? 
+                                     "" : rec->passphrase)) == TRUE)
+    printformat_module("fe-common/silc", NULL, NULL,
+                      MSGLEVEL_CRAP, SILCTXT_CONFIG_PASSCHANGE);
+  else
+    printformat_module("fe-common/silc", NULL, NULL,
+                      MSGLEVEL_CRAP, SILCTXT_CONFIG_PASSCHANGE_FAIL);
+  g_free(rec->old);
+  g_free(rec->file);
+  g_free(rec->passphrase);
+  g_free(rec->pkcs);
+  g_free(rec);
+
+}
+#endif
index 6b703f5d8645b7427c17b26a0c83849a7c7cf4d6..240100a600ed6d9b3c4dfedc82d66d82e7ba4af6 100644 (file)
@@ -31,4 +31,14 @@ void silc_client_list_pkcs();
 int silc_client_check_silc_dir();
 int silc_client_load_keys(SilcClient client);
 
+#ifdef SILC_PLUGIN
+typedef struct {
+  char *old, *passphrase, *file, *pkcs;
+  int bits;
+} CREATE_KEY_REC;
+
+void create_key_passphrase(const char *answer, CREATE_KEY_REC *rec);
+void change_private_key_passphrase(const char *answer, CREATE_KEY_REC *rec);
+#endif
+
 #endif
index 8fbaf2dff4060e07782d8bdb40dcb31442751aea..9e179d6ff28fc512f8a93037c2c29ff7946215b1 100644 (file)
 
 #include "silc-chatnets.h"
 
-void silcnet_create(SILC_CHATNET_REC *rec)
-{
-       g_return_if_fail(rec != NULL);
-
-       rec->chat_type = SILC_PROTOCOL;
-        chatnet_create((CHATNET_REC *) rec);
-}
-
 static void sig_chatnet_read(SILC_CHATNET_REC *rec, CONFIG_NODE *node)
 {
        if (!IS_SILC_CHATNET(rec))
index e9a1f6736b3d4d9a05d57a58a16328fb7a6a7e24..f786c300df7c28bd4d8b6e9600eabba4378b838f 100644 (file)
@@ -20,8 +20,6 @@ struct _SILC_CHATNET_REC {
 
 typedef struct _SILC_CHATNET_REC SILC_CHATNET_REC;
 
-void silcnet_create(SILC_CHATNET_REC *rec);
-
 #define silc_chatnet_find(name) \
        SILC_CHATNET(chatnet_find(name))
 #define silcnet_find(name) silc_chatnet_find(name)
index 259d7a6f8698fd665e988d68b61c64a9d1a99cc8..9510a9756f7b077e6e67fe0c7856cd27aafde75e 100644 (file)
 #include "silc-nicklist.h"
 #include "silc-chatnets.h"
 #include "silc-cmdqueue.h"
+#include "silc-commands.h"
 
 #include "signals.h"
 #include "levels.h"
 #include "settings.h"
+#include "commands.h"
 #include "fe-common/core/printtext.h"
 #include "fe-common/core/fe-channels.h"
 #include "fe-common/core/keyboard.h"
 #include "fe-common/silc/module-formats.h"
 
+#ifndef SILC_PLUGIN
 /* Command line option variables */
 static char *opt_pkcs = NULL;
 static int opt_bits = 0;
+#else
+static int init_failed = 0;
+#endif
 
 static int idletag = -1;
 
@@ -66,6 +72,10 @@ void silc_expandos_deinit(void);
 void silc_lag_init(void);
 void silc_lag_deinit(void);
 
+#ifdef SILC_PLUGIN
+void silc_core_deinit(void);
+#endif
+
 static int my_silc_scheduler(void)
 {
   silc_client_run_one(silc_client);
@@ -169,8 +179,11 @@ static void silc_init_userinfo(void)
   }
 }
 
-#ifdef SILC_DEBUG
+#if defined(SILC_DEBUG) || defined(SILC_PLUGIN)
 static bool i_debug;
+#endif
+
+#ifdef SILC_DEBUG
 static bool silc_irssi_debug_print(char *file, char *function, int line,
                                   char *message, void *context)
 {
@@ -229,7 +242,12 @@ static void silc_register_cipher(SilcClient client, const char *cipher)
 
     if (!silc_cipher_is_supported(cipher)) {
       SILC_LOG_ERROR(("Unknown cipher `%s'", cipher));
+#ifdef SILC_PLUGIN
+      init_failed = -1;
+      returnn;
+#else
       exit(1);
+#endif
     }
   }
 
@@ -250,7 +268,12 @@ static void silc_register_hash(SilcClient client, const char *hash)
 
     if (!silc_hash_is_supported(hash)) {
       SILC_LOG_ERROR(("Unknown hash function `%s'", hash));
+#ifdef SILC_PLUGIN
+      init_failed = -1;
+      returnn;
+#else
       exit(1);
+#endif
     }
   }
 
@@ -271,7 +294,12 @@ static void silc_register_hmac(SilcClient client, const char *hmac)
 
     if (!silc_hmac_is_supported(hmac)) {
       SILC_LOG_ERROR(("Unknown HMAC `%s'", hmac));
+#ifdef SILC_PLUGIN
+      init_failed = -1;
+      returnn;
+#else
       exit(1);
+#endif
     }
   }
 
@@ -281,11 +309,38 @@ static void silc_register_hmac(SilcClient client, const char *hmac)
 
 /* Finalize init. Init finish signal calls this. */
 
+#ifdef SILC_PLUGIN
+#define FUNCTION_EXIT goto out
+void silc_opt_callback(const char *data, SERVER_REC *server,
+                       WI_ITEM_REC *item)
+#else
+#define FUNCTION_EXIT exit(0)
 void silc_opt_callback(poptContext con,
                       enum poptCallbackReason reason,
                       const struct poptOption *opt,
                       const char *arg, void *data)
+#endif
 {
+#ifdef SILC_PLUGIN
+  unsigned char **argv=NULL, *tmp;
+  SilcUInt32 *argv_lens=NULL, *argv_types=NULL, argc=0;
+  int i;
+  unsigned char privkey[128], pubkey[128];
+   
+  memset(privkey, 0, sizeof(privkey));
+  memset(pubkey, 0, sizeof(pubkey));
+  snprintf(pubkey, sizeof(pubkey) - 1, "%s/%s", get_irssi_dir(),
+          SILC_CLIENT_PUBLIC_KEY_NAME);
+  snprintf(privkey, sizeof(privkey) - 1, "%s/%s", get_irssi_dir(),
+          SILC_CLIENT_PRIVATE_KEY_NAME);
+
+  tmp = g_strconcat("SILC", " ", data, NULL);
+  silc_parse_command_line(tmp, &argv, &argv_lens, &argv_types, &argc, 6);
+  g_free(tmp);
+
+  if (argc < 2)
+    goto err;
+#else
   if (strcmp(opt->longName, "nick") == 0) {
     g_free(opt_nickname);
     opt_nickname = g_strdup(arg);
@@ -295,45 +350,138 @@ void silc_opt_callback(poptContext con,
     silc_free(opt_hostname);
     opt_hostname = strdup(arg);
   }
+#endif
 
+#ifdef SILC_PLUGIN
+  if ((argc == 2) && (strcasecmp(argv[1], "list-ciphers") == 0)) {
+#else
   if (strcmp(opt->longName, "list-ciphers") == 0) {
     silc_cipher_register_default();
+#endif
     silc_client_list_ciphers();
-    exit(0);
+    FUNCTION_EXIT;
   }
 
+#ifdef SILC_PLUGIN
+  if ((argc == 2) && (strcasecmp(argv[1], "list-hash-funcs") == 0)) {
+#else
   if (strcmp(opt->longName, "list-hash-funcs") == 0) {
     silc_hash_register_default();
+#endif
     silc_client_list_hash_funcs();
-    exit(0);
+    FUNCTION_EXIT;
   }
 
+#ifdef SILC_PLUGIN
+  if ((argc == 2) && (strcasecmp(argv[1], "list-hmacs") == 0)) {
+#else
   if (strcmp(opt->longName, "list-hmacs") == 0) {
     silc_hmac_register_default();
+#endif
     silc_client_list_hmacs();
-    exit(0);
+    FUNCTION_EXIT;
   }
 
+#ifdef SILC_PLUGIN
+  if ((argc == 2) && (strcasecmp(argv[1], "list-pkcs") == 0)) {
+#else
   if (strcmp(opt->longName, "list-pkcs") == 0) {
     silc_pkcs_register_default();
+#endif
     silc_client_list_pkcs();
-    exit(0);
+    FUNCTION_EXIT;
   }
 
+#ifdef SILC_PLUGIN
+  if ((argc < 5) && (strcasecmp(argv[1], "debug") == 0)) {
+#else
   if (strcmp(opt->longName, "debug") == 0) {
     silc_log_debug(TRUE);
     silc_log_debug_hexdump(TRUE);
     silc_log_set_debug_string(arg);
+#endif
+#ifdef SILC_PLUGIN
+    if (argc == 2) {
+      printformat_module("fe-common/silc", NULL, NULL,
+                        MSGLEVEL_CRAP, SILCTXT_CONFIG_DEBUG,
+                        (i_debug == TRUE ? "enabled" : "disabled"));
+      goto out;
+    }
+#endif
 #ifndef SILC_DEBUG
+#ifdef SILC_PLUGIN
+    printformat_module("fe-common/silc", NULL, NULL,
+                      MSGLEVEL_CRAP, SILCTXT_CONFIG_NODEBUG);
+#else
     fprintf(stdout,
            "Run-time debugging is not enabled. To enable it recompile\n"
            "the client with --enable-debug configuration option.\n");
     sleep(1);
+#endif
+#else
+#ifdef SILC_PLUGIN
+    if (strcasecmp(argv[2], "on") == 0) {
+      settings_set_bool("debug", TRUE);
+      if (argc == 4)
+        settings_set_str("debug_string", argv[3]);
+    } else if ((argc == 3) && (strcasecmp(argv[2], "off") == 0)) {
+      settings_set_bool("debug", FALSE);
+    } else
+      goto err;
+    sig_setup_changed();
+    printformat_module("fe-common/silc", NULL, NULL,
+                      MSGLEVEL_CRAP, SILCTXT_CONFIG_DEBUG,
+                      (settings_get_bool("debug") == TRUE ? 
+                       "enabled" : "disabled"));
+    goto out;
+#endif
 #endif
   }
 
+#ifdef SILC_PLUGIN
+  if (strcasecmp(argv[1], "create-key-pair") == 0) {
+#else
   if (strcmp(opt->longName, "create-key-pair") == 0) {
+#endif
     /* Create new key pair and exit */
+#ifdef SILC_PLUGIN
+    char *endptr, *pkcs=NULL;
+    long int val;
+    int bits=0;
+    CREATE_KEY_REC *rec;
+
+    if ((argc == 3) || (argc == 5))
+      goto err;
+
+    for (i=2; i<argc-1; i+=2)
+      if (strcasecmp(argv[i], "-pkcs") == 0) {
+       if (pkcs == NULL)
+         pkcs = argv[i+1];
+       else
+         goto err;
+      } else if (strcasecmp(argv[i], "-bits") == 0) {
+       if (bits == 0) {
+         val = strtol(argv[i+1], &endptr, 10);
+         if ((*endptr != '\0') || (val <= 0) || (val >= INT_MAX))
+           goto err;
+          bits = val;
+       } else
+         goto err;
+      } else
+       goto err;
+
+    rec = g_new0(CREATE_KEY_REC, 1);
+    rec->pkcs = (pkcs == NULL ? NULL : g_strdup(pkcs));
+    rec->bits = bits;
+             
+    keyboard_entry_redirect((SIGNAL_FUNC) create_key_passphrase,
+                           format_get_text("fe-common/silc", NULL, NULL,
+                                           NULL, SILCTXT_CONFIG_PASS_ASK2),
+                           ENTRY_REDIRECT_FLAG_HIDDEN, rec);
+    printformat_module("fe-common/silc", NULL, NULL,
+                      MSGLEVEL_CRAP, SILCTXT_CONFIG_NEXTTIME);
+    goto out;
+#else
     silc_cipher_register_default();
     silc_pkcs_register_default();
     silc_hash_register_default();
@@ -341,18 +489,37 @@ void silc_opt_callback(poptContext con,
     silc_create_key_pair(opt_pkcs, opt_bits, NULL, NULL,
                         NULL, NULL, NULL, NULL, TRUE);
     exit(0);
+#endif
   }
 
+#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();
@@ -362,7 +529,24 @@ void silc_opt_callback(poptContext con,
     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. */
 
@@ -393,15 +577,23 @@ 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;
   }
 
@@ -410,8 +602,12 @@ static void sig_init_finished(void)
   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;
   }
 
@@ -430,6 +626,7 @@ static void sig_init_finished(void)
 
 void silc_core_init(void)
 {
+#ifndef SILC_PLUGIN
   static struct poptOption silc_options[] = {
     { NULL, '\0', POPT_ARG_CALLBACK, (void *)&silc_opt_callback, '\0', NULL },
     { "list-ciphers", 0, POPT_ARG_NONE, NULL, 0,
@@ -456,16 +653,21 @@ void silc_core_init(void)
       "Show the contents of the public key", "FILE" },
     { NULL, '\0', 0, NULL }
   };
+#endif
 
   CHAT_PROTOCOL_REC *rec;
   SilcClientParams params;
   const char *def_cipher, *def_hash, *def_hmac;
 
+#ifndef SILC_PLUGIN
   args_register(silc_options);
+#endif
 
   /* Settings */
+#ifndef SILC_PLUGIN
   settings_add_bool("server", "skip_motd", FALSE);
   settings_add_str("server", "alternate_nick", NULL);
+#endif
   settings_add_bool("server", "use_auto_addr", FALSE);
   settings_add_str("server", "auto_bind_ip", "");
   settings_add_str("server", "auto_public_ip", "");
@@ -502,9 +704,16 @@ void silc_core_init(void)
 #endif
 
   signal_add("setup changed", (SIGNAL_FUNC) sig_setup_changed);
+#ifndef SILC_PLUGIN
   signal_add("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
+#endif
   signal_add("gui exit", (SIGNAL_FUNC) sig_gui_quit);
 
+#if defined (SILC_PLUGIN) && defined (SILC_DEBUG)
+  if (settings_get_bool("debug") == TRUE)
+    sig_setup_changed();
+#endif
+
   silc_init_userinfo();
 
   silc_log_set_callback(SILC_LOG_INFO, silc_log_stderr, NULL);
@@ -524,10 +733,26 @@ void silc_core_init(void)
   def_hash = settings_get_str("crypto_default_hash");
   def_hmac = settings_get_str("crypto_default_hmac");
   silc_register_cipher(silc_client, def_cipher);
+#ifdef SILC_PLUGIN
+  if (init_failed)
+    return;
+#endif
   silc_register_hash(silc_client, def_hash);
+#ifdef SILC_PLUGIN
+  if (init_failed)
+    return;
+#endif
   silc_register_hmac(silc_client, def_hmac);
+#ifdef SILC_PLUGIN
+  if (init_failed)
+    return;
+#endif
   silc_pkcs_register_default();
 
+#ifdef SILC_PLUGIN
+  command_bind("silc", MODULE_NAME, (SIGNAL_FUNC) silc_opt_callback);
+#endif
+
   /* Register SILC to the irssi */
   rec = g_new0(CHAT_PROTOCOL_REC, 1);
   rec->name = "SILC";
@@ -557,6 +782,14 @@ void silc_core_init(void)
   silc_lag_init();
   silc_chatnets_init();
 
+#ifdef SILC_PLUGIN
+  sig_init_finished();
+  if (init_failed) {
+    silc_core_deinit();
+    return;
+  }
+#endif
+
   module_register("silc", "core");
 }
 
@@ -573,8 +806,12 @@ void silc_core_deinit(void)
     g_free(opt_nickname);
 
   signal_remove("setup changed", (SIGNAL_FUNC) sig_setup_changed);
-  signal_remove("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
   signal_remove("gui exit", (SIGNAL_FUNC) sig_gui_quit);
+#ifdef SILC_PLUGIN
+  command_unbind("silc", (SIGNAL_FUNC) silc_opt_callback);
+#else
+  signal_remove("irssi init finished", (SIGNAL_FUNC) sig_init_finished);
+#endif
 
   silc_hash_free(sha1hash);