1 /* @(#) $Id: ./src/rootcheck/check_rc_dev.c, 2011/09/08 dcid Exp $
4 /* Copyright (C) 2009 Trend Micro Inc.
7 * This program is a free software; you can redistribute it
8 * and/or modify it under the terms of the GNU General Public
9 * License (version 2) as published by the FSF - Free Software
16 #include "rootcheck.h"
22 int read_dev_dir(char *dir_name);
24 int read_dev_file(char *file_name)
28 if(lstat(file_name, &statbuf) < 0)
33 if(S_ISDIR(statbuf.st_mode))
36 verbose("%s: Reading dir: %s\n",ARGV0, file_name);
39 return(read_dev_dir(file_name));
42 else if(S_ISREG(statbuf.st_mode))
44 char op_msg[OS_SIZE_1024 +1];
46 snprintf(op_msg, OS_SIZE_1024, "File '%s' present on /dev."
47 " Possible hidden file.", file_name);
48 notify_rk(ALERT_SYSTEM_CRIT, op_msg);
59 int read_dev_dir(char *dir_name)
67 /* when will these people learn that dev is not
68 * meant to store log files or other kind of texts..
70 char *(ignore_dev[]) = {"MAKEDEV","README.MAKEDEV",
71 "MAKEDEV.README", ".udevdb",
72 ".udev.tdb", ".initramfs-tools",
73 "MAKEDEV.local", ".udev", ".initramfs",
74 "oprofile","fd","cgroup",
79 ".devfsadm_daemon.lock",
80 ".devfsadm_deamon.lock",
81 ".devfsadm_synch_door",
87 /* Full path ignore */
88 char *(ignore_dev_full_path[]) = {"/dev/shm/sysconfig",
89 "/dev/bus/usb/.usbfs",
94 if((dir_name == NULL)||(strlen(dir_name) > PATH_MAX))
96 merror("%s: Invalid directory given.",ARGV0);
100 /* Opening the directory given */
101 dp = opendir(dir_name);
107 while((entry = readdir(dp)) != NULL)
109 char f_name[PATH_MAX +2];
111 /* Just ignore . and .. */
112 if((strcmp(entry->d_name,".") == 0) ||
113 (strcmp(entry->d_name,"..") == 0))
118 /* Do not look for the ignored files */
119 for(i = 0;ignore_dev[i] != NULL;i++)
121 if(strcmp(ignore_dev[i], entry->d_name) == 0)
125 if(ignore_dev[i] != NULL)
128 f_name[PATH_MAX +1] = '\0';
129 snprintf(f_name, PATH_MAX +1, "%s/%s",dir_name, entry->d_name);
132 /* Do not look for the full ignored files */
133 for(i = 0;ignore_dev_full_path[i] != NULL;i++)
135 if(strcmp(ignore_dev_full_path[i], f_name) == 0)
140 /* Checking against the full path. */
141 if(ignore_dev_full_path[i] != NULL)
147 read_dev_file(f_name);
157 /* check_rc_dev: v0.1
160 void check_rc_dev(char *basedir)
162 char file_path[OS_SIZE_1024 +1];
164 _dev_total = 0, _dev_errors = 0;
166 debug1("%s: DEBUG: Starting on check_rc_dev", ARGV0);
168 snprintf(file_path, OS_SIZE_1024, "%s/dev", basedir);
170 read_dev_dir(file_path);
174 char op_msg[OS_SIZE_1024 +1];
175 snprintf(op_msg, OS_SIZE_1024, "No problem detected on the /dev "
176 "directory. Analyzed %d files",
178 notify_rk(ALERT_OK, op_msg);
188 void check_rc_dev(char *basedir)