aboutsummaryrefslogtreecommitdiffstats
path: root/src/slskd/Program.cs
diff options
context:
space:
mode:
authorJP Dillingham <jp@dillingham.me>2022-10-11 08:53:16 -0500
committerJP Dillingham <jp@dillingham.me>2022-10-11 08:53:16 -0500
commitb56a6650e95b3964d22d0af8c4c44b74d2800c29 (patch)
treeb325530d3897131c1592183c2ba9b325d1b19925 /src/slskd/Program.cs
parent3c3cfe6f2c3c49c05aa4de1e86a81fcb2c8af590 (diff)
parent409f66e9a851625346fb1309f6cd41e6a9770e9c (diff)
downloadslskd-b56a6650e95b3964d22d0af8c4c44b74d2800c29.tar.gz
Merge remote-tracking branch 'origin/master' into agent
Diffstat (limited to 'src/slskd/Program.cs')
-rw-r--r--src/slskd/Program.cs69
1 files changed, 64 insertions, 5 deletions
diff --git a/src/slskd/Program.cs b/src/slskd/Program.cs
index 1c0a6852..16e549c2 100644
--- a/src/slskd/Program.cs
+++ b/src/slskd/Program.cs
@@ -131,7 +131,7 @@ namespace slskd
/// <summary>
/// Gets the semantic application version.
/// </summary>
- public static string SemanticVersion { get; } = InformationalVersion.Split('-').First();
+ public static string SemanticVersion { get; } = InformationalVersion.Split('+').First();
/// <summary>
/// Gets the full application version, including both assembly and informational versions.
@@ -265,6 +265,36 @@ namespace slskd
return;
}
+ var reqInitialOwnership = false;
+
+ using (var mutex = new Mutex(reqInitialOwnership, AppName))
+ {
+ var hasHandle = false;
+
+ try
+ {
+ try
+ {
+ if (!mutex.WaitOne(0, false))
+ {
+ Console.WriteLine("Another instance of this program is running");
+ Environment.Exit(0);
+ }
+ }
+ catch (AbandonedMutexException)
+ {
+ hasHandle = true;
+ }
+ }
+ finally
+ {
+ if (hasHandle)
+ {
+ mutex.ReleaseMutex();
+ }
+ }
+ }
+
if (GenerateCertificate)
{
GenerateX509Certificate(password: Cryptography.Random.GetBytes(16).ToBase62(), filename: $"{AppName}.pfx");
@@ -591,6 +621,22 @@ namespace slskd
if (!OptionsAtStartup.Web.Authentication.Disabled)
{
+ services.AddAuthorization(options =>
+ {
+ options.AddPolicy(AuthPolicy.JwtOnly, policy =>
+ {
+ policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme);
+ policy.RequireAuthenticatedUser();
+ });
+
+ options.AddPolicy(AuthPolicy.Any, policy =>
+ {
+ policy.AuthenticationSchemes.Add(ApiKeyAuthentication.AuthenticationScheme);
+ policy.AuthenticationSchemes.Add(JwtBearerDefaults.AuthenticationScheme);
+ policy.RequireAuthenticatedUser();
+ });
+ });
+
services.AddAuthentication(JwtBearerDefaults.AuthenticationScheme)
.AddJwtBearer(options =>
{
@@ -622,9 +668,7 @@ namespace slskd
return Task.CompletedTask;
},
};
- });
-
- services.AddAuthentication(ApiKeyAuthentication.AuthenticationScheme)
+ })
.AddScheme<ApiKeyAuthenticationOptions, ApiKeyAuthenticationHandler>(ApiKeyAuthentication.AuthenticationScheme, options =>
{
options.EnableSignalRSupport = true;
@@ -636,6 +680,21 @@ namespace slskd
{
Log.Warning("Authentication of web requests is DISABLED");
+ services.AddAuthorization(options =>
+ {
+ options.AddPolicy(AuthPolicy.Any, policy =>
+ {
+ policy.AuthenticationSchemes.Add(PassthroughAuthentication.AuthenticationScheme);
+ policy.RequireAuthenticatedUser();
+ });
+
+ options.AddPolicy(AuthPolicy.JwtOnly, policy =>
+ {
+ policy.AuthenticationSchemes.Add(PassthroughAuthentication.AuthenticationScheme);
+ policy.RequireAuthenticatedUser();
+ });
+ });
+
services.AddAuthentication(PassthroughAuthentication.AuthenticationScheme)
.AddScheme<PassthroughAuthenticationOptions, PassthroughAuthenticationHandler>(PassthroughAuthentication.AuthenticationScheme, options =>
{
@@ -725,7 +784,7 @@ namespace slskd
// serve static content from the configured path
FileServerOptions fileServerOptions = default;
- var contentPath = Path.GetFullPath(OptionsAtStartup.Web.ContentPath);
+ var contentPath = Path.Combine(AppContext.BaseDirectory, OptionsAtStartup.Web.ContentPath);
fileServerOptions = new FileServerOptions
{