file: access exec timeout via daemon ops structure
[project/rpcd.git] / file.c
1 /*
2 * rpcd - UBUS RPC server
3 *
4 * Copyright (C) 2013-2014 Jo-Philipp Wich <jow@openwrt.org>
5 * Copyright (C) 2016 Luka Perkov <luka@openwrt.org>
6 *
7 * Permission to use, copy, modify, and/or distribute this software for any
8 * purpose with or without fee is hereby granted, provided that the above
9 * copyright notice and this permission notice appear in all copies.
10 *
11 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18 */
19
20 #include <fcntl.h>
21 #include <errno.h>
22 #include <unistd.h>
23 #include <stdlib.h>
24 #include <string.h>
25 #include <limits.h>
26 #include <dirent.h>
27 #include <sys/stat.h>
28 #include <sys/wait.h>
29 #include <libubus.h>
30 #include <libubox/blobmsg.h>
31 #include <libubox/md5.h>
32 #include <libubox/ustream.h>
33 #include <libubox/utils.h>
34
35 #include <rpcd/plugin.h>
36
37 /* limit of sys & proc files */
38 #define RPC_FILE_MIN_SIZE (128)
39
40 /* limit of regular files and command output data */
41 #define RPC_FILE_MAX_SIZE (4096 * 64)
42
43 #define ustream_for_each_read_buffer(stream, ptr, len) \
44 for (ptr = ustream_get_read_buf(stream, &len); \
45 ptr != NULL && len > 0; \
46 ustream_consume(stream, len), ptr = ustream_get_read_buf(stream, &len))
47
48 #define ustream_declare(us, fd, name) \
49 us.stream.string_data = true; \
50 us.stream.r.buffer_len = 4096; \
51 us.stream.r.max_buffers = RPC_FILE_MAX_SIZE / 4096; \
52 us.stream.notify_read = rpc_file_##name##_read_cb; \
53 us.stream.notify_state = rpc_file_##name##_state_cb; \
54 ustream_fd_init(&us, fd);
55
56 static const struct rpc_daemon_ops *ops;
57
58 struct rpc_file_exec_context {
59 struct ubus_context *context;
60 struct ubus_request_data request;
61 struct uloop_timeout timeout;
62 struct uloop_process process;
63 struct ustream_fd opipe;
64 struct ustream_fd epipe;
65 int outlen;
66 char *out;
67 int errlen;
68 char *err;
69 int stat;
70 };
71
72
73 static struct blob_buf buf;
74
75 enum {
76 RPC_F_R_PATH,
77 __RPC_F_R_MAX,
78 };
79
80 static const struct blobmsg_policy rpc_file_r_policy[__RPC_F_R_MAX] = {
81 [RPC_F_R_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING },
82 };
83
84 enum {
85 RPC_F_RB_PATH,
86 RPC_F_RB_BASE64,
87 __RPC_F_RB_MAX,
88 };
89
90 static const struct blobmsg_policy rpc_file_rb_policy[__RPC_F_RB_MAX] = {
91 [RPC_F_RB_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING },
92 [RPC_F_RB_BASE64] = { .name = "base64", .type = BLOBMSG_TYPE_BOOL },
93 };
94
95 enum {
96 RPC_F_RW_PATH,
97 RPC_F_RW_DATA,
98 RPC_F_RW_APPEND,
99 RPC_F_RW_MODE,
100 RPC_F_RW_BASE64,
101 __RPC_F_RW_MAX,
102 };
103
104 static const struct blobmsg_policy rpc_file_rw_policy[__RPC_F_RW_MAX] = {
105 [RPC_F_RW_PATH] = { .name = "path", .type = BLOBMSG_TYPE_STRING },
106 [RPC_F_RW_DATA] = { .name = "data", .type = BLOBMSG_TYPE_STRING },
107 [RPC_F_RW_APPEND] = { .name = "append", .type = BLOBMSG_TYPE_BOOL },
108 [RPC_F_RW_MODE] = { .name = "mode", .type = BLOBMSG_TYPE_INT32 },
109 [RPC_F_RW_BASE64] = { .name = "base64", .type = BLOBMSG_TYPE_BOOL },
110 };
111
112 enum {
113 RPC_E_CMD,
114 RPC_E_PARM,
115 RPC_E_ENV,
116 __RPC_E_MAX,
117 };
118
119 static const struct blobmsg_policy rpc_exec_policy[__RPC_E_MAX] = {
120 [RPC_E_CMD] = { .name = "command", .type = BLOBMSG_TYPE_STRING },
121 [RPC_E_PARM] = { .name = "params", .type = BLOBMSG_TYPE_ARRAY },
122 [RPC_E_ENV] = { .name = "env", .type = BLOBMSG_TYPE_TABLE },
123 };
124
125 static const char *d_types[] = {
126 [DT_BLK] = "block",
127 [DT_CHR] = "char",
128 [DT_DIR] = "directory",
129 [DT_FIFO] = "fifo",
130 [DT_LNK] = "symlink",
131 [DT_REG] = "file",
132 [DT_SOCK] = "socket",
133 [DT_UNKNOWN] = "unknown",
134 };
135
136
137 static int
138 rpc_errno_status(void)
139 {
140 switch (errno)
141 {
142 case EACCES:
143 return UBUS_STATUS_PERMISSION_DENIED;
144
145 case ENOTDIR:
146 return UBUS_STATUS_INVALID_ARGUMENT;
147
148 case ENOENT:
149 return UBUS_STATUS_NOT_FOUND;
150
151 case EINVAL:
152 return UBUS_STATUS_INVALID_ARGUMENT;
153
154 default:
155 return UBUS_STATUS_UNKNOWN_ERROR;
156 }
157 }
158
159 static struct blob_attr **
160 rpc_check_path(struct blob_attr *msg, char **path, struct stat *s)
161 {
162 static struct blob_attr *tb[__RPC_F_R_MAX];
163
164 blobmsg_parse(rpc_file_r_policy, __RPC_F_R_MAX, tb, blob_data(msg), blob_len(msg));
165
166 if (!tb[RPC_F_R_PATH])
167 {
168 errno = EINVAL;
169 return NULL;
170 }
171
172 *path = blobmsg_data(tb[RPC_F_R_PATH]);
173
174 if (stat(*path, s))
175 return NULL;
176
177 return tb;
178 }
179
180 static int
181 rpc_file_read(struct ubus_context *ctx, struct ubus_object *obj,
182 struct ubus_request_data *req, const char *method,
183 struct blob_attr *msg)
184 {
185 static struct blob_attr *tb[__RPC_F_RB_MAX];
186 bool base64 = false;
187 int fd, rv;
188 ssize_t len;
189 char *path;
190 struct stat s;
191 char *wbuf;
192
193 blobmsg_parse(rpc_file_rb_policy, __RPC_F_RB_MAX, tb, blob_data(msg), blob_len(msg));
194
195 if (!tb[RPC_F_RB_PATH])
196 return rpc_errno_status();
197
198 path = blobmsg_data(tb[RPC_F_RB_PATH]);
199
200 if (stat(path, &s))
201 return rpc_errno_status();
202
203 if (s.st_size >= RPC_FILE_MAX_SIZE)
204 return UBUS_STATUS_NOT_SUPPORTED;
205
206 if ((fd = open(path, O_RDONLY)) < 0)
207 return rpc_errno_status();
208
209 /* some sysfs files do not report a length */
210 if (s.st_size == 0)
211 s.st_size = RPC_FILE_MIN_SIZE;
212
213 blob_buf_init(&buf, 0);
214
215 if (tb[RPC_F_RB_BASE64])
216 base64 = blobmsg_get_bool(tb[RPC_F_RB_BASE64]);
217
218 len = s.st_size + 1;
219 if (base64)
220 len = B64_ENCODE_LEN(s.st_size);
221 wbuf = blobmsg_alloc_string_buffer(&buf, "data", len);
222
223 if (!wbuf)
224 {
225 rv = UBUS_STATUS_UNKNOWN_ERROR;
226 goto out;
227 }
228
229 if ((len = read(fd, wbuf, s.st_size)) <= 0)
230 {
231 rv = UBUS_STATUS_NO_DATA;
232 goto out;
233 }
234
235 if (base64)
236 {
237 uint8_t *data = calloc(len, sizeof(uint8_t));
238 if (!data)
239 {
240 rv = UBUS_STATUS_UNKNOWN_ERROR;
241 goto out;
242 }
243 memcpy(data, wbuf, len);
244
245 len = b64_encode(data, len, wbuf, B64_ENCODE_LEN(len));
246 free(data);
247 if (len < 0)
248 {
249 rv = UBUS_STATUS_UNKNOWN_ERROR;
250 goto out;
251 }
252 }
253
254 *(wbuf + len) = '\0';
255 blobmsg_add_string_buffer(&buf);
256
257 ubus_send_reply(ctx, req, buf.head);
258 rv = UBUS_STATUS_OK;
259
260 out:
261 blob_buf_free(&buf);
262 close(fd);
263 return rv;
264 }
265
266 static int
267 rpc_file_write(struct ubus_context *ctx, struct ubus_object *obj,
268 struct ubus_request_data *req, const char *method,
269 struct blob_attr *msg)
270 {
271 struct blob_attr *tb[__RPC_F_RW_MAX];
272 int append = O_TRUNC;
273 mode_t prev_mode, mode = 0666;
274 int fd, rv = 0;
275 void *data = NULL;
276 ssize_t data_len = 0;
277
278 blobmsg_parse(rpc_file_rw_policy, __RPC_F_RW_MAX, tb,
279 blob_data(msg), blob_len(msg));
280
281 if (!tb[RPC_F_RW_PATH] || !tb[RPC_F_RW_DATA])
282 return UBUS_STATUS_INVALID_ARGUMENT;
283
284 data = blobmsg_data(tb[RPC_F_RW_DATA]);
285 data_len = blobmsg_data_len(tb[RPC_F_RW_DATA]) - 1;
286
287 if (tb[RPC_F_RW_APPEND] && blobmsg_get_bool(tb[RPC_F_RW_APPEND]))
288 append = O_APPEND;
289
290 if (tb[RPC_F_RW_MODE])
291 mode = blobmsg_get_u32(tb[RPC_F_RW_MODE]);
292
293 prev_mode = umask(0);
294 fd = open(blobmsg_data(tb[RPC_F_RW_PATH]), O_CREAT | O_WRONLY | append, mode);
295 umask(prev_mode);
296 if (fd < 0)
297 return rpc_errno_status();
298
299 if (tb[RPC_F_RW_BASE64] && blobmsg_get_bool(tb[RPC_F_RW_BASE64]))
300 {
301 data_len = b64_decode(data, data, data_len);
302 if (data_len < 0)
303 {
304 rv = UBUS_STATUS_UNKNOWN_ERROR;
305 goto out;
306 }
307 }
308
309 if (write(fd, data, data_len) < 0)
310 rv = -1;
311
312 out:
313 if (fsync(fd) < 0)
314 rv = -1;
315
316 close(fd);
317 sync();
318
319 if (rv)
320 return rpc_errno_status();
321
322 return 0;
323 }
324
325 static int
326 rpc_file_md5(struct ubus_context *ctx, struct ubus_object *obj,
327 struct ubus_request_data *req, const char *method,
328 struct blob_attr *msg)
329 {
330 int rv, i;
331 char *path;
332 struct stat s;
333 uint8_t md5[16];
334 char *wbuf;
335
336 if (!rpc_check_path(msg, &path, &s))
337 return rpc_errno_status();
338
339 if (!S_ISREG(s.st_mode))
340 return UBUS_STATUS_NOT_SUPPORTED;
341
342 if ((rv = md5sum(path, md5)) <= 0)
343 return rpc_errno_status();
344
345 blob_buf_init(&buf, 0);
346 wbuf = blobmsg_alloc_string_buffer(&buf, "md5", 33);
347
348 for (i = 0; i < 16; i++)
349 sprintf(wbuf + (i * 2), "%02x", (uint8_t) md5[i]);
350
351 blobmsg_add_string_buffer(&buf);
352 ubus_send_reply(ctx, req, buf.head);
353 blob_buf_free(&buf);
354
355 return UBUS_STATUS_OK;
356 }
357
358 static int
359 rpc_file_list(struct ubus_context *ctx, struct ubus_object *obj,
360 struct ubus_request_data *req, const char *method,
361 struct blob_attr *msg)
362 {
363 DIR *fd;
364 void *c, *d;
365 char *path;
366 struct stat s;
367 struct dirent *e;
368
369 if (!rpc_check_path(msg, &path, &s))
370 return rpc_errno_status();
371
372 if ((fd = opendir(path)) == NULL)
373 return rpc_errno_status();
374
375 blob_buf_init(&buf, 0);
376 c = blobmsg_open_array(&buf, "entries");
377
378 while ((e = readdir(fd)) != NULL)
379 {
380 if (!strcmp(e->d_name, ".") || !strcmp(e->d_name, ".."))
381 continue;
382
383 d = blobmsg_open_table(&buf, NULL);
384 blobmsg_add_string(&buf, "name", e->d_name);
385 blobmsg_add_string(&buf, "type", d_types[e->d_type]);
386 blobmsg_close_table(&buf, d);
387 }
388
389 closedir(fd);
390
391 blobmsg_close_array(&buf, c);
392 ubus_send_reply(ctx, req, buf.head);
393 blob_buf_free(&buf);
394
395 return 0;
396 }
397
398 static int
399 rpc_file_stat(struct ubus_context *ctx, struct ubus_object *obj,
400 struct ubus_request_data *req, const char *method,
401 struct blob_attr *msg)
402 {
403 int type;
404 char *path;
405 struct stat s;
406
407 if (!rpc_check_path(msg, &path, &s))
408 return rpc_errno_status();
409
410 blob_buf_init(&buf, 0);
411
412 type = S_ISREG(s.st_mode) ? DT_REG :
413 S_ISDIR(s.st_mode) ? DT_DIR :
414 S_ISCHR(s.st_mode) ? DT_CHR :
415 S_ISBLK(s.st_mode) ? DT_BLK :
416 S_ISFIFO(s.st_mode) ? DT_FIFO :
417 S_ISLNK(s.st_mode) ? DT_LNK :
418 S_ISSOCK(s.st_mode) ? DT_SOCK :
419 DT_UNKNOWN;
420
421 blobmsg_add_string(&buf, "path", path);
422 blobmsg_add_string(&buf, "type", d_types[type]);
423 blobmsg_add_u32(&buf, "size", s.st_size);
424 blobmsg_add_u32(&buf, "mode", s.st_mode);
425 blobmsg_add_u32(&buf, "atime", s.st_atime);
426 blobmsg_add_u32(&buf, "mtime", s.st_mtime);
427 blobmsg_add_u32(&buf, "ctime", s.st_ctime);
428 blobmsg_add_u32(&buf, "inode", s.st_ino);
429 blobmsg_add_u32(&buf, "uid", s.st_uid);
430 blobmsg_add_u32(&buf, "gid", s.st_gid);
431
432 ubus_send_reply(ctx, req, buf.head);
433 blob_buf_free(&buf);
434
435 return 0;
436 }
437
438 static const char *
439 rpc_file_exec_lookup(const char *cmd)
440 {
441 struct stat s;
442 int plen = 0, clen = strlen(cmd) + 1;
443 char *search, *p;
444 static char path[PATH_MAX];
445
446 if (!stat(cmd, &s) && S_ISREG(s.st_mode))
447 return cmd;
448
449 search = getenv("PATH");
450
451 if (!search)
452 search = "/bin:/usr/bin:/sbin:/usr/sbin";
453
454 p = search;
455
456 do
457 {
458 if (*p != ':' && *p != '\0')
459 continue;
460
461 plen = p - search;
462
463 if ((plen + clen) >= sizeof(path))
464 continue;
465
466 strncpy(path, search, plen);
467 sprintf(path + plen, "/%s", cmd);
468
469 if (!stat(path, &s) && S_ISREG(s.st_mode))
470 return path;
471
472 search = p + 1;
473 }
474 while (*p++);
475
476 return NULL;
477 }
478
479
480 static void
481 rpc_ustream_to_blobmsg(struct ustream *s, const char *name)
482 {
483 int len;
484 char *rbuf, *wbuf;
485
486 if ((len = ustream_pending_data(s, false)) > 0)
487 {
488 wbuf = blobmsg_alloc_string_buffer(&buf, name, len + 1);
489
490 if (!wbuf)
491 return;
492
493 ustream_for_each_read_buffer(s, rbuf, len)
494 {
495 memcpy(wbuf, rbuf, len);
496 wbuf += len;
497 }
498
499 *wbuf = 0;
500 blobmsg_add_string_buffer(&buf);
501 }
502 }
503
504 static void
505 rpc_file_exec_reply(struct rpc_file_exec_context *c, int rv)
506 {
507 uloop_timeout_cancel(&c->timeout);
508 uloop_process_delete(&c->process);
509
510 if (rv == UBUS_STATUS_OK)
511 {
512 blob_buf_init(&buf, 0);
513
514 blobmsg_add_u32(&buf, "code", WEXITSTATUS(c->stat));
515
516 rpc_ustream_to_blobmsg(&c->opipe.stream, "stdout");
517 rpc_ustream_to_blobmsg(&c->epipe.stream, "stderr");
518
519 ubus_send_reply(c->context, &c->request, buf.head);
520 blob_buf_free(&buf);
521 }
522
523 ubus_complete_deferred_request(c->context, &c->request, rv);
524
525 ustream_free(&c->opipe.stream);
526 ustream_free(&c->epipe.stream);
527
528 close(c->opipe.fd.fd);
529 close(c->epipe.fd.fd);
530
531 free(c);
532 }
533
534 static void
535 rpc_file_exec_timeout_cb(struct uloop_timeout *t)
536 {
537 struct rpc_file_exec_context *c =
538 container_of(t, struct rpc_file_exec_context, timeout);
539
540 kill(c->process.pid, SIGKILL);
541 rpc_file_exec_reply(c, UBUS_STATUS_TIMEOUT);
542 }
543
544 static void
545 rpc_file_exec_process_cb(struct uloop_process *p, int stat)
546 {
547 struct rpc_file_exec_context *c =
548 container_of(p, struct rpc_file_exec_context, process);
549
550 c->stat = stat;
551
552 ustream_poll(&c->opipe.stream);
553 ustream_poll(&c->epipe.stream);
554 }
555
556 static void
557 rpc_file_exec_opipe_read_cb(struct ustream *s, int bytes)
558 {
559 struct rpc_file_exec_context *c =
560 container_of(s, struct rpc_file_exec_context, opipe.stream);
561
562 if (ustream_read_buf_full(s))
563 rpc_file_exec_reply(c, UBUS_STATUS_NOT_SUPPORTED);
564 }
565
566 static void
567 rpc_file_exec_epipe_read_cb(struct ustream *s, int bytes)
568 {
569 struct rpc_file_exec_context *c =
570 container_of(s, struct rpc_file_exec_context, epipe.stream);
571
572 if (ustream_read_buf_full(s))
573 rpc_file_exec_reply(c, UBUS_STATUS_NOT_SUPPORTED);
574 }
575
576 static void
577 rpc_file_exec_opipe_state_cb(struct ustream *s)
578 {
579 struct rpc_file_exec_context *c =
580 container_of(s, struct rpc_file_exec_context, opipe.stream);
581
582 if (c->opipe.stream.eof && c->epipe.stream.eof)
583 rpc_file_exec_reply(c, UBUS_STATUS_OK);
584 }
585
586 static void
587 rpc_file_exec_epipe_state_cb(struct ustream *s)
588 {
589 struct rpc_file_exec_context *c =
590 container_of(s, struct rpc_file_exec_context, epipe.stream);
591
592 if (c->opipe.stream.eof && c->epipe.stream.eof)
593 rpc_file_exec_reply(c, UBUS_STATUS_OK);
594 }
595
596 static int
597 rpc_file_exec_run(const char *cmd,
598 const struct blob_attr *arg, const struct blob_attr *env,
599 struct ubus_context *ctx, struct ubus_request_data *req)
600 {
601 pid_t pid;
602
603 int opipe[2];
604 int epipe[2];
605
606 int rem;
607 struct blob_attr *cur;
608
609 char arglen;
610 char **args;
611
612 struct rpc_file_exec_context *c;
613
614 cmd = rpc_file_exec_lookup(cmd);
615
616 if (!cmd)
617 return UBUS_STATUS_NOT_FOUND;
618
619 c = malloc(sizeof(*c));
620
621 if (!c)
622 return UBUS_STATUS_UNKNOWN_ERROR;
623
624 if (pipe(opipe) || pipe(epipe))
625 return rpc_errno_status();
626
627 switch ((pid = fork()))
628 {
629 case -1:
630 return rpc_errno_status();
631
632 case 0:
633 uloop_done();
634
635 dup2(opipe[1], 1);
636 dup2(epipe[1], 2);
637
638 close(0);
639 close(opipe[0]);
640 close(opipe[1]);
641 close(epipe[0]);
642 close(epipe[1]);
643
644 arglen = 2;
645 args = malloc(sizeof(char *) * arglen);
646
647 if (!args)
648 return UBUS_STATUS_UNKNOWN_ERROR;
649
650 args[0] = (char *)cmd;
651 args[1] = NULL;
652
653 if (arg)
654 {
655 blobmsg_for_each_attr(cur, arg, rem)
656 {
657 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
658 continue;
659
660 arglen++;
661
662 if (!(args = realloc(args, sizeof(char *) * arglen)))
663 return UBUS_STATUS_UNKNOWN_ERROR;
664
665 args[arglen-2] = blobmsg_data(cur);
666 args[arglen-1] = NULL;
667 }
668 }
669
670 if (env)
671 {
672 blobmsg_for_each_attr(cur, env, rem)
673 {
674 if (blobmsg_type(cur) != BLOBMSG_TYPE_STRING)
675 continue;
676
677 setenv(blobmsg_name(cur), blobmsg_data(cur), 1);
678 }
679 }
680
681 if (execv(cmd, args))
682 return rpc_errno_status();
683
684 default:
685 memset(c, 0, sizeof(*c));
686
687 ustream_declare(c->opipe, opipe[0], exec_opipe);
688 ustream_declare(c->epipe, epipe[0], exec_epipe);
689
690 c->process.pid = pid;
691 c->process.cb = rpc_file_exec_process_cb;
692 uloop_process_add(&c->process);
693
694 c->timeout.cb = rpc_file_exec_timeout_cb;
695 uloop_timeout_set(&c->timeout, *ops->exec_timeout);
696
697 close(opipe[1]);
698 close(epipe[1]);
699
700 c->context = ctx;
701 ubus_defer_request(ctx, req, &c->request);
702 }
703
704 return UBUS_STATUS_OK;
705 }
706
707 static int
708 rpc_file_exec(struct ubus_context *ctx, struct ubus_object *obj,
709 struct ubus_request_data *req, const char *method,
710 struct blob_attr *msg)
711 {
712 struct blob_attr *tb[__RPC_E_MAX];
713
714 blobmsg_parse(rpc_exec_policy, __RPC_E_MAX, tb,
715 blob_data(msg), blob_len(msg));
716
717 if (!tb[RPC_E_CMD])
718 return UBUS_STATUS_INVALID_ARGUMENT;
719
720 return rpc_file_exec_run(blobmsg_data(tb[RPC_E_CMD]),
721 tb[RPC_E_PARM], tb[RPC_E_ENV], ctx, req);
722 }
723
724
725 static int
726 rpc_file_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx)
727 {
728 static const struct ubus_method file_methods[] = {
729 UBUS_METHOD("read", rpc_file_read, rpc_file_rb_policy),
730 UBUS_METHOD("write", rpc_file_write, rpc_file_rw_policy),
731 UBUS_METHOD("list", rpc_file_list, rpc_file_r_policy),
732 UBUS_METHOD("stat", rpc_file_stat, rpc_file_r_policy),
733 UBUS_METHOD("md5", rpc_file_md5, rpc_file_r_policy),
734 UBUS_METHOD("exec", rpc_file_exec, rpc_exec_policy),
735 };
736
737 static struct ubus_object_type file_type =
738 UBUS_OBJECT_TYPE("luci-rpc-file", file_methods);
739
740 static struct ubus_object obj = {
741 .name = "file",
742 .type = &file_type,
743 .methods = file_methods,
744 .n_methods = ARRAY_SIZE(file_methods),
745 };
746
747 ops = o;
748
749 return ubus_add_object(ctx, &obj);
750 }
751
752 struct rpc_plugin rpc_plugin = {
753 .init = rpc_file_api_init
754 };