本文整理汇总了C++中InitializeSecurityDescriptor函数的典型用法代码示例。如果您正苦于以下问题:C++ InitializeSecurityDescriptor函数的具体用法?C++ InitializeSecurityDescriptor怎么用?C++ InitializeSecurityDescriptor使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了InitializeSecurityDescriptor函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: _CreateFile
HANDLE _CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile )
{
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
memset(&sd,0,sizeof(sd));
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
memset(&sa,0,sizeof(sa));
sa.nLength=sizeof(sa);
sa.lpSecurityDescriptor=&sd;
return ::CreateFile( lpFileName, dwDesiredAccess, dwShareMode, &sa, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile );
}
示例2: InitBranding
int InitBranding() {
char *s;
s = (char *)GlobalAlloc(GPTR,lstrlen(EXENAME)+10);
wsprintf(s,"%s /version",EXENAME);
{
STARTUPINFO si= {sizeof(si),};
SECURITY_ATTRIBUTES sa= {sizeof(sa),};
SECURITY_DESCRIPTOR sd= {0,};
PROCESS_INFORMATION pi= {0,};
HANDLE newstdout=0,read_stdout=0;
OSVERSIONINFO osv= {sizeof(osv)};
GetVersionEx(&osv);
if (osv.dwPlatformId == VER_PLATFORM_WIN32_NT) {
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd,true,NULL,false);
sa.lpSecurityDescriptor = &sd;
}
else sa.lpSecurityDescriptor = NULL;
sa.bInheritHandle = true;
if (!CreatePipe(&read_stdout,&newstdout,&sa,0)) {
return 0;
}
GetStartupInfo(&si);
si.dwFlags = STARTF_USESTDHANDLES|STARTF_USESHOWWINDOW;
si.wShowWindow = SW_HIDE;
si.hStdOutput = newstdout;
si.hStdError = newstdout;
if (!CreateProcess(NULL,s,NULL,NULL,TRUE,CREATE_NEW_CONSOLE,NULL,NULL,&si,&pi)) {
CloseHandle(newstdout);
CloseHandle(read_stdout);
return 0;
}
char szBuf[1024];
DWORD dwRead = 1;
DWORD dwExit = !STILL_ACTIVE;
if (WaitForSingleObject(pi.hProcess,10000)!=WAIT_OBJECT_0) {
return 0;
}
ReadFile(read_stdout, szBuf, sizeof(szBuf)-1, &dwRead, NULL);
szBuf[dwRead] = 0;
if (lstrlen(szBuf)==0) return 0;
g_sdata.branding = (char *)GlobalAlloc(GPTR,lstrlen(szBuf)+6);
wsprintf(g_sdata.branding,"NSIS %s",szBuf);
g_sdata.brandingv = (char *)GlobalAlloc(GPTR,lstrlen(szBuf)+1);
lstrcpy(g_sdata.brandingv,szBuf);
GlobalFree(s);
}
return 1;
}
示例3: SetTokenObjectIntegrityLevel
static void SetTokenObjectIntegrityLevel(DWORD dwIntegrityLevel)
{
SID_IDENTIFIER_AUTHORITY Sia = SECURITY_MANDATORY_LABEL_AUTHORITY;
SECURITY_DESCRIPTOR sd;
HANDLE hToken;
DWORD dwLength;
PACL pAcl;
PSID pSid;
// Do nothing on OSes where mandatory ACEs are not supported
if(pfnAddMandatoryAce == NULL)
return;
// Initialize blank security descriptor
if(!InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION))
return;
// Allocate mandatory label SID
if(!AllocateAndInitializeSid(&Sia, 1, dwIntegrityLevel, 0, 0, 0, 0, 0, 0, 0, &pSid))
return;
// Open current token
if(!OpenThreadToken(GetCurrentThread(), WRITE_OWNER, TRUE, &hToken))
{
if(GetLastError() == ERROR_NO_TOKEN)
OpenProcessToken(GetCurrentProcess(), WRITE_OWNER, &hToken);
}
// If succeeded, set the integrity level
if(hToken != NULL)
{
// Create ACL
dwLength = sizeof(ACL) + sizeof(SYSTEM_MANDATORY_LABEL_ACE) - sizeof(DWORD) + GetLengthSid(pSid);
pAcl = (PACL)HeapAlloc(g_hHeap, 0, dwLength);
if(pAcl != NULL)
{
if(InitializeAcl(pAcl, dwLength, ACL_REVISION))
{
if(pfnAddMandatoryAce(pAcl, ACL_REVISION, 0, SYSTEM_MANDATORY_LABEL_NO_WRITE_UP, pSid))
{
NtSetSecurityObject(hToken, LABEL_SECURITY_INFORMATION, &sd);
}
}
HeapFree(g_hHeap, 0, pAcl);
}
}
FreeSid(pSid);
}
示例4: init_security_attributes_allow_all
bool
init_security_attributes_allow_all (struct security_attributes *obj)
{
CLEAR (*obj);
obj->sa.nLength = sizeof (SECURITY_ATTRIBUTES);
obj->sa.lpSecurityDescriptor = &obj->sd;
obj->sa.bInheritHandle = TRUE;
if (!InitializeSecurityDescriptor (&obj->sd, SECURITY_DESCRIPTOR_REVISION))
return false;
if (!SetSecurityDescriptorDacl (&obj->sd, TRUE, NULL, FALSE))
return false;
return true;
}
示例5: _CreateFileMapping
HANDLE _CreateFileMapping( HANDLE hFile, DWORD flProtect, DWORD dwMaximumSizeHigh, DWORD dwMaximumSizeLow, LPCTSTR lpName)
{
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
memset(&sd,0,sizeof(sd));
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
memset(&sa,0,sizeof(sa));
sa.nLength=sizeof(sa);
sa.lpSecurityDescriptor=&sd;
return ::CreateFileMapping( hFile, &sa, flProtect, dwMaximumSizeHigh, dwMaximumSizeLow, lpName);
}
示例6: _CreateNamedPipe
HANDLE _CreateNamedPipe( LPCTSTR lpName, DWORD dwOpenMode, DWORD dwPipeMode, DWORD nMaxInstances, DWORD nOutBufferSize, DWORD nInBufferSize, DWORD nDefaultTimeOut )
{
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
memset(&sd,0,sizeof(sd));
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
memset(&sa,0,sizeof(sa));
sa.nLength=sizeof(sa);
sa.lpSecurityDescriptor=&sd;
return ::CreateNamedPipe( lpName, dwOpenMode, dwPipeMode, nMaxInstances, nOutBufferSize, nInBufferSize, nDefaultTimeOut, &sa );
}
示例7: CreateBannerInstanceMutex
// Для запуска только одного экземпляра банера
// создаем мютекс.Если он уже создан - значит
// уже банерная часть уже загружена и работает.
HANDLE CreateBannerInstanceMutex()
{
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
sa.nLength = sizeof (SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = FALSE;
return ::CreateMutex(&sa, FALSE, L"Global\\DCCFF93F3ACC4B2F8B4957A6A47D7DFE");
}
示例8: CreateStartedEvent
HANDLE CreateStartedEvent()
{
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
sa.nLength = sizeof (SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = FALSE;
return ::CreateEvent(&sa, TRUE, FALSE, L"Global\\CC64BD66BCA1444C86FC0D8019E381E9");
}
示例9: _CreateMutex
HANDLE _CreateMutex( BOOL bInitialOwner, LPCTSTR lpName )
{
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
memset(&sd,0,sizeof(sd));
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
memset(&sa,0,sizeof(sa));
sa.nLength=sizeof(sa);
sa.lpSecurityDescriptor=&sd;
return ::CreateMutex( &sa, bInitialOwner, lpName );
}
示例10: isc_fsaccess_changeowner
isc_result_t
isc_fsaccess_changeowner(const char *filename, const char *user) {
SECURITY_DESCRIPTOR psd;
BYTE sidBuffer[500];
BYTE groupBuffer[500];
PSID psid=(PSID) &sidBuffer;
DWORD sidBufferSize = sizeof(sidBuffer);
char domainBuffer[100];
DWORD domainBufferSize = sizeof(domainBuffer);
SID_NAME_USE snu;
PSID pSidGroup = (PSID) &groupBuffer;
DWORD groupBufferSize = sizeof(groupBuffer);
/*
* Determine if this is a FAT or NTFS disk and
* call the appropriate function to set the ownership
* FAT disks do not have ownership attributes so it's
* a noop.
*/
if (is_ntfs(filename) == FALSE)
return (ISC_R_SUCCESS);
if (!InitializeSecurityDescriptor(&psd, SECURITY_DESCRIPTOR_REVISION))
return (ISC_R_NOPERM);
if (!LookupAccountName(0, user, psid, &sidBufferSize, domainBuffer,
&domainBufferSize, &snu))
return (ISC_R_NOPERM);
/* Make sure administrators can get to it */
domainBufferSize = sizeof(domainBuffer);
if (!LookupAccountName(0, "Administrators", pSidGroup,
&groupBufferSize, domainBuffer, &domainBufferSize, &snu))
return (ISC_R_NOPERM);
if (!SetSecurityDescriptorOwner(&psd, psid, FALSE))
return (ISC_R_NOPERM);
if (!SetSecurityDescriptorGroup(&psd, pSidGroup, FALSE))
return (ISC_R_NOPERM);
if (!SetFileSecurity(filename,
OWNER_SECURITY_INFORMATION | GROUP_SECURITY_INFORMATION,
&psd))
return (ISC_R_NOPERM);
return (ISC_R_SUCCESS);
}
示例11: VBoxIPCInit
/**
* Initializes the IPC communication.
*
* @return IPRT status code.
* @param pEnv The IPC service's environment.
* @param ppInstance The instance pointer which refer to this object.
* @param pfStartThread Pointer to flag whether the IPC service can be started or not.
*/
int VBoxIPCInit(const VBOXSERVICEENV *pEnv, void **ppInstance, bool *pfStartThread)
{
Log(("VBoxTray: VBoxIPCInit\n"));
*pfStartThread = false;
gCtx.pEnv = pEnv;
int rc = VINF_SUCCESS;
SECURITY_ATTRIBUTES sa;
sa.lpSecurityDescriptor = (PSECURITY_DESCRIPTOR)RTMemAlloc(SECURITY_DESCRIPTOR_MIN_LENGTH);
if (!sa.lpSecurityDescriptor)
rc = VERR_NO_MEMORY;
else
{
if (!InitializeSecurityDescriptor(sa.lpSecurityDescriptor, SECURITY_DESCRIPTOR_REVISION))
rc = RTErrConvertFromWin32(GetLastError());
else
{
if (!SetSecurityDescriptorDacl(sa.lpSecurityDescriptor, TRUE, (PACL)0, FALSE))
rc = RTErrConvertFromWin32(GetLastError());
else
{
sa.nLength = sizeof(sa);
sa.bInheritHandle = TRUE;
}
}
if (RT_SUCCESS(rc))
{
gCtx.hPipe = CreateNamedPipe((LPSTR)VBOXTRAY_PIPE_IPC,
PIPE_ACCESS_DUPLEX,
PIPE_TYPE_MESSAGE | PIPE_READMODE_MESSAGE | PIPE_WAIT,
PIPE_UNLIMITED_INSTANCES,
VBOXTRAY_PIPE_IPC_BUFSIZE, /* Output buffer size. */
VBOXTRAY_PIPE_IPC_BUFSIZE, /* Input buffer size. */
NMPWAIT_USE_DEFAULT_WAIT,
&sa);
if (gCtx.hPipe == INVALID_HANDLE_VALUE)
rc = RTErrConvertFromWin32(GetLastError());
else
{
*pfStartThread = true;
*ppInstance = &gCtx;
}
}
RTMemFree(sa.lpSecurityDescriptor);
}
return rc;
}
示例12: AllocateAndInitializeSid
SECURITY_ATTRIBUTES SecurDescr::CreateSID()
{
SID_IDENTIFIER_AUTHORITY SIDAuthWorld = SECURITY_WORLD_SID_AUTHORITY;
SID_IDENTIFIER_AUTHORITY SIDAuthNT = SECURITY_NT_AUTHORITY;
AllocateAndInitializeSid(&SIDAuthWorld, 1,
SECURITY_WORLD_RID,
0, 0, 0, 0, 0, 0, 0,
&pEveryoneSID);
ZeroMemory(ea, 2 * sizeof(EXPLICIT_ACCESS));
ea[0].grfAccessPermissions = FILE_GENERIC_READ | FILE_GENERIC_WRITE | SYNCHRONIZE;
ea[0].grfAccessMode = SET_ACCESS;
ea[0].grfInheritance= NO_INHERITANCE;
ea[0].Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea[0].Trustee.TrusteeType = TRUSTEE_IS_WELL_KNOWN_GROUP;
ea[0].Trustee.ptstrName = (LPTSTR) pEveryoneSID;
AllocateAndInitializeSid(&SIDAuthNT, 2,
SECURITY_BUILTIN_DOMAIN_RID,
DOMAIN_ALIAS_RID_ADMINS,
0, 0, 0, 0, 0, 0,
&pAdminSID);
ea[1].grfAccessPermissions = FILE_GENERIC_READ | FILE_GENERIC_WRITE | SYNCHRONIZE;
ea[1].grfAccessMode = SET_ACCESS;
ea[1].grfInheritance= NO_INHERITANCE;
ea[1].Trustee.TrusteeForm = TRUSTEE_IS_SID;
ea[1].Trustee.TrusteeType = TRUSTEE_IS_GROUP;
ea[1].Trustee.ptstrName = (LPTSTR) pAdminSID;
SetEntriesInAcl(2, ea, NULL, &pACL);
pSD = (PSECURITY_DESCRIPTOR) LocalAlloc(LPTR,
SECURITY_DESCRIPTOR_MIN_LENGTH);
InitializeSecurityDescriptor(pSD,
SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(pSD,
TRUE, // bDaclPresent flag
pACL,
FALSE);
sa.nLength = sizeof (SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = pSD;
sa.bInheritHandle = FALSE;
return sa;
}
示例13: CreateIpcTable
int
CreateIpcTable()
{
/*2000.9.4 add---------------------------------------------------------------*/
SECURITY_ATTRIBUTES FileMappingAttributes;
SECURITY_DESCRIPTOR SecuDesc;
#ifdef TERMINAL_SERVICE
char *evtname;
#endif /* TERMINAL_SERVICE */
InitializeSecurityDescriptor( &SecuDesc, SECURITY_DESCRIPTOR_REVISION );
SetSecurityDescriptorDacl( &SecuDesc, TRUE, NULL, FALSE );
FileMappingAttributes.nLength = sizeof(FileMappingAttributes);
l_ipclog("[ipcd] CreateIpcTable, FileMappingAttributes.nLength = %d\n", FileMappingAttributes.nLength);
FileMappingAttributes.lpSecurityDescriptor = &SecuDesc;
/*2000.9.4 end---------------------------------------------------------------*/
#ifdef TERMINAL_SERVICE
if( osvi.dwMajorVersion >= 5 ) /* Windows 2000 */
evtname = "Global\\ipct";
else
evtname = "ipct";
#endif /* TERMINAL_SERVICE */
/*2000.9.4 change. NULL -> &FileMappingAttributes */
hIpc=CreateFileMapping( (HANDLE)0xFFFFFFFF, &FileMappingAttributes,
#ifdef TERMINAL_SERVICE
PAGE_READWRITE, 0, sizeof(IPCT), evtname );
#else
PAGE_READWRITE, 0, sizeof(IPCT), "ipct" );
#endif /* TERMINAL_SERVICE */
if (hIpc==NULL)
{
errno=GetLastError();
return -1;
}
ipct=(IPCT *)MapViewOfFile(hIpc, FILE_MAP_ALL_ACCESS, 0, 0, 0);
if (ipct==NULL)
{
errno=GetLastError();
return -1;
}
InitIPCT();
return 0;
}
示例14: _CreateFile
HANDLE _CreateFile( LPCTSTR lpFileName, DWORD dwDesiredAccess, DWORD dwShareMode, DWORD dwCreationDisposition, DWORD dwFlagsAndAttributes, HANDLE hTemplateFile )
{
SECURITY_DESCRIPTOR sd;
SECURITY_ATTRIBUTES sa;
memset(&sd,0,sizeof(sd));
InitializeSecurityDescriptor(&sd,SECURITY_DESCRIPTOR_REVISION);
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
memset(&sa,0,sizeof(sa));
sa.nLength=sizeof(sa);
sa.lpSecurityDescriptor=&sd;
/*
PACL pDacl;
EXPLICIT_ACCESS explicitAccess[3];
SECURITY_ATTRIBUTES sa;
SECURITY_DESCRIPTOR sd;
InitializeSecurityDescriptor(&sd, SECURITY_DESCRIPTOR_REVISION);
BuildExplicitAccessWithName(&explicitAccess[0], TEXT("SYSTEM"), FILE_ALL_ACCESS, GRANT_ACCESS, 0);
BuildExplicitAccessWithName(&explicitAccess[1], TEXT("Administrators"), FILE_ALL_ACCESS, GRANT_ACCESS, 0);
BuildExplicitAccessWithName(&explicitAccess[2], TEXT("Everyone"), FILE_ALL_ACCESS, GRANT_ACCESS, 0);
SetEntriesInAcl(3, explicitAccess, NULL, &pDacl);
SetSecurityDescriptorDacl(&sd, TRUE, pDacl, FALSE);
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = FALSE;
*/
HANDLE hFile = ::CreateFile( lpFileName, dwDesiredAccess, dwShareMode, &sa, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile );
if( hFile == INVALID_HANDLE_VALUE ){
TCHAR* p = (TCHAR*)_tcsrchr(lpFileName, '\\');
TCHAR* szDirPath = NULL;
if( p != NULL ){
int iSize = (int)(p - lpFileName);
szDirPath = new TCHAR[iSize+1];
_tcsncpy_s(szDirPath, iSize+1, lpFileName, iSize);
}
if( szDirPath != NULL ){
_CreateDirectory(szDirPath);
delete[] szDirPath;
hFile = ::CreateFile( lpFileName, dwDesiredAccess, dwShareMode, &sa, dwCreationDisposition, dwFlagsAndAttributes, hTemplateFile );
}
}
return hFile;
}
示例15: GetNamedPipeHandle
HANDLE GetNamedPipeHandle()
{
SECURITY_DESCRIPTOR sd = {0};
InitializeSecurityDescriptor(&sd, 1);
SetSecurityDescriptorDacl(&sd, TRUE, NULL, FALSE);
SECURITY_ATTRIBUTES sa = {0};
sa.nLength = sizeof(SECURITY_ATTRIBUTES);
sa.lpSecurityDescriptor = &sd;
sa.bInheritHandle = NULL;
HANDLE h = CreateFile(TEXT("\\\\.\\pipe\\acsipc_server"), 0xC0000000, 3,
&sa, 3, 0x80000080, NULL);
if(h != (HANDLE)-1 )
return h;
return NULL;
}