From 51f43414f35f09fd43a4e2057ff98323e610ae8f Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Mon, 23 Feb 2004 21:15:29 +0000 Subject: [PATCH] Fixed the WATCH with public keys, and added public key to the WATCH notify sending. --- CHANGES | 8 ++++++++ apps/silcd/command.c | 10 +++++----- apps/silcd/packet_send.c | 20 +++++++++++++------- apps/silcd/packet_send.h | 10 +++++----- apps/silcd/server_util.c | 22 +++++++++++++++++++++- 5 files changed, 52 insertions(+), 18 deletions(-) diff --git a/CHANGES b/CHANGES index 6025100e..f8015a5a 100644 --- a/CHANGES +++ b/CHANGES @@ -5,6 +5,14 @@ Mon Feb 23 23:31:15 EET 2004 Pekka Riikonen crashes on AMD64. Affected files are lib/silcutil/silcbuffmt.h, lib/silcclient/silcvcard.c, silcd/server_util.c. + * Fixed the adding of public key to the WATCH list in server. + Fixed the WATCH notify sending to client. Affected files + are silcd/packet_send.[ch], command.c, server_util.c. + + * Implemented the watching by public key in the SILC Client + Library and SILC Client. Affected files are + lib/silcclient/command.c and client_notify.c. + Mon Feb 23 09:30:30 CET 2004 Pekka Riikonen * Added support for public key watching in server. Affected diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 8adf8bf0..767a0dd3 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -4082,7 +4082,7 @@ SILC_SERVER_CMD_FUNC(watch) } /* Take public key for watching by public key */ - pk = silc_argument_get_arg_type(cmd->args, 3, &pk_len); + pk = silc_argument_get_arg_type(cmd->args, 4, &pk_len); /* Take nickname */ add_nick = silc_argument_get_arg_type(cmd->args, 2, &add_nick_len); @@ -4188,7 +4188,7 @@ SILC_SERVER_CMD_FUNC(watch) 0); goto out; } - + pk = silc_argument_get_next_arg(pkargs, &type, &pk_len); while (pk) { if (!silc_pkcs_public_key_payload_decode(pk, pk_len, &public_key)) @@ -4220,7 +4220,7 @@ SILC_SERVER_CMD_FUNC(watch) /* Add the client to the watcher list with the specified public key. */ - silc_hash_table_add(server->watcher_list, public_key, client); + silc_hash_table_add(server->watcher_list_pk, pkkey, client); } else if (type == 0x01) { /* Delete public key from watch list */ @@ -4240,9 +4240,9 @@ SILC_SERVER_CMD_FUNC(watch) silc_hash_table_del_by_context(server->watcher_list_pk, public_key, client); - /* Now check whether there still exists entries with this key, if + /* Now check whether there still exists entries with this key, if not then free the key to not leak memory. */ - if (!silc_hash_table_find(server->watcher_list, hash, NULL, NULL)) + if (!silc_hash_table_find(server->watcher_list_pk, hash, NULL, NULL)) silc_pkcs_public_key_free(pkkey); silc_pkcs_public_key_free(public_key); } diff --git a/apps/silcd/packet_send.c b/apps/silcd/packet_send.c index 317168e4..17460378 100644 --- a/apps/silcd/packet_send.c +++ b/apps/silcd/packet_send.c @@ -4,7 +4,7 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2003 Pekka Riikonen + Copyright (C) 1997 - 2004 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 @@ -800,8 +800,8 @@ silc_server_packet_relay_to_channel_encrypt(SilcServer server, } memcpy(iv, data + (data_len - iv_len - mac_len), iv_len); - silc_message_payload_encrypt(data, totlen, data_len - mac_len, - iv, iv_len, channel->channel_key, + silc_message_payload_encrypt(data, totlen, data_len - mac_len, + iv, iv_len, channel->channel_key, channel->hmac); } @@ -1548,22 +1548,28 @@ void silc_server_send_notify_watch(SilcServer server, SilcClientEntry watcher, SilcClientEntry client, const char *nickname, - SilcNotifyType type) + SilcNotifyType type, + SilcPublicKey public_key) { - SilcBuffer idp; + SilcBuffer idp, pkp = NULL; unsigned char mode[4], n[2]; idp = silc_id_payload_encode(client->id, SILC_ID_CLIENT); SILC_PUT16_MSB(type, n); SILC_PUT32_MSB(client->mode, mode); + if (public_key) + pkp = silc_pkcs_public_key_payload_encode(public_key); silc_server_send_notify_dest(server, sock, FALSE, watcher->id, SILC_ID_CLIENT, SILC_NOTIFY_TYPE_WATCH, - 4, idp->data, idp->len, + 5, idp->data, idp->len, nickname, nickname ? strlen(nickname) : 0, mode, sizeof(mode), type != SILC_NOTIFY_TYPE_NONE ? - n : NULL, sizeof(n)); + n : NULL, sizeof(n), + pkp ? pkp->data : NULL, + pkp ? pkp->len : 0); silc_buffer_free(idp); + silc_buffer_free(pkp); } /* Sends notify message destined to specific entity. */ diff --git a/apps/silcd/packet_send.h b/apps/silcd/packet_send.h index 6c85c3a8..2b0681b6 100644 --- a/apps/silcd/packet_send.h +++ b/apps/silcd/packet_send.h @@ -4,12 +4,11 @@ Author: Pekka Riikonen - Copyright (C) 1997 - 2003 Pekka Riikonen + Copyright (C) 1997 - 2004 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 @@ -200,7 +199,8 @@ void silc_server_send_notify_watch(SilcServer server, SilcClientEntry watcher, SilcClientEntry client, const char *nickname, - SilcNotifyType type); + SilcNotifyType type, + SilcPublicKey public_key); void silc_server_send_notify_dest(SilcServer server, SilcSocketConnection sock, bool broadcast, @@ -285,4 +285,4 @@ void silc_server_send_opers_notify(SilcServer server, SilcNotifyType type, SilcUInt32 argc, ...); -#endif +#endif /* PACKET_SEND_H */ diff --git a/apps/silcd/server_util.c b/apps/silcd/server_util.c index 48c6f305..ab824897 100644 --- a/apps/silcd/server_util.c +++ b/apps/silcd/server_util.c @@ -1700,7 +1700,8 @@ silc_server_check_watcher_list_foreach(void *key, void *context, notify->client, notify->new_nick ? notify->new_nick : (const char *)notify->client->nickname, - notify->notify); + notify->notify, + notify->client->data.public_key); } } @@ -1783,6 +1784,25 @@ bool silc_server_del_from_watcher_list(SilcServer server, } silc_hash_table_list_reset(&htl); + silc_hash_table_list(server->watcher_list_pk, &htl); + while (silc_hash_table_get(&htl, &key, (void *)&entry)) { + if (entry == client) { + silc_hash_table_del_by_context(server->watcher_list_pk, key, client); + + if (client->id) + SILC_LOG_DEBUG(("Removing %s from WATCH list", + silc_id_render(client->id, SILC_ID_CLIENT))); + + /* Now check whether there still exists entries with this key, if not + then free the key to not leak memory. */ + if (!silc_hash_table_find(server->watcher_list_pk, key, NULL, NULL)) + silc_pkcs_public_key_free(key); + + found = TRUE; + } + } + silc_hash_table_list_reset(&htl); + return found; } -- 2.43.0