From patchwork Sun Mar 15 21:00:50 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Luka Perkov X-Patchwork-Id: 450335 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from arrakis.dune.hu (arrakis.dune.hu [78.24.191.176]) (using TLSv1.1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 7BCCB14007F for ; Mon, 16 Mar 2015 08:01:36 +1100 (AEDT) Received: from arrakis.dune.hu (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 7BF752803E9; Sun, 15 Mar 2015 22:00:56 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.2 (2011-06-06) on arrakis.dune.hu X-Spam-Level: X-Spam-Status: No, score=-2.5 required=5.0 tests=ALL_TRUSTED,BAYES_00 autolearn=unavailable version=3.3.2 Received: from localhost (localhost [127.0.0.1]) by arrakis.dune.hu (Postfix) with ESMTP id 8C6382803E9; Sun, 15 Mar 2015 22:00:51 +0100 (CET) X-Virus-Scanned: at arrakis.dune.hu Received: from t530.lan (141-138-0-166.dhcp.iskon.hr [141.138.0.166]) by arrakis.dune.hu (Postfix) with ESMTPSA id CE48C28039B; Sun, 15 Mar 2015 22:00:49 +0100 (CET) From: Luka Perkov To: openwrt-devel@lists.openwrt.org Date: Sun, 15 Mar 2015 22:00:50 +0100 Message-Id: <1426453252-30326-1-git-send-email-luka@openwrt.org> X-Mailer: git-send-email 2.3.3 Cc: Luka Perkov Subject: [OpenWrt-Devel] [PATCH 1/3] [rpcd] file: add md5sum support X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: openwrt-devel-bounces@lists.openwrt.org Sender: "openwrt-devel" Signed-off-by: Luka Perkov --- file.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) diff --git a/file.c b/file.c index 31a937d..9e87a10 100644 --- a/file.c +++ b/file.c @@ -27,6 +27,7 @@ #include #include #include +#include #include #include @@ -237,6 +238,41 @@ rpc_file_write(struct ubus_context *ctx, struct ubus_object *obj, } static int +rpc_file_md5(struct ubus_context *ctx, struct ubus_object *obj, + struct ubus_request_data *req, const char *method, + struct blob_attr *msg) +{ + int rv, i; + char *path; + struct stat s; + uint8_t md5[16]; + char *wbuf; + + if (!rpc_check_path(msg, &path, &s)) + return rpc_errno_status(); + + if (!S_ISREG(s.st_mode)) + return UBUS_STATUS_NOT_SUPPORTED; + + if ((rv = md5sum(path, md5)) <= 0) + return rpc_errno_status(); + + blob_buf_init(&buf, 0); + wbuf = blobmsg_alloc_string_buffer(&buf, "md5", 33); + + for (i = 0; i < 16; i++) + sprintf((wbuf + (i * 2)), "%02x", (uint8_t) md5[i]); + + *(wbuf + 33) = 0; + + blobmsg_add_string_buffer(&buf); + ubus_send_reply(ctx, req, buf.head); + blob_buf_free(&buf); + + return UBUS_STATUS_OK; +} + +static int rpc_file_list(struct ubus_context *ctx, struct ubus_object *obj, struct ubus_request_data *req, const char *method, struct blob_attr *msg) @@ -611,6 +647,7 @@ rpc_file_api_init(const struct rpc_daemon_ops *o, struct ubus_context *ctx) UBUS_METHOD("write", rpc_file_write, rpc_file_rw_policy), UBUS_METHOD("list", rpc_file_list, rpc_file_r_policy), UBUS_METHOD("stat", rpc_file_stat, rpc_file_r_policy), + UBUS_METHOD("md5", rpc_file_md5, rpc_file_r_policy), UBUS_METHOD("exec", rpc_file_exec, rpc_exec_policy), };