コード例 #1
0
        internal unsafe static void UnsafeSetNamedSecurityInfo(
            string objectName,
            SE_OBJECT_TYPE objectType,
            SECURITY_INFORMATION securityInfo,
            Sid sidOwner,
            Sid sidGroup,
            Dacl dacl,
            Sacl sacl)
        {
            fixed(byte *pSidOwner = (sidOwner != null ? sidOwner.GetNativeSID() : null))
            {
                fixed(byte *pSidGroup = (sidGroup != null ? sidGroup.GetNativeSID() : null))
                {
                    fixed(byte *pDacl = (dacl != null ? dacl.GetNativeACL() : null))
                    {
                        fixed(byte *pSacl = (sacl != null ? sacl.GetNativeACL() : null))
                        {
                            DWORD rc = Win32.SetNamedSecurityInfo(objectName, objectType, securityInfo,
                                                                  (IntPtr)pSidOwner, (IntPtr)pSidGroup, (IntPtr)pDacl, (IntPtr)pSacl);

                            if (rc != Win32.ERROR_SUCCESS)
                            {
                                Win32.SetLastError(rc);
                                Win32.ThrowLastError();
                            }
                        }
                    }
                }
            }
        }
コード例 #2
0
ファイル: SecurityDescriptor.cs プロジェクト: fjwgrace/mcec
        private static void UnsafeSetDacl(SecurityDescriptor secDesc, Dacl dacl, bool defaulted)
        {
            secDesc.MakeAbsolute();

            // First we have to get a copy of the old group ptr, so that
            // we can free it if everything goes well.
            BOOL   rc;
            IntPtr pOldDacl = IntPtr.Zero;

            if (!secDesc.IsNull)
            {
                BOOL oldDefaulted, oldPresent;
                rc = Win32.GetSecurityDescriptorDacl(secDesc._secDesc, out oldPresent, ref pOldDacl, out oldDefaulted);
                Win32.CheckCall(rc);
            }
            else
            {
                secDesc.AllocateAndInitializeSecurityDescriptor();
            }


            IntPtr pNewDacl = IntPtr.Zero;

            try
            {
                if ((dacl != null) && !dacl.IsNull && !dacl.IsEmpty)
                {
                    byte [] pacl = dacl.GetNativeACL();
                    pNewDacl = Win32.AllocGlobal(pacl.Length);
                    Marshal.Copy(pacl, 0, pNewDacl, pacl.Length);
                }

                bool present = ((dacl == null) || dacl.IsNull || (pNewDacl != IntPtr.Zero));
                rc = Win32.SetSecurityDescriptorDacl(
                    secDesc._secDesc, (present ? Win32.TRUE : Win32.FALSE),
                    pNewDacl, (defaulted ?  Win32.TRUE : Win32.FALSE));
                Win32.CheckCall(rc);

                Win32.FreeGlobal(pOldDacl);
            }
            catch
            {
                Win32.FreeGlobal(pNewDacl);
                throw;
            }
        }
コード例 #3
0
ファイル: Win32Helpers.cs プロジェクト: nuxleus/flexwikicore
        internal static unsafe void UnsafeSetSecurityInfo(
			HANDLE handle,
			SE_OBJECT_TYPE ObjectType,
			SECURITY_INFORMATION SecurityInfo,
			Sid sidOwner,
			Sid sidGroup,
			Dacl dacl,
			Sacl sacl)
        {
            fixed(byte *pSidOwner = (sidOwner != null ? sidOwner.GetNativeSID() : null))
            {
                fixed(byte *pSidGroup = (sidGroup != null ? sidGroup.GetNativeSID() : null))
                {
                    fixed(byte *pDacl = (dacl != null ? dacl.GetNativeACL() : null))
                    {
                        fixed(byte *pSacl = (sacl != null ? sacl.GetNativeACL() : null))
                        {
                            DWORD rc = Win32.SetSecurityInfo(handle, ObjectType, SecurityInfo,
                                (IntPtr)pSidOwner, (IntPtr)pSidGroup, (IntPtr)pDacl, (IntPtr)pSacl);
                            if (rc != Win32.ERROR_SUCCESS)
                            {
                                Win32.SetLastError(rc);
                                Win32.ThrowLastError();
                            }
                        }
                    }
                }
            }
        }
コード例 #4
0
        private static void UnsafeSetDacl(SecurityDescriptor secDesc, Dacl dacl, bool defaulted)
        {
            secDesc.MakeAbsolute();

              // First we have to get a copy of the old group ptr, so that
              // we can free it if everything goes well.
              BOOL rc;
              IntPtr pOldDacl = IntPtr.Zero;
              if(!secDesc.IsNull)
              {
            BOOL oldDefaulted, oldPresent;
            rc = Win32.GetSecurityDescriptorDacl(secDesc._secDesc, out oldPresent, ref pOldDacl, out oldDefaulted);
            Win32.CheckCall(rc);
              }
              else
              {
            secDesc.AllocateAndInitializeSecurityDescriptor();
              }

              IntPtr pNewDacl = IntPtr.Zero;
              try
              {
            if((dacl != null) && !dacl.IsNull && !dacl.IsEmpty)
            {
              byte []pacl = dacl.GetNativeACL();
              pNewDacl = Win32.AllocGlobal(pacl.Length);
              Marshal.Copy(pacl, 0, pNewDacl, pacl.Length);
            }

            bool present = ((dacl == null) || dacl.IsNull || (pNewDacl != IntPtr.Zero));
            rc = Win32.SetSecurityDescriptorDacl(
              secDesc._secDesc, (present ? Win32.TRUE : Win32.FALSE),
              pNewDacl, (defaulted ?  Win32.TRUE : Win32.FALSE));
            Win32.CheckCall(rc);

            Win32.FreeGlobal(pOldDacl);
              }
              catch
              {
            Win32.FreeGlobal(pNewDacl);
            throw;
              }
        }
コード例 #5
0
		internal unsafe static void UnsafeSetNamedSecurityInfo(
			string objectName,
			SE_OBJECT_TYPE objectType,
			SECURITY_INFORMATION securityInfo,
			Sid sidOwner,
			Sid sidGroup,
			Dacl dacl,
			Sacl sacl)
		{
            byte[] pSidOwner = (sidOwner != null) ? sidOwner.GetNativeSID() : null;
            byte[] pSidGroup = (sidGroup != null) ? sidGroup.GetNativeSID() : null;
            byte[] pDacl = (dacl != null) ? dacl.GetNativeACL() : null;
            byte[] pSacl = (sacl != null) ? sacl.GetNativeACL() : null;

            DWORD rc = Win32.SetNamedSecurityInfo(objectName, objectType, securityInfo,
              pSidOwner, pSidGroup, pDacl, pSacl);

            if (rc != Win32.ERROR_SUCCESS)
            {
                Win32.SetLastError(rc);
                Win32.ThrowLastError();
            }
		}