Example #1
0
		public static extern BOOL GetSecurityDescriptorOwner(
			PSECURITY_DESCRIPTOR pSecurityDescriptor, 
			out PSID pOwner, 
			out BOOL lpbOwnerDefaulted
			);
Example #2
0
		public static extern BOOL GetSecurityDescriptorGroup(
			PSECURITY_DESCRIPTOR pSecurityDescriptor, 
			out PSID pGroup, 
			out BOOL lpbGroupDefaulted
			);
Example #3
0
		public static extern DWORD GetSecurityDescriptorLength(
			PSECURITY_DESCRIPTOR pSecurityDescriptor
			);
Example #4
0
		public static extern BOOL InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision);
Example #5
0
		public static extern BOOL GetSecurityDescriptorControl(
			PSECURITY_DESCRIPTOR pSecurityDescriptor, 
			out SECURITY_DESCRIPTOR_CONTROL pControl, 
			out DWORD lpdwRevision
			);
Example #6
0
        /// <summary>
        /// Gets the effective permissions for the provided Sid within the Security Descriptor.
        /// </summary>
        /// <param name="pUserSid">A pointer to the Sid of the identity to check.</param>
        /// <param name="serverName">Name of the server. This can be <c>null</c>.</param>
        /// <param name="pSecurityDescriptor">A pointer to the security descriptor.</param>
        /// <returns>An array of access masks.</returns>
        public virtual uint[] GetEffectivePermission(PSID pUserSid, string serverName, PSECURITY_DESCRIPTOR pSecurityDescriptor)
        {
            var mask = pUserSid.GetEffectiveRights(pSecurityDescriptor);

            return(new[] { mask });
        }
Example #7
0
 /// <summary>
 /// Gets the effective permissions for the provided Sid within the Security Descriptor.
 /// Called only when an object type identifier is specified.
 /// </summary>
 /// <param name="objTypeId">The object type identifier.</param>
 /// <param name="pUserSid">A pointer to the Sid of the identity to check.</param>
 /// <param name="serverName">Name of the server. This can be <c>null</c>.</param>
 /// <param name="pSecurityDescriptor">A pointer to the security descriptor.</param>
 /// <param name="objectTypeList">The object type list.</param>
 /// <param name="grantedAccessList">An array of access masks.</param>
 /// <returns></returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public virtual HRESULT GetEffectivePermission(Guid objTypeId, PSID pUserSid, string serverName, PSECURITY_DESCRIPTOR pSecurityDescriptor, out OBJECT_TYPE_LIST[] objectTypeList, out uint[] grantedAccessList)
 {
     objectTypeList    = null;
     grantedAccessList = null;
     return(HRESULT.E_NOTIMPL);
 }
Example #8
0
 public static string ConvertSecurityDescriptorToStringSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor, SECURITY_INFORMATION SecurityInformation) =>
 ConvertSecurityDescriptorToStringSecurityDescriptor(SecurityDescriptor, SDDL_REVISION.SDDL_REVISION_1, SecurityInformation, out var sd, out var sz) ? sd.ToString(-1) : throw new Win32Exception();
Example #9
0
 public static extern bool ConvertSecurityDescriptorToStringSecurityDescriptor(PSECURITY_DESCRIPTOR SecurityDescriptor, SDDL_REVISION RequestedStringSDRevision,
                                                                               SECURITY_INFORMATION SecurityInformation, out SafeLocalHandle StringSecurityDescriptor, out uint StringSecurityDescriptorLen);
 internal static extern DWORD GetSecurityInfo(
     SafeFileHandle handle,
     ObjectType objectType,
     SecurityInformationClass infoClass,
     PSID owner,
     PSID group,
     PACL dacl,
     PACL sacl,
     out PSECURITY_DESCRIPTOR securityDescriptor);
Example #11
0
 /// <summary>Converts a PSECURITY_DESCRIPTOR to a managed RawSecurityDescriptor.</summary>
 /// <param name="securityDescriptor">The security descriptor.</param>
 /// <returns>The RawSecurityDescriptor.</returns>
 public static RawSecurityDescriptor ToManaged(this PSECURITY_DESCRIPTOR securityDescriptor) => new RawSecurityDescriptor(securityDescriptor.ToByteArray(), 0);
 internal static extern bool AuthzAccessCheck(
     AuthzACFlags flags,
     AUTHZ_CLIENT_CONTEXT_HANDLE hAuthzClientContext,
     ref AUTHZ_ACCESS_REQUEST pRequest,
     AUTHZ_AUDIT_EVENT_HANDLE AuditEvent,
     byte[] rawSecurityDescriptor,
     PSECURITY_DESCRIPTOR[] OptionalSecurityDescriptorArray,
     DWORD OptionalSecurityDescriptorCount,
     ref AUTHZ_ACCESS_REPLY pReply,
     AUTHZ_ACCESS_CHECK_RESULTS_HANDLE cachedResults);
