Merge pull request #2400 from MediaBrowser/dev

Dev
pull/1154/head
Luke 8 years ago committed by GitHub
commit 890d9c60dc

@ -1122,7 +1122,7 @@ namespace Emby.Server.Implementations.Connect
} }
} }
public async Task Authenticate(string username, string passwordMd5) public async Task<ConnectAuthenticationResult> Authenticate(string username, string passwordMd5)
{ {
if (string.IsNullOrWhiteSpace(username)) if (string.IsNullOrWhiteSpace(username))
{ {
@ -1151,6 +1151,7 @@ namespace Emby.Server.Implementations.Connect
// No need to examine the response // No need to examine the response
using (var response = (await _httpClient.SendAsync(options, "POST").ConfigureAwait(false)).Content) using (var response = (await _httpClient.SendAsync(options, "POST").ConfigureAwait(false)).Content)
{ {
return _json.DeserializeFromStream<ConnectAuthenticationResult>(response);
} }
} }

@ -1512,7 +1512,8 @@ namespace Emby.Server.Implementations.Dto
return artist; return artist;
} }
} }
return item.GetParent();
return item.DisplayParent ?? item.GetParent();
} }
private void AddInheritedImages(BaseItemDto dto, BaseItem item, DtoOptions options, BaseItem owner) private void AddInheritedImages(BaseItemDto dto, BaseItem item, DtoOptions options, BaseItem owner)

@ -142,12 +142,14 @@ namespace Emby.Server.Implementations.Library.Resolvers.Audio
} }
} }
} }
else
var fullName = fileSystemInfo.FullName;
if (libraryManager.IsAudioFile(fullName, libraryOptions))
{ {
return true; var fullName = fileSystemInfo.FullName;
if (libraryManager.IsAudioFile(fullName, libraryOptions))
{
return true;
}
} }
} }

