int get_metrics_main( int argc, char* argv[] ) { DWORD dwError = 0; DWORD dwInfoLevel = 0; PVOID pMetricPack = NULL; HANDLE hLsaConnection = (HANDLE)NULL; size_t dwErrorBufferSize = 0; BOOLEAN bPrintOrigError = TRUE; ParseArgs(argc, argv, &dwInfoLevel); dwError = LsaOpenServer(&hLsaConnection); BAIL_ON_LSA_ERROR(dwError); dwError = LsaGetMetrics( hLsaConnection, dwInfoLevel, &pMetricPack); BAIL_ON_LSA_ERROR(dwError); switch (dwInfoLevel) { case 0: PrintMetricPack_0( (PLSA_METRIC_PACK_0)pMetricPack); break; case 1: PrintMetricPack_1( (PLSA_METRIC_PACK_1)pMetricPack); break; } cleanup: LW_SAFE_FREE_MEMORY(pMetricPack); if (hLsaConnection != (HANDLE)NULL) { LsaCloseServer(hLsaConnection); } return (dwError); error: dwError = MapErrorCode(dwError); dwErrorBufferSize = LwGetErrorString(dwError, NULL, 0); if (dwErrorBufferSize > 0) { DWORD dwError2 = 0; PSTR pszErrorBuffer = NULL; dwError2 = LwAllocateMemory( dwErrorBufferSize, (PVOID*)&pszErrorBuffer); if (!dwError2) { DWORD dwLen = LwGetErrorString(dwError, pszErrorBuffer, dwErrorBufferSize); if ((dwLen == dwErrorBufferSize) && !LW_IS_NULL_OR_EMPTY_STR(pszErrorBuffer)) { fprintf( stderr, "Failed to query metrics from LSA service. Error code %u (%s).\n%s\n", dwError, LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError)), pszErrorBuffer); bPrintOrigError = FALSE; } } LW_SAFE_FREE_STRING(pszErrorBuffer); } if (bPrintOrigError) { fprintf( stderr, "Failed to query metrics from LSA service. Error code %u (%s).\n", dwError, LW_PRINTF_STRING(LwWin32ExtErrorToName(dwError))); } goto cleanup; }
int get_metrics_main( int argc, char *argv[] ) { HANDLE hLSAConnection = NULL; PLSA_METRIC_PACK_0 pMetrics_0 = NULL; PLSA_METRIC_PACK_1 pMetrics_1 = NULL; PTESTDATA pTestData = NULL; DWORD dwError = LW_ERROR_SUCCESS; dwError = Lwt_LsaTestSetup(argc, argv, &hLSAConnection, &pTestData); BAIL(dwError); /*Start collect the groups for the level 1*/ dwError = LsaGetMetrics(hLSAConnection, 0, (PVOID *) &pMetrics_0); BAIL(dwError); if (pMetrics_0) { Lwt_LsaPrintMetrics((PVOID) pMetrics_0, 0); } dwError = LsaGetMetrics(hLSAConnection, 1, (PVOID *)&pMetrics_1); BAIL(dwError); if (pMetrics_1) { Lwt_LsaPrintMetrics((PVOID) pMetrics_1, 1); } cleanup: if (pMetrics_0 != NULL) { LwFreeMemory(pMetrics_0); pMetrics_0 = NULL; } if (pMetrics_1 != NULL) { LwFreeMemory(pMetrics_1); pMetrics_1 = NULL; } Lwt_LsaTestTeardown(&hLSAConnection, &pTestData); return dwError; error: goto cleanup; }