rpcd: add luci2.ui.crypt call
authorJo-Philipp Wich <jow@openwrt.org>
Tue, 17 Sep 2013 18:15:48 +0000 (20:15 +0200)
committerJo-Philipp Wich <jow@openwrt.org>
Tue, 17 Sep 2013 18:18:17 +0000 (20:18 +0200)
luci2/src/rpcd/CMakeLists.txt
luci2/src/rpcd/luci2.c

index 6693da5..b151889 100644 (file)
@@ -11,8 +11,13 @@ IF(APPLE)
   LINK_DIRECTORIES(/opt/local/lib)
 ENDIF()
 
   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)
 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)
 SET_TARGET_PROPERTIES(luci2-plugin PROPERTIES OUTPUT_NAME luci2 PREFIX "")
 
 INSTALL(TARGETS luci2-plugin LIBRARY DESTINATION lib)
index 208b871..1661424 100644 (file)
@@ -16,6 +16,8 @@
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
  */
 
+#define _GNU_SOURCE /* crypt() */
+
 #include <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
 #include <fcntl.h>
 #include <errno.h>
 #include <unistd.h>
@@ -2136,6 +2138,29 @@ rpc_luci2_ui_acls(struct ubus_context *ctx, struct ubus_object *obj,
        return 0;
 }
 
        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)
 
 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),
 
        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 =
        };
 
        static struct ubus_object_type luci2_ui_type =