diff options
Diffstat (limited to 'src/libs/zbxsysinfo/win32/services.c')
-rw-r--r-- | src/libs/zbxsysinfo/win32/services.c | 27 |
1 files changed, 24 insertions, 3 deletions
diff --git a/src/libs/zbxsysinfo/win32/services.c b/src/libs/zbxsysinfo/win32/services.c index 278dcde3fe6..8628037ecb2 100644 --- a/src/libs/zbxsysinfo/win32/services.c +++ b/src/libs/zbxsysinfo/win32/services.c @@ -25,22 +25,31 @@ int SERVICE_STATE(AGENT_REQUEST *request, AGENT_RESULT *result) { SC_HANDLE mgr, service; char *name; - LPTSTR wname; - TCHAR service_name[MAX_STRING_LEN]; + wchar_t *wname; + wchar_t service_name[MAX_STRING_LEN]; DWORD max_len_name = MAX_STRING_LEN; int i, ret = SYSINFO_RET_FAIL; SERVICE_STATUS status; if (1 < request->nparam) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); return SYSINFO_RET_FAIL; + } name = get_rparam(request, 0); if (NULL == name || '\0' == *name) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter.")); return SYSINFO_RET_FAIL; + } if (NULL == (mgr = OpenSCManager(NULL, NULL, GENERIC_READ))) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain system information.")); return SYSINFO_RET_FAIL; + } wname = zbx_utf8_to_unicode(name); @@ -184,7 +193,10 @@ int SERVICES(AGENT_REQUEST *request, AGENT_RESULT *result) DWORD sz = 0, szn, i, services, resume_handle = 0; if (3 < request->nparam) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Too many parameters.")); return SYSINFO_RET_FAIL; + } type = get_rparam(request, 0); state = get_rparam(request, 1); @@ -199,7 +211,10 @@ int SERVICES(AGENT_REQUEST *request, AGENT_RESULT *result) else if (0 == strcmp(type, "disabled")) start_type = ZBX_SRV_STARTTYPE_DISABLED; else + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid first parameter.")); return SYSINFO_RET_FAIL; + } if (NULL == state || '\0' == *state || 0 == strcmp(state, "all")) /* default parameter */ service_state = ZBX_SRV_STATE_ALL; @@ -220,13 +235,19 @@ int SERVICES(AGENT_REQUEST *request, AGENT_RESULT *result) else if (0 == strcmp(state, "paused")) service_state = ZBX_SRV_STATE_PAUSED; else + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Invalid second parameter.")); return SYSINFO_RET_FAIL; + } if (NULL == (h_mgr = OpenSCManager(NULL, NULL, GENERIC_READ))) + { + SET_MSG_RESULT(result, zbx_strdup(NULL, "Cannot obtain system information.")); return SYSINFO_RET_FAIL; + } while (0 != (ret = EnumServicesStatusEx(h_mgr, SC_ENUM_PROCESS_INFO, SERVICE_WIN32, SERVICE_STATE_ALL, - (LPBYTE)ssp, sz, &szn, &services, &resume_handle, NULL)) || ERROR_MORE_DATA == GetLastError()) + (unsigned char *)ssp, sz, &szn, &services, &resume_handle, NULL)) || ERROR_MORE_DATA == GetLastError()) { for (i = 0; i < services; i++) { |