Skip to content

Commit

Permalink
Added support for skipping "Did not receive identification string" fr…
Browse files Browse the repository at this point in the history
…om logs
  • Loading branch information
winromulus committed Nov 19, 2019
1 parent 247c818 commit b7edc01
Show file tree
Hide file tree
Showing 5 changed files with 20 additions and 7 deletions.
1 change: 1 addition & 0 deletions ES.SFTP.Host/Business/Configuration/GlobalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ public class GlobalConfiguration
{
public ChrootDefinition Chroot { get; set; }
public List<string> Directories { get; set; } = new List<string>();
public LoggingDefinition Logging { get; set; }
}
}
7 changes: 7 additions & 0 deletions ES.SFTP.Host/Business/Configuration/LoggingDefinition.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
namespace ES.SFTP.Host.Business.Configuration
{
public class LoggingDefinition
{
public bool IgnoreNoIdentificationString { get; set; }
}
}
12 changes: 8 additions & 4 deletions ES.SFTP.Host/Orchestrator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,8 @@ public class Orchestrator : IRequestHandler<PamEventRequest, bool>

private readonly ILogger<Orchestrator> _logger;
private readonly IOptionsMonitor<SftpConfiguration> _sftpOptionsMonitor;
private Process _serverProcess;
private SftpConfiguration _config;
private Process _serverProcess;

public Orchestrator(ILogger<Orchestrator> logger, IOptionsMonitor<SftpConfiguration> sftpOptionsMonitor)
{
Expand Down Expand Up @@ -129,6 +129,7 @@ private Task PrepareAndValidateConfiguration()
config.Global ??= new GlobalConfiguration();

config.Global.Directories ??= new List<string>();
config.Global.Logging ??= new LoggingDefinition();
config.Global.Chroot ??= new ChrootDefinition();
if (string.IsNullOrWhiteSpace(config.Global.Chroot.Directory)) config.Global.Chroot.Directory = "%h";
if (string.IsNullOrWhiteSpace(config.Global.Chroot.StartPath)) config.Global.Chroot.StartPath = null;
Expand Down Expand Up @@ -218,7 +219,7 @@ private async Task ConfigureOpenSSH()
builder.AppendLine();
builder.AppendLine();
builder.AppendLine("# Match all users");
builder.Append($"Match User \"*");
builder.Append("Match User \"*");
if (_config.Users.Any(s => s.Chroot != null))
{
var exceptionUsers = _config.Users
Expand All @@ -229,6 +230,7 @@ private async Task ConfigureOpenSSH()
builder.Append(",");
builder.Append(exceptionList);
}

builder.Append("\"");


Expand Down Expand Up @@ -297,7 +299,6 @@ private async Task SyncUsersAndGroups()
await GroupUtil.GroupAddUser(SftpUserInventoryGroup, user.Username);
}



_logger.LogDebug("Updating the password for user '{user}'", user.Username);
await UserUtil.UserSetPassword(user.Username, user.Password, user.PasswordIsEncrypted);
Expand Down Expand Up @@ -332,7 +333,7 @@ private async Task PrepareUserForSftp(string username)
{
Username = username,
Chroot = _config.Global.Chroot,
Directories = _config.Global.Directories,
Directories = _config.Global.Directories
};

var homeDirPath = Path.Combine(HomeBasePath, username);
Expand Down Expand Up @@ -414,6 +415,9 @@ private async Task StartOpenSSH()

private void OnSSHOutput(object sender, DataReceivedEventArgs e)
{
if (string.IsNullOrWhiteSpace(e.Data)) return;
if (_config.Global.Logging.IgnoreNoIdentificationString &&
e.Data.Trim().StartsWith("Did not receive identification string from")) return;
_logger.LogTrace($"sshd - {e.Data}");
}
}
Expand Down
2 changes: 0 additions & 2 deletions ES.SFTP.Host/Startup.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
using System.IO;
using System.Net.NetworkInformation;
using System.Reflection;
using Autofac;
using ES.SFTP.Host.Business.Configuration;
Expand Down
5 changes: 4 additions & 1 deletion ES.SFTP.Host/config/sftp.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@
"Directory": "%h",
"StartPath": "sftp"
},
"Directories": ["sftp"]
"Directories": ["sftp"],
"Logging": {
"IgnoreNoIdentificationString": true
}
},
"Users": [
{
Expand Down

0 comments on commit b7edc01

Please sign in to comment.