__SystemSecurity 클래스의 SetSD 메서드

SetSD 메서드는 사용자가 연결된 네임스페이스의 보안 설명자를 설정합니다. 이 메서드에는 이진 바이트 배열 형식의 보안 설명자가 필요합니다. 스크립트를 작성하는 경우 SetSecurityDescriptor 메서드를 사용합니다. 자세한 내용은 WMI 네임스페이스 보안보안 개체에 대한 액세스 보안 변경을 참조하세요.

C++에서 프로그래밍하는 경우 SDDL 및 변환 메서드 ConvertSecurityDescriptorToStringSecurityDescriptorConvertStringSecurityDescriptorToSecurityDescriptor를 사용하여 이진 보안 설명자를 조작할 수 있습니다.

사용자는 WRITE_DAC 권한이 있어야 하며 기본적으로 관리자에게 해당 권한이 있습니다. 사용되는 보안 설명자의 유일한 부분은 DACL(임의 액세스 제어 목록)에서 상속되지 않은 ACE(액세스 제어 항목)입니다. ACE에서 CONTAINER_INHERIT 플래그를 설정하면 보안 설명자가 자식 네임스페이스에 영향을 미칩니다. 허용 및 거부 ACE가 모두 허용됩니다.

참고

거부 및 허용 ACE는 모두 DACL에서 허용되기 때문에 ACE의 순서가 중요합니다. 자세한 내용은 DACL의 ACE 순서를 참조하세요.

구문

HRESULT SetSD(
  [in] uint8 SD[]
);

매개 변수

SD [in]

보안 설명자를 구성하는 바이트 배열입니다.

반환 값

메서드 호출의 상태를 나타내는 HRESULT를 반환합니다. 스크립팅 및 Visual Basic 애플리케이션의 경우 결과는 OutParameters.ReturnValue에서 획득할 수 있습니다. 자세한 내용은 InParameters 개체 생성 및 OutParameters 개체 구문 분석을 참조하세요.

다음 목록에는 SetSD에 중요한 반환 값이 나열되어 있습니다.

S_OK

메서드가 성공적으로 실행되었습니다.

WBEM_E_ACCESS_DENIED

호출자는 이 메서드를 호출할 수 있는 권한이 없습니다.

WBEM_E_METHOD_DISABLED

지원하지 않는 OS에서 이 메서드를 실행하려고 했습니다.

WBEM_E_INVALID_OBJECT

SD는 기본적인 유효성 테스트를 통과하지 못합니다.

WBEM_E_INVALID_PARAMETER

다음 중 하나로 인해 SD가 유효하지 않습니다.

  • DACL이 없습니다.
  • DACL이 유효하지 않습니다.
  • ACE에는 WBEM_FULL_WRITE_REP 플래그가 설정되어 있고 WBEM_PARTIAL_WRITE_REP 또는 WBEM_WRITE_PROVIDER 플래그는 설정되어 있지 않습니다.
  • ACE에는 CONTAINER_INHERIT_ACE 플래그 없이 설정된 INHERIT_ONLY_ACE 플래그가 있습니다.
  • ACE에 알 수 없는 액세스 비트가 설정되어 있습니다.
  • ACE에 테이블에 없는 플래그 집합이 있습니다.
  • ACE에 테이블에 없는 유형이 있습니다.
  • 소유자와 그룹이 SD에서 누락되었습니다.

ACE(액세스 제어 항목) 플래그에 대한 자세한 내용은 WMI 보안 상수를 참조하세요.

설명

프로그래밍 방식 또는 수동으로 네임스페이스 보안을 수정하는 방법에 대한 자세한 내용은 WMI 네임스페이스 보안을 참조하세요.

예제

다음 스크립트는 SetSD를 사용하여 루트 네임스페이스에 대한 네임스페이스 보안 설명자를 설정하고 이를 strSD에 표시된 바이트 배열로 변경하는 방법을 보여줍니다.

' Hard-coded security descriptor
strSD = array( 1, 0, 4,129,72, 0, 0, 0, _ 
              88, 0, 0,  0, 0, 0, 0, 0, _
              20, 0, 0,  0, 2, 0,52, 0, _
               2, 0, 0,  0, 0, 2,24, 0, _
              63, 0, 6,  0, 1, 2, 0, 0, _
               0, 0, 0,  5,32, 0, 0, 0, _
              32, 2, 0,  0, 0, 2,20, 0, _
              63, 0, 6,  0, 1, 1, 0, 0, _
               0, 0, 0,  1, 0, 0, 0, 0, _
               1, 2, 0,  0, 0, 0, 0, 5, _
              32, 0, 0,  0,32, 2, 0, 0, _
               1, 2, 0,  0, 0, 0, 0, 5, _
              32, 0, 0,  0,32, 2, 0, 0)

' Connect to WMI and the root namespace.
Set oSvc = CreateObject( _
                         "WbemScripting.SWbemLocator"). _
                         ConnectServer(,"Root\Cimv2")

' Get the single __SystemSecurity object in this namespace.
Set oSecurity = oSvc.Get("__SystemSecurity=@")

' Change the namespace security.
nReturn = oSecurity.SetSD(strSD)
WScript.Echo "ReturnValue " & nReturn

다음 C# 코드 샘플은 System.Security.AccessControl.RawSecurityDescriptor를 사용하여 RawSecurityDescriptor.DiscretionaryAcl에서 새 CommonAce 개체를 열거, 삽입 및 제거한 다음 다시 바이트 배열로 변환하여 SetSD를 통해 저장합니다. SecurityIdentifier는 NTAccount 및 Translate를 사용하여 검색할 수 있습니다.

 byte[] sdValueByteArray = new Byte[0];

            string accountName = "My User or Group";

            AceFlags aceFlags = AceFlags.ContainerInherit;

            int accessRights = 131107; // Search for Namespace Access Rights Constants and build an Flags enum

            RawSecurityDescriptor rawSecurityDescriptor = new RawSecurityDescriptor(sdValueByteArray, 0);

            NTAccount ntAccount = new NTAccount(accountName);

            IdentityReference identityReference = ntAccount.Translate(typeof(SecurityIdentifier));

            if (identityReference == null)

            {

                string message = string.Format("The IdentityReference of NTAccount '{0}' is null.", accountName);

                throw new Exception(message);

            }

            SecurityIdentifier securityIdentifier = identityReference as SecurityIdentifier;

            if (securityIdentifier == null)

            {

                string message = "The IdentityReference of NTAccount '{0}' is not an SecurityIdentifier.";

                throw new Exception(message);

            }

            CommonAce commonAce;

            foreach (GenericAce genericAce in rawSecurityDescriptor.DiscretionaryAcl)

            {

                commonAce = genericAce as CommonAce;

                if (commonAce == null)

                {

                    continue;

                }

                if (commonAce.SecurityIdentifier.Value.Equals(securityIdentifier.Value, StringComparison.OrdinalIgnoreCase))

                {

                    return;

                }

            }

            commonAce = new CommonAce(aceFlags, AceQualifier.AccessAllowed, (int)accessRights, securityIdentifier, false, null);

            rawSecurityDescriptor.DiscretionaryAcl.InsertAce(rawSecurityDescriptor.DiscretionaryAcl.Count, commonAce);

요구 사항

요구 사항
지원되는 최소 클라이언트
Windows Vista
지원되는 최소 서버
Windows Server 2008
네임스페이스
모든 WMI 네임스페이스

추가 정보

WMI 시스템 클래스

__SystemSecurity

__SystemSecurity::GetSD

WMI 보안 상수

Win32_ACE

Win32_SecurityDescriptor

WMI 네임스페이스 보안