X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;f=src%2Frootcheck%2Funix-process.c;h=9bc753ae4e3a0cb959c8770a7c337990b1cd8125;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hp=072964e9433036c769e0c489aea26df024d5f759;hpb=301048b51990573e58a30dc4a5bb4ec285cad554;p=ossec-hids.git diff --git a/src/rootcheck/unix-process.c b/src/rootcheck/unix-process.c old mode 100755 new mode 100644 index 072964e..9bc753a --- a/src/rootcheck/unix-process.c +++ b/src/rootcheck/unix-process.c @@ -1,5 +1,3 @@ -/* @(#) $Id$ */ - /* Copyright (C) 2009 Trend Micro Inc. * All right reserved. * @@ -7,139 +5,111 @@ * and/or modify it under the terms of the GNU General Public * License (version 2) as published by the FSF - Free Software * Foundation - * - * License details at the LICENSE file included with OSSEC or - * online at: http://www.ossec.net/main/license/ . */ - #include "shared.h" #include "rootcheck.h" + #ifndef WIN32 -char *_os_get_runps(char *ps, int mpid) +static char *_os_get_runps(const char *ps, int mpid) { char *tmp_str, *nbuf; - char buf[OS_SIZE_2048 +1]; - char command[OS_SIZE_1024 +1]; + char buf[OS_SIZE_2048 + 1]; + char command[OS_SIZE_1024 + 1]; FILE *fp; - - + buf[0] = '\0'; command[0] = '\0'; - command[OS_SIZE_1024] = '\0'; - - - snprintf(command, OS_SIZE_1024, "%s -p %d 2> /dev/null", ps, mpid); + command[OS_SIZE_1024] = '\0'; + snprintf(command, OS_SIZE_1024, "%s -p %d 2> /dev/null", ps, mpid); fp = popen(command, "r"); - if(fp) - { - while(fgets(buf, OS_SIZE_2048, fp) != NULL) - { + if (fp) { + while (fgets(buf, OS_SIZE_2048, fp) != NULL) { tmp_str = strchr(buf, ':'); - if(!tmp_str) - { + if (!tmp_str) { continue; } nbuf = tmp_str++; tmp_str = strchr(nbuf, ' '); - if(!tmp_str) - { + if (!tmp_str) { continue; } tmp_str++; + /* Remove whitespaces */ + while (*tmp_str == ' ') { + tmp_str++; + } - /* Removing white spaces. */ - while(*tmp_str == ' ') - tmp_str++; - - nbuf = tmp_str; - tmp_str = strchr(nbuf, '\n'); - if(tmp_str) - { + if (tmp_str) { *tmp_str = '\0'; } pclose(fp); - return(strdup(nbuf)); + return (strdup(nbuf)); } pclose(fp); } - return(NULL); + return (NULL); } - - -/* os_get_unix_process_list: Get list of Unix processes */ -void *os_get_process_list() +/* Get list of Unix processes */ +OSList *os_get_process_list() { int i = 1; pid_t max_pid = MAX_PID; OSList *p_list = NULL; - - char ps[OS_SIZE_1024 +1]; + char ps[OS_SIZE_1024 + 1]; - - /* Checking where ps is */ - memset(ps, '\0', OS_SIZE_1024 +1); + /* Check where ps is */ + memset(ps, '\0', OS_SIZE_1024 + 1); strncpy(ps, "/bin/ps", OS_SIZE_1024); - if(!is_file(ps)) - { + if (!is_file(ps)) { strncpy(ps, "/usr/bin/ps", OS_SIZE_1024); - if(!is_file(ps)) - { + if (!is_file(ps)) { merror("%s: ERROR: 'ps' not found.", ARGV0); - return(NULL); + return (NULL); } } - - /* Creating process list */ + /* Create process list */ p_list = OSList_Create(); - if(!p_list) - { + if (!p_list) { merror(LIST_ERROR, ARGV0); - return(NULL); + return (NULL); } + for (i = 1; i <= max_pid; i++) { + /* Check if the pid is present */ + if ((!((getsid(i) == -1) && (errno == ESRCH))) && + (!((getpgid(i) == -1) && (errno == ESRCH)))) { + Proc_Info *p_info; + char *p_name; + p_name = _os_get_runps(ps, (int)i); + if (!p_name) { + continue; + } - for(i = 1; i<= max_pid; i++) - { - /* Checking if the pid is present. */ - if((!((getsid(i) == -1)&&(errno == ESRCH))) && - (!((getpgid(i) == -1)&&(errno == ESRCH)))) - { - Proc_Info *p_info; - char *p_name; - - p_name = _os_get_runps(ps, (int)i); - if(!p_name) - { - continue; - } - - os_calloc(1, sizeof(Proc_Info), p_info); - p_info->p_path = p_name; - p_info->p_name = NULL; - OSList_AddData(p_list, p_info); - } + os_calloc(1, sizeof(Proc_Info), p_info); + p_info->p_path = p_name; + p_info->p_name = NULL; + OSList_AddData(p_list, p_info); + } } - - return((void *)p_list); + + return (p_list); } - - -#endif -/* EOF */ +#endif /* WIN32 */ +