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