From 65e6c5916f1cdf89dd597a21cf56f060ddd396b7 Mon Sep 17 00:00:00 2001 From: Jo-Philipp Wich Date: Tue, 17 Sep 2013 20:15:48 +0200 Subject: [PATCH] rpcd: add luci2.ui.crypt call --- luci2/src/rpcd/CMakeLists.txt | 7 ++++++- luci2/src/rpcd/luci2.c | 29 ++++++++++++++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/luci2/src/rpcd/CMakeLists.txt b/luci2/src/rpcd/CMakeLists.txt index 6693da5..b151889 100644 --- a/luci2/src/rpcd/CMakeLists.txt +++ b/luci2/src/rpcd/CMakeLists.txt @@ -11,8 +11,13 @@ IF(APPLE) LINK_DIRECTORIES(/opt/local/lib) ENDIF() +FIND_LIBRARY(crypt NAMES crypt) +IF(crypt STREQUAL "LIBS-NOTFOUND") + SET(crypt "") +ENDIF() + ADD_LIBRARY(luci2-plugin MODULE luci2.c) -TARGET_LINK_LIBRARIES(luci2-plugin ubox ubus) +TARGET_LINK_LIBRARIES(luci2-plugin ubox ubus ${crypt}) SET_TARGET_PROPERTIES(luci2-plugin PROPERTIES OUTPUT_NAME luci2 PREFIX "") INSTALL(TARGETS luci2-plugin LIBRARY DESTINATION lib) 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 = -- 2.11.0