From patchwork Fri Oct 25 00:06:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Cerrito X-Patchwork-Id: 873 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director11.mail.ord1d.rsapps.net ([172.27.255.55]) by backend30.mail.ord1d.rsapps.net with LMTP id 0AA9OKbXsl1PJAAAIUCqbw for ; Fri, 25 Oct 2019 07:08:22 -0400 Received: from proxy9.mail.iad3a.rsapps.net ([172.27.255.55]) by director11.mail.ord1d.rsapps.net with LMTP id CHGcNabXsl1cYgAAvGGmqA ; Fri, 25 Oct 2019 07:08:22 -0400 Received: from smtp36.gate.iad3a ([172.27.255.55]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy9.mail.iad3a.rsapps.net with LMTP id EGPQL6bXsl2kcgAAGuSQww ; Fri, 25 Oct 2019 07:08:22 -0400 X-Spam-Threshold: 95 X-Spam-Score: 0 X-Spam-Flag: NO X-Virus-Scanned: OK X-Orig-To: openvpnslackdevel@openvpn.net X-Originating-Ip: [216.105.38.7] Authentication-Results: smtp36.gate.iad3a.rsapps.net; iprev=pass policy.iprev="216.105.38.7"; spf=pass smtp.mailfrom="openvpn-devel-bounces@lists.sourceforge.net" smtp.helo="lists.sourceforge.net"; dkim=fail (signature verification failed) header.d=sourceforge.net; dkim=fail (signature verification failed) header.d=sf.net; dmarc=fail (p=none; dis=none) header.from=gmail.com X-Suspicious-Flag: YES X-Classification-ID: c1c963c6-f717-11e9-a8a1-525400575b2b-1-1 Received: from [216.105.38.7] ([216.105.38.7:40748] helo=lists.sourceforge.net) by smtp36.gate.iad3a.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 07/65-03996-6A7D2BD5; Fri, 25 Oct 2019 07:08:22 -0400 Received: from [127.0.0.1] (helo=sfs-ml-4.v29.lw.sourceforge.com) by sfs-ml-4.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1iNxRB-00038u-SF; Fri, 25 Oct 2019 11:07:21 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-4.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1iNxRA-00038n-OA for openvpn-devel@lists.sourceforge.net; Fri, 25 Oct 2019 11:07:20 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sourceforge.net; s=x; h=Content-Transfer-Encoding:MIME-Version:Message-Id: Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc :Resent-Message-ID:In-Reply-To:References:List-Id:List-Help:List-Unsubscribe: List-Subscribe:List-Post:List-Owner:List-Archive; bh=OfuWQ5eQynPLNWFxJ6Bp+rTlocMqCSsozoeTupmNVGY=; b=lJO3jJw0yQt0w/YTCVQxqqILk0 +Tedrf6sj7FylngK01k3/gVOe7XiIvbZJJXvri32EtsU8c2QSXo5dGWpwCqBHAXcpfMgRb06BlHts wWX1anQLK4nBWxRrXBB2Z7hIa230tyNfUyf16tRjxXC1FB/q97p4VCeaXkoLc48Kx3ow=; DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=sf.net; s=x ; h=Content-Transfer-Encoding:MIME-Version:Message-Id:Date:Subject:Cc:To:From :Sender:Reply-To:Content-Type:Content-ID:Content-Description:Resent-Date: Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To: References:List-Id:List-Help:List-Unsubscribe:List-Subscribe:List-Post: List-Owner:List-Archive; bh=OfuWQ5eQynPLNWFxJ6Bp+rTlocMqCSsozoeTupmNVGY=; b=c 2FDw+mzYDq36smGwmui7XG0dMCSUisZs30CpEmREnt/JrqiRNQN3TNzj/qJcDY0c4W3ux882/9YK0 O5898VebDIBdyKWQLKbvRewr0ZSD5weHrR7DIA+eYhTa7lpbJJRKLxgMOYnDbFrjoLBOZdKZPJ1/Z PHkTwZ5NNhuUDE98=; Received: from smtp.uniroma2.it ([160.80.6.16]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1iNxR5-003Bl9-Tq for openvpn-devel@lists.sourceforge.net; Fri, 25 Oct 2019 11:07:20 +0000 Received: from openvpndev.ccd.uniroma2.it ([160.80.3.24]) by smtp-2015.uniroma2.it (8.14.4/8.14.4/Debian-8) with ESMTP id x9PB70LP010618; Fri, 25 Oct 2019 13:07:05 +0200 From: wardragon78@gmail.com To: openvpn-devel@lists.sourceforge.net Date: Fri, 25 Oct 2019 13:06:31 +0200 Message-Id: <20191025110631.15540-1-wardragon78@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 X-Virus-Status: Clean X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (wardragon78[at]gmail.com) 0.0 DKIM_ADSP_CUSTOM_MED No valid author signature, adsp_override is CUSTOM_MED 1.0 SPF_SOFTFAIL SPF: sender does not match SPF record (softfail) 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit (wardragon78[at]gmail.com) 1.2 NML_ADSP_CUSTOM_MED ADSP custom_med hit, and not from a mailing list 2.0 SPOOFED_FREEMAIL No description available. X-Headers-End: 1iNxR5-003Bl9-Tq Subject: [Openvpn-devel] [PATCH] [PATCH v2] Insert client connection data into PAM environment X-BeenThere: openvpn-devel@lists.sourceforge.net X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: lorenzo.catucci@uniroma2.it, paolo.cerrito@uniroma2.it Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox From: Paolo Cerrito Without this patch, the PAM environment lacks any information about the remote client address. syslog output for auth and authpriv facilities changes from: Oct 25 11:52:02 openvpndev openvpn: pam_unix(openvpn:auth): authentication failure; logname=root uid=0 euid=0 tty= ruser= rhost= Oct 25 11:52:33 openvpndev openvpn: pam_unix(openvpn:auth): authentication failure; logname=root uid=0 euid=0 tty= ruser= rhost= user=**** to: Oct 25 10:56:11 openvpndev openvpn: pam_unix(openvpn:auth): authentication failure; logname=root uid=0 euid=0 tty= ruser= rhost=198.51.100.10 Oct 25 10:57:02 openvpndev openvpn: pam_unix(openvpn:auth): authentication failure; logname=root uid=0 euid=0 tty= ruser= rhost=198.51.100.10 user=**** Furthermore, the presence of the remote client address in PAM environment, enables usage of pam modules like pam_recent [https://github.com/az143/pam_recent]. Signed-off-by: Paolo Cerrito --- src/plugins/auth-pam/auth-pam.c | 39 ++++++++++++++++++++++++++++----- 1 file changed, 33 insertions(+), 6 deletions(-) diff --git a/src/plugins/auth-pam/auth-pam.c b/src/plugins/auth-pam/auth-pam.c index 88b53204..f7b39e36 100644 --- a/src/plugins/auth-pam/auth-pam.c +++ b/src/plugins/auth-pam/auth-pam.c @@ -115,6 +115,7 @@ struct user_pass { char password[128]; char common_name[128]; char response[128]; + char remote[40]; const struct name_value_list *name_value_list; }; @@ -517,13 +518,15 @@ 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_ip6", envp) ? get_env("untrusted_ip6", envp) : get_env("untrusted_ip", envp); if (username && strlen(username) > 0 && password) { if (send_control(context->foreground_fd, COMMAND_VERIFY) == -1 || send_string(context->foreground_fd, username) == -1 || send_string(context->foreground_fd, password) == -1 - || send_string(context->foreground_fd, common_name) == -1) + || send_string(context->foreground_fd, common_name) == -1 + || send_string(context->foreground_fd, remote) == -1) { fprintf(stderr, "AUTH-PAM: Error sending auth info to background process\n"); } @@ -750,8 +753,16 @@ pam_auth(const char *service, const struct user_pass *up) status = pam_start(service, name_value_list_provided ? NULL : up->username, &conv, &pamh); if (status == PAM_SUCCESS) { + /* Set PAM_RHOST environment variable */ + if (*(up->remote)) + { + status = pam_set_item(pamh, PAM_RHOST, up->remote); + } /* Call PAM to verify username/password */ - status = pam_authenticate(pamh, 0); + if (status == PAM_SUCCESS) + { + status = pam_authenticate(pamh, 0); + } if (status == PAM_SUCCESS) { status = pam_acct_mgmt(pamh, 0); @@ -839,7 +850,8 @@ pam_server(int fd, const char *service, int verb, const struct name_value_list * case COMMAND_VERIFY: if (recv_string(fd, up.username, sizeof(up.username)) == -1 || recv_string(fd, up.password, sizeof(up.password)) == -1 - || recv_string(fd, up.common_name, sizeof(up.common_name)) == -1) + || recv_string(fd, up.common_name, sizeof(up.common_name)) == -1 + || recv_string(fd, up.remote, sizeof(up.remote)) == -1) { fprintf(stderr, "AUTH-PAM: BACKGROUND: read error on command channel: code=%d, exiting\n", command); @@ -848,12 +860,27 @@ pam_server(int fd, const char *service, int verb, const struct name_value_list * if (DEBUG(verb)) { + if (up.remote) + { #if 0 - fprintf(stderr, "AUTH-PAM: BACKGROUND: USER/PASS: %s/%s\n", - up.username, up.password); + fprintf(stderr, "AUTH-PAM: BACKGROUND: USER/PASS/REMOTE: %s/%s/%s\n", + up.username, up.password, up.remote); #else - fprintf(stderr, "AUTH-PAM: BACKGROUND: USER: %s\n", up.username); + fprintf(stderr, "AUTH-PAM: BACKGROUND: USER/REMOTE: %s/%s\n", + up.username, up.remote); #endif + } + else + { +#if 0 + fprintf(stderr, "AUTH-PAM: BACKGROUND: USER/PASS: %s/%s\n", + up.username, up.password); +#else + fprintf(stderr, "AUTH-PAM: BACKGROUND: USER: %s/\n", + up.username); +#endif + + } } /* If password is of the form SCRV1:base64:base64 split it up */