Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

System.DirectoryServices is not supported on Ubuntu 14.04 #25121

Closed
Petermarcu opened this issue Feb 21, 2018 · 2 comments
Closed

System.DirectoryServices is not supported on Ubuntu 14.04 #25121

Petermarcu opened this issue Feb 21, 2018 · 2 comments
Labels
area-System.DirectoryServices os-linux Linux OS (any supported distro)
Milestone

Comments

@Petermarcu
Copy link
Member

@coolrz commented on Wed Feb 07 2018

Issue Title

System.DirectoryServices is not supported on Ubuntu 14.04

General

I use the .net core 2.0 to get domain user group information and it works well in IIS. I installed theSystem.DirectoryServices 4.5.0-preview2-26202-05 via Nuget in the project. But when i use the same code deploy on ubuntu 14.04, it throws exception "System.DirectoryServices is not supported on this platform." Is that possible to work well in Ubuntu ? if not any third part LDAP library provide and can work well in Ubuntu? The purpose is to get the domain user information and the hosted Ubuntu server is joined the company domain network.

asp.net core code see below
UserController.cs

using Microsoft.AspNetCore.Mvc;
using System;
using System.Collections.Generic;
using System.DirectoryServices;
using System.Net.Http;
using System.Security.Principal;

// For more information on enabling Web API for empty projects, visit https://go.microsoft.com/fwlink/?LinkID=397860

namespace IsupportESOApi
{
[Route("api/[controller]")]
public class UserController : Controller
{
IList groups = new List();
// GET: api/user/steven.rui.zhang
[HttpGet("{eid}")]
public IActionResult Get(string eid)
{
try
{
DirectorySearcher ds = new DirectorySearcher();
ds.Filter = String.Format("(&(objectClass=user)(sAMAccountName={0}))", eid);
SearchResult sr = ds.FindOne();

            DirectoryEntry user = sr.GetDirectoryEntry();
            user.RefreshCache(new string[] { "tokenGroups" });

            for (int i = 0; i < user.Properties["tokenGroups"].Count; i++)
            {
                SecurityIdentifier sid = new SecurityIdentifier((byte[])user.Properties["tokenGroups"][i], 0);
                try
                {
                    NTAccount nt = (NTAccount)sid.Translate(typeof(NTAccount));
                    //result.Add(nt.Value.ToLower());
                    groups.Add(nt.Value);
                }
                catch (Exception ex)
                {
                    continue;
                }
            }
        }
        catch (Exception ex)
        {
            return new ObjectResult(ex.Message);
        }

        return new ObjectResult(groups);
    }


    
}

}

@gfoidl
Copy link
Member

gfoidl commented Feb 21, 2018

@danmoseley
Copy link
Member

@coolrz we would welcome community involvement in adding Linux support. We do not currently have plans at the moment.

Further discussion can go in #23944

@msftgits msftgits transferred this issue from dotnet/corefx Jan 31, 2020
@msftgits msftgits added this to the 2.1.0 milestone Jan 31, 2020
@ghost ghost locked as resolved and limited conversation to collaborators Dec 18, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-System.DirectoryServices os-linux Linux OS (any supported distro)
Projects
None yet
Development

No branches or pull requests

4 participants