int	SYSTEM_UNAME(const char *cmd, const char *param, unsigned flags, AGENT_RESULT *result)
{
#ifdef _WINDOWS
	typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);

	DWORD		dwSize = 256;
	TCHAR		computer_name[256];
	SYSTEM_INFO	si;
	OSVERSIONINFOEX	vi;
	char		*os = NULL, *utf8;
	size_t		os_alloc = 256, os_offset = 0;
	PGNSI		pGNSI;

	/* Buffer size is chosen large enough to contain any DNS name, not just MAX_COMPUTERNAME_LENGTH + 1 */
	/* characters. MAX_COMPUTERNAME_LENGTH is usually less than 32, but it varies among systems, so we  */
	/* cannot use the constant in a precompiled Windows agent, which is expected to work on any system. */
	if (0 == GetComputerName(computer_name, &dwSize))
		*computer_name = '\0';

	memset(&si, 0, sizeof(si));
	memset(&vi, 0, sizeof(vi));

	vi.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
	if (TRUE != GetVersionEx((OSVERSIONINFO *)&vi))
		return SYSINFO_RET_FAIL;

	if (NULL != (pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo")))
		pGNSI(&si);
	else
		GetSystemInfo(&si);

	os = zbx_malloc(os, os_alloc);

	zbx_strcpy_alloc(&os, &os_alloc, &os_offset, "Windows");

	if ('\0' != *computer_name)
	{
		utf8 = zbx_unicode_to_utf8(computer_name);
		zbx_snprintf_alloc(&os, &os_alloc, &os_offset, " %s", utf8);
		zbx_free(utf8);
	}

	zbx_snprintf_alloc(&os, &os_alloc, &os_offset, " %d.%d.%d",
			vi.dwMajorVersion, vi.dwMinorVersion, vi.dwBuildNumber);

	if (VER_PLATFORM_WIN32_NT == vi.dwPlatformId)
	{
		switch (vi.dwMajorVersion)
		{
			case 5:
				switch (vi.dwMinorVersion)
				{
					case 0:
						get_50_version(&os, &os_alloc, &os_offset, &vi);
						break;
					case 1:
						get_51_version(&os, &os_alloc, &os_offset, &vi);
						break;
					case 2:
						get_52_version(&os, &os_alloc, &os_offset, &vi, &si);
						break;
				}
				break;
			case 6:
				get_6x_version(&os, &os_alloc, &os_offset, &vi, &si);
				break;
		}
	}

	if ('\0' != *vi.szCSDVersion)
	{
		utf8 = zbx_unicode_to_utf8(vi.szCSDVersion);
		zbx_snprintf_alloc(&os, &os_alloc, &os_offset, " %s", utf8);
		zbx_free(utf8);
	}

	get_cpu_type(&os, &os_alloc, &os_offset, &si);

	SET_STR_RESULT(result, os);

	return SYSINFO_RET_OK;
#else
	return EXECUTE_STR(cmd, "uname -a", flags, result);
#endif
}
Beispiel #2
0
int	SYSTEM_UNAME(AGENT_REQUEST *request, AGENT_RESULT *result)
{
	typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);

	DWORD			dwSize = 256;
	TCHAR			computer_name[256];
	SYSTEM_INFO		si;
	const OSVERSIONINFOEX	*vi;
	char			*os = NULL, *utf8;
	size_t			os_alloc = 256, os_offset = 0;
	PGNSI			pGNSI;

	/* Buffer size is chosen large enough to contain any DNS name, not just MAX_COMPUTERNAME_LENGTH + 1 */
	/* characters. MAX_COMPUTERNAME_LENGTH is usually less than 32, but it varies among systems, so we  */
	/* cannot use the constant in a precompiled Windows agent, which is expected to work on any system. */
	if (0 == GetComputerName(computer_name, &dwSize))
		*computer_name = '\0';

	memset(&si, 0, sizeof(si));

	if (NULL == (vi = zbx_win_getversion()))
	{
		SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot retrieve system version."));
		return SYSINFO_RET_FAIL;
	}

	if (NULL != (pGNSI = (PGNSI)GetProcAddress(GetModuleHandle(TEXT("kernel32.dll")), "GetNativeSystemInfo")))
		pGNSI(&si);
	else
		GetSystemInfo(&si);

	os = zbx_malloc(os, os_alloc);

	zbx_strcpy_alloc(&os, &os_alloc, &os_offset, "Windows");

	if ('\0' != *computer_name)
	{
		utf8 = zbx_unicode_to_utf8(computer_name);
		zbx_snprintf_alloc(&os, &os_alloc, &os_offset, " %s", utf8);
		zbx_free(utf8);
	}

	zbx_snprintf_alloc(&os, &os_alloc, &os_offset, " %d.%d.%d",
			vi->dwMajorVersion, vi->dwMinorVersion, vi->dwBuildNumber);

	if (VER_PLATFORM_WIN32_NT == vi->dwPlatformId)
	{
		switch (vi->dwMajorVersion)
		{
			case 5:
				switch (vi->dwMinorVersion)
				{
					case 0:
						get_50_version(&os, &os_alloc, &os_offset, vi);
						break;
					case 1:
						get_51_version(&os, &os_alloc, &os_offset, vi);
						break;
					case 2:
						get_52_version(&os, &os_alloc, &os_offset, vi, &si);
						break;
				}
				break;
			case 6:
				get_6x_version(&os, &os_alloc, &os_offset, vi, &si);
				break;
		}
	}

	if ('\0' != *vi->szCSDVersion)
	{
		utf8 = zbx_unicode_to_utf8(vi->szCSDVersion);
		zbx_snprintf_alloc(&os, &os_alloc, &os_offset, " %s", utf8);
		zbx_free(utf8);
	}

	get_cpu_type(&os, &os_alloc, &os_offset, &si);

	SET_STR_RESULT(result, os);

	return SYSINFO_RET_OK;
}