X-Git-Url: http://git.silcnet.org/gitweb/?a=blobdiff_plain;f=apps%2Fsilcd%2Fprotocol.c;h=eb7b3013a01e2f5cdf6c0777ca54fdb4793209e0;hb=aab72291cf0379050d3b327b43f366d7e886d7c8;hp=65fafeeae26e53ab27c5f39f2231a9f7e39a4eaa;hpb=ec4a54ed22b46fe1c02bc5ecbf0eb15c45fe7967;p=silc.git diff --git a/apps/silcd/protocol.c b/apps/silcd/protocol.c index 65fafeea..eb7b3013 100644 --- a/apps/silcd/protocol.c +++ b/apps/silcd/protocol.c @@ -325,60 +325,36 @@ int silc_server_protocol_ke_set_keys(SilcServer server, SilcSKEStatus silc_ske_check_version(SilcSKE ske, unsigned char *version, SilcUInt32 len, void *context) { - SilcSKEStatus status = SILC_SKE_STATUS_OK; - char *cp; - int maj = 0, min = 0, build = 0, maj2 = 0, min2 = 0, build2 = 0; + SilcUInt32 l_protocol_version = 0, r_protocol_version = 0; SILC_LOG_INFO(("%s (%s) is version %s", ske->sock->hostname, ske->sock->ip, version)); - /* Check for initial version string. Allowed "SILC-x.x-". More - specific protocol version is checked later in session. */ - if (!strstr(version, "SILC-")) - status = SILC_SKE_STATUS_BAD_VERSION; - - /* Check software version */ - - cp = version + 9; - if (!cp) - status = SILC_SKE_STATUS_BAD_VERSION; - - maj = atoi(cp); - cp = strchr(cp, '.'); - if (cp) { - min = atoi(cp + 1); - cp++; - } - if (cp) { - cp = strchr(cp, '.'); - if (cp) - build = atoi(cp + 1); + if (!silc_parse_version_string(version, &r_protocol_version, NULL, NULL, + NULL, NULL)) { + SILC_LOG_ERROR(("%s (%s) %s is not allowed/supported version", + ske->sock->hostname, ske->sock->ip, version)); + return SILC_SKE_STATUS_BAD_VERSION; } - cp = silc_version_string + 9; - if (!cp) - status = SILC_SKE_STATUS_BAD_VERSION; - - maj2 = atoi(cp); - cp = strchr(cp, '.'); - if (cp) { - min2 = atoi(cp + 1); - cp++; - } - if (cp) { - cp = strchr(cp, '.'); - if (cp) - build2 = atoi(cp + 1); + if (!silc_parse_version_string(silc_version_string, + &l_protocol_version, NULL, NULL, + NULL, NULL)) { + SILC_LOG_ERROR(("%s (%s) %s is not allowed/supported version", + ske->sock->hostname, ske->sock->ip, version)); + return SILC_SKE_STATUS_BAD_VERSION; } - if (maj != maj2) - status = SILC_SKE_STATUS_BAD_VERSION; - - if (status == SILC_SKE_STATUS_BAD_VERSION) + /* If remote is too new, don't connect */ + if (l_protocol_version < r_protocol_version) { SILC_LOG_ERROR(("%s (%s) %s is not allowed/supported version", ske->sock->hostname, ske->sock->ip, version)); + return SILC_SKE_STATUS_BAD_VERSION; + } + + ske->sock->version = r_protocol_version; - return status; + return SILC_SKE_STATUS_OK; } /* Callback that is called by the SKE to indicate that it is safe to