Skip to content

Commit b7edc01

Browse files
committed
Added support for skipping "Did not receive identification string" from logs
1 parent 247c818 commit b7edc01

File tree

5 files changed

+20
-7
lines changed

5 files changed

+20
-7
lines changed

ES.SFTP.Host/Business/Configuration/GlobalConfiguration.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,6 @@ public class GlobalConfiguration
66
{
77
public ChrootDefinition Chroot { get; set; }
88
public List<string> Directories { get; set; } = new List<string>();
9+
public LoggingDefinition Logging { get; set; }
910
}
1011
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
namespace ES.SFTP.Host.Business.Configuration
2+
{
3+
public class LoggingDefinition
4+
{
5+
public bool IgnoreNoIdentificationString { get; set; }
6+
}
7+
}

ES.SFTP.Host/Orchestrator.cs

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,8 +32,8 @@ public class Orchestrator : IRequestHandler<PamEventRequest, bool>
3232

3333
private readonly ILogger<Orchestrator> _logger;
3434
private readonly IOptionsMonitor<SftpConfiguration> _sftpOptionsMonitor;
35-
private Process _serverProcess;
3635
private SftpConfiguration _config;
36+
private Process _serverProcess;
3737

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

131131
config.Global.Directories ??= new List<string>();
132+
config.Global.Logging ??= new LoggingDefinition();
132133
config.Global.Chroot ??= new ChrootDefinition();
133134
if (string.IsNullOrWhiteSpace(config.Global.Chroot.Directory)) config.Global.Chroot.Directory = "%h";
134135
if (string.IsNullOrWhiteSpace(config.Global.Chroot.StartPath)) config.Global.Chroot.StartPath = null;
@@ -218,7 +219,7 @@ private async Task ConfigureOpenSSH()
218219
builder.AppendLine();
219220
builder.AppendLine();
220221
builder.AppendLine("# Match all users");
221-
builder.Append($"Match User \"*");
222+
builder.Append("Match User \"*");
222223
if (_config.Users.Any(s => s.Chroot != null))
223224
{
224225
var exceptionUsers = _config.Users
@@ -229,6 +230,7 @@ private async Task ConfigureOpenSSH()
229230
builder.Append(",");
230231
builder.Append(exceptionList);
231232
}
233+
232234
builder.Append("\"");
233235

234236

@@ -297,7 +299,6 @@ private async Task SyncUsersAndGroups()
297299
await GroupUtil.GroupAddUser(SftpUserInventoryGroup, user.Username);
298300
}
299301

300-
301302

302303
_logger.LogDebug("Updating the password for user '{user}'", user.Username);
303304
await UserUtil.UserSetPassword(user.Username, user.Password, user.PasswordIsEncrypted);
@@ -332,7 +333,7 @@ private async Task PrepareUserForSftp(string username)
332333
{
333334
Username = username,
334335
Chroot = _config.Global.Chroot,
335-
Directories = _config.Global.Directories,
336+
Directories = _config.Global.Directories
336337
};
337338

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

415416
private void OnSSHOutput(object sender, DataReceivedEventArgs e)
416417
{
418+
if (string.IsNullOrWhiteSpace(e.Data)) return;
419+
if (_config.Global.Logging.IgnoreNoIdentificationString &&
420+
e.Data.Trim().StartsWith("Did not receive identification string from")) return;
417421
_logger.LogTrace($"sshd - {e.Data}");
418422
}
419423
}

ES.SFTP.Host/Startup.cs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
using System.IO;
2-
using System.Net.NetworkInformation;
31
using System.Reflection;
42
using Autofac;
53
using ES.SFTP.Host.Business.Configuration;

ES.SFTP.Host/config/sftp.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,10 @@
44
"Directory": "%h",
55
"StartPath": "sftp"
66
},
7-
"Directories": ["sftp"]
7+
"Directories": ["sftp"],
8+
"Logging": {
9+
"IgnoreNoIdentificationString": true
10+
}
811
},
912
"Users": [
1013
{

0 commit comments

Comments
 (0)