Fixed the WATCH with public keys, and added public key to the
authorPekka Riikonen <priikone@silcnet.org>
Mon, 23 Feb 2004 21:15:29 +0000 (21:15 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 23 Feb 2004 21:15:29 +0000 (21:15 +0000)
WATCH notify sending.

CHANGES
apps/silcd/command.c
apps/silcd/packet_send.c
apps/silcd/packet_send.h
apps/silcd/server_util.c

diff --git a/CHANGES b/CHANGES
index 6025100e1893f602b7982319eec051b9af56f594..f8015a5a55b19e443ae898aa561f222b561a66b6 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -5,6 +5,14 @@ Mon Feb 23 23:31:15 EET 2004  Pekka Riikonen <priikone@silcnet.org>
          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 <priikone@silcnet.org>
 
        * Added support for public key watching in server.  Affected
index 8adf8bf0195bff7884e9d8475dc8260a4648ebfd..767a0dd390450fce4c8bd1e57daccad32d01979c 100644 (file)
@@ -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);
       }
index 317168e4559b2d5ab31b2737c9ac9b3757d27121..17460378593c6a874c2d1ec646621873797245da 100644 (file)
@@ -4,7 +4,7 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  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. */
index 6c85c3a8c6c8a52d7bba8deced511e7a201bfd01..2b0681b6012079463602f9fa9fbecc270878b880 100644 (file)
@@ -4,12 +4,11 @@
 
   Author: Pekka Riikonen <priikone@silcnet.org>
 
-  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 */
index 48c6f30599613fb6fce9ef466031d44462bf4173..ab8248974b4f6a0efff9de35a6bce5b3105b3d2a 100644 (file)
@@ -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;
 }