From f7476b133b1a7768c7d9fd63aa308c9fed6a8448 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 27 May 2001 16:20:25 +0000 Subject: [PATCH] updates. --- apps/irssi/src/silc/core/clientutil.c | 31 ++++-- apps/irssi/src/silc/core/clientutil.h | 1 + apps/irssi/src/silc/core/silc-channels.c | 13 --- apps/irssi/src/silc/core/silc-core.c | 46 +++++++++ apps/irssi/src/silc/core/silc-nicklist.c | 119 ++++++++++++----------- 5 files changed, 131 insertions(+), 79 deletions(-) diff --git a/apps/irssi/src/silc/core/clientutil.c b/apps/irssi/src/silc/core/clientutil.c index cbd0c184..fa7cf625 100644 --- a/apps/irssi/src/silc/core/clientutil.c +++ b/apps/irssi/src/silc/core/clientutil.c @@ -43,7 +43,7 @@ #include "fe-common/core/printtext.h" #include "fe-common/core/keyboard.h" -/* Lists supported (builtin) ciphers */ +/* Lists supported ciphers */ void silc_client_list_ciphers() { @@ -52,7 +52,7 @@ void silc_client_list_ciphers() silc_free(ciphers); } -/* Lists supported (builtin) hash functions */ +/* Lists supported hash functions */ void silc_client_list_hash_funcs() { @@ -61,6 +61,15 @@ void silc_client_list_hash_funcs() silc_free(hash); } +/* Lists supported hash functions */ + +void silc_client_list_hmacs() +{ + char *hash = silc_hmac_get_supported(); + fprintf(stdout, "%s\n", hash); + silc_free(hash); +} + /* Lists supported PKCS algorithms */ void silc_client_list_pkcs() @@ -107,14 +116,16 @@ char *silc_client_get_input(const char *prompt) char *silc_client_create_identifier() { char *username = NULL, *realname = NULL; - char hostname[256], email[256]; + char *hostname, email[256]; + char *ident; /* Get realname */ realname = silc_get_real_name(); /* Get hostname */ - memset(hostname, 0, sizeof(hostname)); - gethostname(hostname, sizeof(hostname)); + hostname = silc_net_localhost(); + if (!hostname) + return NULL; /* Get username (mandatory) */ username = silc_get_username(); @@ -124,8 +135,14 @@ char *silc_client_create_identifier() /* Create default email address, whether it is right or not */ snprintf(email, sizeof(email), "%s@%s", username, hostname); - return silc_pkcs_encode_identifier(username, hostname, realname, email, - NULL, NULL); + ident = silc_pkcs_encode_identifier(username, hostname, realname, email, + NULL, NULL); + if (realname) + silc_free(realname); + silc_free(hostname); + silc_free(username); + + return ident; } /* Creates new public key and private key pair. This is used only diff --git a/apps/irssi/src/silc/core/clientutil.h b/apps/irssi/src/silc/core/clientutil.h index ab7c0208..efd69da0 100644 --- a/apps/irssi/src/silc/core/clientutil.h +++ b/apps/irssi/src/silc/core/clientutil.h @@ -27,6 +27,7 @@ char *silc_client_get_input(const char *prompt); void silc_client_list_ciphers(); void silc_client_list_hash_funcs(); +void silc_client_list_hmacs(); void silc_client_list_pkcs(); char *silc_client_create_identifier(); int silc_client_create_key_pair(char *pkcs_name, int bits, diff --git a/apps/irssi/src/silc/core/silc-channels.c b/apps/irssi/src/silc/core/silc-channels.c index a19ca5ac..a522bc4b 100644 --- a/apps/irssi/src/silc/core/silc-channels.c +++ b/apps/irssi/src/silc/core/silc-channels.c @@ -550,8 +550,6 @@ typedef struct { SILC_SERVER_REC *server; } *KeyInternal; -static SilcSKEKeyMaterial *curr_key = NULL; - /* Key agreement callback that is called after the key agreement protocol has been performed. This is called also if error occured during the key agreement protocol. The `key' is the allocated key material and @@ -569,8 +567,6 @@ static void keyagr_completion(SilcClient client, { KeyInternal i = (KeyInternal)context; - curr_key = NULL; - switch(status) { case SILC_KEY_AGREEMENT_OK: printformat_module("fe-common/silc", i->server, NULL, MSGLEVEL_NOTICES, @@ -741,15 +737,6 @@ static void command_key(const char *data, SILC_SERVER_REC *server, if (!strcasecmp(argv[3], "set")) { command = 1; - if (argc == 4) { - if (curr_key && type == 1 && client_entry) { - silc_client_del_private_message_key(silc_client, conn, client_entry); - silc_client_add_private_message_key_ske(silc_client, conn, - client_entry, NULL, curr_key); - goto out; - } - } - if (argc >= 5) { if (type == 1 && client_entry) { /* Set private message key */ diff --git a/apps/irssi/src/silc/core/silc-core.c b/apps/irssi/src/silc/core/silc-core.c index 4cfcd54d..787290cc 100644 --- a/apps/irssi/src/silc/core/silc-core.c +++ b/apps/irssi/src/silc/core/silc-core.c @@ -43,6 +43,11 @@ /* Command line option variables */ static bool opt_create_keypair = FALSE; static bool opt_debug = FALSE; +static bool opt_list_ciphers = FALSE; +static bool opt_list_hash = FALSE; +static bool opt_list_hmac = FALSE; +static bool opt_list_pkcs = FALSE; +static bool opt_version = FALSE; static char *opt_pkcs = NULL; static char *opt_keyfile = NULL; static int opt_bits = 0; @@ -180,8 +185,18 @@ void silc_core_init(void) "Set the length of the public key pair", "VALUE" }, { "show-key", 'S', POPT_ARG_STRING, &opt_keyfile, 0, "Show the contents of the public key", "FILE" }, + { "list-ciphers", 'C', POPT_ARG_NONE, &opt_list_ciphers, 0, + "List supported ciphers", NULL }, + { "list-hash-funcs", 'H', POPT_ARG_NONE, &opt_list_hash, 0, + "List supported hash functions", NULL }, + { "list-hmacs", 'H', POPT_ARG_NONE, &opt_list_hmac, 0, + "List supported HMACs", NULL }, + { "list-pkcs", 'P', POPT_ARG_NONE, &opt_list_pkcs, 0, + "List supported PKCSs", NULL }, { "debug", 'd', POPT_ARG_NONE, &opt_debug, 0, "Enable debugging", NULL }, + { "version", 'V', POPT_ARG_NONE, &opt_version, 0, + "Show version", NULL }, { NULL, '\0', 0, NULL } }; @@ -215,6 +230,37 @@ void silc_core_init_finish(void) exit(0); } + if (opt_list_ciphers) { + silc_cipher_register_default(); + silc_client_list_ciphers(); + exit(0); + } + + if (opt_list_hash) { + silc_hash_register_default(); + silc_client_list_hash_funcs(); + exit(0); + } + + if (opt_list_hmac) { + silc_hmac_register_default(); + silc_client_list_hmacs(); + exit(0); + } + + if (opt_list_pkcs) { + silc_pkcs_register_default(); + silc_client_list_pkcs(); + exit(0); + } + + if (opt_version) { + printf("SILC Secure Internet Live Conferencing, version %s\n", + silc_version); + printf("(c) 1997 - 2001 Pekka Riikonen \n"); + exit(0); + } + silc_debug = opt_debug; silc_log_set_callbacks(silc_log_info, silc_log_warning, silc_log_error, NULL); diff --git a/apps/irssi/src/silc/core/silc-nicklist.c b/apps/irssi/src/silc/core/silc-nicklist.c index f84d1dd2..9ffa1138 100644 --- a/apps/irssi/src/silc/core/silc-nicklist.c +++ b/apps/irssi/src/silc/core/silc-nicklist.c @@ -29,33 +29,32 @@ SILC_NICK_REC *silc_nicklist_insert(SILC_CHANNEL_REC *channel, SilcChannelUser user, int send_massjoin) { - SILC_NICK_REC *rec; + SILC_NICK_REC *rec; - g_return_val_if_fail(IS_SILC_CHANNEL(channel), NULL); - g_return_val_if_fail(user != NULL, NULL); + g_return_val_if_fail(IS_SILC_CHANNEL(channel), NULL); + g_return_val_if_fail(user != NULL, NULL); - rec = g_new0(SILC_NICK_REC, 1); - rec->nick = g_strdup(user->client->nickname); - rec->host = g_strdup(user->client->username); - rec->silc_user = user; - rec->unique_id = user->client; + rec = g_new0(SILC_NICK_REC, 1); + rec->nick = g_strdup(user->client->nickname); + rec->host = g_strdup(user->client->username); + rec->silc_user = user; + rec->unique_id = user->client; - if (user->mode & SILC_CHANNEL_UMODE_CHANOP) - rec->op = TRUE; - if (user->mode & SILC_CHANNEL_UMODE_CHANFO) - rec->founder = TRUE; - rec->send_massjoin = send_massjoin; + if (user->mode & SILC_CHANNEL_UMODE_CHANOP) + rec->op = TRUE; + if (user->mode & SILC_CHANNEL_UMODE_CHANFO) + rec->founder = TRUE; + rec->send_massjoin = send_massjoin; - nicklist_insert(CHANNEL(channel), (NICK_REC *) rec); - return rec; + nicklist_insert(CHANNEL(channel), (NICK_REC *) rec); + return rec; } SILC_NICK_REC *silc_nicklist_find(SILC_CHANNEL_REC *channel, SilcClientEntry client) { - return (SILC_NICK_REC *) - nicklist_find_unique(CHANNEL(channel), - client->nickname, client); + return (SILC_NICK_REC *)nicklist_find_unique(CHANNEL(channel), + client->nickname, client); } #define isnickchar(a) \ @@ -66,66 +65,68 @@ SILC_NICK_REC *silc_nicklist_find(SILC_CHANNEL_REC *channel, /* Remove all "extra" characters from `nick'. Like _nick_ -> nick */ char *silc_nick_strip(const char *nick) { - char *stripped, *spos; - - g_return_val_if_fail(nick != NULL, NULL); - - spos = stripped = g_strdup(nick); - while (isnickchar(*nick)) { - if (isalnum((int) *nick)) - *spos++ = *nick; - nick++; - } - if ((unsigned char) *nick >= 128) - *spos++ = *nick; /* just add it so that nicks won't match.. */ - *spos = '\0'; - return stripped; + char *stripped, *spos; + + g_return_val_if_fail(nick != NULL, NULL); + + spos = stripped = g_strdup(nick); + while (isnickchar(*nick)) { + if (isalnum((int) *nick)) + *spos++ = *nick; + nick++; + } + if ((unsigned char) *nick >= 128) + *spos++ = *nick; /* just add it so that nicks won't match.. */ + *spos = '\0'; + + return stripped; } /* Check is `msg' is meant for `nick'. */ int silc_nick_match(const char *nick, const char *msg) { - char *stripnick, *stripmsg; - int ret, len; - - g_return_val_if_fail(nick != NULL, FALSE); - g_return_val_if_fail(msg != NULL, FALSE); - - len = strlen(nick); - if (g_strncasecmp(msg, nick, len) == 0 && !isalnum((int) msg[len])) - return TRUE; - - stripnick = silc_nick_strip(nick); - stripmsg = silc_nick_strip(msg); - - len = strlen(stripnick); - ret = len > 0 && g_strncasecmp(stripmsg, stripnick, len) == 0 && - !isalnum((int) stripmsg[len]) && - (unsigned char) stripmsg[len] < 128; - - g_free(stripnick); - g_free(stripmsg); - return ret; + char *stripnick, *stripmsg; + int ret, len; + + g_return_val_if_fail(nick != NULL, FALSE); + g_return_val_if_fail(msg != NULL, FALSE); + + len = strlen(nick); + if (g_strncasecmp(msg, nick, len) == 0 && !isalnum((int) msg[len])) + return TRUE; + + stripnick = silc_nick_strip(nick); + stripmsg = silc_nick_strip(msg); + + len = strlen(stripnick); + ret = len > 0 && g_strncasecmp(stripmsg, stripnick, len) == 0 && + !isalnum((int) stripmsg[len]) && + (unsigned char) stripmsg[len] < 128; + + g_free(stripnick); + g_free(stripmsg); + + return ret; } static const char *get_nick_flags(void) { - static char flags[3] = { '@', '+', '\0' }; - return flags; + static char flags[3] = { '@', '+', '\0' }; + return flags; } static void sig_connected(SILC_SERVER_REC *server) { - if (IS_SILC_SERVER(server)) - server->get_nick_flags = (void *) get_nick_flags; + if (IS_SILC_SERVER(server)) + server->get_nick_flags = (void *) get_nick_flags; } void silc_nicklist_init(void) { - signal_add("server connected", (SIGNAL_FUNC) sig_connected); + signal_add("server connected", (SIGNAL_FUNC) sig_connected); } void silc_nicklist_deinit(void) { - signal_remove("server connected", (SIGNAL_FUNC) sig_connected); + signal_remove("server connected", (SIGNAL_FUNC) sig_connected); } -- 2.43.0