static DWORD LsaPstorepCallPlugin( IN PCSTR Operation, IN LSA_PSTORE_CALL_PLUGIN_CALLBACK Callback, IN PLSA_PSTORE_CALL_PLUGIN_ARGS Arguments ) { DWORD dwError = 0; int EE = 0; LSA_PSTORE_PLUGIN_INFO pluginInfo = { 0 }; PSTR* pluginNames = 0; DWORD pluginCount = 0; DWORD i = 0; PCSTR method = NULL; dwError = LsaPstorepGetPluginNames(&pluginNames, &pluginCount); GOTO_CLEANUP_ON_WINERROR_EE(dwError, EE); for (i = 0; i < pluginCount; i++) { LsaPstorepCleanupPlugin(&pluginInfo); dwError = LsaPstorepInitializePlugin(&pluginInfo, pluginNames[i]); if (dwError) { LW_RTL_LOG_ERROR("Failed to load plugin %s with error = %u (%s)", pluginNames[i], dwError, LW_RTL_LOG_SAFE_STRING(LwWin32ExtErrorToName(dwError))); dwError = 0; continue; } dwError = Callback( pluginInfo.Name, pluginInfo.Dispatch, pluginInfo.Context, Arguments, &method); if (dwError) { if (method) { LW_RTL_LOG_ERROR( "Failed %s operation on plugin %s " "while calling %s method with error = %u (%s)", LW_RTL_LOG_SAFE_STRING(Operation), pluginNames[i], method, dwError, LW_RTL_LOG_SAFE_STRING(LwWin32ExtErrorToName(dwError))); } else { LW_RTL_LOG_ERROR( "Failed %s operation on plugin %s " "with error = %u (%s)", LW_RTL_LOG_SAFE_STRING(Operation), pluginNames[i], dwError, LW_RTL_LOG_SAFE_STRING(LwWin32ExtErrorToName(dwError))); } dwError = 0; continue; } } cleanup: LsaPstorepCleanupPlugin(&pluginInfo); LSA_PSTORE_FREE_STRING_ARRAY_A(&pluginNames, &pluginCount); LSA_PSTORE_LOG_LEAVE_ERROR_EE(dwError, EE); return dwError; }
static VOID LogCallback( IN OPTIONAL LW_PVOID Context, IN LW_RTL_LOG_LEVEL Level, IN OPTIONAL PCSTR ComponentName, IN PCSTR FunctionName, IN PCSTR FileName, IN ULONG LineNumber, IN PCSTR Format, IN ... ) { DWORD dwError = 0; PSTR formattedMessage = NULL; va_list argList; PCSTR levelString = NULL; size_t messageLength = 0; PCSTR optionalNewLine = NULL; va_start(argList, Format); dwError = LwAllocateStringPrintfV(&formattedMessage, Format, argList); va_end(argList); if (dwError) { goto error; } switch (Level) { case LW_RTL_LOG_LEVEL_ALWAYS: levelString = "ALWAYS"; break; case LW_RTL_LOG_LEVEL_ERROR: levelString = "ERROR"; break; case LW_RTL_LOG_LEVEL_WARNING: levelString = "WARNING"; break; case LW_RTL_LOG_LEVEL_INFO: levelString = "INFO"; break; case LW_RTL_LOG_LEVEL_VERBOSE: levelString = "VERBOSE"; break; case LW_RTL_LOG_LEVEL_DEBUG: levelString = "DEBUG"; break; case LW_RTL_LOG_LEVEL_TRACE: levelString = "TRACE"; break; default: levelString = NULL; break; } messageLength = strlen(formattedMessage); if (!messageLength || formattedMessage[messageLength-1] != '\n') { optionalNewLine = "\n"; } printf("%s: [%s() %s:%d] %s%s", LW_RTL_LOG_SAFE_STRING(levelString), FunctionName, FileName, LineNumber, formattedMessage, optionalNewLine); error: if (dwError) { printf("WARNING: Failed to format log message"); } LW_SAFE_FREE_STRING(formattedMessage); }