MI_Result FormatServerURLsForDscCache( _In_ RegistrationManager *self, _Outptr_result_maybenull_z_ MI_Char** registeredServerURLs, _Outptr_result_maybenull_ MI_Instance **cimErrorDetails) { MI_Result result = MI_RESULT_OK; size_t totalLengthOfServerURLs = 0; MI_Uint32 i = 0; for (i = 0; i < self->numberOfServerURLs; i++) { totalLengthOfServerURLs += Tcslen(self->serverURLs[i]); // Add 1 for ; between each ServerURL and thumbprint totalLengthOfServerURLs += 1; totalLengthOfServerURLs += Tcslen(self->serverCertificateThumbprints[i]); // Add 1 for ; between each series totalLengthOfServerURLs += 1; } // For '\0' totalLengthOfServerURLs += 1; memset(registeredServerURLs, 0, sizeof(MI_Char)); *registeredServerURLs = (MI_Char*)DSC_malloc(totalLengthOfServerURLs*sizeof(MI_Char), NitsHere()); if (*registeredServerURLs == NULL) { EH_Fail_(GetCimMIError(MI_RESULT_SERVER_LIMITS_EXCEEDED, cimErrorDetails, ID_LCMHELPER_MEMORY_ERROR)); } memset(*registeredServerURLs, 0, totalLengthOfServerURLs); for (i = 0; i < self->numberOfServerURLs; i++) { *registeredServerURLs = Tcscat(*registeredServerURLs, totalLengthOfServerURLs, self->serverURLs[i]); if (*registeredServerURLs == NULL) { EH_Fail_(GetCimMIError(MI_RESULT_FAILED, cimErrorDetails, ID_ENGINEHELPER_CAT_ERROR)); } *registeredServerURLs = Tcscat(*registeredServerURLs, totalLengthOfServerURLs, ";"); if (*registeredServerURLs == NULL) { EH_Fail_(GetCimMIError(MI_RESULT_FAILED, cimErrorDetails, ID_ENGINEHELPER_CAT_ERROR)); } *registeredServerURLs = Tcscat(*registeredServerURLs, totalLengthOfServerURLs, self->serverCertificateThumbprints[i]); if (*registeredServerURLs == NULL) { EH_Fail_(GetCimMIError(MI_RESULT_FAILED, cimErrorDetails, ID_ENGINEHELPER_CAT_ERROR)); } *registeredServerURLs = Tcscat(*registeredServerURLs, totalLengthOfServerURLs, ";"); if (*registeredServerURLs == NULL) { EH_Fail_(GetCimMIError(MI_RESULT_FAILED, cimErrorDetails, ID_ENGINEHELPER_CAT_ERROR)); } } EH_UNWIND: return result; }
void SignalInjector() { PAL_Char nameSignal[128] = PAL_T(CONFIG_SEMNAMELOCALPREFIX) PAL_T("NitsInjectorIn_"); PAL_Char nameWait[128] = PAL_T(CONFIG_SEMNAMELOCALPREFIX) PAL_T("NitsInjectorOut_"); PAL_Char nameLock[128] = PAL_T(CONFIG_SEMNAMELOCALPREFIX) PAL_T("NitsInjectorLock_"); NamedSem semaphore; NamedSem lockSemaphore; PAL_Char conversionBuf[64] = PAL_T(""); const PAL_Char *convertedStr = NULL; size_t convertedSize = 0; // int waitSemValue = 0; int waitMilliSeconds = 100; int waitForLockMilliSeconds = 500; #ifndef _MSC_VER waitForLockMilliSeconds = 1000; #endif TcsFromUInt64(conversionBuf, Process_ID(), &convertedStr, &convertedSize); Tcscat(nameSignal, 128, convertedStr); Tcscat(nameWait, 128, convertedStr); Tcscat(nameLock, 128, convertedStr); if(NamedSem_Open_Injected(&lockSemaphore, SEM_USER_ACCESS_ALLOW_ALL, 0, nameLock, 0, NitsReservedCallSite()) != 0) { /* The injector isn't there. */ return; } if(NamedSem_TimedWait(&lockSemaphore, waitForLockMilliSeconds) != 0) { // could not acquire lock to the injector; some further shouldFault call will attempt to NamedSem_Close(&lockSemaphore); return; } if(NamedSem_Open_Injected(&semaphore, SEM_USER_ACCESS_ALLOW_ALL, 0, nameSignal, 0, NitsReservedCallSite()) != 0) { /* The injector isn't there. */ goto End; } NamedSem_Post(&semaphore, 1); NamedSem_Close(&semaphore); if(NamedSem_Open_Injected(&semaphore, SEM_USER_ACCESS_ALLOW_ALL, 0, nameWait, 0, NitsReservedCallSite()) != 0) { /* The injector isn't there. */ goto End; } /* Use a short timeout to prevent undesired behavior. In the worst * case, the injector thread will be starved and the patching will * happen later. */ #ifndef _MSC_VER // for non-windows the wait required is greater; this looks like a problem with the timedwait of namedsem; waitMilliSeconds = 1000; #endif NamedSem_TimedWait(&semaphore, waitMilliSeconds); NamedSem_Close(&semaphore); End: NamedSem_Post(&lockSemaphore, 1); NamedSem_Close(&lockSemaphore); return; }