Added support for multiple PublicKey instances in the config
[silc.git] / apps / silcd / server.c
index 85cd3c0066ab64953937b8d05ecc527b69f43518..1f468f1dac29103a9450488c7af211a98e8f44c5 100644 (file)
@@ -765,20 +765,18 @@ SILC_TASK_CALLBACK(silc_server_connect_to_router_second)
     conn = sconn->conn;
 
   if (conn) {
-    /* Match found. Use the configured authentication method */
+    /* Match found. Use the configured authentication method. Take only
+       the passphrase, since for public key auth we automatically use
+       our local key pair. */
     if (conn->passphrase) {
-      if (conn->publickey && !server->config->prefer_passphrase_auth) {
-       proto_ctx->auth_data = conn->publickey;
-       proto_ctx->auth_data_len = 0;
+      if (conn->publickeys && !server->config->prefer_passphrase_auth) {
        proto_ctx->auth_meth = SILC_AUTH_PUBLIC_KEY;
       } else {
        proto_ctx->auth_data = strdup(conn->passphrase);
        proto_ctx->auth_data_len = strlen(conn->passphrase);
        proto_ctx->auth_meth = SILC_AUTH_PASSWORD;
       }
-    } else if (conn->publickey) {
-      proto_ctx->auth_data = conn->publickey;
-      proto_ctx->auth_data_len = 0;
+    } else if (conn->publickeys) {
       proto_ctx->auth_meth = SILC_AUTH_PUBLIC_KEY;
     } else {
       proto_ctx->auth_meth = SILC_AUTH_NONE;
@@ -1311,7 +1309,8 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
 
   entry->data.last_receive = time(NULL);
 
-  num_sockets = silc_server_num_sockets_by_ip(server, sock->ip);
+  num_sockets = silc_server_num_sockets_by_ip(server, sock->ip, 
+                                             ctx->conn_type);
 
   switch (ctx->conn_type) {
   case SILC_SOCKET_TYPE_CLIENT:
@@ -1336,7 +1335,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
        max_per_host = conn->param->connections_max_per_host;
       }
 
-      if (num_sockets > max_per_host) {
+      if (num_sockets >= max_per_host) {
        SILC_LOG_INFO(("Too many connections from %s (%s), closing connection",
                       sock->hostname, sock->ip));
        silc_server_disconnect_remote(server, sock, 
@@ -1439,7 +1438,7 @@ SILC_TASK_CALLBACK(silc_server_accept_new_connection_final)
        backup_router = sconn->backup_router;
       }
 
-      if (num_sockets > max_per_host) {
+      if (num_sockets >= max_per_host) {
        SILC_LOG_INFO(("Too many connections from %s (%s), closing connection",
                       sock->hostname, sock->ip));
        silc_server_disconnect_remote(server, sock,