Example #13
0
 public static extern BOOL SetUserObjectSecurity(
     HANDLE hObj,
     SECURITY_INFORMATION SecurityInformation,
     PSECURITY_DESCRIPTOR SecurityDescriptor
     );
        public static byte[] ConvertSecurityDescriptorToByteArray(PSECURITY_DESCRIPTOR securityDescriptor)
        {
            DWORD sdLength = NativeMethods.GetSecurityDescriptorLength(securityDescriptor);

            byte[] buffer = new byte[sdLength];
            Marshal.Copy(securityDescriptor, buffer, 0, (int)sdLength);

            return buffer;
        }
Example #15
0
		public static extern BOOL GetSecurityDescriptorSacl(
			PSECURITY_DESCRIPTOR pSecurityDescriptor, 
			out BOOL lpbSaclPresent, 
			ref PACL pSacl,     // By ref, because if "present" == false, value is unchanged
			out BOOL lpbSaclDefaulted
			);
Example #16
0
		public static extern BOOL GetFileSecurity(
			LPCTSTR lpFileName, 
			SECURITY_INFORMATION RequestedInformation, 
			PSECURITY_DESCRIPTOR pSecurityDescriptor, 
			DWORD nLength, 
			out DWORD lpnLengthNeeded
			);
Example #17
0
 public static extern BOOL SetSecurityDescriptorDacl(
     PSECURITY_DESCRIPTOR pSecurityDescriptor,
     BOOL bDaclPresent,
     PACL pDacl,
     BOOL bDaclDefaulted
     );
Example #18
0
 public static extern DWORD GetSecurityDescriptorLength(
     PSECURITY_DESCRIPTOR pSecurityDescriptor
     );
Example #19
0
 public static extern BOOL GetSecurityDescriptorSacl(
     PSECURITY_DESCRIPTOR pSecurityDescriptor,
     out BOOL lpbSaclPresent,
     ref PACL pSacl,                 // By ref, because if "present" == false, value is unchanged
     out BOOL lpbSaclDefaulted
     );
Example #20
0
 public static extern BOOL SetKernelObjectSecurity(
     HANDLE Handle,
     SECURITY_INFORMATION SecurityInformation,
     PSECURITY_DESCRIPTOR SecurityDescriptor
     );
Example #21
0
 public static extern BOOL GetSecurityDescriptorControl(
     PSECURITY_DESCRIPTOR pSecurityDescriptor,
     out SECURITY_DESCRIPTOR_CONTROL pControl,
     out DWORD lpdwRevision
     );
Example #22
0
 public static extern BOOL SetSecurityDescriptorOwner(
     PSECURITY_DESCRIPTOR pSecurityDescriptor,
     PSID pOwner,
     BOOL bOwnerDefaulted
     );
Example #23
0
 public static extern LONG RegGetKeySecurity(
     HKEY hKey,                                // handle to key
     SECURITY_INFORMATION SecurityInformation, // request
     PSECURITY_DESCRIPTOR pSecurityDescriptor, // SD
     ref DWORD lpcbSecurityDescriptor          // buffer size
     );
Example #24
0
		public static extern DWORD GetNamedSecurityInfo(
			LPCTSTR pObjectName,		//REVIEW: Why is it documented as LPTSTR
			SE_OBJECT_TYPE ObjectType,
			SECURITY_INFORMATION SecurityInfo,
			ref PSID ppsidOwner,
			ref PSID ppsidGroup,
			ref PACL ppDacl,
			ref PACL ppSacl,
			ref PSECURITY_DESCRIPTOR ppSecurityDescriptor);
Example #25
0
 /// <summary>Converts a security descriptor to its SDDL string format.</summary>
 /// <param name="pSD">The security descriptor.</param>
 /// <param name="si">The elements of the security descriptor to return.</param>
 /// <returns>The SDDL string representation of the security descriptor.</returns>
 public static string ToSddl(this PSECURITY_DESCRIPTOR pSD, SECURITY_INFORMATION si) => ConvertSecurityDescriptorToStringSecurityDescriptor(pSD, si);
