Added command lagging support. Added idle counting support.
authorPekka Riikonen <priikone@silcnet.org>
Mon, 17 Jul 2000 11:47:30 +0000 (11:47 +0000)
committerPekka Riikonen <priikone@silcnet.org>
Mon, 17 Jul 2000 11:47:30 +0000 (11:47 +0000)
apps/silcd/command.c
apps/silcd/idlist.c
apps/silcd/idlist.h
apps/silcd/server.c
apps/silcd/server_version.c

index fae70a4f7772cc8e1eaf9dcfd8238bd7561897d7..f0d2447062af5f93a32047e888a7d0e54435b9c1 100644 (file)
@@ -20,6 +20,9 @@
 /*
  * $Id$
  * $Log$
+ * Revision 1.10  2000/07/17 11:47:30  priikone
+ *     Added command lagging support. Added idle counting support.
+ *
  * Revision 1.9  2000/07/12 05:59:41  priikone
  *     Major rewrite of ID Cache system. Support added for the new
  *     ID cache system. Major rewrite of ID List stuff on server.  All
@@ -157,6 +160,24 @@ void silc_server_command_process(SilcServer server,
 {
   SilcServerCommandContext ctx;
   SilcServerCommand *cmd;
+
+  /* Check whether it is allowed for this connection to execute any
+     command. */
+  if (sock->type == SILC_SOCKET_TYPE_CLIENT) {
+    time_t curtime;
+    SilcClientEntry client = (SilcClientEntry)sock->user_data;
+
+    if (!client)
+      goto out;
+
+    /* Allow only one command executed in 2 seconds. */
+    curtime = time(NULL);
+    if (client->last_command && (curtime - client->last_command) < 2)
+      goto out;
+
+    /* Update access time */
+    client->last_command = curtime;
+  }
   
   /* Allocate command context. This must be free'd by the
      command routine receiving it. */
@@ -195,6 +216,7 @@ void silc_server_command_process(SilcServer server,
     return;
   }
 
+ out:
   silc_buffer_free(packet->buffer);
 }
 
