Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add Owner Validation switch #2042

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 37 additions & 0 deletions LibGit2Sharp/Core/Proxy.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

/// <summary>
Expand Down Expand Up @@ -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;
}

/// <summary>
/// Enable or disable the ownership validation
/// </summary>
/// <param name="enabled">true to enable the ownership validation capabilty, false otherwise</param>
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_
Expand Down
9 changes: 9 additions & 0 deletions LibGit2Sharp/GlobalSettings.cs
Original file line number Diff line number Diff line change
Expand Up @@ -346,6 +346,15 @@ public static void SetStrictHashVerification(bool enabled)
Proxy.git_libgit2_opts_enable_strict_hash_verification(enabled);
}

/// <summary>
/// Enable or disable dubious owner validation
/// </summary>
/// <param name="enabled">true to enable owner validation; false otherwise.</param>
public static void SetOwnerValidation(bool enabled)
{
Proxy.git_libgit2_opts_set_owner_validation(enabled);
}

/// <summary>
/// Enable or disable the libgit2 cache
/// </summary>
Expand Down