Hello!
I'm trying to get ACL from HKEY_LOCAL_MACHINE (also such problem with HKEY_CURRENT_CONFIG) registry key.
#include <iostream>
#include <conio.h>
#include <sddl.h>
#include <Aclapi.h>
#include<string.h>
#include <strsafe.h>
#include <windows.h>
char information[1024];
int My_GetObjectAcl(int qtype,char *filestr){
int i,j;
char sd[4096];
char temp1[256];
DWORD sdsize;
char strnew[4096];
DWORD sdnewlen=0; DWORD count;
PEXPLICIT_ACCESS pList[10];
BOOL d1,d2;
PACL pDacl=NULL;
DWORD aclSize;
BYTE bACEType;
LPVOID pAce;
LPBOOL bbb=0;
PSID pSID=NULL;
PSID osid=NULL;
SID_NAME_USE SidType;
ACCESS_ALLOWED_ACE *ACE;
DWORD tmp;
SE_OBJECT_TYPE otype;
char Name[100], Domain[100];
DWORD NameSize = 100, DomainSize = 100;
LPSTR *sidstring;
char str1[512], str2[512];
memset(temp1,0,256);
switch (qtype){
case 1: otype=SE_FILE_OBJECT; break;
case 2: otype=SE_REGISTRY_KEY; break;
default: return 5;
}
printf("Trying read: %s\n",filestr);
pDacl=(PACL)GlobalAlloc(GMEM_FIXED,1000);
if (qtype==1){
if (!GetFileSecurityA((LPCSTR)filestr,DACL_SECURITY_INFORMATION,sd,4096,&sdsize)) {printf("Error %d\n",GetLastError());return 5;}
i=GetSecurityDescriptorDacl(sd,&d1,&pDacl,&d2);
if (!i){ printf("Error %d\n",GetLastError());return 5;}
} else
if(GetNamedSecurityInfoA((LPSTR)filestr,otype,DACL_SECURITY_INFORMATION,NULL,NULL,&pDacl,NULL,NULL)!=ERROR_SUCCESS){printf("::%d",qtype); return 5;}
memset(temp1,0,256);
sprintf(temp1,"Number of ace entries: %d \n",pDacl->AceCount);
strcat(information,temp1);
for (i=0;i<pDacl->AceCount;i++){
memset(str1,'\0',512);
j=0;
NameSize = 100; DomainSize = 100;
GetAce(pDacl,i,&pAce);
bACEType = ((ACE_HEADER*)pAce)->AceType;
ACE = ((ACCESS_ALLOWED_ACE *)pAce);
pSID = (PSID)&(ACE->SidStart);
j=LookupAccountSidA(NULL,pSID,Name,&NameSize,Domain, &DomainSize,&SidType);
if (j==0) printf("\n\n%lu\n\n",GetLastError());
strcpy(str1,Domain);
strcat(str1,"\\");
strcat(str1,Name);
CharToOemA(Name,Name);
memset(temp1,0,256);
sprintf(temp1,"%s\\%s: \n",Domain,Name);
strcat(information,temp1);
switch(bACEType){
case ACCESS_ALLOWED_ACE_TYPE:memset(temp1,0,256);sprintf(temp1,"%s","TYPE:ALLOWED ");strcat(information,temp1);break;
case ACCESS_DENIED_ACE_TYPE:memset(temp1,0,256);sprintf(temp1,"%s","TYPE:DENIED ");strcat(information,temp1); break;
}
memset(temp1,0,256);
sprintf(temp1,"Mask: %X\n",ACE->Mask);
strcat(information,temp1);
memset(temp1,0,256);
tmp=0x80000000;
for (j=0;j<32;j++){
if ((ACE->Mask)&tmp) strcat(temp1,"1"); else strcat(temp1,"0");
tmp=tmp>>1;
}
strcat(information,temp1);
}
return 0;
}
int main()
{int k;
k=My_GetObjectAcl(2,"CURRENT_USER\\");
printf("%s\n",information);
memset(information,0,1024);
k=My_GetObjectAcl(2,"LOCAL_MACHINE\\");
printf("%s\n",information);
getch();
} ;
With CURRENT_USER\\ , USERS\\ and CLASSES_ROOT\\ - all fine. But LOCAL_MACHINE\\ and CURRENT_CONFIG\\ - error. It's really necessary to me to understand why it doesn't work. Please, help me to manage with this problem.Thank You.
modified on Sunday, May 3, 2009 5:53 AM
|