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 404B0BEDB for ; Fri, 11 Aug 2023 12:30:24 +0200 (CEST) Received: from firstgate.proxmox.com (localhost [127.0.0.1]) by firstgate.proxmox.com (Proxmox) with ESMTP id 1EC0ABB5F for ; Fri, 11 Aug 2023 12:29:54 +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 ; Fri, 11 Aug 2023 12:29:52 +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 58DE745F78 for ; Fri, 11 Aug 2023 12:29:52 +0200 (CEST) Date: Fri, 11 Aug 2023 12:29:51 +0200 From: Wolfgang Bumiller To: Christoph Heiss Cc: pbs-devel@lists.proxmox.com Message-ID: References: <20230808122239.1025524-1-c.heiss@proxmox.com> <20230808122239.1025524-2-c.heiss@proxmox.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20230808122239.1025524-2-c.heiss@proxmox.com> X-SPAM-LEVEL: Spam detection results: 0 AWL 0.106 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 URIBL_BLOCKED 0.001 ADMINISTRATOR NOTICE: The query to URIBL was blocked. See http://wiki.apache.org/spamassassin/DnsBlocklists#dnsbl-block for more information. [lib.rs, rfc-editor.org, glauth.rs] Subject: Re: [pbs-devel] [PATCH proxmox 01/12] ldap: add method for retrieving root DSE attributes X-BeenThere: pbs-devel@lists.proxmox.com X-Mailman-Version: 2.1.29 Precedence: list List-Id: Proxmox Backup Server development discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 11 Aug 2023 10:30:24 -0000 On Tue, Aug 08, 2023 at 02:22:03PM +0200, Christoph Heiss wrote: > The root DSE holds common attributes about the LDAP server itself. > Needed to e.g. support Active Directory-based LDAP servers to retrieve > the base DN from the server itself, based on an valid bind. > > See also RFC 4512, Section 5.1 [0] for more information about this > special object. > > [0] https://www.rfc-editor.org/rfc/rfc4512#section-5.1 > > Signed-off-by: Christoph Heiss > --- > proxmox-ldap/src/lib.rs | 22 ++++++++++++++++++++++ > proxmox-ldap/tests/assets/glauth.cfg | 1 + > proxmox-ldap/tests/glauth.rs | 16 ++++++++++++++++ > 3 files changed, 39 insertions(+) > > diff --git a/proxmox-ldap/src/lib.rs b/proxmox-ldap/src/lib.rs > index b3b5d65..534c0c8 100644 > --- a/proxmox-ldap/src/lib.rs > +++ b/proxmox-ldap/src/lib.rs > @@ -198,6 +198,28 @@ impl Connection { > Ok(()) > } > > + /// Retrieves an attribute from the root DSE according to RFC 4512, Section 5.1 > + /// https://www.rfc-editor.org/rfc/rfc4512#section-5.1 > + pub async fn retrieve_root_dse_attr(&self, attr: &str) -> Result, Error> { > + let mut ldap = self.create_connection().await?; > + > + let (entries, _res) = ldap > + .search("", Scope::Base, "(objectClass=*)", vec![attr]) The last parameter of `search` is an `impl AsRef<[impl AsRef]>`, so you can just pass `&[attr]` here. The 2 other existing search calls in the crate should also be adapted, there's no point in the extra allocation. > + .await? > + .success()?; > + > + if entries.len() > 1 { > + bail!("found multiple root DSEs with attribute '{attr}'"); > + } > + > + entries > + .into_iter() > + .next() > + .map(SearchEntry::construct) > + .and_then(|e| e.attrs.get(attr).cloned()) > + .ok_or_else(|| format_err!("failed to retrieve root DSE attribute '{attr}'")) > + } > + > /// Retrive port from LDAP configuration, otherwise use the correct default > fn port_from_config(&self) -> u16 { > self.config.port.unwrap_or_else(|| {