Changeset 78 for trunk/src/sh_processcheck.c
- Timestamp:
- Jan 9, 2007, 10:32:21 PM (18 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_processcheck.c
r77 r78 48 48 #endif 49 49 50 #ifdef HAVE_SYS_STATVFS_H 51 #include <sys/statvfs.h> 52 #endif 53 54 50 55 #ifdef HAVE_REGEX_H 51 56 #include <regex.h> … … 58 63 #include "sh_error.h" 59 64 #include "sh_extern.h" 65 #include "sh_calls.h" 60 66 61 67 #ifdef SH_USE_PROCESSCHECK … … 157 163 158 164 static const short SH_PR_PRIORITY = 0x0100; 159 160 static const short SH_PR_PS2 = 0x0200; 161 static const short SH_PR_PS_ANY = 0x0400; 162 static const short SH_PR_ALL = 0x0800; 163 static const short SH_PR_ANY = 0x1000; 165 static const short SH_PR_STATVSF = 0x0200; 166 167 static const short SH_PR_PS2 = 0x1000; 168 static const short SH_PR_PS_ANY = 0x2000; 169 static const short SH_PR_ALL = 0x4000; 170 static const short SH_PR_ANY = 0x8000; 164 171 165 172 /* /proc: … … 168 175 * solaris10: /proc/pid/path/a.out 169 176 */ 177 static char * get_user_and_path (pid_t pid, char * user, size_t usrlen) 178 { 179 extern char * sh_unix_getUIDname (int level, uid_t uid); 180 181 char path[128]; 182 char * buf; 183 struct stat sbuf; 184 int len; 185 char * tmp; 186 187 sl_snprintf (path, sizeof(path), "/proc/%ld/exe", (unsigned long) pid); 188 189 if (0 == retry_lstat(FIL__, __LINE__, path, &sbuf) && S_ISLNK(sbuf.st_mode)) 190 { 191 goto linkread; 192 } 193 194 sl_snprintf (path, sizeof(path), "/proc/%ld/file", (unsigned long) pid); 195 196 if (0 == retry_lstat(FIL__, __LINE__, path, &sbuf) && S_ISLNK(sbuf.st_mode)) 197 { 198 goto linkread; 199 } 200 201 sl_snprintf (path, sizeof(path), "/proc/%ld/path/a.out", (unsigned long) pid); 202 203 if (0 == retry_lstat(FIL__, __LINE__, path, &sbuf) && S_ISLNK(sbuf.st_mode)) 204 { 205 goto linkread; 206 } 207 208 return NULL; 209 210 linkread: 211 212 buf = SH_ALLOC(PATH_MAX); 213 len = readlink(path, buf, PATH_MAX); /* flawfinder: ignore */ 214 len = (len >= PATH_MAX) ? (PATH_MAX-1) : len; 215 216 if (len > 0) 217 { 218 buf[len] = '\0'; 219 } 220 else 221 { 222 SH_FREE(buf); 223 return NULL; 224 } 225 226 tmp = sh_unix_getUIDname (SH_ERR_ALL, sbuf.st_uid); 227 228 if (tmp) 229 sl_strlcpy(user, tmp, usrlen); 230 else 231 sl_snprintf (user, usrlen, "%ld", (unsigned long) sbuf.st_uid); 232 233 return buf; 234 } 235 170 236 171 237 struct watchlist { … … 483 549 size_t value; 484 550 char * foo; 485 int retval = 0;551 int retval = -1; 486 552 487 553 SL_ENTER(_("sh_prochk_set_maxpid")); 488 554 489 555 value = (size_t) strtoul(str, &foo, 0); 490 if (*foo != '\0') { 491 retval = -1; 492 } else { 556 557 if (*foo == '\0' && SL_TRUE == sl_ok_adds(value, 1)) { 493 558 sh_prochk_maxpid = value + 1; 494 559 userdef_maxpid = 1; … … 593 658 if (res & SH_PR_GETPGID) sl_strlcat(list, _(" getpgid"), len); 594 659 if (res & SH_PR_KILL) sl_strlcat(list, _(" kill"), len); 660 if (res & SH_PR_STATVSF) sl_strlcat(list, _(" statvfs"), len); 595 661 if (res & SH_PR_PS2) sl_strlcat(list, _(" ps(final)"), len); 596 662 return; 597 663 } 598 664 599 /* FIXME: add open, statvfs, sched_getaffinity 600 */ 665 601 666 static short sh_processes_check (pid_t pid, short res) 602 667 { 668 int retval; 603 669 int have_checks = 0; 604 670 int need_checks = 0; … … 608 674 DIR * dir; 609 675 #endif 676 #ifdef HAVE_STATVFS 677 struct statvfs vfsbuf; 678 #endif 610 679 611 680 #if !defined(sun) && !defined(__sun) && !defined(__sun__) … … 624 693 ++need_checks; 625 694 } 695 626 696 627 697 #ifdef HAVE_GETPGID … … 666 736 sl_snprintf (path, sizeof(path), "/proc/%ld", (unsigned long) pid); 667 737 668 if (0 == lstat (path, &buf))738 if (0 == retry_lstat (FIL__, __LINE__, path, &buf)) 669 739 { 670 740 res |= SH_PR_LSTAT; res |= SH_PR_ANY; ++have_checks; … … 678 748 } 679 749 ++need_checks; 750 751 #ifdef HAVE_STATVFS 752 do { 753 retval = statvfs (path, &vfsbuf); 754 } while (retval < 0 && errno == EINTR); 755 756 if (0 == retval) 757 { 758 res |= SH_PR_STATVSF; res |= SH_PR_ANY; ++have_checks; 759 } 760 ++need_checks; 761 #endif 680 762 681 763 #if !defined(SH_PROFILE) … … 972 1054 if (S_FALSE == is_in_list(&list_hidden, NULL, i)) 973 1055 { 974 sh_error_handle(sh_prochk_severity, FIL__, __LINE__, 0, 975 MSG_PCK_HIDDEN, 976 (unsigned long) i, tests); 1056 char user[16]; 1057 char * aout; 1058 char * safe; 1059 1060 aout = get_user_and_path ((pid_t) i, user, sizeof(user)); 1061 1062 if (aout) 1063 { 1064 safe = sh_util_safe_name (aout); 1065 sh_error_handle(sh_prochk_severity, FIL__, __LINE__, 0, 1066 MSG_PCK_P_HIDDEN, 1067 (unsigned long) i, tests, safe, user); 1068 SH_FREE(safe); 1069 SH_FREE(aout); 1070 } 1071 else 1072 sh_error_handle(sh_prochk_severity, FIL__, __LINE__, 0, 1073 MSG_PCK_HIDDEN, 1074 (unsigned long) i, tests); 1075 977 1076 } 978 1077 }
Note:
See TracChangeset
for help on using the changeset viewer.