diff --git a/src/Console/Program.cs b/src/Console/Program.cs index 7c943e61..8d9a7b9c 100644 --- a/src/Console/Program.cs +++ b/src/Console/Program.cs @@ -342,14 +342,22 @@ namespace Bit.Console config.Ldap.Path = parameters["path"]; } - if(parameters.ContainsKey("u")) + if(parameters.ContainsKey("cu")) { - config.Ldap.Username = parameters["u"]; + config.Ldap.Username = null; + config.Ldap.Password = null; } - - if(parameters.ContainsKey("p")) + else { - config.Ldap.Password = new EncryptedData(parameters["p"]); + if(parameters.ContainsKey("u")) + { + config.Ldap.Username = parameters["u"]; + } + + if(parameters.ContainsKey("p")) + { + config.Ldap.Password = new EncryptedData(parameters["p"]); + } } } } @@ -419,7 +427,7 @@ namespace Bit.Console } else { - config.Ldap = new LdapConfiguration(); + config.Ldap = config.Ldap ?? new LdapConfiguration(); Con.Write("Address [{0}]: ", config.Ldap.Address); input = Con.ReadLine(); @@ -439,18 +447,36 @@ namespace Bit.Console { config.Ldap.Path = input.Trim(); } - Con.Write("Username [{0}]: ", config.Ldap.Username); - input = Con.ReadLine(); + + var currentUser = string.IsNullOrWhiteSpace(config.Ldap.Username) && + config.Ldap.Password == null; + Con.Write("Authenticate as current user? [{0}]: ", currentUser ? "y" : "n"); + input = Con.ReadLine().ToLower(); if(!string.IsNullOrEmpty(input)) { - config.Ldap.Username = input.Trim(); + currentUser = input == "y" || input == "yes"; } - Con.Write("Password: "); - input = ReadSecureLine(); - if(!string.IsNullOrEmpty(input)) + + if(currentUser) { - config.Ldap.Password = new EncryptedData(input); - input = null; + config.Ldap.Username = null; + config.Ldap.Password = null; + } + else + { + Con.Write("Username [{0}]: ", config.Ldap.Username); + input = Con.ReadLine(); + if(!string.IsNullOrEmpty(input)) + { + config.Ldap.Username = input.Trim(); + } + Con.Write("Password: "); + input = ReadSecureLine(); + if(!string.IsNullOrEmpty(input)) + { + config.Ldap.Password = new EncryptedData(input); + input = null; + } } } diff --git a/src/Core/Models/LdapConfiguration.cs b/src/Core/Models/LdapConfiguration.cs index 763b954b..9f09fe75 100644 --- a/src/Core/Models/LdapConfiguration.cs +++ b/src/Core/Models/LdapConfiguration.cs @@ -21,8 +21,14 @@ namespace Bit.Core.Models public DirectoryEntry GetDirectoryEntry() { - var entry = new DirectoryEntry(ServerPath, Username, Password.DecryptToString(), AuthenticationTypes.None); - return entry; + if(Password == null && string.IsNullOrWhiteSpace(Username)) + { + return new DirectoryEntry(ServerPath); + } + else + { + return new DirectoryEntry(ServerPath, Username, Password.DecryptToString(), AuthenticationTypes.None); + } } } } diff --git a/src/Core/Services/LdapDirectoryService.cs b/src/Core/Services/LdapDirectoryService.cs index 03f62302..486fcf60 100644 --- a/src/Core/Services/LdapDirectoryService.cs +++ b/src/Core/Services/LdapDirectoryService.cs @@ -149,7 +149,7 @@ namespace Bit.Core.Services if(item.Properties.Contains("objectGUID") && item.Properties["objectGUID"].Count > 0) { - externalId = item.Properties["objectGUID"][0].ToString(); + externalId = item.Properties["objectGUID"][0].FromGuidToString(); } dict.Add(referenceId, externalId); @@ -172,7 +172,7 @@ namespace Bit.Core.Services // External Id if(item.Properties.Contains("objectGUID") && item.Properties["objectGUID"].Count > 0) { - group.ExternalId = item.Properties["objectGUID"][0].ToString(); + group.ExternalId = item.Properties["objectGUID"][0].FromGuidToString(); } else { @@ -309,7 +309,7 @@ namespace Bit.Core.Services // External Id if(item.Properties.Contains("objectGUID") && item.Properties["objectGUID"].Count > 0) { - user.ExternalId = item.Properties["objectGUID"][0].ToString(); + user.ExternalId = item.Properties["objectGUID"][0].FromGuidToString(); } else { diff --git a/src/Core/Utilities/Extensions.cs b/src/Core/Utilities/Extensions.cs index b1276be1..784f406d 100644 --- a/src/Core/Utilities/Extensions.cs +++ b/src/Core/Utilities/Extensions.cs @@ -52,5 +52,18 @@ namespace Bit.Core.Utilities return queryParameters; } + + public static string FromGuidToString(this object property) + { + var propBytes = property as byte[]; + if(propBytes != null) + { + return new Guid(propBytes).ToString(); + } + else + { + return property.ToString(); + } + } } }