[Openvpn-devel,V3] - changed remote lenght and refactored get_env

Message ID 20200326084704.45458-1-wardragon78@gmail.com
State Superseded
Headers show
Series [Openvpn-devel,V3] - changed remote lenght and refactored get_env | expand

Commit Message

Paolo Cerrito March 25, 2020, 9:47 p.m. UTC
1) I put remote lenght to 51, as it have to hold ipv6/ipv4 ip address
plus string terminator.

2) As asked, i refactor the call to get_env, so now first of all there
   is a one call to get_env to get the ipv6 address, if is not set, and
   only in this case,  we recall get_env for ipv4.
---
 .gitignore                      | 1 +
 src/plugins/auth-pam/auth-pam.c | 8 ++++++--
 2 files changed, 7 insertions(+), 2 deletions(-)

Patch

diff --git a/.gitignore b/.gitignore
index 0d68ec4b..3977882f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -72,3 +72,4 @@  nbproject
 test-driver
 compile
 stamp-h2
+outgoing/*
diff --git a/src/plugins/auth-pam/auth-pam.c b/src/plugins/auth-pam/auth-pam.c
index 9d8dfb95..b55a2ecd 100644
--- a/src/plugins/auth-pam/auth-pam.c
+++ b/src/plugins/auth-pam/auth-pam.c
@@ -115,7 +115,7 @@  struct user_pass {
     char password[128];
     char common_name[128];
     char response[128];
-    char remote[128];
+    char remote[51]; //51 as ipv6 form n:n:n:n:n:n:d.d.d.d/mask and terminator+1
 
     const struct name_value_list *name_value_list;
 };
@@ -518,7 +518,11 @@  openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, const cha
         const char *username = get_env("username", envp);
         const char *password = get_env("password", envp);
         const char *common_name = get_env("common_name", envp) ? get_env("common_name", envp) : "";
-        const char *remote = get_env("untrusted_ip", envp) ? get_env("untrusted_ip", envp) : get_env("untrusted_ip6", envp);
+        const char *remote = get_env("untrusted_ip6", envp);
+       
+	if (remote == NULL){ 
+		remote = get_env("untrusted_ip", envp); //try to take ipv4 if not set ipv6
+	}
 
         if (username && strlen(username) > 0 && password)
         {