Check the socks user name and password when comparing forwarding settings
authorFabian Keil <fk@fabiankeil.de>
Thu, 10 Sep 2020 10:42:15 +0000 (12:42 +0200)
committerFabian Keil <fk@fabiankeil.de>
Tue, 22 Sep 2020 14:22:04 +0000 (16:22 +0200)
gateway.c
jcc.c
project.h

index f1de538..66ec64a 100644 (file)
--- a/gateway.c
+++ b/gateway.c
@@ -287,6 +287,8 @@ void mark_connection_closed(struct reusable_connection *closed_connection)
    closed_connection->forwarder_type = SOCKS_NONE;
    freez(closed_connection->gateway_host);
    closed_connection->gateway_port = 0;
+   freez(closed_connection->auth_username);
+   freez(closed_connection->auth_password);
    freez(closed_connection->forward_host);
    closed_connection->forward_port = 0;
 }
@@ -409,6 +411,24 @@ int connection_destination_matches(const struct reusable_connection *connection,
       return FALSE;
    }
 
+   if (!connection_detail_matches(connection->auth_username, fwd->auth_username))
+   {
+      log_error(LOG_LEVEL_CONNECT, "Socks user name mismatch. "
+         "Previous user name: %s. Current user name: %s",
+         connection->auth_username != NULL ? connection->auth_username : "none",
+         fwd->auth_username != NULL ? fwd->auth_username : "none");
+      return FALSE;
+   }
+
+   if (!connection_detail_matches(connection->auth_password, fwd->auth_password))
+   {
+      log_error(LOG_LEVEL_CONNECT, "Socks user name mismatch. "
+         "Previous password: %s. Current password: %s",
+         connection->auth_password != NULL ? connection->auth_password : "none",
+         fwd->auth_password != NULL ?  fwd->auth_password : "none");
+      return FALSE;
+   }
+
    if (!connection_detail_matches(connection->forward_host, fwd->forward_host))
    {
       log_error(LOG_LEVEL_CONNECT,
diff --git a/jcc.c b/jcc.c
index 581768f..49a6b10 100644 (file)
--- a/jcc.c
+++ b/jcc.c
@@ -1176,6 +1176,22 @@ void save_connection_destination(jb_socket sfd,
       server_connection->gateway_host = NULL;
    }
    server_connection->gateway_port = fwd->gateway_port;
+   if (NULL != fwd->auth_username)
+   {
+      server_connection->auth_username = strdup_or_die(fwd->auth_username);
+   }
+   else
+   {
+      server_connection->auth_username = NULL;
+   }
+   if (NULL != fwd->auth_password)
+   {
+      server_connection->auth_password = strdup_or_die(fwd->auth_password);
+   }
+   else
+   {
+      server_connection->auth_password = NULL;
+   }
 
    if (NULL != fwd->forward_host)
    {
index 6821aa0..a9fe894 100644 (file)
--- a/project.h
+++ b/project.h
@@ -766,6 +766,9 @@ struct reusable_connection
    enum forwarder_type forwarder_type;
    char *gateway_host;
    int  gateway_port;
+   char *auth_username;
+   char *auth_password;
+
    char *forward_host;
    int  forward_port;
 };