24 #include <sys/capability.h>
36 #include <sys/types.h>
61 if (!strcmp(key,
"CACHE_MAX_SIZE")) {
62 unsigned int cacheMaxSize;
64 std::stringstream ss(value);
70 }
else if (!strcmp(key,
"CLEAN_CACHE_ON_UPDATE")) {
71 int cleanCacheOnUpdate = 1;
73 if (!strcmp(value,
"yes")) {
75 }
else if (!strcmp(value,
"no")) {
78 fprintf(stderr,
"illegal value '%s' for CLEAN_CACHE_ON_UPDATE \n",
81 }
else if (!strcmp(key,
"EXCLUDE_PATH")) {
82 std::string val = value;
84 if (0 == val.length() || *(val.rbegin()++) !=
'/') {
88 }
else if (!strcmp(key,
"LOCAL_FS")) {
90 }
else if (!strcmp(key,
"NOMARK_FS")) {
92 }
else if (!strcmp(key,
"NOMARK_MNT")) {
94 }
else if (!strcmp(key,
"THREADS")) {
97 std::stringstream ss(value);
114 static void hdl(
int sig) {
116 fprintf(stderr,
"Main received SIGINT\n");
118 if (sig == SIGTERM) {
119 fprintf(stderr,
"Main received SIGTERM\n");
121 if (sig == SIGUSR1) {
122 fprintf(stderr,
"Main received SIGUSR1\n");
136 fd = open(filename, O_CREAT | O_TRUNC | O_WRONLY,
139 std::stringstream msg;
140 msg <<
"Cannot create pid file '" << filename <<
"'";
143 len = snprintf(buffer,
sizeof (buffer),
"%d", (
int) getpid());
144 ret = write(fd, buffer, len);
146 std::stringstream msg;
148 msg <<
"Cannot write to pid file '" << filename <<
"': "
149 << strerror_r(errno, errbuf,
sizeof(errbuf));
167 printf(
"Skyld AV, version %s\n", VERSION);
180 cap_flag_value_t value;
182 caps = cap_get_proc();
184 fprintf(stderr,
"Cannot access capabilities\n");
187 if (cap_get_flag(caps, cap, CAP_EFFECTIVE, &value) == -1) {
188 fprintf(stderr,
"Cannot get capability 1.\n");
189 }
else if (value == CAP_SET) {
192 if (cap_free(caps)) {
193 fprintf(stderr,
"Failure to free capability state\n");
205 "Missing capability CAP_SYS_ADMIN.\n"
206 "Call the program as root.\n");
219 if (getppid() == 1) {
224 signal(SIGCHLD, SIG_IGN);
229 perror(
"Cannot fork");
238 if (chdir(
"/") == -1) {
239 perror(
"Cannot change directory");
246 if (setsid() == -1) {
247 perror(
"Cannot create session");
250 if (NULL == freopen(
"/dev/null",
"r", stdin)) {
251 perror(
"Cannot redirect /dev/null to stdin");
253 if (NULL == freopen(
"/dev/null",
"w", stdout)) {
254 perror(
"Cannot redirect stdout to /dev/null");
256 if (NULL == freopen(
"/dev/null",
"w", stderr)) {
257 perror(
"Cannot redirect stderr to /dev/null");
268 int main(
int argc,
char *argv[]) {
274 int shalldaemonize = 0;
276 struct sigaction act;
293 nThread = sysconf(_SC_NPROCESSORS_ONLN);
301 for (i = 1; i < argc; i++) {
331 std::istringstream(argv[i]) >> messageLevel;
359 "At least one thread is needed for scanning.\n");
367 if (shalldaemonize) {
382 sigemptyset(&blockset);
383 sigaddset(&blockset, SIGUSR1);
384 if (sigprocmask(SIG_BLOCK, &blockset, NULL) == -1) {
390 act.sa_handler =
hdl;
391 sigemptyset(&act.sa_mask);
393 if (sigaction(SIGTERM, &act, NULL)
394 || sigaction(SIGINT, &act, NULL)
395 || sigaction(SIGUSR1, &act, NULL)) {
404 "Failure starting fanotify listener.");
413 printf(
"Press any key to terminate\n");
static void hdl(int sig)
Handles signal.
static void teardown()
Deletes the singleton.
static void setLevel(const enum Level)
Sets message level.
Error, e.g. malfunction of the code, malware detected.
StringSet * getLocalFileSystems()
Gets the list of file systems considered local. This list can be used to decide if scan results shall...
void setCacheMaxSize(unsigned int)
Sets the maximum number of entries in the cache with scan results.
void add(const char *value)
Adds entry to string set.
int parseConfigurationFile(char *filename, conf_cb cb, void *info)
Parses configuration file. If cb is NULL the key value pairs are output to the console. Returns 0 if successful.
const char * VERSION_TEXT
static void version()
Shows version information and exits.
static void error(const std::string &)
Sends an error message based on errno.
static int configurationCallback(const char *key, const char *value, void *info)
Callback function for reading configuration file.
StringSet * getNoMarkMounts()
Gets the list of mounts not to be scanned.
static void pidfile()
Creates pidfile for daemon.
Information, e.g. access scanning has started.
static void message(const enum Level, const std::string &)
Sends message.
static void authcheck(Environment *e)
Checks authorization.
void setCleanCacheOnUpdate(int)
Sets if cache shall be cleaned when the virus scanner receives a new pattern file.
int main(int argc, char *argv[])
Main.
void setNumberOfThreads(int)
sets the number of threads used to call the virus scanner.
static void help()
Prints help message and exits.
StringSet * getNoMarkFileSystems()
Gets the list of file systems that shall not be scanned.
static int capable(cap_value_t cap)
Check if the process has a capability.
Debugging information only to be shown in the console.
The environment holds variables that are shared by instances of multiple classes. ...
Level
Message levels available.
static void daemonize(Environment *e)
Daemonizes.
Analyze configuration file.
StringSet * getExcludePaths()
Gets the set of paths that shall not be scanned.