1
목표는 NTFS 보안 설명자를 동일한 기본 상태로 저장하는 것입니다. 목적은 주문형으로 복원하는 것입니다.NTFS 보안 설명자를 C에 저장
그 목적을 위해 코드를 작성 했으므로 샘플을 검증하는 것이 마음에 들었습니까? (for 루프는 기본 디스크립터를 저장하는 방식을 나타냅니다.)
이 샘플에는 "OWNER"에 대한 플래그 만 포함되어 있지만 모든 보안 설명자 플래그에 대해 동일한 방법을 적용합니다.
저는 초보자 일뿐입니다. 감사합니다, 두리 바
#define _WIN32_WINNT 0x0501
#define WINVER 0x0501
#include <stdio.h>
#include <windows.h>
#include "accctrl.h"
#include "aclapi.h"
#include "sddl.h"
int main (void)
{
DWORD lasterror;
PSECURITY_DESCRIPTOR PSecurityD1, PSecurityD2;
HANDLE hFile;
PSID owner;
LPTSTR ownerstr;
BOOL ownerdefault;
int ret = 0;
unsigned int i;
hFile = CreateFile("c:\\boot.ini", GENERIC_READ | ACCESS_SYSTEM_SECURITY,
FILE_SHARE_READ, NULL, OPEN_EXISTING,
FILE_FLAG_BACKUP_SEMANTICS, NULL);
if (hFile == INVALID_HANDLE_VALUE) {
fprintf(stderr,"CreateFile() failed. Error: INVALID_HANDLE_VALUE\n");
return 1;
}
lasterror = GetSecurityInfo(hFile, SE_FILE_OBJECT, OWNER_SECURITY_INFORMATION
, &owner, NULL, NULL, NULL, &PSecurityD1);
if (lasterror != ERROR_SUCCESS) {
fprintf(stderr,"GetSecurityInfo() failed. Error: %lu;\n", lasterror);
ret = 1;
goto ret1;
}
ConvertSidToStringSid(owner,&ownerstr);
printf("ownerstr of PSecurityD1: %s\n", ownerstr);
/* The for loop represents the way I store the native descriptor */
PSecurityD2 = malloc(GetSecurityDescriptorLength(PSecurityD1) *
sizeof(unsigned char));
for (i=0; i < GetSecurityDescriptorLength(PSecurityD1); i++)
((unsigned char *) PSecurityD2)[i] = ((unsigned char *) PSecurityD1)[i];
if (IsValidSecurityDescriptor(PSecurityD2) == 0) {
fprintf(stderr,"IsValidSecurityDescriptor(PSecurityD2) failed.\n");
ret = 2;
goto ret2;
}
if (GetSecurityDescriptorOwner(PSecurityD2,&owner,&ownerdefault) == 0) {
fprintf(stderr,"GetSecurityDescriptorOwner() failed.");
ret = 2;
goto ret2;
}
ConvertSidToStringSid(owner,&ownerstr);
printf("ownerstr of PSecurityD2: %s\n", ownerstr);
ret2:
free(owner);
free(ownerstr);
free(PSecurityD1);
free(PSecurityD2);
ret1:
CloseHandle(hFile);
return ret;
}