From f33c4ed1d6693231d06a08590dae0cc87c97e857 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Rytis=20Slatkevi=C3=A8ius?= Date: Tue, 3 Nov 2015 10:15:07 +0200 Subject: [PATCH] Sched: use X-Forwarded-For as the client's IP address in case it is set (if the scheduler is behind a load balancer, environment's remote_addr will contain load balancer's IP). --- sched/handle_request.cpp | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/sched/handle_request.cpp b/sched/handle_request.cpp index 023e688686..80b75cdad9 100644 --- a/sched/handle_request.cpp +++ b/sched/handle_request.cpp @@ -498,6 +498,17 @@ got_host: return 0; } +inline static const char* get_remote_addr() { + // Server is behind a load balancer or proxy + const char* p = getenv("HTTP_X_FORWARDED_FOR"); + if (p) { + return p; + } + + const char * r = getenv("REMOTE_ADDR"); + return r ? r : "?.?.?.?"; +} + // modify host struct based on request. // Copy all fields that are determined by the client. // @@ -585,7 +596,7 @@ static int update_host_record(HOST& initial_host, HOST& xhost, USER& user) { md5_block((const unsigned char*)buf, strlen(buf), host.host_cpid); } - char* p = getenv("REMOTE_ADDR"); + const char* p = get_remote_addr(); if (p) { strlcpy(host.external_ip_addr, p, sizeof(host.external_ip_addr)); } @@ -1044,11 +1055,6 @@ bool wrong_core_client_version() { return true; } -inline static const char* get_remote_addr() { - const char * r = getenv("REMOTE_ADDR"); - return r ? r : "?.?.?.?"; -} - void handle_msgs_from_host() { unsigned int i; DB_MSG_FROM_HOST mfh;