求助,如何通过c#获取和管理AD LDS(Active Directory 轻型目录服务)的ACL?
AD LDS(Active Directory 轻型目录服务,老版本叫ADAM)一般都是通过System.DirectoryServices.DirectoryEntry来访问的,但是这个下面唯独没有获取和管理ACL(访问控制列表)的东西,目前我只能在DOS命令行下用ADAM提供的命令工具来修改添加ACL,急切需要在c#内实现对ACL的管理
我自己一直在翻MSDN,估计对ACL的控制在System.DirectoryServices.ActiveDirectorySecurity内,这里面也有名为AddAccessRule、GetAccessRules之类的方法,但是MSDN的网页上都没有提供源码例子,个人才疏学浅,变成属于文科生半路出家自学,没办法求各路大神相助,有没有熟悉这一块的高人啊? c# AD LDS ADAM --------------------编程问答-------------------- 自顶,在线等待中
是我问题描述的不清楚还是没人知道答案啊?迅速沉贴了...... --------------------编程问答-------------------- --------------------编程问答-------------------- 连个指方向的人都没有啊? --------------------编程问答-------------------- acl 要针对具体的对象,例如文件的访问,注册表的访问
using System;
using System.IO;
using System.Security.AccessControl;
namespace FileSystemExample
{
class FileExample
{
public static void Main()
{
try
{
string fileName = "test.xml";
Console.WriteLine("Adding access control entry for "
+ fileName);
// Add the access control entry to the file.
AddFileSecurity(fileName, @"DomainName\AccountName",
FileSystemRights.ReadData, AccessControlType.Allow);
Console.WriteLine("Removing access control entry from "
+ fileName);
// Remove the access control entry from the file.
RemoveFileSecurity(fileName, @"DomainName\AccountName",
FileSystemRights.ReadData, AccessControlType.Allow);
Console.WriteLine("Done.");
}
catch (Exception e)
{
Console.WriteLine(e);
}
}
// Adds an ACL entry on the specified file for the specified account.
public static void AddFileSecurity(string fileName, string account,
FileSystemRights rights, AccessControlType controlType)
{
// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(fileName);
// Add the FileSystemAccessRule to the security settings.
fSecurity.AddAccessRule(new FileSystemAccessRule(account,
rights, controlType));
// Set the new access settings.
File.SetAccessControl(fileName, fSecurity);
}
// Removes an ACL entry on the specified file for the specified account.
public static void RemoveFileSecurity(string fileName, string account,
FileSystemRights rights, AccessControlType controlType)
{
// Get a FileSecurity object that represents the
// current security settings.
FileSecurity fSecurity = File.GetAccessControl(fileName);
// Add the FileSystemAccessRule to the security settings.
fSecurity.RemoveAccessRule(new FileSystemAccessRule(account,
rights, controlType));
// Set the new access settings.
File.SetAccessControl(fileName, fSecurity);
}
}
} --------------------编程问答-------------------- 谢楼上,我知道ACL是针对不同对象的
我想要针对的对象是windows server 提供的基于轻量目录访问协议(LDAP)的轻型目录服务(AD LDS或者adam)
轻型目录服务提供根据ACL来控制访问资源的方法,c#在System.DirectoryServices.DirectoryEntry中提供了对目录条目本身的各类操作,如添加删除修改之类,但是对条目(entry)的访问控制是配置在ACL中的,所以我需要找到对轻型目录服务下ACL管理的方法
昨天试了一晚上,目前我已经能通过System.DirectoryServices.DirectoryEntry.objectSecurity.getAccessRules取到已有ACL集合,但是实在看不懂里面包含的东西是啥意思,就是如何解析ACL成为比较直观的内容呢? --------------------编程问答-------------------- 既然知道,你要通过adsi获取的话会出现什么情况? --------------------编程问答-------------------- 结贴,凭着不断摸索msdn一条条试验终于解决,
补充:.NET技术 , C#