Server IP : 103.169.32.36 / Your IP : 216.73.217.13 Web Server : Apache System : Linux web.dpmptsp 3.10.0-1160.119.1.el7.x86_64 #1 SMP Tue Jun 4 14:43:51 UTC 2024 x86_64 User : apache ( 48) PHP Version : 5.6.40 Disable Function : NONE MySQL : ON | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : ON Directory : /var/opt/eset/efs/eventd/eset_rtp/ |
Upload File : |
| Current File : /var/opt/eset/efs/eventd/eset_rtp/ertp_sysfs.c |
/*
* eset_rtp (ESET Real-time file system protection module)
* Copyright (C) 1992-2023 ESET, spol. s r.o.
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*
* In case of any questions, you can contact us at ESET, spol. s r.o., Einsteinova 24, 851 01 Bratislava, Slovakia.
*/
#include "ertp.h"
#include "ertp_cache.h"
#include "ertp_event_queue.h"
#include "ertp_logs.h"
#include <linux/module.h>
static ssize_t ertp_cache_size_show(struct kobject *s,
struct kobj_attribute *attr, char *buf) {
return sprintf(buf, "%ld\n", ertp_cache_get_size());
}
static ssize_t ertp_cache_size_store(struct kobject *s,
struct kobj_attribute *attr,
const char *buf, size_t count) {
size_t size;
int err = kstrtoul(buf, 10, &size);
if (err) {
ertp_pr_warning("invalid cache size: %s", buf);
return err;
}
ertp_cache_set_size(size);
ertp_pr_info("max size of kernel module's cache has been changed to %zu",
size);
return strlen(buf);
}
static ssize_t ertp_enabler_show(struct kobject *s, struct kobj_attribute *attr,
char *buf) {
return sprintf(buf, "%d\n", !ertp_event_queue_is_disabled());
}
static ssize_t ertp_enabler_store(struct kobject *s,
struct kobj_attribute *attr, const char *buf,
size_t count) {
int enable = 0;
int err = kstrtoint(buf, 10, &enable);
if (err) {
ertp_pr_warning("invalid value: %s", buf);
return err;
}
if (enable) {
ertp_event_queue_enable();
ertp_pr_log(ERTP_LOG_EVENTS, "scanning enabled");
} else {
ertp_event_queue_disable();
ertp_pr_log(ERTP_LOG_EVENTS, "scanning disabled");
}
return strlen(buf);
}
static struct kobject *ertp_kobj;
static const struct kobj_attribute enabler_attr =
__ATTR(enable, 0600, ertp_enabler_show, ertp_enabler_store);
static struct kobject *ertp_cache_kobj;
static const struct kobj_attribute cache_attr =
__ATTR(max_size, 0600, ertp_cache_size_show, ertp_cache_size_store);
int ertp_sysfs_init(void) {
int ret;
ertp_kobj = kobject_create_and_add("settings", &THIS_MODULE->mkobj.kobj);
if (!ertp_kobj) {
ret = -ENOMEM;
goto error;
}
ertp_cache_kobj = kobject_create_and_add("cache", ertp_kobj);
if (!ertp_cache_kobj) {
ret = -ENOMEM;
goto error;
}
ret = sysfs_create_file(ertp_kobj, &enabler_attr.attr);
if (ret) goto error;
ret = sysfs_create_file(ertp_cache_kobj, &cache_attr.attr);
if (ret) goto err_cache;
return 0;
err_cache:
sysfs_remove_file(ertp_kobj, &enabler_attr.attr);
error:
if (ertp_cache_kobj) kobject_put(ertp_cache_kobj);
if (ertp_kobj) kobject_put(ertp_kobj);
return ret;
}
void ertp_sysfs_deinit(void) {
sysfs_remove_file(ertp_cache_kobj, &cache_attr.attr);
kobject_put(ertp_cache_kobj);
sysfs_remove_file(ertp_kobj, &enabler_attr.attr);
kobject_put(ertp_kobj);
}