From dbf2d68359e3c539515c8efbd6676b6c60a7bf22 Mon Sep 17 00:00:00 2001
From: Theo Buehler <tb@openbsd.org>
Date: Fri, 30 Aug 2024 14:34:42 +0200
Subject: [PATCH 1/3] db_meth will be removed from X509V3_CTX

---
 openssl-sys/src/handwritten/types.rs | 1 +
 1 file changed, 1 insertion(+)

diff --git a/openssl-sys/src/handwritten/types.rs b/openssl-sys/src/handwritten/types.rs
index 8c69c3efb..593e20cdb 100644
--- a/openssl-sys/src/handwritten/types.rs
+++ b/openssl-sys/src/handwritten/types.rs
@@ -472,6 +472,7 @@ pub struct X509V3_CTX {
     subject_cert: *mut c_void,
     subject_req: *mut c_void,
     crl: *mut c_void,
+    #[cfg(not(libressl400))]
     db_meth: *mut c_void,
     db: *mut c_void,
     #[cfg(ossl300)]

From 337325d6100ec4add6ea45d7aed0f2bf712386d5 Mon Sep 17 00:00:00 2001
From: Theo Buehler <tb@openbsd.org>
Date: Fri, 30 Aug 2024 14:45:32 +0200
Subject: [PATCH 2/3] disable the conf module for LibreSSL 4

---
 openssl/build.rs    | 4 ++++
 openssl/src/conf.rs | 4 ++--
 2 files changed, 6 insertions(+), 2 deletions(-)

diff --git a/openssl/build.rs b/openssl/build.rs
index 16101ea30..41a047d97 100644
--- a/openssl/build.rs
+++ b/openssl/build.rs
@@ -31,6 +31,7 @@ fn main() {
     println!("cargo:rustc-check-cfg=cfg(libressl380)");
     println!("cargo:rustc-check-cfg=cfg(libressl382)");
     println!("cargo:rustc-check-cfg=cfg(libressl390)");
+    println!("cargo:rustc-check-cfg=cfg(libressl400)");
 
     println!("cargo:rustc-check-cfg=cfg(ossl101)");
     println!("cargo:rustc-check-cfg=cfg(ossl102)");
@@ -112,6 +113,9 @@ fn main() {
         if version >= 0x3_09_00_00_0 {
             println!("cargo:rustc-cfg=libressl390");
         }
+        if version >= 0x4_00_00_00_0 {
+            println!("cargo:rustc-cfg=libressl400");
+        }
     }
 
     if let Ok(vars) = env::var("DEP_OPENSSL_CONF") {
diff --git a/openssl/src/conf.rs b/openssl/src/conf.rs
index 715519c59..88740298b 100644
--- a/openssl/src/conf.rs
+++ b/openssl/src/conf.rs
@@ -8,7 +8,7 @@ foreign_type_and_impl_send_sync! {
     pub struct ConfRef;
 }
 
-#[cfg(not(boringssl))]
+#[cfg(not(any(boringssl, libressl400)))]
 mod methods {
     use super::Conf;
     use crate::cvt_p;
@@ -61,5 +61,5 @@ mod methods {
         }
     }
 }
-#[cfg(not(boringssl))]
+#[cfg(not(any(boringssl, libressl400)))]
 pub use methods::*;

From 44c2be5792ae2839e6308c59e66338f5bd6900be Mon Sep 17 00:00:00 2001
From: Theo Buehler <tb@openbsd.org>
Date: Fri, 30 Aug 2024 14:35:15 +0200
Subject: [PATCH 3/3] const correct NCONF_new(), remove NCONF_default()

---
 openssl-sys/src/handwritten/conf.rs | 8 +++++++-
 1 file changed, 7 insertions(+), 1 deletion(-)

diff --git a/openssl-sys/src/handwritten/conf.rs b/openssl-sys/src/handwritten/conf.rs
index 2348d7d4c..fa05c5554 100644
--- a/openssl-sys/src/handwritten/conf.rs
+++ b/openssl-sys/src/handwritten/conf.rs
@@ -1,7 +1,13 @@
 use super::super::*;
 
+const_ptr_api! {
+    extern "C" {
+        pub fn NCONF_new(meth: #[const_ptr_if(libressl400)] CONF_METHOD) -> *mut CONF;
+    }
+}
+
 extern "C" {
-    pub fn NCONF_new(meth: *mut CONF_METHOD) -> *mut CONF;
+    #[cfg(not(libressl400))]
     pub fn NCONF_default() -> *mut CONF_METHOD;
     pub fn NCONF_free(conf: *mut CONF);
 }