@ -236,29 +236,63 @@ namespace Emby.Server.Implementations.Library
var user = Users var user = Users
.FirstOrDefault(i => string.Equals(username, i.Name, StringComparison.OrdinalIgnoreCase)); .FirstOrDefault(i => string.Equals(username, i.Name, StringComparison.OrdinalIgnoreCase));
if (user == null) var success = false;
{
throw new SecurityException("Invalid username or password entered.");
}
if (user.Policy.IsDisabled) if (user != null)
{ {
throw new SecurityException(string.Format("The {0} account is currently disabled. Please consult with your administrator.", user.Name)); // Authenticate using local credentials if not a guest
} if (!user.ConnectLinkType.HasValue || user.ConnectLinkType.Value != UserLinkType.Guest)
{
success = string.Equals(GetPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase);
var success = false; if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword)
{
success = string.Equals(GetLocalPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase);
}
}
// Authenticate using local credentials if not a guest // Maybe user accidently entered connect credentials. let's be flexible
if (!user.ConnectLinkType.HasValue || user.ConnectLinkType.Value != UserLinkType.Guest) if (!success && user.ConnectLinkType.HasValue && !string.IsNullOrWhiteSpace(passwordMd5) && !string.IsNullOrWhiteSpace(user.ConnectUserName))
{
try
{
await _connectFactory().Authenticate(user.ConnectUserName, passwordMd5).ConfigureAwait(false);
success = true;
}
catch
{
}
}
}
// Try originally entered username
if (!success && (user == null || !string.Equals(user.ConnectUserName, username, StringComparison.OrdinalIgnoreCase)))
{ {
success = string.Equals(GetPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase); try
{
var connectAuthResult = await _connectFactory().Authenticate(username, passwordMd5).ConfigureAwait(false);
if (!success && _networkManager.IsInLocalNetwork(remoteEndPoint) && user.Configuration.EnableLocalPassword) user = Users.FirstOrDefault(i => string.Equals(i.ConnectUserId, connectAuthResult.User.Id, StringComparison.OrdinalIgnoreCase));
success = user != null;
}
catch
{ {
success = string.Equals(GetLocalPasswordHash(user), passwordSha1.Replace("-", string.Empty), StringComparison.OrdinalIgnoreCase);
} }
} }
if (user == null)
{
throw new SecurityException("Invalid username or password entered.");
}
if (user.Policy.IsDisabled)
{
throw new SecurityException(string.Format("The {0} account is currently disabled. Please consult with your administrator.", user.Name));
}
// Update LastActivityDate and LastLoginDate, then save // Update LastActivityDate and LastLoginDate, then save
if (success) if (success)
{ {

@ -61,7 +61,7 @@ namespace MediaBrowser.Controller.Connect
/// <param name="username">The username.</param> /// <param name="username">The username.</param>
/// <param name="passwordMd5">The password MD5.</param> /// <param name="passwordMd5">The password MD5.</param>
/// <returns>Task.</returns> /// <returns>Task.</returns>
Task Authenticate(string username, string passwordMd5); Task<ConnectAuthenticationResult> Authenticate(string username, string passwordMd5);
/// <summary> /// <summary>
/// Gets the local user. /// Gets the local user.

@ -136,34 +136,36 @@ namespace Mono.Nat.Pmp
{ {
while (!cancellationToken.IsCancellationRequested) while (!cancellationToken.IsCancellationRequested)
{ {
var result = await udpClient.ReceiveAsync().ConfigureAwait(false); try
var endPoint = result.RemoteEndPoint; {
byte[] data = data = result.Buffer; var result = await udpClient.ReceiveAsync().ConfigureAwait(false);
var endPoint = result.RemoteEndPoint;
byte[] data = data = result.Buffer;
if (data.Length < 16) if (data.Length < 16)
continue; continue;
if (data[0] != PmpConstants.Version) if (data[0] != PmpConstants.Version)
continue; continue;
var opCode = (byte)(data[1] & 127); var opCode = (byte)(data[1] & 127);
var protocol = Protocol.Tcp; var protocol = Protocol.Tcp;
if (opCode == PmpConstants.OperationCodeUdp) if (opCode == PmpConstants.OperationCodeUdp)
protocol = Protocol.Udp; protocol = Protocol.Udp;
short resultCode = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 2)); short resultCode = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 2));
int epoch = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data, 4)); int epoch = IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data, 4));
short privatePort = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 8)); short privatePort = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 8));
short publicPort = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 10)); short publicPort = IPAddress.NetworkToHostOrder(BitConverter.ToInt16(data, 10));
var lifetime = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data, 12)); var lifetime = (uint)IPAddress.NetworkToHostOrder(BitConverter.ToInt32(data, 12));
if (privatePort < 0 || publicPort < 0 || resultCode != PmpConstants.ResultCodeSuccess) if (privatePort < 0 || publicPort < 0 || resultCode != PmpConstants.ResultCodeSuccess)
{ {
var errors = new[] var errors = new[]
{ {
"Success", "Success",
"Unsupported Version", "Unsupported Version",
"Not Authorized/Refused (e.g. box supports mapping, but user has turned feature off)" "Not Authorized/Refused (e.g. box supports mapping, but user has turned feature off)"
@ -173,19 +175,25 @@ namespace Mono.Nat.Pmp
"Unsupported opcode" "Unsupported opcode"
}; };
var errorMsg = errors[resultCode]; var errorMsg = errors[resultCode];
NatUtility.Log("Error in CreatePortMapListen: " + errorMsg); NatUtility.Log("Error in CreatePortMapListen: " + errorMsg);
return; return;
} }
if (lifetime == 0) return; //mapping was deleted if (lifetime == 0) return; //mapping was deleted
//mapping was created //mapping was created
//TODO: verify that the private port+protocol are a match //TODO: verify that the private port+protocol are a match
mapping.PublicPort = publicPort; mapping.PublicPort = publicPort;
mapping.Protocol = protocol; mapping.Protocol = protocol;
mapping.Expiration = DateTime.Now.AddSeconds(lifetime); mapping.Expiration = DateTime.Now.AddSeconds(lifetime);
return; return;
}
catch (Exception ex)
{
NatUtility.Logger.ErrorException("Error in CreatePortMapListen", ex);
return;
}
} }
} }

Loading…
Cancel
Save