在 Exchange 邮箱上设置 ACL

发布于 2024-12-11 05:20:29 字数 819 浏览 0 评论 0原文

我正在尝试将组添加到邮箱(在 C# 中)。我混合使用了 CDOEXM、DirectoryServices.AccountManagement 调用,但失败了。这是我的代码:

// userDe is a DirectoryEntry
IExchangeMailbox exMb = (IExchangeMailbox)userDe.NativeObject;
IADsSecurityDescriptor securityDescriptor = (IADsSecurityDescriptor)exMb.MailboxRights;
IADsAccessControlList acl = (IADsAccessControlList)securityDescriptor.DiscretionaryAcl;
AccessControlEntry ace = new AccessControlEntry();

// groupName - I have successfully created the group earlier
ace.Trustee = groupName;
acl.AddAce(ace);
securityDescriptor.DiscretionaryAcl = acl;
exMb.MailboxRights = securityDescriptor;

// How do I save it?
exMb.CommitChanges() etc etc
...or userDe.Properties["ntSecurityDescriptor"] = securityDescriptor;

不确定下一步要做什么,我尝试的所有操作都会导致编译错误或 InvalidCastException。

请帮忙

I'm trying to add a group to a mailbox (in C#). I'm using a mix of CDOEXM, DirectoryServices.AccountManagement calls, and failing. This is my code:

// userDe is a DirectoryEntry
IExchangeMailbox exMb = (IExchangeMailbox)userDe.NativeObject;
IADsSecurityDescriptor securityDescriptor = (IADsSecurityDescriptor)exMb.MailboxRights;
IADsAccessControlList acl = (IADsAccessControlList)securityDescriptor.DiscretionaryAcl;
AccessControlEntry ace = new AccessControlEntry();

// groupName - I have successfully created the group earlier
ace.Trustee = groupName;
acl.AddAce(ace);
securityDescriptor.DiscretionaryAcl = acl;
exMb.MailboxRights = securityDescriptor;

// How do I save it?
exMb.CommitChanges() etc etc
...or userDe.Properties["ntSecurityDescriptor"] = securityDescriptor;

Not sure what to do next, everything I try results in a compilation error or a InvalidCastException.

Please help

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

那请放手 2024-12-18 05:20:29

经过相当多的痛苦之后才得到它(我设置的整数值在某种程度上对应于 API 中的枚举值,但我无法让它们工作)。变量 userDe 是一个 DirectoryEntry。

            IExchangeMailbox exMb = (IExchangeMailbox)userDe.NativeObject;
            IADsSecurityDescriptor securityDescriptor = (IADsSecurityDescriptor)exMb.MailboxRights;
            IADsAccessControlList acl = (IADsAccessControlList)securityDescriptor.DiscretionaryAcl;
            AccessControlEntry ace = new AccessControlEntry();
            ace.Trustee = groupName;
            ace.AccessMask = 1;
            ace.AceFlags = 2;
            ace.AceType = 0;

            acl.AddAce(ace);
            securityDescriptor.DiscretionaryAcl = acl;
            IADsUser iadsUser = (IADsUser)userDe.NativeObject;
            iadsUser.Put("msExchMailboxSecurityDescriptor", securityDescriptor);

            iadsUser.SetInfo();  

Got it after quite a bit of pain (the integer values I am setting somehow correspond to enum values in the API but I couldn't get them to work). The variable userDe is a DirectoryEntry.

            IExchangeMailbox exMb = (IExchangeMailbox)userDe.NativeObject;
            IADsSecurityDescriptor securityDescriptor = (IADsSecurityDescriptor)exMb.MailboxRights;
            IADsAccessControlList acl = (IADsAccessControlList)securityDescriptor.DiscretionaryAcl;
            AccessControlEntry ace = new AccessControlEntry();
            ace.Trustee = groupName;
            ace.AccessMask = 1;
            ace.AceFlags = 2;
            ace.AceType = 0;

            acl.AddAce(ace);
            securityDescriptor.DiscretionaryAcl = acl;
            IADsUser iadsUser = (IADsUser)userDe.NativeObject;
            iadsUser.Put("msExchMailboxSecurityDescriptor", securityDescriptor);

            iadsUser.SetInfo();  
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文