Path: blob/main/crypto/krb5/src/ccapi/common/win/OldCC/ccutils.c
39587 views
/* ccapi/common/win/OldCC/ccutils.c */1/*2* Copyright 2008 Massachusetts Institute of Technology.3* All Rights Reserved.4*5* Export of this software from the United States of America may6* require a specific license from the United States Government.7* It is the responsibility of any person or organization contemplating8* export to obtain such a license before exporting.9*10* WITHIN THAT CONSTRAINT, permission to use, copy, modify, and11* distribute this software and its documentation for any purpose and12* without fee is hereby granted, provided that the above copyright13* notice appear in all copies and that both that copyright notice and14* this permission notice appear in supporting documentation, and that15* the name of M.I.T. not be used in advertising or publicity pertaining16* to distribution of the software without specific, written prior17* permission. Furthermore if you modify this software you must label18* your software as modified software and not distribute it in such a19* fashion that it might be confused with the original M.I.T. software.20* M.I.T. makes no representations about the suitability of21* this software for any purpose. It is provided "as is" without express22* or implied warranty.23*/2425#include <windows.h>26#include <stdlib.h>27#include <malloc.h>2829#include "cci_debugging.h"30#include "util.h"3132BOOL isNT(void) {33OSVERSIONINFO osvi;34DWORD status = 0;35BOOL bSupportedVersion = FALSE;36BOOL bIsNT = FALSE;3738memset(&osvi, 0, sizeof(osvi));39osvi.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);4041status = !GetVersionEx(&osvi); // Returns a boolean. Invert to 0 is OK.4243if (!status) {44switch(osvi.dwPlatformId) {45case VER_PLATFORM_WIN32_WINDOWS:46bIsNT = FALSE;47bSupportedVersion = TRUE;48break;49case VER_PLATFORM_WIN32_NT:50bIsNT = TRUE;51bSupportedVersion = TRUE;52break;53case VER_PLATFORM_WIN32s:54default:55bIsNT = FALSE;56break;57}5859if (!bSupportedVersion) {60cci_debug_printf("%s Running on an unsupported version of Windows", __FUNCTION__);61status = 1;62}63}6465return (!status && bIsNT && bSupportedVersion);66}6768char* allocEventName(char* uuid_string, char* suffix) {69LPSTR event_name = NULL;70cc_int32 err = ccNoError;7172event_name = malloc(strlen(uuid_string) + strlen(suffix) + 3);73if (!event_name) err = cci_check_error(ccErrNoMem);7475if (!err) {76strcpy(event_name, uuid_string);77strcat(event_name, "_");78strcat(event_name, suffix);79}8081return event_name;82}8384HANDLE createThreadEvent(char* uuid, char* suffix) {85LPSTR event_name = NULL;86HANDLE hEvent = NULL;87PSECURITY_ATTRIBUTES psa = 0; // Everything having to do with88SECURITY_ATTRIBUTES sa = { 0 }; // sa, psa, security is copied89DWORD status = 0; // from the previous implementation.9091psa = isNT() ? &sa : 0;9293if (isNT()) {94sa.nLength = sizeof(sa);95status = alloc_own_security_descriptor_NT(&sa.lpSecurityDescriptor);96cci_check_error(status);97}9899if (!status) {100event_name = allocEventName(uuid, suffix);101if (!event_name) status = cci_check_error(ccErrNoMem);102}103if (!status) {104hEvent = CreateEvent(psa, FALSE, FALSE, event_name);105if (!hEvent) status = cci_check_error(GetLastError());106}107108if (!status) ResetEvent(hEvent);109110111if (event_name) free(event_name);112if (isNT()) free(sa.lpSecurityDescriptor);113114return hEvent;115}116117HANDLE openThreadEvent(char* uuid, char* suffix) {118LPSTR event_name = NULL;119HANDLE hEvent = NULL;120DWORD status = 0;121122event_name = allocEventName(uuid, suffix);123if (!event_name) status = cci_check_error(ccErrNoMem);124if (!status) {125hEvent = OpenEvent(EVENT_MODIFY_STATE, FALSE, event_name);126if (!hEvent) status = cci_check_error(GetLastError());127}128129if (event_name) free(event_name);130131return hEvent;132}133134135