From bd2c9343055303a5517a33401f57a0414639a953 Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sat, 5 Jan 2002 12:38:42 +0000 Subject: [PATCH] updates. --- CHANGES | 35 +++++++++++++++++++++++++ Makefile.am.pre | 2 +- TODO | 10 +------ apps/irssi/src/silc/core/silc-core.c | 7 +++-- apps/silcd/command.c | 33 +++++------------------ apps/silcd/packet_receive.c | 37 +++++++++++++------------- apps/silcd/server_util.c | 39 ++++++++++++++++++++++++++++ apps/silcd/server_util.h | 7 +++++ configure.in.pre | 1 - lib/silcclient/README | 7 ++++- lib/silcclient/client.c | 21 ++++++++++----- lib/silcclient/client.h | 3 ++- lib/silcclient/client_notify.c | 17 +++++------- lib/silcclient/command.c | 7 +++-- lib/silcclient/command_reply.c | 2 +- lib/silcclient/idlist.c | 8 +++++- lib/silcsim/Makefile.am | 10 +++---- lib/silcutil/silcutil.c | 11 ++++---- lib/silcutil/silcutil.h | 11 ++++---- 19 files changed, 165 insertions(+), 103 deletions(-) diff --git a/CHANGES b/CHANGES index ee6beaa6..a29581d8 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,38 @@ +Sat Jan 5 13:37:29 EET 2002 Pekka Riikonen + + * Added the silc_client_del_client to remove the client from + all channels as well. Affected file lib/silcclient/idlist.c. + + * Fixed the client library to correctly remove the client + from all channels when the client entry is being destroyed. + Affected file lib/silcclient/client_notify.c, command.c. + + * Added auto-nicking support to the client library. If the + applicatio now sets client->nickname it will be sent to the + server after connecting by the library. This way for example + SILCNICK (or IRCNICK) environment variables will have effect + and always change the nickname automatically to whatever + it is wanted. Affected file lib/silcclient/client.[ch]. + + * Renamed silc_server_command_bad_chars to the + silc_server_name_bad_chars and moved it to the + silcd/server_util.[ch]. Added also new function + silc_server_name_modify_bad to return nickname that + includes bad characters as new nickname without those + bad characters. This check and modify is now used in + silc_server_new_client when the username is initially set + as nickname, so it must be checked to be valid nickname. + Affected file silcd/packet_receive.c. + + * The nickname length is now taken from the packet for real + and not trusted to strlen() since it clearly can return + wrong length for nickname including bad characters. This + also applies to channel names. Affected file silcd/command.c. + + * Removed the lib/silcsilm/modules directory. Modules are now + compiled into the lib/silcsim. Fixed the copying of the + modules to follow symbolic links in Makefile.am.pre. + Wed Jan 2 18:56:21 EET 2002 Pekka Riikonen * Fixed silc_string_regexify list creation. Fixes bugs with diff --git a/Makefile.am.pre b/Makefile.am.pre index 510b418a..dc200b2e 100644 --- a/Makefile.am.pre +++ b/Makefile.am.pre @@ -55,7 +55,7 @@ generate-server-key: fi sim-install: - -cp -fR $(srcdir)/lib/silcsim/modules/*.so $(modulesdir)/ + -cp -fRL $(srcdir)/lib/silcsim/*.so $(modulesdir)/ doc-install: $(INSTALL_DATA) $(srcdir)/doc/CodingStyle $(docdir)/ diff --git a/TODO b/TODO index a159efef..6f8aa18b 100644 --- a/TODO +++ b/TODO @@ -17,10 +17,6 @@ TODO/bugs in Irssi SILC client cipher, hash, hmac and pkcs configuration to the Irssi SILC's config file. - o Add auto-nick support to Irssi, so that the user specified nickname - would be sent to the server immediately (automatically) after the - client is connected to the server. - o Add PERL scripting support from Irssi CVS. o Extend the /HELP command to support sub commands or something. So @@ -51,11 +47,6 @@ TODO/bugs In SILC Client Library not needed and its usage is buggy when the context is registered to multiple pending commands. - o Add perhaps an option of setting the nickname to the client context. - If set (and username != nickname) the client libary would send NICK - command to the server after connecting to automatically set the - nickname. - o Additions to do after protocol version 1.1: o Fix the NICK_CHANGE notify handling not to create new entry @@ -70,6 +61,7 @@ TODO/bugs In SILC Server ======================== o strerror messages from premature EOF's to signoff messages. + (add perhaps a socket error thingy to SilcSockeConnection). o Backup router related issues diff --git a/apps/irssi/src/silc/core/silc-core.c b/apps/irssi/src/silc/core/silc-core.c index f5ea52a3..1bc44d98 100644 --- a/apps/irssi/src/silc/core/silc-core.c +++ b/apps/irssi/src/silc/core/silc-core.c @@ -122,13 +122,11 @@ static void silc_init_userinfo(void) } /* nick */ - /* Actually take SILCUSER or IRCUSER since nickname cannot be set - beforehand in SILC (XXX auto-nicking support should be added to Irssi). */ nick = settings_get_str("nick"); if (nick == NULL || *nick == '\0') { - str = g_getenv("SILCUSER"); + str = g_getenv("SILCNICK"); if (!str) - str = g_getenv("IRCUSER"); + str = g_getenv("IRCNICK"); settings_set_str("nick", str != NULL ? str : user_name); nick = settings_get_str("nick"); @@ -312,6 +310,7 @@ void silc_core_init_finish(void) /* Get user information */ silc_client->username = g_strdup(settings_get_str("user_name")); + silc_client->nickname = g_strdup(settings_get_str("nick")); silc_client->hostname = silc_net_localhost(); silc_client->realname = g_strdup(settings_get_str("real_name")); diff --git a/apps/silcd/command.c b/apps/silcd/command.c index e83ef754..cb487e23 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -1951,25 +1951,6 @@ SILC_SERVER_CMD_FUNC(identify) silc_server_command_free(cmd); } -/* Checks string for bad characters and returns TRUE if they are found. */ - -static int silc_server_command_bad_chars(char *nick) -{ - int i; - - for (i = 0; i < strlen(nick); i++) { - if (!isascii(nick[i])) - return TRUE; - if (nick[i] <= 32) return TRUE; - if (nick[i] == ' ') return TRUE; - if (nick[i] == '*') return TRUE; - if (nick[i] == '?') return TRUE; - if (nick[i] == ',') return TRUE; - } - - return FALSE; -} - /* Server side of command NICK. Sets nickname for user. Setting nickname causes generation of a new client ID for the client. The new client ID is sent to the client after changing the nickname. */ @@ -1981,6 +1962,7 @@ SILC_SERVER_CMD_FUNC(nick) SilcServer server = cmd->server; SilcBuffer packet, nidp, oidp = NULL; SilcClientID *new_id; + uint32 nick_len; char *nick; uint16 ident = silc_command_get_ident(cmd->payload); int nickfail = 0; @@ -1991,16 +1973,15 @@ SILC_SERVER_CMD_FUNC(nick) SILC_SERVER_COMMAND_CHECK(SILC_COMMAND_NICK, cmd, 1, 1); /* Check nickname */ - nick = silc_argument_get_arg_type(cmd->args, 1, NULL); - if (silc_server_command_bad_chars(nick) == TRUE) { + nick = silc_argument_get_arg_type(cmd->args, 1, &nick_len); + if (nick_len > 128) + nick[128] = '\0'; + if (silc_server_name_bad_chars(nick, nick_len) == TRUE) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_NICK, SILC_STATUS_ERR_BAD_NICKNAME); goto out; } - if (strlen(nick) > 128) - nick[128] = '\0'; - /* Check for same nickname */ if (!strcmp(client->nickname, nick)) { nidp = silc_id_payload_encode(client->id, SILC_ID_CLIENT); @@ -3297,10 +3278,10 @@ SILC_SERVER_CMD_FUNC(join) } channel_name = tmp; - if (strlen(channel_name) > 256) + if (tmp_len > 256) channel_name[255] = '\0'; - if (silc_server_command_bad_chars(channel_name) == TRUE) { + if (silc_server_name_bad_chars(channel_name, tmp_len) == TRUE) { silc_server_command_send_status_reply(cmd, SILC_COMMAND_JOIN, SILC_STATUS_ERR_BAD_CHANNEL); goto out; diff --git a/apps/silcd/packet_receive.c b/apps/silcd/packet_receive.c index 9dcc3fa7..ae4f909c 100644 --- a/apps/silcd/packet_receive.c +++ b/apps/silcd/packet_receive.c @@ -1472,6 +1472,7 @@ SilcClientEntry silc_server_new_client(SilcServer server, SilcBuffer reply; SilcIDListData idata; char *username = NULL, *realname = NULL, *id_string; + uint16 username_len; uint32 id_len; int ret; char *hostname, *nickname; @@ -1496,14 +1497,13 @@ SilcClientEntry silc_server_new_client(SilcServer server, /* Parse incoming packet */ ret = silc_buffer_unformat(buffer, - SILC_STR_UI16_STRING_ALLOC(&username), + SILC_STR_UI16_NSTRING_ALLOC(&username, + &username_len), SILC_STR_UI16_STRING_ALLOC(&realname), SILC_STR_END); if (ret == -1) { - if (username) - silc_free(username); - if (realname) - silc_free(realname); + silc_free(username); + silc_free(realname); silc_server_disconnect_remote(server, sock, "Server closed connection: " "Incomplete client information"); return NULL; @@ -1511,17 +1511,22 @@ SilcClientEntry silc_server_new_client(SilcServer server, if (!username) { silc_free(username); - if (realname) - silc_free(realname); + silc_free(realname); silc_server_disconnect_remote(server, sock, "Server closed connection: " "Incomplete client information"); return NULL; } - if (strlen(username) > 128) - username[127] = '\0'; + if (username_len > 128) + username[128] = '\0'; - nickname = strdup(username); + /* Check for bad characters for nickname, and modify the nickname if + it includes those. */ + if (silc_server_name_bad_chars(username, username_len)) { + nickname = silc_server_name_modify_bad(username, username_len); + } else { + nickname = strdup(username); + } /* Make sanity checks for the hostname of the client. If the hostname is provided in the `username' check that it is the same than the @@ -1540,8 +1545,7 @@ SilcClientEntry silc_server_new_client(SilcServer server, strcmp(sock->hostname, hostname)) { silc_free(username); silc_free(hostname); - if (realname) - silc_free(realname); + silc_free(realname); silc_server_disconnect_remote(server, sock, "Server closed connection: " "Incomplete client information"); @@ -1558,18 +1562,15 @@ SilcClientEntry silc_server_new_client(SilcServer server, phostname && strcmp(phostname, hostname)) { silc_free(username); silc_free(hostname); - if (phostname) - silc_free(phostname); - if (realname) - silc_free(realname); + silc_free(phostname); + silc_free(realname); silc_server_disconnect_remote(server, sock, "Server closed connection: " "Incomplete client information"); return NULL; } - if (phostname) - silc_free(phostname); + silc_free(phostname); } else { /* The hostname is not present, add it. */ char *newusername; diff --git a/apps/silcd/server_util.c b/apps/silcd/server_util.c index 1f21972e..f090ff1d 100644 --- a/apps/silcd/server_util.c +++ b/apps/silcd/server_util.c @@ -723,3 +723,42 @@ bool silc_server_client_on_channel(SilcClientEntry client, return FALSE; } + +/* Checks string for bad characters and returns TRUE if they are found. */ + +bool silc_server_name_bad_chars(const char *name, uint32 name_len) +{ + int i; + + for (i = 0; i < name_len; i++) { + if (!isascii(name[i])) + return TRUE; + if (name[i] <= 32) return TRUE; + if (name[i] == ' ') return TRUE; + if (name[i] == '*') return TRUE; + if (name[i] == '?') return TRUE; + if (name[i] == ',') return TRUE; + } + + return FALSE; +} + +/* Modifies the `name' if it includes bad characters and returns new + allocated name that does not include bad characters. */ + +char *silc_server_name_modify_bad(const char *name, uint32 name_len) +{ + int i; + char *newname = strdup(name); + + for (i = 0; i < name_len; i++) { + if (!isascii(newname[i])) newname[i] = '_'; + if (newname[i] <= 32) newname[i] = '_'; + if (newname[i] == ' ') newname[i] = '_'; + if (newname[i] == '*') newname[i] = '_'; + if (newname[i] == '?') newname[i] = '_'; + if (newname[i] == ',') newname[i] = '_'; + } + + return newname; +} diff --git a/apps/silcd/server_util.h b/apps/silcd/server_util.h index 8ac40c45..9cfe1607 100644 --- a/apps/silcd/server_util.h +++ b/apps/silcd/server_util.h @@ -74,4 +74,11 @@ bool silc_server_channel_has_local(SilcChannelEntry channel); bool silc_server_client_on_channel(SilcClientEntry client, SilcChannelEntry channel); +/* Checks string for bad characters and returns TRUE if they are found. */ +bool silc_server_name_bad_chars(const char *name, uint32 name_len); + +/* Modifies the `nick' if it includes bad characters and returns new + allocated nickname that does not include bad characters. */ +char *silc_server_name_modify_bad(const char *name, uint32 name_len); + #endif /* SERVER_UTIL_H */ diff --git a/configure.in.pre b/configure.in.pre index 831465cb..dc2d40ba 100644 --- a/configure.in.pre +++ b/configure.in.pre @@ -786,7 +786,6 @@ lib/silcmath/Makefile lib/silcmath/mpi/Makefile.defines lib/silcmath/mpi/Makefile.defines_int lib/silcsim/Makefile -lib/silcsim/modules/Makefile lib/silcske/Makefile lib/silcutil/Makefile lib/silcutil/unix/Makefile diff --git a/lib/silcclient/README b/lib/silcclient/README index 4295f27c..c5a392e0 100644 --- a/lib/silcclient/README +++ b/lib/silcclient/README @@ -1,7 +1,7 @@ SILC Client Library Manual - Version 0.5 + Version 0.7 1.0 Introduction @@ -79,6 +79,11 @@ the initializing function: client->public_key client->private_key +You may also set client->nickname if you want. If it is set then the +library will change the nickname to that one after the client is connected +to the server. If not set, then server will initially give the nickname +which is same as the username. + After setting the pointers one must call: silc_client_init(client); diff --git a/lib/silcclient/client.c b/lib/silcclient/client.c index fe670596..ba3c70e9 100644 --- a/lib/silcclient/client.c +++ b/lib/silcclient/client.c @@ -1,16 +1,15 @@ /* - client.c + client.c Author: Pekka Riikonen - Copyright (C) 1997 - 2001 Pekka Riikonen + Copyright (C) 1997 - 2002 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - + the Free Software Foundation; version 2 of the License. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -385,7 +384,8 @@ bool silc_client_start_key_exchange(SilcClient client, Make sure they do not do that. */ silc_schedule_task_del_by_fd(client->schedule, fd); - conn->nickname = strdup(client->username); + conn->nickname = (client->nickname ? strdup(client->nickname) : + strdup(client->username)); conn->sock->hostname = strdup(conn->remote_host); conn->sock->ip = strdup(conn->remote_host); conn->sock->port = conn->remote_port; @@ -1500,7 +1500,14 @@ void silc_client_receive_new_id(SilcClient client, (void *)conn->local_entry, 0, NULL); if (connecting) { - /* Issue INFO comqmand to fetch the real server name and server information + /* Send NICK command if the nickname was set by the application (and is + not same as the username). */ + if (client->nickname && strcmp(client->nickname, client->username)) + silc_client_command_send(client, conn, SILC_COMMAND_NICK, + ++conn->cmd_ident, 1, 1, + client->nickname, strlen(client->nickname)); + + /* Issue INFO command to fetch the real server name and server information and other stuff. */ silc_client_command_register(client, SILC_COMMAND_INFO, NULL, NULL, silc_client_command_reply_info_i, 0, diff --git a/lib/silcclient/client.h b/lib/silcclient/client.h index 2b40557b..63593f79 100644 --- a/lib/silcclient/client.h +++ b/lib/silcclient/client.h @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2001 Pekka Riikonen + Copyright (C) 1997 - 2002 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -152,6 +152,7 @@ struct SilcClientConnectionStruct { /* Main client structure. */ struct SilcClientStruct { char *username; /* Username, must be set by application */ + char *nickname; /* Nickname, may be set by application */ char *hostname; /* hostname, must be set by application */ char *realname; /* Real name, must be set be application */ diff --git a/lib/silcclient/client_notify.c b/lib/silcclient/client_notify.c index 8b3663b9..987d5d08 100644 --- a/lib/silcclient/client_notify.c +++ b/lib/silcclient/client_notify.c @@ -1,16 +1,15 @@ /* - client_notify.c + client_notify.c Author: Pekka Riikonen - Copyright (C) 1997 - 2001 Pekka Riikonen + Copyright (C) 1997 - 2002 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - + the Free Software Foundation; version 2 of the License. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the @@ -851,11 +850,9 @@ void silc_client_notify_by_server(SilcClient client, /* Notify application. */ client->internal->ops->notify(client, conn, type, client_entry, tmp); - if (client_entry != conn->local_entry) { - /* Remove client from all channels */ - silc_client_remove_from_channels(client, conn, client_entry); + if (client_entry != conn->local_entry) + /* Remove the client from all channels and free it */ silc_client_del_client(client, conn, client_entry); - } break; @@ -904,7 +901,7 @@ void silc_client_notify_by_server(SilcClient client, if (client_entry == conn->local_entry) continue; - silc_client_remove_from_channels(client, conn, client_entry); + /* Remove the client from all channels and free it */ silc_client_del_client(client, conn, client_entry); } silc_free(clients); diff --git a/lib/silcclient/command.c b/lib/silcclient/command.c index 37ea4d6f..8329e803 100644 --- a/lib/silcclient/command.c +++ b/lib/silcclient/command.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2001 Pekka Riikonen + Copyright (C) 1997 - 2002 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -746,10 +746,9 @@ SILC_TASK_CALLBACK(silc_client_command_kill_remove_later) /* Get the target client */ target = silc_idlist_get_client(cmd->client, conn, nickname, cmd->argv[1], FALSE); - if (target) { - silc_client_remove_from_channels(client, conn, target); + if (target) + /* Remove the client from all channels and free it */ silc_client_del_client(client, conn, target); - } silc_free(nickname); silc_client_command_free(cmd); diff --git a/lib/silcclient/command_reply.c b/lib/silcclient/command_reply.c index 50601561..affe3d60 100644 --- a/lib/silcclient/command_reply.c +++ b/lib/silcclient/command_reply.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2001 Pekka Riikonen + Copyright (C) 1997 - 2002 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by diff --git a/lib/silcclient/idlist.c b/lib/silcclient/idlist.c index d56421c2..5eb11b4b 100644 --- a/lib/silcclient/idlist.c +++ b/lib/silcclient/idlist.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 2001 Pekka Riikonen + Copyright (C) 2001 - 2002 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -700,7 +700,13 @@ bool silc_client_del_client(SilcClient client, SilcClientConnection conn, SilcClientEntry client_entry) { bool ret = silc_idcache_del_by_context(conn->client_cache, client_entry); + + /* Remove from channels */ + silc_client_remove_from_channels(client, conn, client_entry); + + /* Free the client entry data */ silc_client_del_client_entry(client, conn, client_entry); + return ret; } diff --git a/lib/silcsim/Makefile.am b/lib/silcsim/Makefile.am index ac9d278d..866c941c 100644 --- a/lib/silcsim/Makefile.am +++ b/lib/silcsim/Makefile.am @@ -28,10 +28,6 @@ libsilcsim_a_SOURCES = \ silcsim.c \ silcsimutil.c -SIM_MODULES_DIR = modules - -SUBDIRS = modules - # # SILC Ciphers to be compiled as modules # @@ -60,14 +56,14 @@ endif $(SIM_CIPHER_OBJS): ../silccrypt/libsilccrypt.a $(LTCOMPILE) -c $(srcdir)/../silccrypt/$*.c $(LIBTOOL) --mode=link $(LINK) -rpath $(silc_modulesdir) -o lib$*.la $*.lo - cd $(srcdir)/$(SIM_MODULES_DIR) && $(LN_S) -f $(srcdir)/../.libs/lib$*.so $(srcdir)/$*.sim.so + cd $(srcdir) && $(LN_S) -f $(srcdir)/../.libs/lib$*.so $(srcdir)/$*.sim.so $(SIM_HASH_OBJS): ../silccrypt/libsilccrypt.a $(LTCOMPILE) -c $(srcdir)/../silccrypt/$*.c $(LIBTOOL) --mode=link $(LINK) -rpath $(silc_modulesdir) -o lib$*.la $*.lo - cd $(srcdir)/$(SIM_MODULES_DIR) && $(LN_S) -f $(srcdir)/../.libs/lib$*.so $(srcdir)/$*.sim.so + cd $(srcdir) && $(LN_S) -f $(srcdir)/../.libs/lib$*.so $(srcdir)/$*.sim.so -CLEANFILES = $(SIM_MODULES_DIR)/*.sim.so *.la +CLEANFILES = *.sim.so *.la if SILC_DIST_TOOLKIT include_HEADERS = silcsim.h silcsimutil.h diff --git a/lib/silcutil/silcutil.c b/lib/silcutil/silcutil.c index 6b5a36ce..450694b0 100644 --- a/lib/silcutil/silcutil.c +++ b/lib/silcutil/silcutil.c @@ -1,16 +1,15 @@ /* - silcutil.c + silcutil.c - Author: Pekka Riikonen + Author: Pekka Riikonen - Copyright (C) 1997 - 2000 Pekka Riikonen + Copyright (C) 1997 - 2002 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - + the Free Software Foundation; version 2 of the License. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the diff --git a/lib/silcutil/silcutil.h b/lib/silcutil/silcutil.h index 03071194..a8e2adda 100644 --- a/lib/silcutil/silcutil.h +++ b/lib/silcutil/silcutil.h @@ -1,16 +1,15 @@ /* - silcutil.h + silcutil.h - Author: Pekka Riikonen + Author: Pekka Riikonen - Copyright (C) 1997 - 2000 Pekka Riikonen + Copyright (C) 1997 - 2002 Pekka Riikonen This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. - + the Free Software Foundation; version 2 of the License. + This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the -- 2.24.0