Exemple #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();
                            }
                        }
                    }
                }
            }
        }
Exemple #2
0
        private static void UnsafeSetSacl(SecurityDescriptor secDesc, Sacl sacl, bool defaulted)
        {
            if (sacl == null)
            {
                throw new ArgumentException("Can't set null SACL on a security descriptor", "sacl");
            }

            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 pOldSacl = IntPtr.Zero;

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


            IntPtr pNewSacl = IntPtr.Zero;

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

                bool present = (sacl.IsNull || (pNewSacl != IntPtr.Zero));
                rc = Win32.SetSecurityDescriptorSacl(
                    secDesc._secDesc, (present ? Win32.TRUE : Win32.FALSE),
                    pNewSacl, (defaulted ?  Win32.TRUE : Win32.FALSE));
                Win32.CheckCall(rc);

                Win32.FreeGlobal(pOldSacl);
            }
            catch
            {
                Win32.FreeGlobal(pNewSacl);
                throw;
            }
        }
Exemple #3
0
        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();
                            }
                        }
                    }
                }
            }
        }
        private static void UnsafeSetSacl(SecurityDescriptor secDesc, Sacl sacl, bool defaulted)
        {
            if (sacl == null)
            throw new ArgumentException("Can't set null SACL on a security descriptor", "sacl");

              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 pOldSacl = IntPtr.Zero;
              if(!secDesc.IsNull)
              {
            BOOL oldDefaulted, oldPresent;
            rc = Win32.GetSecurityDescriptorSacl(secDesc._secDesc, out oldPresent, ref pOldSacl, out oldDefaulted);
            Win32.CheckCall(rc);
              }
              else
              {
            secDesc.AllocateAndInitializeSecurityDescriptor();
              }

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

            bool present = (sacl.IsNull || (pNewSacl != IntPtr.Zero));
            rc = Win32.SetSecurityDescriptorSacl(
              secDesc._secDesc, (present ? Win32.TRUE : Win32.FALSE),
              pNewSacl, (defaulted ?  Win32.TRUE : Win32.FALSE));
            Win32.CheckCall(rc);

            Win32.FreeGlobal(pOldSacl);
              }
              catch
              {
            Win32.FreeGlobal(pNewSacl);
            throw;
              }
        }
		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();
            }
		}