X-Git-Url: http://git.archive.openwrt.org/?p=project%2Fluci2%2Fui.git;a=blobdiff_plain;f=luci2%2Fsrc%2Frpcd%2Fluci2.c;h=1661424d72244eeb6ce42e6830f2b275d63659b3;hp=f136c56eaf87e7f5cfa62dec47bfe4f15fedf606;hb=65e6c5916f1cdf89dd597a21cf56f060ddd396b7;hpb=2f0e65dd27549ef4fde5b18588083968a59b66bd diff --git a/luci2/src/rpcd/luci2.c b/luci2/src/rpcd/luci2.c index f136c56..1661424 100644 --- a/luci2/src/rpcd/luci2.c +++ b/luci2/src/rpcd/luci2.c @@ -16,6 +16,8 @@ * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#define _GNU_SOURCE /* crypt() */ + #include #include #include @@ -31,6 +33,7 @@ #include #include #include +#include #include #include @@ -41,7 +44,7 @@ #define RPC_LUCI2_DEF_LOGSIZE (16 * 1024) /* location of menu definitions */ -#define RPC_LUCI2_MENU_FILES "/usr/share/luci2/menu.d/*.json" /* */ +#define RPC_LUCI2_MENU_FILES "/usr/share/rpcd/menu.d/*.json" /* */ static const struct rpc_daemon_ops *ops; @@ -1998,7 +2001,7 @@ menu_access(struct blob_attr *sid, struct blob_attr *acls, struct blob_buf *e) blobmsg_for_each_attr(acl, acls, rem) { - if (!ops->session_access(blobmsg_data(sid), "luci-ui", + if (!ops->session_access(blobmsg_data(sid), "access-group", blobmsg_data(acl), "read")) { rv = false; @@ -2006,7 +2009,7 @@ menu_access(struct blob_attr *sid, struct blob_attr *acls, struct blob_buf *e) } blobmsg_add_u8(e, blobmsg_data(acl), - ops->session_access(blobmsg_data(sid), "luci-ui", + ops->session_access(blobmsg_data(sid), "access-group", blobmsg_data(acl), "write")); } @@ -2087,6 +2090,78 @@ skip: } +static void +parse_acl_file(struct blob_buf *acls, const char *path) +{ + struct blob_buf acl = { 0 }; + struct blob_attr *cur; + void *c; + int rem; + + blob_buf_init(&acl, 0); + + if (blobmsg_add_json_from_file(&acl, path)) + { + c = blobmsg_open_table(acls, NULL); + + blob_for_each_attr(cur, acl.head, rem) + blobmsg_add_blob(acls, cur); + + blobmsg_close_table(acls, c); + } + + blob_buf_free(&acl); +} + +static int +rpc_luci2_ui_acls(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + int i; + void *c; + glob_t gl; + + if (glob(RPC_SESSION_ACL_DIR "/*.json", 0, NULL, &gl)) + return rpc_errno_status(); + + blob_buf_init(&buf, 0); + c = blobmsg_open_array(&buf, "acls"); + + for (i = 0; i < gl.gl_pathc; i++) + parse_acl_file(&buf, gl.gl_pathv[i]); + + globfree(&gl); + blobmsg_close_array(&buf, c); + + ubus_send_reply(ctx, req, buf.head); + return 0; +} + +static int +rpc_luci2_ui_crypt(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + char *hash; + struct blob_attr *tb[__RPC_D_MAX]; + + blobmsg_parse(rpc_data_policy, __RPC_D_MAX, tb, + blob_data(msg), blob_len(msg)); + + if (!tb[RPC_D_DATA] || blobmsg_data_len(tb[RPC_D_DATA]) >= 128) + return UBUS_STATUS_INVALID_ARGUMENT; + + hash = crypt(blobmsg_get_string(tb[RPC_D_DATA]), "$1$"); + + blob_buf_init(&buf, 0); + blobmsg_add_string(&buf, "crypt", hash); + + ubus_send_reply(ctx, req, buf.head); + return 0; +} + + static int rpc_luci2_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx) { @@ -2191,7 +2266,10 @@ rpc_luci2_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx) static const struct ubus_method luci2_ui_methods[] = { - UBUS_METHOD_NOARG("menu", rpc_luci2_ui_menu) + UBUS_METHOD_NOARG("menu", rpc_luci2_ui_menu), + UBUS_METHOD_NOARG("acls", rpc_luci2_ui_acls), + UBUS_METHOD("crypt", rpc_luci2_ui_crypt, + rpc_data_policy) }; static struct ubus_object_type luci2_ui_type =