当前位置: 首页>>代码示例>>C#>>正文


C# DiscretionaryAcl.GetBinaryForm方法代码示例

本文整理汇总了C#中System.Security.AccessControl.DiscretionaryAcl.GetBinaryForm方法的典型用法代码示例。如果您正苦于以下问题:C# DiscretionaryAcl.GetBinaryForm方法的具体用法?C# DiscretionaryAcl.GetBinaryForm怎么用?C# DiscretionaryAcl.GetBinaryForm使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在System.Security.AccessControl.DiscretionaryAcl的用法示例。


在下文中一共展示了DiscretionaryAcl.GetBinaryForm方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EmptyBinaryFormDSOK

		public void EmptyBinaryFormDSOK()
		{
			DiscretionaryAcl dacl = new DiscretionaryAcl (false, true, 0);
			byte[] buffer = new byte[8];
			dacl.GetBinaryForm (buffer, 0);

			Assert.AreEqual (4, buffer [0]); // Revision
			Assert.AreEqual (8, ToUInt16 (buffer, 2)); // ACL Size
			Assert.AreEqual (0, ToUInt16 (buffer, 4)); // ACE Count
		}
开发者ID:adbre,项目名称:mono,代码行数:10,代码来源:CommonAclTest.cs

示例2: BinaryRoundtrip

		public void BinaryRoundtrip ()
		{
			RawAcl acl = GetRemovesMeaninglessAcesAcl ();

			DiscretionaryAcl dacl1 = new DiscretionaryAcl (false, false, acl);
			byte[] binaryForm1 = new byte[dacl1.BinaryLength];
			dacl1.GetBinaryForm (binaryForm1, 0);

			DiscretionaryAcl dacl2 = new DiscretionaryAcl (false, false, new RawAcl (binaryForm1, 0));
			byte[] binaryForm2 = new byte[dacl2.BinaryLength];
			dacl2.GetBinaryForm (binaryForm2, 0);

			Assert.AreEqual (binaryForm1.Length, binaryForm2.Length);
			for (int i = 0; i < binaryForm1.Length; i ++)
				Assert.AreEqual (binaryForm1 [i], binaryForm2 [i]);
		}
开发者ID:nlhepler,项目名称:mono,代码行数:16,代码来源:CommonAclTest.cs

示例3: SetAcl

        public static bool SetAcl(this ServiceController controller, Action<DiscretionaryAcl> fn)
        {
            // from http://pinvoke.net/default.aspx/advapi32/QueryServiceObjectSecurity.html (thx!)

            using (SafeHandle handle = controller.ServiceHandle)
            {
                var psd = new byte[0];
                uint bufSizeNeeded;

                bool success = QueryServiceObjectSecurity(handle, SecurityInfos.DiscretionaryAcl, psd, 0,
                    out bufSizeNeeded);

                if (!success)
                {
                    int error = Marshal.GetLastWin32Error();

                    if (error == ErrorInsufficientBuffer)
                    {
                        psd = new byte[bufSizeNeeded];
                        success = QueryServiceObjectSecurity(handle, SecurityInfos.DiscretionaryAcl, psd, bufSizeNeeded,
                            out bufSizeNeeded);
                    }
                    else
                    {
                        return false;
                    }
                }

                if (!success)
                {
                    return false;
                }

                // get security descriptor via raw into DACL form so ACE
                // ordering checks are done for us.
                var rsd = new RawSecurityDescriptor(psd, 0);
                var dacl = new DiscretionaryAcl(false, false, rsd.DiscretionaryAcl);

                fn(dacl);

                // convert discretionary ACL back to raw form; looks like via byte[] is only way
                var rawdacl = new byte[dacl.BinaryLength];
                dacl.GetBinaryForm(rawdacl, 0);
                rsd.DiscretionaryAcl = new RawAcl(rawdacl, 0);

                // set raw security descriptor on service again
                var rawsd = new byte[rsd.BinaryLength];
                rsd.GetBinaryForm(rawsd, 0);

                success = SetServiceObjectSecurity(handle, SecurityInfos.DiscretionaryAcl, rawsd);

                return success;
            }
        }
开发者ID:Jabe,项目名称:procstub,代码行数:54,代码来源:ServiceWrapper.cs

示例4: EnsureServiceAclsCorrect

        internal static void EnsureServiceAclsCorrect()
        {
            var psd = new byte[0];
            uint bufSizeNeeded;
            var ok = Advapi32.QueryServiceObjectSecurity(Controller.Value.ServiceHandle, SecurityInfos.DiscretionaryAcl, psd, 0, out bufSizeNeeded);
            if (!ok) {
                int err = Marshal.GetLastWin32Error();
                if (err == 122) {
                    // ERROR_INSUFFICIENT_BUFFER
                    // expected; now we know bufsize
                    psd = new byte[bufSizeNeeded];
                    ok = Advapi32.QueryServiceObjectSecurity(
                        Controller.Value.ServiceHandle, SecurityInfos.DiscretionaryAcl, psd, bufSizeNeeded, out bufSizeNeeded);
                } else {
                    throw new ApplicationException("error calling QueryServiceObjectSecurity() to get DACL for Service: error code=" + err);
                }
            }
            if (!ok) {
                throw new ApplicationException("error calling QueryServiceObjectSecurity(2) to get DACL for Service: error code=" + Marshal.GetLastWin32Error());
            }

            // get security descriptor via raw into DACL form so ACE
            // ordering checks are done for us.
            var rsd = new RawSecurityDescriptor(psd, 0);
            var dacl = new DiscretionaryAcl(false, false, rsd.DiscretionaryAcl);

            dacl.AddAccess(AccessControlType.Allow, new SecurityIdentifier(WellKnownSidType.AuthenticatedUserSid, null), (int)ServiceAccess.ServiceCoapp, InheritanceFlags.None, PropagationFlags.None);

            // convert discretionary ACL back to raw form; looks like via byte[] is only way
            var rawdacl = new byte[dacl.BinaryLength];
            dacl.GetBinaryForm(rawdacl, 0);
            rsd.DiscretionaryAcl = new RawAcl(rawdacl, 0);

            // set raw security descriptor on service again
            var rawsd = new byte[rsd.BinaryLength];
            rsd.GetBinaryForm(rawsd, 0);

            ok = Advapi32.SetServiceObjectSecurity(Controller.Value.ServiceHandle, SecurityInfos.DiscretionaryAcl, rawsd);
            if (!ok) {
                throw new ApplicationException("error calling SetServiceObjectSecurity(); error code=" + Marshal.GetLastWin32Error());
            }
        }
开发者ID:fearthecowboy,项目名称:coapp,代码行数:42,代码来源:EngineServiceManager.cs


注:本文中的System.Security.AccessControl.DiscretionaryAcl.GetBinaryForm方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。