From patchwork Fri Oct 23 00:58:27 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Christian Marangi X-Patchwork-Id: 1386481 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.openwrt.org (client-ip=2001:8b0:10b:1231::1; helo=merlin.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; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=merlin.20170209 header.b=WG5AUFBN; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=FKgbveWt; dkim-atps=neutral Received: from merlin.infradead.org (merlin.infradead.org [IPv6:2001:8b0:10b:1231::1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CHQtS1rwLz9sSn for ; Fri, 23 Oct 2020 12:02:07 +1100 (AEDT) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=merlin.20170209; h=Sender:Content-Transfer-Encoding: Content-Type:Cc:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=nfqkl2VdUIkXzVNKDOKdZHnP0+EkhjsZC7OyxZ24Egk=; b=WG5AUFBNWclyvyRg30Ujh3lHDi UKuJsRFZ54lfYrXzO8PqE0ZtO0KglE0HpbdVr/bc1jsOhpoX5CEqo41T0iP7zZBTQorZNHn47L+mm /WVNCmuhAqgtUULGSiKqfxptm7UKJq7try8CWNF8ZCY7GgjpPLLbqGSqAAcct4FW6bhpTFrnUKUB5 n2Zcnbk/5m8nq2REur4Eoh16Xi5EolKZ7utjeCLc97lyfw1BIHGW8aKE4yTYRq9VGUw/EbQLjrwX+ YvWxIPmboZQgao2TWTrfx0JKpMTAENqdH/+jvLQ/+zWglzjXrBolNlaoAB5vHMjk2hGL1VVyycvQR Xwx0L82Q==; Received: from localhost ([::1] helo=merlin.infradead.org) by merlin.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVlQY-0007lY-Bs; Fri, 23 Oct 2020 00:59:30 +0000 Received: from mail-ej1-x62b.google.com ([2a00:1450:4864:20::62b]) by merlin.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1kVlQV-0007l7-1P for openwrt-devel@lists.openwrt.org; Fri, 23 Oct 2020 00:59:27 +0000 Received: by mail-ej1-x62b.google.com with SMTP id w27so32170ejb.3 for ; Thu, 22 Oct 2020 17:59:23 -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:mime-version :content-transfer-encoding; bh=B0QtDR4AYknjX0D+K/Jbh78mrFz6atfcvouNcxBewB0=; b=FKgbveWt99nbnth5lsl9cDkSDLb8P6VIQAXvpXzJmxCPp0ftRkFYk8DYpPnLMDcu3u i/bOqqAjbDsbsTvQdWwkEFKF9izKG/ByI5oJKTEJm36pC4aU2i1zBQas/vfY/dMSVUKG mfMd+pVb6VgM1+9/4zO8k9lVa4mFud9fHOg5hCt0WHmulne6e3pSULUDNeWRaJ39aXXO GgV8bMyObQ2MGWT2qAlCW9YirhvqzxVRYH0s20xqUHnWbZmhfSBZGEF1C5tFRkUp0NZJ l7MQhGgHuhNrG1dJn1SGOOoWNTEhm+8HsVkkfUCsiw4e9+Av80XKeidJKrTuCtHZOcpe 7oJQ== 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:mime-version :content-transfer-encoding; bh=B0QtDR4AYknjX0D+K/Jbh78mrFz6atfcvouNcxBewB0=; b=tzgrWqCNPVLP8IpJdvhhQWokw9heIkZPSHdZpY3aE8x6YGTnl5hVzJaXG3z96ch942 zJ9NK7eRQswBmawLjJoCoB2DGBSRSAMDujmhwA5uY2gpKeb0rvooRfHWDy5FCdsOCRD7 iAFzUHVwi8Wy0s3+6TdX7CjvwnZ7ZLv+OHLgmTkSdsCepIKYn9oQmQnFUIGLswoNCKdc B/rdmKKNpUHUPUaxFQ5C/eKkDlt2mzw23ZC2J9X2cJ07LeJMd9cJq6wUsSpLmEQ//YvA yUQ+r2y4lwW3ZI+iSc2HBqBSxTQmLdAfDC9K92amNtDAXXqBHzmZYf3CNsfgugi5CwE/ C/ag== X-Gm-Message-State: AOAM530w6fVz9QfROHog9yZQtpMAhJ3+Nsf+5goZ9VhFHea0tT0U0KNc JIqMrykRQgPiZzynvcHEQCmifWcXHQ+G/0vx X-Google-Smtp-Source: ABdhPJwjvOH1HeqCrQM//u5PByIK4RCNZ32BlacxEJdsRO0lRaE47qQlZrdgyF9o7dQAT/k9py5efw== X-Received: by 2002:a17:906:4b0f:: with SMTP id y15mr4710992eju.198.1603414762306; Thu, 22 Oct 2020 17:59:22 -0700 (PDT) Received: from Ansuel-XPS.localdomain (93-39-149-95.ip76.fastwebnet.it. [93.39.149.95]) by smtp.googlemail.com with ESMTPSA id a10sm1310edu.78.2020.10.22.17.58.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Oct 2020 17:58:54 -0700 (PDT) From: Ansuel Smith To: openwrt-devel@lists.openwrt.org Subject: [PATCH ubus] ubusd_acl: add support for wildcard in methods Date: Fri, 23 Oct 2020 02:58:27 +0200 Message-Id: <20201023005827.16234-1-ansuelsmth@gmail.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20201022_205927_129253_1EAE621E X-CRM114-Status: GOOD ( 19.10 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on merlin.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2a00:1450:4864:20:0:0:0:62b listed in] [list.dnswl.org] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [ansuelsmth[at]gmail.com] -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Ansuel Smith Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Add support for wildcard in methods to permiss access to all methods defined by the object. This can be usefull for process that run as non-root user and needs to access ubus method. Signed-off-by: Ansuel Smith --- ...-add-support-for-wildcard-in-methods.patch | 37 +++++++++++++++++++ ubusd_acl.c | 8 +++- 2 files changed, 43 insertions(+), 2 deletions(-) create mode 100644 0001-ubusd_acl-add-support-for-wildcard-in-methods.patch diff --git a/0001-ubusd_acl-add-support-for-wildcard-in-methods.patch b/0001-ubusd_acl-add-support-for-wildcard-in-methods.patch new file mode 100644 index 0000000..48dff5d --- /dev/null +++ b/0001-ubusd_acl-add-support-for-wildcard-in-methods.patch @@ -0,0 +1,37 @@ +From a1a5e03e652ac22851c58c68639d7d79ce5fc9ce Mon Sep 17 00:00:00 2001 +From: Ansuel Smith +Date: Fri, 23 Oct 2020 02:50:12 +0200 +Subject: [PATCH ubus] ubusd_acl: add support for wildcard in methods + +Add support for wildcard in methods to permiss access to all methods +defined by the object. This can be usefull for process that run as +non-root user and needs to access ubus method. + +Signed-off-by: Ansuel Smith +--- + ubusd_acl.c | 5 ++++- + 1 file changed, 4 insertions(+), 1 deletion(-) + +diff --git a/ubusd_acl.c b/ubusd_acl.c +index e426a4a..734b3d0 100644 +--- a/ubusd_acl.c ++++ b/ubusd_acl.c +@@ -147,11 +147,14 @@ ubusd_acl_check(struct ubus_client *cl, const char *obj, + case UBUS_ACL_ACCESS: + if (acl->methods) { + struct blob_attr *cur; ++ char *cur_method; + size_t rem; + + blobmsg_for_each_attr(cur, acl->methods, rem) + if (blobmsg_type(cur) == BLOBMSG_TYPE_STRING) +- if (!strcmp(method, blobmsg_get_string(cur))) ++ cur_method = blobmsg_get_string(cur); ++ ++ if (!strcmp(method, cur_method) || !strcmp("*", cur_method)) + return 0; + } + break; +-- +2.27.0 + diff --git a/ubusd_acl.c b/ubusd_acl.c index e426a4a..e050e2c 100644 --- a/ubusd_acl.c +++ b/ubusd_acl.c @@ -147,12 +147,16 @@ ubusd_acl_check(struct ubus_client *cl, const char *obj, case UBUS_ACL_ACCESS: if (acl->methods) { struct blob_attr *cur; + char *cur_method; size_t rem; blobmsg_for_each_attr(cur, acl->methods, rem) - if (blobmsg_type(cur) == BLOBMSG_TYPE_STRING) - if (!strcmp(method, blobmsg_get_string(cur))) + if (blobmsg_type(cur) == BLOBMSG_TYPE_STRING) { + cur_method = blobmsg_get_string(cur); + + if (!strcmp(method, cur_method) || !strcmp("*", cur_method)) return 0; + } } break; }