Метод NTAccount.Translate завершается с ошибкой Некоторые или все ссылки на удостоверения не могут быть переведены

PipeAccessRule par = new PipeAccessRule("Everyone", PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);

Этот код завершается с ошибкой:

Не удалось перевести некоторые или все ссылки на удостоверения.

Я предполагаю, что это потому, что я использую «Все» при запуске своего приложения не на английском языке. В английской системе все ок.

Как этого избежать? Есть ли какое-то перечисление, описывающее общие группы пользователей?

Трассировки стека:

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 System.IO.Pipes.PipeSecurity.AddAccessRule(PipeAccessRule rule)    

person Ksice    schedule 17.07.2012    source источник


Ответы (2)


Решено с помощью второго конструктора PipeAccessRule и SecurityIdentifier вместо строки:

System.Security.Principal.SecurityIdentifier sid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null);
PipeAccessRule par = new PipeAccessRule(sid, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);
person Ksice    schedule 17.07.2012
comment
это хорошо, но если вы хотите добавить разрешение для определенного пользователя или группы? что тогда ? как можно получить сид? - person David Gidony; 20.07.2015
comment
В моем случае мне нужна встроенная группа onlu. В случае, если это не так, я думаю, достаточно использовать просто строку, как это было в моем исходном вопросе. - person Ksice; 04.05.2016
comment
И на самом деле моя проблема заключалась в том, что один и тот же кусок кода работал в другой культуре. Если культура такая же, я думаю, можно использовать жестко запрограммированные имена. - person Ksice; 04.05.2016
comment
+1, но на случай, если другие сочтут, что это WellKnownSidType.WorldSid больше соответствует первоначальному намерению использовать "Everyone" - person hellyale; 30.10.2018

По некоторым причинам BuiltinUsersSid в моем случае не работает должным образом (удаленные серверы могут получить доступ к каналу, но локальный доступ к каналу не работает!)

Вот код, который я использовал для предоставления доступа почти ко всему, и теперь доступ к каналу можно получить локально или удаленно:

Обратите внимание, что параметр DomainSid в некоторых случаях заполняется текущим доменом пользователя.

using System.IO.Pipes;
using System.Security.Principal;
using System.Security.AccessControl;
[...]

            PipeSecurity lPipeSecurity = new PipeSecurity();
            try
            {
                PipeAccessRule lPar1 = new PipeAccessRule(@"NT AUTHORITY\NETWORK", PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Allow);
                lPipeSecurity.AddAccessRule(lPar1);
            }
            catch (Exception E1)
            {
                Console.WriteLine(PrinterBase.DumpTimestamp(DateTime.UtcNow, true) + ": Exception when trying to give pipe rights to AUTORITY NT NETWORK"+E1.Message);
            }
            try
            {
                System.Security.Principal.SecurityIdentifier lSid = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.BuiltinUsersSid, null);
                PipeAccessRule lPar2 = new PipeAccessRule(lSid, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);

                lPipeSecurity.AddAccessRule(lPar2);
            }
            catch (Exception E2)
            {
                Console.WriteLine(PrinterBase.DumpTimestamp(DateTime.UtcNow, true) + ": Exception when trying to give pipe rights to BuiltInSid "+E2.Message);
            }
            try
            {
                PipeAccessRule lPar3 = new PipeAccessRule(string.Format(@"{0}\{1}", Environment.UserDomainName, Environment.UserName), PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Allow);
                lPipeSecurity.AddAccessRule(lPar3);
            }
            catch (Exception E3)
            {
                Console.WriteLine(PrinterBase.DumpTimestamp(DateTime.UtcNow, true) + ": Exception when trying to give pipe rights to current user "+E3.Message);
            }
            try
            {
                System.Security.Principal.SecurityIdentifier lSidWorld = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.WorldSid, null);
                PipeAccessRule lPar4 = new PipeAccessRule(lSidWorld, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);
                lPipeSecurity.AddAccessRule(lPar4);
            }
            catch (Exception E4)
            {
                Console.WriteLine(PrinterBase.DumpTimestamp(DateTime.UtcNow, true) + ": Exception when trying to give rights to World "+E4.Message);
            }

            try
            {
                System.Security.Principal.SecurityIdentifier lSidLocal = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.LocalSid, null);
                PipeAccessRule lPar5 = new PipeAccessRule(lSidLocal, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);
                lPipeSecurity.AddAccessRule(lPar5);
            }
            catch (Exception E5)
            {
                Console.WriteLine(PrinterBase.DumpTimestamp(DateTime.UtcNow, true) + ": Exception when trying to give rights to Local "+E5.Message);
            }
            try
            {
                PipeAccessRule lPar6 = new PipeAccessRule(@"geneos", PipeAccessRights.FullControl, System.Security.AccessControl.AccessControlType.Allow);
                lPipeSecurity.AddAccessRule(lPar6);
            }
            catch (Exception E6)
            {
                Console.WriteLine(PrinterBase.DumpTimestamp(DateTime.UtcNow, true) + ": Exception when trying to give pipe rights to geneos" + E6.Message);
            }
            try
            {
                WindowsIdentity lCurrentId = WindowsIdentity.GetCurrent();
                System.Security.Principal.SecurityIdentifier lSidLocal = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.AccountAdministratorSid, lCurrentId.User.AccountDomainSid);
                PipeAccessRule lPar5 = new PipeAccessRule(lSidLocal, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);
                lPipeSecurity.AddAccessRule(lPar5);
            }
            catch (Exception E7)
            {
                Console.WriteLine(PrinterBase.DumpTimestamp(DateTime.UtcNow, true) + ": Exception when trying to give rights to administrators " + E7.Message);
            }
            try
            {
                System.Security.Principal.SecurityIdentifier lSidLocal = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.AuthenticatedUserSid, null);
                PipeAccessRule lPar8 = new PipeAccessRule(lSidLocal, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);
                lPipeSecurity.AddAccessRule(lPar8);
            }
            catch (Exception E8)
            {
                Console.WriteLine(PrinterBase.DumpTimestamp(DateTime.UtcNow, true) + ": Exception when trying to give rights to authenticated users " + E8.Message);
            }
            try
            {
                WindowsIdentity lCurrentId = WindowsIdentity.GetCurrent();
                System.Security.Principal.SecurityIdentifier lSidLocal = new System.Security.Principal.SecurityIdentifier(System.Security.Principal.WellKnownSidType.AuthenticatedUserSid, lCurrentId.User.AccountDomainSid);
                PipeAccessRule lPar9 = new PipeAccessRule(lSidLocal, PipeAccessRights.ReadWrite, System.Security.AccessControl.AccessControlType.Allow);
                lPipeSecurity.AddAccessRule(lPar9);
            }
            catch (Exception E9)
            {
                Console.WriteLine(PrinterBase.DumpTimestamp(DateTime.UtcNow, true) + ": Exception when trying to give rights to authenticated users on current user domain " + E9.Message);
            }


            lPipeServer = new NamedPipeServerStream(
                lNamedPipe, 
                PipeDirection.InOut, 
                NamedPipeServerStream.MaxAllowedServerInstances, 
                PipeTransmissionMode.Byte, 
                PipeOptions.Asynchronous, 
                0, 
                0, 
                lPipeSecurity);
person Laurent PELE    schedule 23.09.2015