From a9efb269620c62a2ddd326b8824ab1173710590c Mon Sep 17 00:00:00 2001 From: kdl Date: Sat, 10 Jun 2023 19:08:28 +0200 Subject: [PATCH] add Owner Validation switch --- LibGit2Sharp/Core/Proxy.cs | 37 ++++++++++++++++++++++++++++++++++ LibGit2Sharp/GlobalSettings.cs | 9 +++++++++ 2 files changed, 46 insertions(+) diff --git a/LibGit2Sharp/Core/Proxy.cs b/LibGit2Sharp/Core/Proxy.cs index 50cefc0df..fcc015d4b 100644 --- a/LibGit2Sharp/Core/Proxy.cs +++ b/LibGit2Sharp/Core/Proxy.cs @@ -3397,6 +3397,8 @@ private enum LibGit2Option SetOdbLoosePriority, // GIT_OPT_SET_ODB_LOOSE_PRIORITY, GetExtensions, // GIT_OPT_GET_EXTENSIONS, SetExtensions, // GIT_OPT_SET_EXTENSIONS + GetOwnerValidation, // GIT_OPT_GET_OWNER_VALIDATION + SetOwnerValidation // GIT_OPT_SET_OWNER_VALIDATION } /// @@ -3570,6 +3572,41 @@ public static string[] git_libgit2_opts_get_extensions() } } + public static string git_libgit2_opts_get_owner_validation() + { + string userAgent; + + using (var buf = new GitBuf()) + { + int res; + if (isOSXArm64) + res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.GetUserAgent, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, buf); + else + res = NativeMethods.git_libgit2_opts((int)LibGit2Option.GetOwnerValidation, buf); + Ensure.ZeroResult(res); + + userAgent = LaxUtf8Marshaler.FromNative(buf.ptr) ?? string.Empty; + } + + return userAgent; + } + + /// + /// Enable or disable the ownership validation + /// + /// true to enable the ownership validation capabilty, false otherwise + public static void git_libgit2_opts_set_owner_validation(bool enabled) + { + // libgit2 expects non-zero value for true + int res; + if (isOSXArm64) + res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.SetOwnerValidation, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, enabled ? 1 : 0); + else + res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetOwnerValidation, enabled ? 1 : 0); + Ensure.ZeroResult(res); + } + + #endregion #region git_worktree_ diff --git a/LibGit2Sharp/GlobalSettings.cs b/LibGit2Sharp/GlobalSettings.cs index 31cba0965..6c5d00d08 100644 --- a/LibGit2Sharp/GlobalSettings.cs +++ b/LibGit2Sharp/GlobalSettings.cs @@ -346,6 +346,15 @@ public static void SetStrictHashVerification(bool enabled) Proxy.git_libgit2_opts_enable_strict_hash_verification(enabled); } + /// + /// Enable or disable dubious owner validation + /// + /// true to enable owner validation; false otherwise. + public static void SetOwnerValidation(bool enabled) + { + Proxy.git_libgit2_opts_set_owner_validation(enabled); + } + /// /// Enable or disable the libgit2 cache ///