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=208b8716ce8fe9dab70db0086fd5e2e28d7d6137;hb=65e6c5916f1cdf89dd597a21cf56f060ddd396b7;hpb=0ce8022fb7701cc270c3011ae9534dc05633aed8 diff --git a/luci2/src/rpcd/luci2.c b/luci2/src/rpcd/luci2.c index 208b871..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 @@ -2136,6 +2138,29 @@ rpc_luci2_ui_acls(struct ubus_context *ctx, struct ubus_object *obj, 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) @@ -2242,7 +2267,9 @@ 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("acls", rpc_luci2_ui_acls) + 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 =