@@ -409,6 +431,7 @@ SILC_SERVER_CMD_FUNC(whois)
   /* XXX */
   if (cmd->sock->type == SILC_SOCKET_TYPE_CLIENT) {
     char nh[256], uh[256];
+    unsigned char idle[4];
     SilcSocketConnection hsock;
 
     memset(uh, 0, sizeof(uh));
@@ -427,23 +450,27 @@ SILC_SERVER_CMD_FUNC(whois)
     len = hsock->hostname ? strlen(hsock->hostname) : strlen(hsock->ip);
     strncat(uh, hsock->hostname ? hsock->hostname : hsock->ip, len);
 
+    SILC_PUT32_MSB((time(NULL) - entry->last_receive), idle);
+
     /* XXX */
     if (entry->userinfo)
       packet = 
         silc_command_encode_reply_payload_va(SILC_COMMAND_WHOIS,
-                                            SILC_STATUS_OK, 4
+                                            SILC_STATUS_OK, 5
                                             2, id_string, SILC_ID_CLIENT_LEN,
                                             3, nh, strlen(nh),
                                             4, uh, strlen(uh),
                                             5, entry->userinfo, 
-                                            strlen(entry->userinfo));
+                                            strlen(entry->userinfo),
+                                            7, idle, 4);
     else
       packet = 
         silc_command_encode_reply_payload_va(SILC_COMMAND_WHOIS,
-                                            SILC_STATUS_OK, 3
+                                            SILC_STATUS_OK, 4
                                             2, id_string, SILC_ID_CLIENT_LEN,
                                             3, nh, strlen(nh),
-                                            4, uh, strlen(uh));
+                                            4, uh, strlen(uh),
+                                            7, idle, 4);
 
   } else {
     /* XXX */
index 2bb1636d66811dbcb2fdad00440215a888712b73..bc198fa0f8bc62f3e97784ad410ccdbb189b733d 100644 (file)
@@ -20,6 +20,9 @@
 /*
  * $Id$
  * $Log$
+ * Revision 1.6  2000/07/17 11:47:30  priikone
+ *     Added command lagging support. Added idle counting support.
+ *
  * Revision 1.5  2000/07/12 05:59:41  priikone
  *     Major rewrite of ID Cache system. Support added for the new
  *     ID cache system. Major rewrite of ID List stuff on server.  All
@@ -162,10 +165,6 @@ void silc_idlist_del_client(SilcIDList id_list, SilcClientEntry entry)
       silc_pkcs_public_key_free(entry->public_key);
     if (entry->hmac)
       silc_hmac_free(entry->hmac);
-    if (entry->hmac_key) {
-      memset(entry->hmac_key, 0, entry->hmac_key_len);
-      silc_free(entry->hmac_key);
-    }
   }
 }
 
index d9bfe339fa219f416b41eb93c829c078e34bb6ab..66fa094bf6d1badd579859275bfb25faabc3b715 100644 (file)
@@ -61,6 +61,10 @@ typedef struct SilcChannelEntryStruct *SilcChannelEntry;
        the server SILC will ever need. These are also the informations
        that is broadcasted between servers and routers in the SILC network.
 
+   long last_receive
+
+       Time when data was received from the server last time.
+
    SilcServerEntry router
 
        This is a pointer back to the server list. This is the router server 
@@ -68,9 +72,10 @@ typedef struct SilcChannelEntryStruct *SilcChannelEntry;
        it doesn't have a route this is NULL.
 
    SilcCipher send_key
-   
    SilcCipher receive_key
 
+       Data sending and receiving keys.
+
    void *connection
 
        A pointer, usually, to the socket list for fast referencing to
@@ -83,6 +88,7 @@ struct SilcServerEntryStruct {
   char *server_name;
   int server_type;
   SilcServerID *id;
+  long last_receive;
 
   /* TRUE when server is registered to server */
   int registered;
@@ -165,6 +171,23 @@ struct SilcServerEntryStruct {
        Client's mode.  Client maybe for example server operator or
        router operator (SILC operator).
 
+   long last_receive
+
+       Time of last time data was received from the client. This is
+       result of normal time().
+
+   long last_command
+
+       Time of last time client executed command. We are strict and will
+       not allow any command to be exeucted more than once in about
+       2 seconds. This is result of normal time().
+
+   int registered
+
+       Boolean value to indicate whether this client has registered itself
+       to the server. After KE and authentication protocols has been
+       successfully completed will client become registered.
+
    SilcServerEntry router
 
        This is a pointer to the server list. This is the router server whose 
@@ -181,8 +204,6 @@ struct SilcServerEntryStruct {
        PKCS of the client. This maybe NULL.
 
    SilcHmac hmac
-   unsigned char *hmac_key
-   unsigned int hmac_key_len
 
        MAC key used to compute MAC's for packets. 
 
@@ -201,6 +222,10 @@ struct SilcClientEntryStruct {
   SilcClientID *id;
   int mode;
 
+  /* Time of last accesses of the client */
+  long last_receive;
+  long last_command;
+
   /* TRUE when client is registered to server */
   int registered;
 
@@ -217,8 +242,6 @@ struct SilcClientEntryStruct {
   SilcPKCS pkcs;
   SilcHmac hmac;
   SilcPublicKey public_key;
-  unsigned char *hmac_key;
-  unsigned int hmac_key_len;
 
   /* Connection data */
   void *connection;
index 5c9580cd417ad1b01cb24a74c1c437b4f9459c12..c17d2c7ffe30f1103c5846f40b61c12777af11d9 100644 (file)
@@ -25,6 +25,9 @@
 /*
  * $Id$
  * $Log$
+ * Revision 1.10  2000/07/17 11:47:30  priikone
+ *     Added command lagging support. Added idle counting support.
+ *
  * Revision 1.9  2000/07/14 06:15:47  priikone
  *     Moved all the generic packet sending, encryption, reception,
  *     decryption and processing functions to library as they were
@@ -961,9 +964,6 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
        break;
       }
 
-      client->hmac_key = conn_data->hmac_key;
-      client->hmac_key_len = conn_data->hmac_key_len;
-      
       /* Free the temporary connection data context from key exchange */
       silc_free(conn_data);
 
@@ -1157,6 +1157,8 @@ SILC_TASK_CALLBACK(silc_server_packet_process)
        if (!clnt)
          break;
 
+       clnt->last_receive = time(NULL);
+
        cipher = clnt->receive_key;
        hmac = clnt->hmac;
        break;
@@ -1168,6 +1170,8 @@ SILC_TASK_CALLBACK(silc_server_packet_process)
        if (!srvr)
          break;
 
+       srvr->last_receive = time(NULL);
+
        cipher = srvr->receive_key;
        hmac = srvr->hmac;
        break;
index 08d93ce915752a3c91594f2fa2daf8c05a531d7e..b57b84d7e10cfc7dc2641a944750913fec2cc59c 100644 (file)
@@ -20,4 +20,4 @@
 
 #include "serverincludes.h"
 
-const char server_version[] = "10072000";
+const char server_version[] = "14072000";