Skip to content

Commit 0a29b6c

Browse files
committed
Added config comments and variable expansion
If we want Kerberos.NET to be completely compliant with MIT Kerberos defaults, then we can change some of the paths. The location of krb5.conf is usually system-wide (/etc/krb5.conf) and the kdc.conf is in the $LOCALSTATEDIR/krb5kdc. /etc isn't a user configuration location so I changed it to $XDG_CONFIG_HOME, and I added the ability to expand variables set in the krb5.conf. That can allow putting the krb5ccache in the home directory with %HOME%. We should consider honoring the %KRB5CCNAME% environment variable.
1 parent bbf1d79 commit 0a29b6c

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

.gitignore

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ bld/
2626

2727
# Visual Studio 2015 cache/options directory
2828
.vs/
29+
# Visual Studio Code directory
30+
.vscode/
2931
# Uncomment if you have tasks that create the project's static files in wwwroot
3032
#wwwroot/
3133

@@ -285,4 +287,4 @@ __pycache__/
285287
*.btp.cs
286288
*.btm.cs
287289
*.odx.cs
288-
*.xsd.cs
290+
*.xsd.cs

Kerberos.NET/Configuration/Krb5Config.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,14 +74,18 @@ public Krb5Config()
7474
public Krb5Logging Logging { get; private set; }
7575

7676
public static string UserConfigurationPath => GetFilePath(
77-
envVar: "%KRB5_CONFIG%",
77+
envVar: "%KRB5_CONFIG%", // %KRB_CONFIG% is being used to specify the user
78+
// configuration path, but it should be the path to krb5.conf itself
79+
// (see https://web.mit.edu/kerberos/krb5-1.12/doc/admin/env_variables.html)
7880
winPath: "%APPDATA%\\Kerberos.NET\\",
7981
osxPath: "Library/Preferences/Kerberos.NET/",
8082
linuxPath: "%HOME%/.config/Kerberos.NET/" // use XDG_CONFIG_HOME default
8183
);
8284

8385
public static string ServiceConfigurationPath => GetFilePath(
84-
envVar: "%KRB5_KDC_PROFILE%",
86+
envVar: "%KRB5_KDC_PROFILE%", // %KRB5_KDC_PROFILE% is being used to specify the service
87+
// configuration path, but it should be the path to kdc.conf itself
88+
// (see https://web.mit.edu/kerberos/krb5-1.12/doc/admin/env_variables.html)
8589
winPath: "%APPDATA%\\Kerberos.NET\\",
8690
osxPath: "Library/Preferences/Kerberos.NET/",
8791
linuxPath: "/var/krb5kdc"
@@ -117,6 +121,7 @@ public static Krb5Config CurrentUser(string path = null)
117121
path = DefaultUserConfigurationPath;
118122
}
119123

124+
// Expansion allows the use of environment variables in krb5.conf, but they must be in %VAR% format
120125
var expandedPath = Environment.ExpandEnvironmentVariables(path);
121126
if (File.Exists(expandedPath))
122127
{
@@ -181,7 +186,9 @@ private static string GetFilePath(string envVar, string winPath, string osxPath,
181186
}
182187
else if (OSPlatform.IsLinux)
183188
{
184-
return linuxPath;
189+
// Environment variables use %VAR% format
190+
// (see https://github.com/dotnet/runtime/issues/25792)
191+
return Environment.ExpandEnvironmentVariables(linuxPath);
185192
}
186193

187194
return string.Empty;

0 commit comments

Comments
 (0)