Skip to content

Commit

Permalink
#150 Added handling for NET 452 memberOf return a list of byte[]
Browse files Browse the repository at this point in the history
  • Loading branch information
Richard Hessinger committed Nov 25, 2020
1 parent 63e61cf commit fd9e866
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 7 deletions.
3 changes: 3 additions & 0 deletions InedoCore/InedoExtension/InedoExtension.csproj
Expand Up @@ -27,4 +27,7 @@
<PackageReference Include="System.DirectoryServices.Protocols" Version="5.0.0" />
<PackageReference Include="Novell.Directory.Ldap.NETStandard" Version="3.3.1" />
</ItemGroup>
<Target Name="PostBuild" AfterTargets="PostBuildEvent" Condition="$(TargetFramework) == 'net452'">
<Exec Command="powershell -Command &quot;if ((Test-Path C:\LocalDev\Tools\inedoxpack\inedoxpack.exe) -And (Test-Path C:\LocalDev\Otter\Extensions -PathType Container)) { C:\LocalDev\Tools\inedoxpack\inedoxpack.exe '$(TargetDir)..\$(TargetFileName)' 'C:\LocalDev\Otter\Extensions\$(TargetName).upack' 0.0.0 }&quot;" />
</Target>
</Project>
Expand Up @@ -3,6 +3,7 @@
using System.DirectoryServices.Protocols;
using System.Linq;
using System.Net;
using System.Text;

namespace Inedo.Extensions.UserDirectories
{
Expand Down Expand Up @@ -58,15 +59,31 @@ public override string GetPropertyValue(string propertyName)
public override ISet<string> ExtractGroupNames()
{
var groups = new HashSet<string>(StringComparer.OrdinalIgnoreCase);
foreach (string memberOf in this.result.Attributes["memberof"])
foreach (var memberOfObj in this.result.Attributes["memberof"])
{
var groupNames = from part in memberOf.Split(',')
where part.StartsWith("CN=", StringComparison.OrdinalIgnoreCase)
let name = part.Substring("CN=".Length)
where !string.IsNullOrWhiteSpace(name)
select name;
string memberOf = null;
switch(memberOfObj)
{
case byte[] memberOfBytes:
memberOf = InedoLib.UTF8Encoding.GetString(memberOfBytes, 0, memberOfBytes.Length);
break;
case string memberOfStr:
memberOf = memberOfStr;
break;
default:
break;
}

groups.UnionWith(groupNames);
if (!string.IsNullOrWhiteSpace(memberOf))
{
var groupNames = from part in memberOf.Split(',')
where part.StartsWith("CN=", StringComparison.OrdinalIgnoreCase)
let name = part.Substring("CN=".Length)
where !string.IsNullOrWhiteSpace(name)
select name;

groups.UnionWith(groupNames);
}
}

return groups;
Expand Down

0 comments on commit fd9e866

Please sign in to comment.