Example #26
0
		public static extern BOOL SetSecurityDescriptorSacl(
			PSECURITY_DESCRIPTOR pSecurityDescriptor, 
			BOOL bSaclPresent, 
			PACL pSacl, 
			BOOL bSaclDefaulted
			);
Example #27
0
		public static extern DWORD GetSecurityInfo(
			HANDLE handle,
			SE_OBJECT_TYPE ObjectType,
			SECURITY_INFORMATION SecurityInfo,
			ref PSID ppsidOwner,
			ref PSID ppsidGroup,
			ref PACL ppDacl,
			ref PACL ppSacl,
			ref PSECURITY_DESCRIPTOR ppSecurityDescriptor);
Example #28
0
		public static extern BOOL SetSecurityDescriptorOwner(
			PSECURITY_DESCRIPTOR pSecurityDescriptor, 
			PSID pOwner, 
			BOOL bOwnerDefaulted
			);
Example #29
0
		public static extern BOOL SetSecurityDescriptorGroup(
			PSECURITY_DESCRIPTOR pSecurityDescriptor, 
			PSID pGroup, 
			BOOL bGroupDefaulted
			);
Example #30
0
		public static extern BOOL SetSecurityDescriptorControl(
			PSECURITY_DESCRIPTOR pSecurityDescriptor, 
			SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest, 
			SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
			);
Example #31
0
 public static extern BOOL SetSecurityDescriptorControl(
     PSECURITY_DESCRIPTOR pSecurityDescriptor,
     SECURITY_DESCRIPTOR_CONTROL ControlBitsOfInterest,
     SECURITY_DESCRIPTOR_CONTROL ControlBitsToSet
     );
Example #32
0
        /// <summary>
        /// Gets the effective permissions for the provided Sid within the Security Descriptor.
        /// </summary>
        /// <param name="pUserSid">A pointer to the Sid of the identity to check.</param>
        /// <param name="serverName">Name of the server. This can be <c>null</c>.</param>
        /// <param name="pSecurityDescriptor">A pointer to the security descriptor.</param>
        /// <returns>An array of access masks.</returns>
        public virtual ACCESS_MASK[] GetEffectivePermission(PSID pUserSid, string serverName, PSECURITY_DESCRIPTOR pSecurityDescriptor)
        {
            ACCESS_MASK mask = pSecurityDescriptor.GetEffectiveRights(pUserSid);

            return(new[] { mask });
        }
Example #33
0
		public static extern BOOL MakeSelfRelativeSD(
			PSECURITY_DESCRIPTOR pAbsoluteSD, 
			PSECURITY_DESCRIPTOR pSelfRelativeSD, 
			ref DWORD lpdwBufferLength
			);
Example #34
0
 public static extern BOOL SetFileSecurity(
     LPCTSTR lpFileName, // file name
     SECURITY_INFORMATION SecurityInformation, // contents
     PSECURITY_DESCRIPTOR pSecurityDescriptor // SD
     );
Example #35
0
 public static extern BOOL SetSecurityDescriptorGroup(
     PSECURITY_DESCRIPTOR pSecurityDescriptor,
     PSID pGroup,
     BOOL bGroupDefaulted
     );
Example #36
0
 public static extern LONG RegGetKeySecurity(
     HKEY hKey,                                // handle to key
     SECURITY_INFORMATION SecurityInformation, // request
     PSECURITY_DESCRIPTOR pSecurityDescriptor, // SD
     ref DWORD lpcbSecurityDescriptor            // buffer size
     );
Example #37
0
 public static extern BOOL SetFileSecurity(
     LPCTSTR lpFileName,                       // file name
     SECURITY_INFORMATION SecurityInformation, // contents
     PSECURITY_DESCRIPTOR pSecurityDescriptor  // SD
     );
Example #38
0
 public static extern LONG RegSetKeySecurity(
     HKEY hKey,
     SECURITY_INFORMATION SecurityInformation,
     PSECURITY_DESCRIPTOR pSecurityDescriptor
     );
Example #39
0
 public static extern LONG RegSetKeySecurity(
     HKEY hKey,
     SECURITY_INFORMATION SecurityInformation,
     PSECURITY_DESCRIPTOR pSecurityDescriptor
     );
Example #40
0
		public static extern BOOL GetKernelObjectSecurity(
			HANDLE Handle,                             // handle to object
			SECURITY_INFORMATION RequestedInformation, // request
			PSECURITY_DESCRIPTOR pSecurityDescriptor,  // SD
			DWORD nLength,                             // size of SD
			out DWORD lpnLengthNeeded                    // required size of buffer
			);
