Skip to content
This repository was archived by the owner on Jan 23, 2023. It is now read-only.

Commit 2985bcb

Browse files
committed
Merge pull request #2806 from bartonjs/X509Store_Unix_CurrentUser
Enable CurrentUser X509Stores on Unix.
2 parents 501d998 + 0522e19 commit 2985bcb

File tree

10 files changed

+810
-6
lines changed

10 files changed

+810
-6
lines changed

src/Common/src/Interop/Unix/System.Native/Interop.Stat.cs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,12 @@ internal static partial class Interop
88
{
99
internal static partial class Sys
1010
{
11+
// Even though csc will by default use a sequential layout, a CS0649 warning as error
12+
// is produced for un-assigned fields when no StructLayout is specified.
13+
//
14+
// Explicitly saying Sequential disables that warning/error for consumers which only
15+
// use Stat in debug builds.
16+
[StructLayout(LayoutKind.Sequential)]
1117
internal struct FileStatus
1218
{
1319
internal FileStatusFlags Flags;
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright (c) Microsoft. All rights reserved.
2+
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
3+
4+
using System.Diagnostics;
5+
6+
namespace System.IO
7+
{
8+
internal static class PersistedFiles
9+
{
10+
// If we ever need system persisted data, /etc/dotnet/corefx/
11+
private const string TopLevelDirectory = "dotnet";
12+
// User persisted data, ~/.dotnet/corefx/
13+
private const string TopLevelUserDirectory = "." + TopLevelDirectory;
14+
private const string SecondLevelDirectory = "corefx";
15+
16+
private static string s_userProductDirectory;
17+
18+
/// <summary>
19+
/// Get the location of where to persist information for a particular aspect of the framework,
20+
/// such as "cryptography".
21+
/// </summary>
22+
/// <param name="featureName">The directory name for the feature</param>
23+
/// <returns>A path within the user's home directory for persisting data for the feature</returns>
24+
internal static string GetUserFeatureDirectory(string featureName)
25+
{
26+
if (s_userProductDirectory == null)
27+
{
28+
EnsureUserDirectories();
29+
}
30+
31+
return Path.Combine(s_userProductDirectory, featureName);
32+
}
33+
34+
/// <summary>
35+
/// Get the location of where to persist information for a particular aspect of a feature of
36+
/// the framework, such as "x509stores" within "cryptography".
37+
/// </summary>
38+
/// <param name="featureName">The directory name for the feature</param>
39+
/// <param name="subFeatureName">The directory name for the sub-feature</param>
40+
/// <returns>A path within the user's home directory for persisting data for the sub-feature</returns>
41+
internal static string GetUserFeatureDirectory(string featureName, string subFeatureName)
42+
{
43+
if (s_userProductDirectory == null)
44+
{
45+
EnsureUserDirectories();
46+
}
47+
48+
return Path.Combine(s_userProductDirectory, featureName, subFeatureName);
49+
}
50+
51+
/// <summary>
52+
/// Get the location of where to persist information for a particular aspect of the framework,
53+
/// with a lot of hierarchy, such as ["cryptography", "x509stores", "my"]
54+
/// </summary>
55+
/// <param name="featurePathParts">A non-empty set of directories to use for the storage hierarchy</param>
56+
/// <returns>A path within the user's home directory for persisting data for the feature</returns>
57+
internal static string GetUserFeatureDirectory(params string[] featurePathParts)
58+
{
59+
Debug.Assert(featurePathParts != null);
60+
Debug.Assert(featurePathParts.Length > 0);
61+
62+
if (s_userProductDirectory == null)
63+
{
64+
EnsureUserDirectories();
65+
}
66+
67+
return Path.Combine(s_userProductDirectory, Path.Combine(featurePathParts));
68+
}
69+
70+
private static void EnsureUserDirectories()
71+
{
72+
// TODO (2820): Use getpwuid_r(geteuid(), ...) instead of the HOME environment variable
73+
string userHomeDirectory = Environment.GetEnvironmentVariable("HOME");
74+
75+
if (string.IsNullOrEmpty(userHomeDirectory))
76+
{
77+
throw new InvalidOperationException(SR.PersistedFiles_NoHomeDirectory);
78+
}
79+
80+
s_userProductDirectory = Path.Combine(
81+
userHomeDirectory,
82+
TopLevelUserDirectory,
83+
SecondLevelDirectory);
84+
}
85+
}
86+
}

0 commit comments

Comments
 (0)