| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -102,5 +102,20 @@ public void SetExtensions() | |||
| 102 | 102 | extensions = GlobalSettings.GetExtensions(); | |
| 103 | 103 | Assert.Equal(new[] { "newext", "noop", "objectformat", "partialclone", "worktreeconfig" }, extensions); | |
| 104 | 104 | } | |
| 105 | + | ||
| 106 | + [Fact] | ||
| 107 | + public void OwnerValidation() | ||
| 108 | + { | ||
| 109 | + // Assert that owner validation is enabled by default | ||
| 110 | + Assert.True(GlobalSettings.GetOwnerValidation()); | ||
| 111 | + | ||
| 112 | + // Disable owner validation | ||
| 113 | + GlobalSettings.SetOwnerValidation(false); | ||
| 114 | + Assert.False(GlobalSettings.GetOwnerValidation()); | ||
| 115 | + | ||
| 116 | + // Enable it again | ||
| 117 | + GlobalSettings.SetOwnerValidation(true); | ||
| 118 | + Assert.True(GlobalSettings.GetOwnerValidation()); | ||
| 119 | + } | ||
| 105 | 120 | } | |
| 106 | 121 | } | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -1,6 +1,8 @@ | |||
| 1 | 1 | using System; | |
| 2 | 2 | using System.IO; | |
| 3 | + #if NET | ||
| 3 | 4 | using System.Reflection; | |
| 5 | + #endif | ||
| 4 | 6 | using System.Runtime.CompilerServices; | |
| 5 | 7 | using System.Runtime.ConstrainedExecution; | |
| 6 | 8 | using System.Runtime.InteropServices; | |
@@ -743,6 +745,7 @@ internal static extern int git_libgit2_opts(int option, uint level, | |||
| 743 | 745 | [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string path); | |
| 744 | 746 | ||
| 745 | 747 | // git_libgit2_opts(GIT_OPT_ENABLE_*, int enabled) | |
| 748 | + // git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, int enabled) | ||
| 746 | 749 | [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] | |
| 747 | 750 | internal static extern int git_libgit2_opts(int option, int enabled); | |
| 748 | 751 | ||
@@ -762,6 +765,10 @@ internal static extern int git_libgit2_opts(int option, | |||
| 762 | 765 | // git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, git_strarray *out) | |
| 763 | 766 | [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] | |
| 764 | 767 | internal static extern int git_libgit2_opts(int option, out GitStrArray extensions); | |
| 768 | + | ||
| 769 | + // git_libgit2_opts(GIT_OPT_GET_OWNER_VALIDATION, int *enabled) | ||
| 770 | + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] | ||
| 771 | + internal static extern unsafe int git_libgit2_opts(int option, int* enabled); | ||
| 765 | 772 | #endregion | |
| 766 | 773 | ||
| 767 | 774 | #region git_libgit2_opts_osxarm64 | |
@@ -779,6 +786,7 @@ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, In | |||
| 779 | 786 | [MarshalAs(UnmanagedType.CustomMarshaler, MarshalCookie = UniqueId.UniqueIdentifier, MarshalTypeRef = typeof(StrictUtf8Marshaler))] string path); | |
| 780 | 787 | ||
| 781 | 788 | // git_libgit2_opts(GIT_OPT_ENABLE_*, int enabled) | |
| 789 | + // git_libgit2_opts(GIT_OPT_SET_OWNER_VALIDATION, int enabled) | ||
| 782 | 790 | [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")] | |
| 783 | 791 | internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, int enabled); | |
| 784 | 792 | ||
@@ -798,6 +806,10 @@ internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, In | |||
| 798 | 806 | // git_libgit2_opts(GIT_OPT_GET_EXTENSIONS, git_strarray *out) | |
| 799 | 807 | [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")] | |
| 800 | 808 | internal static extern int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, out GitStrArray extensions); | |
| 809 | + | ||
| 810 | + // git_libgit2_opts(GIT_OPT_GET_OWNER_VALIDATION, int *enabled) | ||
| 811 | + [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl, EntryPoint = "git_libgit2_opts")] | ||
| 812 | + internal static extern unsafe int git_libgit2_opts_osxarm64(int option, IntPtr nop2, IntPtr nop3, IntPtr nop4, IntPtr nop5, IntPtr nop6, IntPtr nop7, IntPtr nop8, int* enabled); | ||
| 801 | 813 | #endregion | |
| 802 | 814 | ||
| 803 | 815 | [DllImport(libgit2, CallingConvention = CallingConvention.Cdecl)] | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -3397,6 +3397,8 @@ private enum LibGit2Option | |||
| 3397 | 3397 | SetOdbLoosePriority, // GIT_OPT_SET_ODB_LOOSE_PRIORITY, | |
| 3398 | 3398 | GetExtensions, // GIT_OPT_GET_EXTENSIONS, | |
| 3399 | 3399 | SetExtensions, // GIT_OPT_SET_EXTENSIONS | |
| 3400 | + GetOwnerValidation, // GIT_OPT_GET_OWNER_VALIDATION | ||
| 3401 | + SetOwnerValidation, // GIT_OPT_SET_OWNER_VALIDATION | ||
| 3400 | 3402 | } | |
| 3401 | 3403 | ||
| 3402 | 3404 | /// <summary> | |
@@ -3570,6 +3572,47 @@ public static string[] git_libgit2_opts_get_extensions() | |||
| 3570 | 3572 | } | |
| 3571 | 3573 | } | |
| 3572 | 3574 | ||
| 3575 | + /// <summary> | ||
| 3576 | + /// Gets the value of owner validation | ||
| 3577 | + /// </summary> | ||
| 3578 | + public static unsafe bool git_libgit2_opts_get_owner_validation() | ||
| 3579 | + { | ||
| 3580 | + int res; | ||
| 3581 | + int enabled; | ||
| 3582 | + | ||
| 3583 | + if (isOSXArm64) | ||
| 3584 | + { | ||
| 3585 | + res = NativeMethods.git_libgit2_opts_osxarm64((int)LibGit2Option.GetOwnerValidation, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, IntPtr.Zero, &enabled); | ||
| 3586 | + } | ||
| 3587 | + else | ||
| 3588 | + { | ||
| 3589 | + res = NativeMethods.git_libgit2_opts((int)LibGit2Option.GetOwnerValidation, &enabled); | ||
| 3590 | + } | ||
| 3591 | + | ||
| 3592 | + Ensure.ZeroResult(res); | ||
| 3593 | + | ||
| 3594 | + return enabled != 0; | ||
| 3595 | + } | ||
| 3596 | + | ||
| 3597 | + /// <summary> | ||
| 3598 | + /// Enable or disable owner validation | ||
| 3599 | + /// </summary> | ||
| 3600 | + /// <param name="enabled">true to enable owner validation, false otherwise</param> | ||
| 3601 | + public static void git_libgit2_opts_set_owner_validation(bool enabled) | ||
| 3602 | + { | ||
| 3603 | + int res; | ||
| 3604 | + | ||
| 3605 | + if (isOSXArm64) | ||
| 3606 | + { | ||
| 3607 | + 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); | ||
| 3608 | + } | ||
| 3609 | + else | ||
| 3610 | + { | ||
| 3611 | + res = NativeMethods.git_libgit2_opts((int)LibGit2Option.SetOwnerValidation, enabled ? 1 : 0); | ||
| 3612 | + } | ||
| 3613 | + | ||
| 3614 | + Ensure.ZeroResult(res); | ||
| 3615 | + } | ||
| 3573 | 3616 | #endregion | |
| 3574 | 3617 | ||
| 3575 | 3618 | #region git_worktree_ | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -417,5 +417,26 @@ public static string GetUserAgent() | |||
| 417 | 417 | { | |
| 418 | 418 | return Proxy.git_libgit2_opts_get_user_agent(); | |
| 419 | 419 | } | |
| 420 | + | ||
| 421 | + /// <summary> | ||
| 422 | + /// Gets the owner validation setting for repository directories. | ||
| 423 | + /// </summary> | ||
| 424 | + /// <returns></returns> | ||
| 425 | + public static bool GetOwnerValidation() | ||
| 426 | + { | ||
| 427 | + return Proxy.git_libgit2_opts_get_owner_validation(); | ||
| 428 | + } | ||
| 429 | + | ||
| 430 | + /// <summary> | ||
| 431 | + /// Sets whether repository directories should be owned by the current user. The default is to validate ownership. | ||
| 432 | + /// </summary> | ||
| 433 | + /// <remarks> | ||
| 434 | + /// Disabling owner validation can lead to security vulnerabilities (see CVE-2022-24765). | ||
| 435 | + /// </remarks> | ||
| 436 | + /// <param name="enabled">true to enable owner validation; otherwise, false.</param> | ||
| 437 | + public static void SetOwnerValidation(bool enabled) | ||
| 438 | + { | ||
| 439 | + Proxy.git_libgit2_opts_set_owner_validation(enabled); | ||
| 440 | + } | ||
| 420 | 441 | } | |
| 421 | 442 | } | |
| Back | FazBrowse Home | New Git URL |
0 commit comments