From patchwork Sat Jun 20 04:39:40 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gert Doering X-Patchwork-Id: 1154 Return-Path: Delivered-To: patchwork@openvpn.net Delivered-To: patchwork@openvpn.net Received: from director8.mail.ord1d.rsapps.net ([172.30.191.6]) by backend30.mail.ord1d.rsapps.net with LMTP id kIspBsQo7l6kRgAAIUCqbw for ; Sat, 20 Jun 2020 11:18:28 -0400 Received: from proxy5.mail.ord1d.rsapps.net ([172.30.191.6]) by director8.mail.ord1d.rsapps.net with LMTP id AJIXBsQo7l5gaAAAfY0hYg ; Sat, 20 Jun 2020 11:18:28 -0400 Received: from smtp6.gate.ord1d ([172.30.191.6]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) by proxy5.mail.ord1d.rsapps.net with LMTP id 4NerBcQo7l7APAAA8Zzt7w ; Sat, 20 Jun 2020 11:18:28 -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: smtp6.gate.ord1d.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=none (p=nil; dis=none) header.from=greenie.muc.de X-Suspicious-Flag: YES X-Classification-ID: 4a1bc324-b309-11ea-808e-52540050e3e0-1-1 Received: from [216.105.38.7] ([216.105.38.7:35402] helo=lists.sourceforge.net) by smtp6.gate.ord1d.rsapps.net (envelope-from ) (ecelerity 4.2.38.62370 r(:)) with ESMTPS (cipher=DHE-RSA-AES256-GCM-SHA384) id 93/B5-30833-3C82EEE5; Sat, 20 Jun 2020 11:18:27 -0400 Received: from [127.0.0.1] (helo=sfs-ml-1.v29.lw.sourceforge.com) by sfs-ml-1.v29.lw.sourceforge.com with esmtp (Exim 4.90_1) (envelope-from ) id 1jmfFQ-0006WX-Mt; Sat, 20 Jun 2020 15:17:36 +0000 Received: from [172.30.20.202] (helo=mx.sourceforge.net) by sfs-ml-1.v29.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.90_1) (envelope-from ) id 1jmfFP-0006WJ-0w for openvpn-devel@lists.sourceforge.net; Sat, 20 Jun 2020 15:17:35 +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:To:From:Sender:Reply-To:Cc: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=b8d5Pu0RMYn7+Ohh4C7nE4CVvRODTa2QNPk3Aj28Z+c=; b=Cb29R53CewgxqSnWuKu0Fs3w98 aItV4PzeWvzYYT1bNJWrBtBW96TY93yCFcgvGh0qczEEU3bKwqKxF6tSXhgQxz34Wznt0hHKGhk1u SZAoc2memetYFg+rcXbUkFvlTPNRVQQVhDm91buPQ1SNk3x52rWiqSTjE5FtXZekP79U=; 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:To:From: Sender:Reply-To:Cc: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=b8d5Pu0RMYn7+Ohh4C7nE4CVvRODTa2QNPk3Aj28Z+c=; b=E EWMu5a5DGiyfhCNWlQh+hDJfMkeB/+/3iddCmyreD7veLRCkSWjFi/nuxZtc5VoUuRJhIWvSRiV8/ oInYDe5DyxfVCLo40KxMNEOHRTI4zZRxngC4kJSw+0iRgkJUswhi5nNt5yKk4Es0KtnALZsKsGpCd NQFt1Y/HyNGNialE=; Received: from vmail1.greenie.net ([195.30.8.66]) by sfi-mx-3.v28.lw.sourceforge.com with esmtps (TLSv1.2:ECDHE-RSA-AES256-GCM-SHA384:256) (Exim 4.92.2) id 1jmfFL-00A7mh-7F for openvpn-devel@lists.sourceforge.net; Sat, 20 Jun 2020 15:17:34 +0000 Received: from gentoo.ov.greenie.net (gentoo.ov.greenie.net [IPv6:2001:608:0:814:0:0:f000:11]) by vmail1.greenie.net (8.15.2/8.12.11) with SMTP id 05KEdeuw020911 for ; Sat, 20 Jun 2020 16:39:40 +0200 (CEST) Received: (nullmailer pid 11750 invoked by uid 1000); Sat, 20 Jun 2020 14:39:40 -0000 From: Gert Doering To: openvpn-devel@lists.sourceforge.net Date: Sat, 20 Jun 2020 16:39:40 +0200 Message-Id: <20200620143940.11704-1-gert@greenie.muc.de> X-Mailer: git-send-email 2.26.2 MIME-Version: 1.0 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.6.2 (vmail1.greenie.net [IPv6:2001:608:1:995a:20c:29ff:feb8:10eb]); Sat, 20 Jun 2020 16:39:40 +0200 (CEST) X-Spam-Report: Spam Filtering performed by mx.sourceforge.net. See http://spamassassin.org/tag/ for more details. 0.0 URIBL_BLOCKED ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [URIs: muc.de] 0.2 HEADER_FROM_DIFFERENT_DOMAINS From and EnvelopeFrom 2nd level mail domains are different 0.0 SPF_NONE SPF: sender does not publish an SPF Record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record X-Headers-End: 1jmfFL-00A7mh-7F Subject: [Openvpn-devel] [PATCH] Convert plugin/auth-pam.c from stderr logging to plugin_log(). 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: , Errors-To: openvpn-devel-bounces@lists.sourceforge.net X-getmail-retrieved-from-mailbox: Inbox More recent OpenVPN APIs pass a function pointer for a logging function (plugin_log()) to plugins. Using this will make the plugin logs appear wherever openvpn logs to - file, syslog, stderr. This patch converts plugin/auth-pam.c "fairly mechanically" to use this new API. Real errors are logged with PLOG_ERR or PLOG_ERR|PLOG_ERRNO, while debug info is logged with PLOG_NOTE (subject to the already-existing debug level handling inside plugin/auth-pam, via "setenv verb "). Signed-off-by: Gert Doering Acked-by: Selva Nair --- src/plugins/auth-pam/auth-pam.c | 62 +++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 27 deletions(-) diff --git a/src/plugins/auth-pam/auth-pam.c b/src/plugins/auth-pam/auth-pam.c index 88b53204..9a11876d 100644 --- a/src/plugins/auth-pam/auth-pam.c +++ b/src/plugins/auth-pam/auth-pam.c @@ -64,9 +64,13 @@ #define RESPONSE_VERIFY_FAILED 13 /* Pointers to functions exported from openvpn */ +static plugin_log_t plugin_log = NULL; static plugin_secure_memzero_t plugin_secure_memzero = NULL; static plugin_base64_decode_t plugin_base64_decode = NULL; +/* module name for plugin_log() */ +static char * MODULE = "AUTH-PAM"; + /* * Plugin state, used by foreground */ @@ -211,7 +215,7 @@ daemonize(const char *envp[]) } if (daemon(0, 0) < 0) { - fprintf(stderr, "AUTH-PAM: daemonization failed\n"); + plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "daemonization failed"); } else if (fd >= 3) { @@ -297,7 +301,7 @@ split_scrv1_password(struct user_pass *up) char *tmp = strdup(up->password); if (!tmp) { - fprintf(stderr, "AUTH-PAM: out of memory parsing static challenge password\n"); + plugin_log(PLOG_ERR, MODULE, "out of memory parsing static challenge password"); goto out; } @@ -319,7 +323,7 @@ split_scrv1_password(struct user_pass *up) up->response[n] = '\0'; if (DEBUG(up->verb)) { - fprintf(stderr, "AUTH-PAM: BACKGROUND: parsed static challenge password\n"); + plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: parsed static challenge password"); } goto out; } @@ -330,7 +334,7 @@ split_scrv1_password(struct user_pass *up) plugin_secure_memzero(up->response, sizeof(up->response)); strcpy(up->password, tmp); /* tmp is guaranteed to fit in up->password */ - fprintf(stderr, "AUTH-PAM: base64 decode error while parsing static challenge password\n"); + plugin_log(PLOG_ERR, MODULE, "base64 decode error while parsing static challenge password"); out: if (tmp) @@ -379,6 +383,7 @@ openvpn_plugin_open_v3(const int v3structver, ret->type_mask = OPENVPN_PLUGIN_MASK(OPENVPN_PLUGIN_AUTH_USER_PASS_VERIFY); /* Save global pointers to functions exported from openvpn */ + plugin_log = args->callbacks->plugin_log; plugin_secure_memzero = args->callbacks->plugin_secure_memzero; plugin_base64_decode = args->callbacks->plugin_base64_decode; @@ -388,7 +393,7 @@ openvpn_plugin_open_v3(const int v3structver, */ if (string_array_len(argv) < base_parms) { - fprintf(stderr, "AUTH-PAM: need PAM service parameter\n"); + plugin_log(PLOG_ERR, MODULE, "need PAM service parameter"); goto error; } @@ -404,7 +409,7 @@ openvpn_plugin_open_v3(const int v3structver, if ((nv_len & 1) == 1 || (nv_len / 2) > N_NAME_VALUE) { - fprintf(stderr, "AUTH-PAM: bad name/value list length\n"); + plugin_log(PLOG_ERR, MODULE, "bad name/value list length"); goto error; } @@ -434,7 +439,7 @@ openvpn_plugin_open_v3(const int v3structver, */ if (socketpair(PF_UNIX, SOCK_DGRAM, 0, fd) == -1) { - fprintf(stderr, "AUTH-PAM: socketpair call failed\n"); + plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "socketpair call failed"); goto error; } @@ -460,7 +465,7 @@ openvpn_plugin_open_v3(const int v3structver, /* don't let future subprocesses inherit child socket */ if (fcntl(fd[0], F_SETFD, FD_CLOEXEC) < 0) { - fprintf(stderr, "AUTH-PAM: Set FD_CLOEXEC flag on socket file descriptor failed\n"); + plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "Set FD_CLOEXEC flag on socket file descriptor failed"); } /* wait for background child process to initialize */ @@ -469,6 +474,7 @@ openvpn_plugin_open_v3(const int v3structver, { context->foreground_fd = fd[0]; ret->handle = (openvpn_plugin_handle_t *) context; + plugin_log( PLOG_NOTE, MODULE, "initialization succeeded (fg)" ); return OPENVPN_PLUGIN_FUNC_SUCCESS; } } @@ -525,7 +531,7 @@ openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, const cha || send_string(context->foreground_fd, password) == -1 || send_string(context->foreground_fd, common_name) == -1) { - fprintf(stderr, "AUTH-PAM: Error sending auth info to background process\n"); + plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "Error sending auth info to background process"); } else { @@ -536,7 +542,7 @@ openvpn_plugin_func_v1(openvpn_plugin_handle_t handle, const int type, const cha } if (status == -1) { - fprintf(stderr, "AUTH-PAM: Error receiving auth confirmation from background process\n"); + plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "Error receiving auth confirmation from background process"); } } } @@ -551,7 +557,7 @@ openvpn_plugin_close_v1(openvpn_plugin_handle_t handle) if (DEBUG(context->verb)) { - fprintf(stderr, "AUTH-PAM: close\n"); + plugin_log(PLOG_NOTE, MODULE, "close"); } if (context->foreground_fd >= 0) @@ -559,7 +565,7 @@ openvpn_plugin_close_v1(openvpn_plugin_handle_t handle) /* tell background process to exit */ if (send_control(context->foreground_fd, COMMAND_EXIT) == -1) { - fprintf(stderr, "AUTH-PAM: Error signaling background process to exit\n"); + plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "Error signaling background process to exit"); } /* wait for background process to exit */ @@ -621,7 +627,7 @@ my_conv(int n, const struct pam_message **msg_array, if (DEBUG(up->verb)) { - fprintf(stderr, "AUTH-PAM: BACKGROUND: my_conv[%d] query='%s' style=%d\n", + plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: my_conv[%d] query='%s' style=%d", i, msg->msg ? msg->msg : "NULL", msg->msg_style); @@ -646,7 +652,7 @@ my_conv(int n, const struct pam_message **msg_array, if (DEBUG(up->verb)) { - fprintf(stderr, "AUTH-PAM: BACKGROUND: name match found, query/match-string ['%s', '%s'] = '%s'\n", + plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: name match found, query/match-string ['%s', '%s'] = '%s'", msg->msg, match_name, match_value); @@ -764,7 +770,7 @@ pam_auth(const char *service, const struct user_pass *up) /* Output error message if failed */ if (!ret) { - fprintf(stderr, "AUTH-PAM: BACKGROUND: user '%s' failed to authenticate: %s\n", + plugin_log(PLOG_ERR, MODULE, "BACKGROUND: user '%s' failed to authenticate: %s", up->username, pam_strerror(pamh, status)); } @@ -793,7 +799,7 @@ pam_server(int fd, const char *service, int verb, const struct name_value_list * */ if (DEBUG(verb)) { - fprintf(stderr, "AUTH-PAM: BACKGROUND: INIT service='%s'\n", service); + plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: INIT service='%s'", service); } #ifdef USE_PAM_DLOPEN @@ -802,7 +808,7 @@ pam_server(int fd, const char *service, int verb, const struct name_value_list * */ if (!dlopen_pam(pam_so)) { - fprintf(stderr, "AUTH-PAM: BACKGROUND: could not load PAM lib %s: %s\n", pam_so, dlerror()); + plugin_log(PLOG_ERR, MODULE, "BACKGROUND: could not load PAM lib %s: %s", pam_so, dlerror()); send_control(fd, RESPONSE_INIT_FAILED); goto done; } @@ -813,10 +819,12 @@ pam_server(int fd, const char *service, int verb, const struct name_value_list * */ if (send_control(fd, RESPONSE_INIT_SUCCEEDED) == -1) { - fprintf(stderr, "AUTH-PAM: BACKGROUND: write error on response socket [1]\n"); + plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: write error on response socket [1]"); goto done; } + plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: initialization succeeded"); + /* * Event loop */ @@ -831,7 +839,7 @@ pam_server(int fd, const char *service, int verb, const struct name_value_list * if (DEBUG(verb)) { - fprintf(stderr, "AUTH-PAM: BACKGROUND: received command code: %d\n", command); + plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: received command code: %d", command); } switch (command) @@ -841,7 +849,7 @@ pam_server(int fd, const char *service, int verb, const struct name_value_list * || recv_string(fd, up.password, sizeof(up.password)) == -1 || recv_string(fd, up.common_name, sizeof(up.common_name)) == -1) { - fprintf(stderr, "AUTH-PAM: BACKGROUND: read error on command channel: code=%d, exiting\n", + plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: read error on command channel: code=%d, exiting", command); goto done; } @@ -849,10 +857,10 @@ pam_server(int fd, const char *service, int verb, const struct name_value_list * if (DEBUG(verb)) { #if 0 - fprintf(stderr, "AUTH-PAM: BACKGROUND: USER/PASS: %s/%s\n", + plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: USER/PASS: %s/%s", up.username, up.password); #else - fprintf(stderr, "AUTH-PAM: BACKGROUND: USER: %s\n", up.username); + plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: USER: %s", up.username); #endif } @@ -863,7 +871,7 @@ pam_server(int fd, const char *service, int verb, const struct name_value_list * { if (send_control(fd, RESPONSE_VERIFY_SUCCEEDED) == -1) { - fprintf(stderr, "AUTH-PAM: BACKGROUND: write error on response socket [2]\n"); + plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: write error on response socket [2]"); goto done; } } @@ -871,7 +879,7 @@ pam_server(int fd, const char *service, int verb, const struct name_value_list * { if (send_control(fd, RESPONSE_VERIFY_FAILED) == -1) { - fprintf(stderr, "AUTH-PAM: BACKGROUND: write error on response socket [3]\n"); + plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: write error on response socket [3]"); goto done; } } @@ -882,11 +890,11 @@ pam_server(int fd, const char *service, int verb, const struct name_value_list * goto done; case -1: - fprintf(stderr, "AUTH-PAM: BACKGROUND: read error on command channel\n"); + plugin_log(PLOG_ERR|PLOG_ERRNO, MODULE, "BACKGROUND: read error on command channel"); goto done; default: - fprintf(stderr, "AUTH-PAM: BACKGROUND: unknown command code: code=%d, exiting\n", + plugin_log(PLOG_ERR, MODULE, "BACKGROUND: unknown command code: code=%d, exiting", command); goto done; } @@ -900,7 +908,7 @@ done: #endif if (DEBUG(verb)) { - fprintf(stderr, "AUTH-PAM: BACKGROUND: EXIT\n"); + plugin_log(PLOG_NOTE, MODULE, "BACKGROUND: EXIT"); } return;