From 12bec955584a6a74af2972814b1a44ab2ead3dfe Mon Sep 17 00:00:00 2001 From: Pekka Riikonen Date: Sun, 17 Dec 2000 13:07:35 +0000 Subject: [PATCH] Added require_reverse_mapping for ServerParams. --- CHANGES | 12 ++++++++++++ apps/silcd/command.c | 8 ++++---- apps/silcd/packet_send.c | 4 ++-- apps/silcd/protocol.c | 5 ++--- apps/silcd/server.c | 28 ++++++++++++++++------------ apps/silcd/server.h | 4 +++- lib/silcutil/silcnet.c | 8 ++++++-- 7 files changed, 45 insertions(+), 24 deletions(-) diff --git a/CHANGES b/CHANGES index 426d317c..7163d0d6 100644 --- a/CHANGES +++ b/CHANGES @@ -1,9 +1,21 @@ +Sun Dec 17 14:40:08 EET 2000 Pekka Riikonen + + * Added `require_reverse_mapping' boolean value to ServerParams + structure. If TRUE (not default) the server will require that + the connecting host has fully qualified domain name. + + If the reverse mapping is not required and hostname could not be + found the IP address is used as hostname. + Sat Dec 16 17:39:54 EET 2000 Pekka Riikonen * Implemented version string checking to both client and server. The check is incomplete currently due to the abnormal version strings used in development version of SILC. + * Changed all command functions in server to use the new + CHECK_ARGS macro. + Fri Dec 15 15:55:12 EET 2000 Pekka Riikonen * Changed char *data to unsigned char *data in ID Cache system to diff --git a/apps/silcd/command.c b/apps/silcd/command.c index 7373d1a5..361e3891 100644 --- a/apps/silcd/command.c +++ b/apps/silcd/command.c @@ -461,8 +461,8 @@ silc_server_command_whois_send_reply(SilcServerCommandContext cmd, if (!strchr(entry->username, '@')) { strncat(uh, "@", 1); hsock = (SilcSocketConnection)entry->connection; - len = hsock->hostname ? strlen(hsock->hostname) : strlen(hsock->ip); - strncat(uh, hsock->hostname ? hsock->hostname : hsock->ip, len); + len = strlen(hsock->hostname); + strncat(uh, hsock->hostname, len); } SILC_PUT32_MSB((time(NULL) - entry->data.last_receive), idle); @@ -847,8 +847,8 @@ silc_server_command_identify_send_reply(SilcServerCommandContext cmd, if (!strchr(entry->username, '@')) { strncat(uh, "@", 1); hsock = (SilcSocketConnection)entry->connection; - len = hsock->hostname ? strlen(hsock->hostname) : strlen(hsock->ip); - strncat(uh, hsock->hostname ? hsock->hostname : hsock->ip, len); + len = strlen(hsock->hostname); + strncat(uh, hsock->hostname, len); } packet = silc_command_reply_payload_encode_va(SILC_COMMAND_IDENTIFY, diff --git a/apps/silcd/packet_send.c b/apps/silcd/packet_send.c index 775ab48e..c936583c 100644 --- a/apps/silcd/packet_send.c +++ b/apps/silcd/packet_send.c @@ -587,8 +587,8 @@ void silc_server_packet_relay_to_channel(SilcServer server, sock = (SilcSocketConnection)client->connection; idata = (SilcIDListData)client; - SILC_LOG_DEBUG(("Sending packet to client %s", - sock->hostname ? sock->hostname : sock->ip)); + SILC_LOG_DEBUG(("Sending packet to client %s (%s)", + sock->hostname, sock->ip)); /* Send the packet */ silc_server_packet_send_to_channel_real(server, sock, &packetdata, diff --git a/apps/silcd/protocol.c b/apps/silcd/protocol.c index fbe1f566..b7744da8 100644 --- a/apps/silcd/protocol.c +++ b/apps/silcd/protocol.c @@ -514,9 +514,8 @@ SILC_TASK_CALLBACK(silc_server_protocol_connection_auth) unsigned short conn_type; unsigned char *auth_data; - SILC_LOG_INFO(("Performing authentication protocol for %s", - ctx->sock->hostname ? ctx->sock->hostname : - ctx->sock->ip)); + SILC_LOG_INFO(("Performing authentication protocol for %s (%s)", + ctx->sock->hostname, ctx->sock->ip)); /* Parse the received authentication data packet. The received payload is Connection Auth Payload. */ diff --git a/apps/silcd/server.c b/apps/silcd/server.c index 286ac5b6..047cca05 100644 --- a/apps/silcd/server.c +++ b/apps/silcd/server.c @@ -80,11 +80,13 @@ void silc_server_free(SilcServer server) if (server->rng) silc_rng_free(server->rng); +#ifdef SILC_SIM while ((sim = silc_dlist_get(server->sim)) != SILC_LIST_END) { silc_dlist_del(server->sim, sim); silc_sim_free(sim); } silc_dlist_uninit(server->sim); +#endif if (server->params) silc_free(server->params); @@ -122,6 +124,7 @@ int silc_server_init(SilcServer server) server->params->retry_interval_max = SILC_SERVER_RETRY_INTERVAL_MAX; server->params->retry_keep_trying = FALSE; server->params->protocol_timeout = 60; + server->params->require_reverse_mapping = FALSE; /* Set log files where log message should be saved. */ server->config->server = server; @@ -219,11 +222,9 @@ int silc_server_init(SilcServer server) server->local_list->servers = silc_idcache_alloc(0); server->local_list->channels = silc_idcache_alloc(0); - /* XXX for now these are allocated for normal server as well as these - hold some global information that the server has fetched from its - router. For router these are used as they are supposed to be used - on router. The XXX can be remoevd later if this is the way we are - going to do this in the normal server as well. */ + /* These are allocated for normal server as well as these hold some + global information that the server has fetched from its router. For + router these are used as they are supposed to be used on router. */ server->global_list->clients = silc_idcache_alloc(0); server->global_list->servers = silc_idcache_alloc(0); server->global_list->channels = silc_idcache_alloc(0); @@ -365,7 +366,9 @@ void silc_server_stop(SilcServer server) SILC_LOG_DEBUG(("Server stopped")); } -/* The heart of the server. This runs the scheduler thus runs the server. */ +/* The heart of the server. This runs the scheduler thus runs the server. + When this returns the server has been stopped and the program will + be terminated. */ void silc_server_run(SilcServer server) { @@ -722,8 +725,7 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router_final) /* Add the connected router to local server list */ server->standalone = FALSE; - id_entry = silc_idlist_add_server(server->local_list, - sock->hostname ? sock->hostname : sock->ip, + id_entry = silc_idlist_add_server(server->local_list, sock->hostname, SILC_ROUTER, ctx->dest_id, NULL, sock); if (!id_entry) { if (ctx->dest_id) @@ -797,13 +799,15 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection) /* XXX This MUST be done async as this will block the entire server process. Either we have to do our own resolver stuff or in the future we can use threads. */ - /* Perform mandatory name and address lookups for the remote host. */ + /* Perform name and address lookups for the remote host. */ silc_net_check_host_by_sock(sock, &newsocket->hostname, &newsocket->ip); - if (!newsocket->ip || !newsocket->hostname) { - SILC_LOG_DEBUG(("IP lookup/DNS lookup failed")); - SILC_LOG_ERROR(("IP lookup/DNS lookup failed")); + if ((server->params->require_reverse_mapping && !newsocket->hostname) || + !newsocket->ip) { + SILC_LOG_ERROR(("IP/DNS lookup failed")); return; } + if (!newsocket->hostname) + newsocket->hostname = strdup(newsocket->ip); SILC_LOG_INFO(("Incoming connection from %s (%s)", newsocket->hostname, newsocket->ip)); diff --git a/apps/silcd/server.h b/apps/silcd/server.h index dd952162..7d38a7e7 100644 --- a/apps/silcd/server.h +++ b/apps/silcd/server.h @@ -55,10 +55,12 @@ typedef struct { unsigned long retry_interval_min; unsigned long retry_interval_min_usec; unsigned long retry_interval_max; - unsigned int retry_keep_trying; + char retry_keep_trying; unsigned long protocol_timeout; unsigned long protocol_timeout_usec; + + char require_reverse_mapping; } *SilcServerParams; /* Macros */ diff --git a/lib/silcutil/silcnet.c b/lib/silcutil/silcnet.c index c4d6d9d7..d06731d1 100644 --- a/lib/silcutil/silcnet.c +++ b/lib/silcutil/silcnet.c @@ -20,6 +20,9 @@ /* * $Id$ * $Log$ + * Revision 1.3 2000/12/17 13:07:35 priikone + * Added require_reverse_mapping for ServerParams. + * * Revision 1.2 2000/10/31 19:48:32 priikone * A LOT updates. Cannot separate. :) * @@ -254,7 +257,8 @@ int silc_net_is_ip(const char *addr) return inet_aton(addr, &tmp); } -/* Performs lookups for remote name and IP address. */ +/* Performs lookups for remote name and IP address. This peforms reverse + lookup as well to verify that the IP has FQDN. */ void silc_net_check_host_by_sock(int sock, char **hostname, char **ip) { @@ -282,7 +286,7 @@ void silc_net_check_host_by_sock(int sock, char **hostname, char **ip) if (!dest) return; - /* Get same hsot by name to see that the remote host really is + /* Get same host by name to see that the remote host really is the who it says it is */ memset(host_name, 0, sizeof(host_name)); memcpy(host_name, dest->h_name, strlen(dest->h_name)); -- 2.24.0