3 /* Copyright (C) 2009 Trend Micro Inc.
6 * This program is a free software; you can redistribute it
7 * and/or modify it under the terms of the GNU General Public
8 * License (version 2) as published by the FSF - Free Software
15 #include "rootcheck.h"
21 int read_dev_dir(char *dir_name);
23 int read_dev_file(char *file_name)
27 if(lstat(file_name, &statbuf) < 0)
32 if(S_ISDIR(statbuf.st_mode))
35 verbose("%s: Reading dir: %s\n",ARGV0, file_name);
38 return(read_dev_dir(file_name));
41 else if(S_ISREG(statbuf.st_mode))
43 char op_msg[OS_SIZE_1024 +1];
45 snprintf(op_msg, OS_SIZE_1024, "File '%s' present on /dev."
46 " Possible hidden file.", file_name);
47 notify_rk(ALERT_SYSTEM_CRIT, op_msg);
58 int read_dev_dir(char *dir_name)
66 /* when will these people learn that dev is not
67 * meant to store log files or other kind of texts..
69 char *(ignore_dev[]) = {"MAKEDEV","README.MAKEDEV",
70 "MAKEDEV.README", ".udevdb",
71 ".udev.tdb", ".initramfs-tools",
72 "MAKEDEV.local", ".udev", ".initramfs",
78 ".devfsadm_daemon.lock",
79 ".devfsadm_deamon.lock",
80 ".devfsadm_synch_door",
86 /* Full path ignore */
87 char *(ignore_dev_full_path[]) = {"/dev/shm/sysconfig",
88 "/dev/bus/usb/.usbfs",
93 if((dir_name == NULL)||(strlen(dir_name) > PATH_MAX))
95 merror("%s: Invalid directory given.",ARGV0);
99 /* Opening the directory given */
100 dp = opendir(dir_name);
106 while((entry = readdir(dp)) != NULL)
108 char f_name[PATH_MAX +2];
110 /* Just ignore . and .. */
111 if((strcmp(entry->d_name,".") == 0) ||
112 (strcmp(entry->d_name,"..") == 0))
117 /* Do not look for the ignored files */
118 for(i = 0;ignore_dev[i] != NULL;i++)
120 if(strcmp(ignore_dev[i], entry->d_name) == 0)
124 if(ignore_dev[i] != NULL)
127 f_name[PATH_MAX +1] = '\0';
128 snprintf(f_name, PATH_MAX +1, "%s/%s",dir_name, entry->d_name);
131 /* Do not look for the full ignored files */
132 for(i = 0;ignore_dev_full_path[i] != NULL;i++)
134 if(strcmp(ignore_dev_full_path[i], f_name) == 0)
139 /* Checking against the full path. */
140 if(ignore_dev_full_path[i] != NULL)
146 read_dev_file(f_name);
156 /* check_rc_dev: v0.1
159 void check_rc_dev(char *basedir)
161 char file_path[OS_SIZE_1024 +1];
163 _dev_total = 0, _dev_errors = 0;
165 debug1("%s: DEBUG: Starting on check_rc_dev", ARGV0);
167 snprintf(file_path, OS_SIZE_1024, "%s/dev", basedir);
169 read_dev_dir(file_path);
173 char op_msg[OS_SIZE_1024 +1];
174 snprintf(op_msg, OS_SIZE_1024, "No problem detected on the /dev "
175 "directory. Analyzed %d files",
177 notify_rk(ALERT_OK, op_msg);
187 void check_rc_dev(char *basedir)