3

我正在与奇怪的问题作斗争,我想知道是否有人可以帮助我。在我的程序的某个时刻,我喜欢向文件夹添加具有适当权限的安全组。步骤看起来像这样。

  1. 创建文件夹
  2. 创建域本地安全组
  3. 创建全局安全组
  4. 将全局组添加到本地组
  5. 将域本地安全组添加到文件夹“\domain\dfs\folder”

我从 Microsoft 页面获得了以下代码来执行此操作

 public static void AddDirectorySecurity(string DirectoryName, string Group, FileSystemRights Rights, InheritanceFlags iFlag, PropagationFlags pFlag, AccessControlType ControlType)
{
    // Create a new DirectoryInfo object.
    DirectoryInfo dInfo = new DirectoryInfo(DirectoryName);

    // Get a DirectorySecurity object that represents the  
    // current security settings.
    DirectorySecurity dSecurity = dInfo.GetAccessControl();

    // Add the FileSystemAccessRule to the security settings. 
    dSecurity.AddAccessRule(new FileSystemAccessRule(Group,Rights,iFlag,pFlag,ControlType));

    // Set the new access settings.
    dInfo.SetAccessControl(dSecurity); // 

}

添加过程如下所示:

path = @"\\domain\dfs\folder"

gRDL_RW = "RDL-group-RW"

    AddDirectorySecurity(path, gRDL_RW, FileSystemRights.Modify, InheritanceFlags.ContainerInherit | InheritanceFlags.ObjectInherit, PropagationFlags.None, AccessControlType.Allow);

它在我的测试环境中运行良好,但是当我想在生产环境中运行它时出现错误:

************** Exception Text **************
System.Security.Principal.IdentityNotMappedException: Some or all identity references could not be translated.
at System.Security.Principal.NTAccount.Translate(IdentityReferenceCollection sourceAccounts, Type targetType, Boolean forceSuccess)
at System.Security.Principal.NTAccount.Translate(Type targetType)
at System.Security.AccessControl.CommonObjectSecurity.ModifyAccess(AccessControlModification modification, AccessRule rule, Boolean& modified)
at System.Security.AccessControl.CommonObjectSecurity.AddAccessRule(AccessRule rule)
at Program_dev_1.Form1.button1_Click(Object sender, EventArgs e) in  c:\Users\?????????\Documents\Visual Studio 2012\Projects\brite_dev_1\brite_dev_1\Form1.cs:line 191
at System.Windows.Forms.Button.OnMouseUp(MouseEventArgs mevent)
at System.Windows.Forms.Control.WmMouseUp(Message& m, MouseButtons button, Int32 clicks)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.ButtonBase.WndProc(Message& m)
at System.Windows.Forms.Button.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

“管理员权限”有问题吗?我在生产环境中拥有上帝般的权限。那么发生了什么?

我感觉由于某种原因,所有那些用户友好的名称,例如“FileSystemRights.Modify”都无法翻译。我检查了测试和生产环境的语言环境,两者都是一样的。

是否可以使用隐藏在这些用户友好名称后面的原始数字?

也许还有其他方法可以将安全组添加到文件夹?我真正喜欢的只是一个可行的解决方案。

4

1 回答 1

1

当尝试将组添加到文件夹时,应用程序崩溃了,因为所有域控制器都不会立即知道新创建的组。在继续执行其余代码之前,我必须创建一个程序来检查新创建的组是否已在整个房地产中同步。这是不可能的,或者我找不到在将组添加到文件夹权限时指定使用的域控制器的方法。

于 2015-04-22T09:28:54.527 回答