From: Pekka Riikonen Date: Mon, 17 Jul 2000 11:47:30 +0000 (+0000) Subject: Added command lagging support. Added idle counting support. X-Git-Tag: SILC.0.1~445 X-Git-Url: http://git.silcnet.org/gitweb/?a=commitdiff_plain;h=ce2d1b81e5a907849a877e0a067f7e032fc71f17;p=silc.git Added command lagging support. Added idle counting support. --- diff --git a/apps/silcd/command.c b/apps/silcd/command.c index fae70a4f..f0d24470 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -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 */ diff --git a/apps/silcd/idlist.c b/apps/silcd/idlist.c index 2bb1636d..bc198fa0 100644 --- a/apps/silcd/idlist.c +++ b/apps/silcd/idlist.c @@ -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); - } } } diff --git a/apps/silcd/idlist.h b/apps/silcd/idlist.h index d9bfe339..66fa094b 100644 --- a/apps/silcd/idlist.h +++ b/apps/silcd/idlist.h @@ -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; diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 5c9580cd..c17d2c7f 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -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; diff --git a/apps/silcd/server_version.c b/apps/silcd/server_version.c index 08d93ce9..b57b84d7 100644 --- a/apps/silcd/server_version.c +++ b/apps/silcd/server_version.c @@ -20,4 +20,4 @@ #include "serverincludes.h" -const char server_version[] = "10072000"; +const char server_version[] = "14072000";