From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from firstgate.proxmox.com (firstgate.proxmox.com [212.224.123.68]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.proxmox.com (Postfix) with ESMTPS id 57A78F9AA for ; Mon, 24 Jul 2023 11:04:51 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 393B0BD50 for ; Mon, 24 Jul 2023 11:04:21 +0200 (CEST) Received: from proxmox-new.maurer-it.com (proxmox-new.maurer-it.com [94.136.29.106]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by firstgate.proxmox.com (Proxmox) with ESMTPS for ; Mon, 24 Jul 2023 11:04:20 +0200 (CEST) Received: from proxmox-new.maurer-it.com (localhost.localdomain [127.0.0.1]) by proxmox-new.maurer-it.com (Proxmox) with ESMTP id 6A8DF43A86 for ; Mon, 24 Jul 2023 11:04:20 +0200 (CEST) From: Christoph Heiss To: pve-devel@lists.proxmox.com Date: Mon, 24 Jul 2023 11:03:48 +0200 Message-ID: <20230724090408.221672-4-c.heiss@proxmox.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230724090408.221672-1-c.heiss@proxmox.com> References: <20230724090408.221672-1-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-SPAM-LEVEL: Spam detection results: 0 AWL -0.055 Adjusted score from AWL reputation of From: address BAYES_00 -1.9 Bayes spam probability is 0 to 1% DMARC_MISSING 0.1 Missing DMARC policy KAM_DMARC_STATUS 0.01 Test Rule for DKIM or SPF Failure with Strict Alignment SPF_HELO_NONE 0.001 SPF: HELO does not publish an SPF Record SPF_PASS -0.001 SPF: sender matches SPF record T_SCC_BODY_TEXT_LINE -0.01 - Subject: [pve-devel] [PATCH common v2 3/5] ldap: handle errors explicitly everywhere instead of simply `die`ing X-BeenThere: pve-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox VE development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 24 Jul 2023 09:04:51 -0000 Most codepaths already have explicit error handling (by the means of checking the return value), which is essential dead code due to setting `onerror`. As LDAP errors might get presented to users due to upcoming changes, the error location should not be present in these error messages, thus switch to explicit handling. Only two calls were missing such explicit handling of errors, so these are amended as appropriate. Further, some `die`s were missing newlines at the end of the message, which - again - would cause the error location to be included. Signed-off-by: Christoph Heiss --- Changes v1 -> v2: * No changes src/PVE/LDAP.pm | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/PVE/LDAP.pm b/src/PVE/LDAP.pm index 342c352..16a0a8e 100644 --- a/src/PVE/LDAP.pm +++ b/src/PVE/LDAP.pm @@ -22,7 +22,6 @@ sub ldap_connect { scheme => $scheme, port => $port, timeout => 10, - onerror => 'die', ); my $hosts = []; @@ -41,7 +40,8 @@ sub ldap_connect { my $ldap = Net::LDAP->new($hosts, %ldap_opts) || die "$@\n"; if ($start_tls) { - $ldap->start_tls(%$opts); + my $res = $ldap->start_tls(%$opts); + die $res->error . "\n" if $res->code; } return $ldap; @@ -73,6 +73,7 @@ sub get_user_dn { filter => "$attr=$name", attrs => ['dn'] ); + die $result->error . "\n" if $result->code; return undef if !$result->entries; my @entries = $result->entries; return $entries[0]->dn; @@ -93,7 +94,7 @@ sub auth_user_dn { if ($code) { return undef if $noerr; - die $err; + die "$err\n"; } return 1; @@ -184,7 +185,7 @@ sub query_users { $err = "LDAP user query unsuccessful" if !$err; } - die $err if $err; + die "$err\n" if $err; return $users; } @@ -265,7 +266,7 @@ sub query_groups { $err = "LDAP group query unsuccessful" if !$err; } - die $err if $err; + die "$err\n" if $err; return $groups; } -- 2.41.0