我正在尝试编写一个程序来收集有关文件的安全信息并将其转换为人类可读的信息。但是,我在初始化指向结构的指针时遇到了问题:
#include <stdio.h>
#include <aclapi.h>
#pragma comment(lib, "advapi32.lib")
struct file_perms {
char user_domain[2050];
unsigned long user_mask;
};
static myfunc (){
PSECURITY_DESCRIPTOR pSD = NULL;
PACL pDACL = NULL;
char *file = "D:/code/test.c";
ACL_SIZE_INFORMATION aclSize;
ULONG result = GetNamedSecurityInfo(file,SE_FILE_OBJECT, DACL_SECURITY_INFORMATION, NULL, NULL, &pDACL, NULL, &pSD);
if (ERROR_SUCCESS != result) {
printf( "GetNamedSecurityInfo Error %u\n", result );
}
if(pDACL != NULL){printf ("2\n");}
//ACL_SIZE_INFORMATION aclSize = {0};
ZeroMemory(&aclSize, sizeof(ACL_SIZE_INFORMATION));
if(pDACL != NULL){
if(!GetAclInformation(pDACL, &aclSize, sizeof(aclSize),
AclSizeInformation)){
printf("GetAclInformation Error \n");
return 0;
}
printf("AceCount %d\n",aclSize.AceCount);
}
file_perms *fp = new file_perms[aclSize.AceCount];
}
编译时,我收到以下错误。被命名的.c
getnamed.c(34) : error C2065: 'file_perms' : undeclared identifier
getnamed.c(34) : error C2065: 'fp' : undeclared identifier
getnamed.c(34) : error C2065: 'new' : undeclared identifier
getnamed.c(34) : error C2106: '=' : left operand must be l-value
getnamed.c(34) : error C2146: syntax error : missing ';' before identifier 'file
_perms'
getnamed.c(34) : error C2065: 'file_perms' : undeclared identifier
getnamed.c(34) : error C2109: subscript requires array or pointer type
有人可以帮我理解为什么 file_perms 被标记为未声明的标识符吗?虽然它已经被声明为一个结构?
感谢您的帮助。