Example #41
0
 public static extern BOOL InitializeSecurityDescriptor(PSECURITY_DESCRIPTOR pSecurityDescriptor, DWORD dwRevision);
Example #42
0
		public static extern BOOL SetKernelObjectSecurity(
			HANDLE Handle,
			SECURITY_INFORMATION SecurityInformation,
			PSECURITY_DESCRIPTOR SecurityDescriptor
			);
Example #43
0
 public static extern BOOL GetSecurityDescriptorGroup(
     PSECURITY_DESCRIPTOR pSecurityDescriptor,
     out PSID pGroup,
     out BOOL lpbGroupDefaulted
     );
Example #44
0
 /// <summary>Determines whether the security descriptor is self-relative.</summary>
 /// <param name="pSD">The pointer to the SECURITY_DESCRIPTOR structure to query.</param>
 /// <returns><c>true</c> if it is self-relative; otherwise, <c>false</c>.</returns>
 public static bool IsSelfRelative(this PSECURITY_DESCRIPTOR pSD) => GetSecurityDescriptorControl(pSD, out var ctrl, out _) ? ctrl.IsFlagSet(SECURITY_DESCRIPTOR_CONTROL.SE_SELF_RELATIVE) : throw Win32Error.GetLastError().GetException();
Example #45
0
 public static extern BOOL GetSecurityDescriptorOwner(
     PSECURITY_DESCRIPTOR pSecurityDescriptor,
     out PSID pOwner,
     out BOOL lpbOwnerDefaulted
     );
Example #46
0
 /// <summary>Determines whether the components of a security descriptor are valid.</summary>
 /// <param name="pSD">The pointer to the SECURITY_DESCRIPTOR structure to query.</param>
 /// <returns>
 /// <c>true</c> if the components of the security descriptor are valid. If any of the components of the security descriptor are not
 /// valid, the return value is <c>false</c>.
 /// </returns>
 public static bool IsValidSecurityDescriptor(this PSECURITY_DESCRIPTOR pSD) => AdvApi32.IsValidSecurityDescriptor(pSD);
Example #47
0
 public static extern BOOL MakeSelfRelativeSD(
     PSECURITY_DESCRIPTOR pAbsoluteSD,
     PSECURITY_DESCRIPTOR pSelfRelativeSD,
     ref DWORD lpdwBufferLength
     );
Example #48
0
 /// <summary>Gets the size, in bytes, of a security descriptor. If it is not valid, 0 is returned.</summary>
 /// <param name="pSD">The pointer to the SECURITY_DESCRIPTOR structure to query.</param>
 /// <returns>The size, in bytes, of a security descriptor. If it is not valid, 0 is returned.</returns>
 public static uint Length(this PSECURITY_DESCRIPTOR pSD) => IsValidSecurityDescriptor(pSD) ? GetSecurityDescriptorLength(pSD) : 0U;
Example #49
0
 /// <summary>
 /// Gets the effective permissions for the provided Sid within the Security Descriptor.
 /// Called only when an object type identifier is specified.
 /// </summary>
 /// <param name="objTypeId">The object type identifier.</param>
 /// <param name="pUserSid">A pointer to the Sid of the identity to check.</param>
 /// <param name="serverName">Name of the server. This can be <c>null</c>.</param>
 /// <param name="pSecurityDescriptor">A pointer to the security descriptor.</param>
 /// <param name="objectTypeList">The object type list.</param>
 /// <returns>An array of access masks.</returns>
 /// <exception cref="System.NotImplementedException"></exception>
 public virtual uint[] GetEffectivePermission(Guid objTypeId, PSID pUserSid, string serverName, PSECURITY_DESCRIPTOR pSecurityDescriptor, out OBJECT_TYPE_LIST[] objectTypeList)
 {
     throw new NotImplementedException();
 }
Example #50
-2
		public static extern BOOL MakeAbsoluteSD(
			PSECURITY_DESCRIPTOR pSelfRelativeSD, 
			PSECURITY_DESCRIPTOR pAbsoluteSD, 
			ref DWORD lpdwAbsoluteSDSize, 
			PACL pDacl, 
			ref DWORD lpdwDaclSize, 
			PACL pSacl, 
			ref DWORD lpdwSaclSize, 
			PSID pOwner, 
			ref DWORD lpdwOwnerSize, 
			PSID pPrimaryGroup, 
			ref DWORD lpdwPrimaryGroupSize
			);