From patchwork Wed Oct 3 13:36:17 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Hans Dedecker X-Patchwork-Id: 978333 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=lists.openwrt.org (client-ip=2607:7c80:54:e::133; helo=bombadil.infradead.org; envelope-from=openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org; receiver=) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="oRE81OZD"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OJBFRsEk"; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 42QHF568l4z9s7h for ; Wed, 3 Oct 2018 23:39:37 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id:Subject:References: In-Reply-To:Message-Id:Date:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=hw3vK5Bf5JoeZ0Vfk5ARllDgg+kmJ35JyCjEzkdxL6Y=; b=oRE81OZD9MCXE3 EDM6LThYjh5ktWztMCP1e4TXGTZM5a89JEC8u4mrWbpKJF8y2b4FbAvcmgLtUr42m95plccL1b/tq P15pWnYXRUTTtlmQMlkzX8YEIo5rcU9iOkvxuC2kLBN4Uw0h7mN6uIB7aMuhq9xdyvAIdyP7Kq3/d /cO1kmoYDuvTRgxkoTRHYTfozMjeviQ7sW8M5+kcYSOWQs8jNRPbA+REpHqu6ybO6I08VmaGFV3QW SGSFtc8H40liEfQUC7HFtY/TFkWED4PmWda8qp80GzLegQb86quoD9lRAkKPniKGlW2QX/fYs41Si 65DzxxDt3pBrDDoXbt0g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.90_1 #2 (Red Hat Linux)) id 1g7hNA-0006NT-7Z; Wed, 03 Oct 2018 13:39:28 +0000 Received: from mail-wm1-f50.google.com ([209.85.128.50]) by bombadil.infradead.org with esmtps (Exim 4.90_1 #2 (Red Hat Linux)) id 1g7hKS-0005Ce-Vz for openwrt-devel@lists.openwrt.org; Wed, 03 Oct 2018 13:38:27 +0000 Received: by mail-wm1-f50.google.com with SMTP id 185-v6so5705431wmt.2 for ; Wed, 03 Oct 2018 06:36:30 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=VludbmG2lAjOX3fsF+cnY7R9q4gEQwcdZxGfNSi+PKo=; b=OJBFRsEkmhqpZQO0qekPAYdz+jrfyZRXTIqUe7h0qfEVLIzSrqTytfh0by6MoN3b0p OfguTLvRkb7K2hgsS8dz89VbnsqbuXc4OPb0GCNrmrbLlv+bfY/Y7fmvmwrvo4As4XsQ FDXxnLO26zOYgelzYzQUyhKLlvQ0Lw7luGMH2icU1aFkThTsh4IxU/INZcU3q/b/kNGk OCNClojFKCvU0xxJNo7UdnOzCNQP2fmC7JihiPW3IaCm5+CgpkS6NezgkpliZvDDoNEP w/We0rRZsWCI3xKHx2jPEevPFiWSA+iHfD61XgqZuKMICRiTbn9n22NsCL5CXCiOjjD1 Je7w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=VludbmG2lAjOX3fsF+cnY7R9q4gEQwcdZxGfNSi+PKo=; b=IVAwxo5dAnjwScQo04OdK21ziF88Ul4yHglddCxD0DUO6IWAnxdnwsQgzgp6bkmEIm oSV6SBjntHDtQzIO5V3TwmJ1G0yEFtS3zyfRfoyPbROVO2IgiTUmgzDMXKOWQd0mgFeq JFLcNKbuHHS3MO86tbhZA06KoOgZKPF6b0v6RvzJlKcUt7IiJtKCVo9PWxm9LN627jc+ wN6BaCKpyYg8mBeQnh9NUcTDJQYWSkNiH/RNoFqJrAW4Mwf984wzhI4kqZn/QBPgjtBu Su19FUbwrbZ5dt2AJBx6/nl9xx5YPYxfF/wU2Vd1dtjmwk0J9oC7SSxXOQK4njleFAyS uxEA== X-Gm-Message-State: ABuFfogqD/M6a59ybJblsnJvPf4tukfeeSzHibblUJWodDkjpwWtNVXh JBCvu0lFtVJe2G854rd6dtoYNsKG X-Google-Smtp-Source: ACcGV63YPy5E64n7yXXy85JhC9tfWZSBOruDY4MbL64oQTYHIz2MM+hNS1H+4p3BvLSL7G6o6c4p7Q== X-Received: by 2002:a1c:13c4:: with SMTP id 187-v6mr1567196wmt.66.1538573788331; Wed, 03 Oct 2018 06:36:28 -0700 (PDT) Received: from cplx43.eu.thmulti.com (14.125.146.82.ipv4.evonet.be. [82.146.125.14]) by smtp.gmail.com with ESMTPSA id a6-v6sm1815633wmf.22.2018.10.03.06.36.27 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Wed, 03 Oct 2018 06:36:27 -0700 (PDT) From: Hans Dedecker To: openwrt-devel@lists.openwrt.org Date: Wed, 3 Oct 2018 15:36:17 +0200 Message-Id: <20181003133618.8371-3-dedeckeh@gmail.com> X-Mailer: git-send-email 2.18.0 In-Reply-To: <20181003133618.8371-1-dedeckeh@gmail.com> References: <20181003133618.8371-1-dedeckeh@gmail.com> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20181003_063641_061719_99A20824 X-CRM114-Status: GOOD ( 13.31 ) X-Spam-Score: -0.1 (/) X-Spam-Report: SpamAssassin version 3.4.1 on bombadil.infradead.org summary: Content analysis details: (-0.1 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at http://www.dnswl.org/, no trust [209.85.128.50 listed in list.dnswl.org] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider (dedeckeh[at]gmail.com) -0.0 SPF_PASS SPF: sender matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain Subject: [OpenWrt-Devel] [PATCH 3/4][ubus] ubusd_acl: event listen access list support X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hans Dedecker , john@phrozen.org, Koen Dergent , nbd@nbd.name MIME-Version: 1.0 Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Adds event listen access list support in ubus via the "listen" keyword Example of a json file: { "user": "superuser", "listen": [ "network.*" ], } Signed-off-by: Koen Dergent Signed-off-by: Hans Dedecker --- ubusd_acl.c | 20 ++++++++++++++++++++ ubusd_acl.h | 1 + ubusd_event.c | 3 +++ 3 files changed, 24 insertions(+) diff --git a/ubusd_acl.c b/ubusd_acl.c index fc11993..992d0ea 100644 --- a/ubusd_acl.c +++ b/ubusd_acl.c @@ -51,6 +51,7 @@ struct ubusd_acl_obj { struct blob_attr *priv; bool subscribe; bool publish; + bool listen; }; struct ubusd_acl_file { @@ -132,6 +133,11 @@ ubusd_acl_check(struct ubus_client *cl, const char *obj, return 0; break; + case UBUS_ACL_LISTEN: + if (acl->listen) + return 0; + break; + case UBUS_ACL_ACCESS: if (acl->methods) { struct blob_attr *cur; @@ -279,6 +285,13 @@ ubusd_acl_add_publish(struct ubusd_acl_file *file, const char *obj) o->publish = true; } +static void ubusd_acl_add_listen(struct ubusd_acl_file *file, const char *obj) +{ + struct ubusd_acl_obj *o = ubusd_acl_alloc_obj(file, obj); + + o->listen = true; +} + enum { ACL_USER, ACL_GROUP, @@ -286,6 +299,7 @@ enum { ACL_PUBLISH, ACL_SUBSCRIBE, ACL_INHERIT, + ACL_LISTEN, __ACL_MAX }; @@ -296,6 +310,7 @@ static const struct blobmsg_policy acl_policy[__ACL_MAX] = { [ACL_PUBLISH] = { .name = "publish", .type = BLOBMSG_TYPE_ARRAY }, [ACL_SUBSCRIBE] = { .name = "subscribe", .type = BLOBMSG_TYPE_ARRAY }, [ACL_INHERIT] = { .name = "inherit", .type = BLOBMSG_TYPE_ARRAY }, + [ACL_LISTEN] = { .name= "listen", .type = BLOBMSG_TYPE_ARRAY }, }; static void @@ -327,6 +342,11 @@ ubusd_acl_file_add(struct ubusd_acl_file *file) blobmsg_for_each_attr(cur, tb[ACL_PUBLISH], rem) if (blobmsg_type(cur) == BLOBMSG_TYPE_STRING) ubusd_acl_add_publish(file, blobmsg_get_string(cur)); + + if (tb[ACL_LISTEN]) + blobmsg_for_each_attr(cur, tb[ACL_LISTEN], rem) + if (blobmsg_type(cur) == BLOBMSG_TYPE_STRING) + ubusd_acl_add_listen(file, blobmsg_get_string(cur)); } static void diff --git a/ubusd_acl.h b/ubusd_acl.h index c5dfd8a..a6a6a30 100644 --- a/ubusd_acl.h +++ b/ubusd_acl.h @@ -18,6 +18,7 @@ enum ubusd_acl_type { UBUS_ACL_PUBLISH, UBUS_ACL_SUBSCRIBE, UBUS_ACL_ACCESS, + UBUS_ACL_LISTEN, }; int ubusd_acl_check(struct ubus_client *cl, const char *obj, const char *method, enum ubusd_acl_type type); diff --git a/ubusd_event.c b/ubusd_event.c index f07f826..6e612a1 100644 --- a/ubusd_event.c +++ b/ubusd_event.c @@ -88,6 +88,9 @@ static int ubusd_alloc_event_pattern(struct ubus_client *cl, struct blob_attr *m len--; } + if (pattern[0] && ubusd_acl_check(cl, pattern, NULL, UBUS_ACL_LISTEN)) + return UBUS_STATUS_PERMISSION_DENIED; + ev = calloc(1, sizeof(*ev) + len + 1); if (!ev) return UBUS_STATUS_NO_DATA;