From patchwork Mon May 24 12:42:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Arjun AK X-Patchwork-Id: 1483046 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=none (no SPF record) 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; dkim=pass (2048-bit key; secure) header.d=lists.infradead.org header.i=@lists.infradead.org header.a=rsa-sha256 header.s=bombadil.20210309 header.b=0km2V8JG; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=infradead.org header.i=@infradead.org header.a=rsa-sha256 header.s=casper.20170209 header.b=k/3vQrCp; 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=BBBC9drT; dkim-atps=neutral Received: from bombadil.infradead.org (bombadil.infradead.org [IPv6:2607:7c80:54:e::133]) (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 4Fpx1m1BCWz9s1l for ; Tue, 25 May 2021 11:14:20 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc :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=8mCWznpupRjSB3t+w++WsqIAqMzURj6yVh+OV5Nf4EM=; b=0km2V8JGT+Px3X Kl3n2Fnqm0DUo7yucT2RlXxkrPV/T3cGh9yOejyblCOiYxwgrekaihfyHYU4TAsVx8077bi6DvLh2 ag5w6jGpgAniNLp50+yMKn4ievy1KXjtPQr0y7aKGHOH+kSEzbdOahKO5o2Gtw6J/bXrYD5S0o8GV 23Ii9czn9caQMc/cSIUSK/YT/JXM+y43/wzKp1CdZJMLC6VCinBoP0kE34PkPv80XXCKQa/1xK2v/ l6SZSdIR/carbSsmnTkGBg0a+GR74u1yRio1KY/LnxpYjOWcHSrh4WbkGyuUf1wwgYY3DgHY19DK3 EvZCcD+3B43db9oBkvcw==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1llLc3-002irN-HS; Tue, 25 May 2021 01:12:04 +0000 Received: from casper.infradead.org ([2001:8b0:10b:1236::1]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1llGsO-001mzS-5D for openwrt-devel@bombadil.infradead.org; Mon, 24 May 2021 20:08:36 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=casper.20170209; h=Content-Transfer-Encoding:MIME-Version: Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type:Content-ID: Content-Description:In-Reply-To:References; bh=bUZOEUMUkAhO0W7zp/yX/fmyocyT5qEtYCBIrdhlCh8=; b=k/3vQrCp9gQtgGW5DM+sSyIeMw NPtqg/AmtyphIHFStEM7J+y0fz/2kVKpFR0pUI9hYdx9sa9dYKAGM0i8/BI8baLaxFE+yiEV5T4Nz 9bdbWWCxXjyI6CTeSncJ1mNAViWZzJkaMcDzvebijcOnsQlFz4lCLrcGEegJCRaT/sgK7ArhcVL9X SwyxP5JwFxEiodZ+4Nw944sm7t+3r9MM6k5jp7tTD13ZeIXhbbBpAdM4UJ54+oHHeSr73aYIjVAMk zKqDSc34uZP1u2eUhqovtPO71n4Fz09tiPNpT4pyyvzK32SpLSUaT/FvsooLgn7RsKmcuZIrNvE2O 6Vd229LA==; Received: from mail-pl1-x631.google.com ([2607:f8b0:4864:20::631]) by casper.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1ll9w8-002MvU-Vr for openwrt-devel@lists.openwrt.org; Mon, 24 May 2021 12:44:17 +0000 Received: by mail-pl1-x631.google.com with SMTP id a7so5875573plh.3 for ; Mon, 24 May 2021 05:44:00 -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=bUZOEUMUkAhO0W7zp/yX/fmyocyT5qEtYCBIrdhlCh8=; b=BBBC9drTyyNGtxoLDfjRnU7OTEGruWieFrEULlBsN3pHWFYPpGXjSNK/Fkf5yn9XqE DlvtUREuCgAEQ6ZEeg4Ela0raxc2iqpkYvkpgnuLSTwU5WZWNVqcIqhSI2j05FjIixEF a0khw2Nr+6H1PGUHI9jLC0G4lLa+tcDF4V0psR+i4dwtaeMW6DH2YrWEHoRAUYI1IZhI /gJtgPzkD2I/vv/TEV/9Xx0P80IS3oadijnT5L+Opf7unpWK/FYjck22EzIwD/gLsni+ m4AUApNbmpd5wPmz+urPECqyb5SKaMy3DVuodQZNNuW+dYOgUFUdaq5ABXXtmRizDPYr lU5A== 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=bUZOEUMUkAhO0W7zp/yX/fmyocyT5qEtYCBIrdhlCh8=; b=HhhXJJLmEWfSNODKUoYF1MYzXYRrwlAvIX89nLOHnGJNsu1wJgdD2L6VomvGyRxonb seyy7YaROJt6hZJJYbeCs4WivcnZbFBwti88y2oHp5D5VSIKCsXCAzlaGy7GBFMtO+zo e7jdNXBgRcTVLjaBkJyERKTt9Ck9EA0MuBJtSloWBoo4yi962lThEromZw3JjysNZ5+R 8yIzcVULE+ISlOB8cS426Mu/22BCDt4YNqv4NoFNktUW3IOM0v+5cI0HAU71bm7rutny 0k0Ie5c2S1hB+LIdUqvgm2LZflfuPPov7XIEyyGOm6WP+iUfulQW8LHdEL4aAyd0WhUX q7pg== X-Gm-Message-State: AOAM530844eUY6dMPxEyX2XNHKH0eXfmHEwH74/Ij++ExKzz2+hncQe2 Say1GpJUiWVutGlvY70TB/Asi9Igq7o= X-Google-Smtp-Source: ABdhPJz52B2YjdMkVHMiuSXDYVL6ltCpOcjtop5AJF5f8L5yVQZ/FtNZ/F4UFFuuB3KSjejOkvbVmg== X-Received: by 2002:a17:902:e88f:b029:f6:1818:33c4 with SMTP id w15-20020a170902e88fb02900f6181833c4mr22609417plg.8.1621860177047; Mon, 24 May 2021 05:42:57 -0700 (PDT) Received: from debian.lan ([49.206.14.41]) by smtp.gmail.com with ESMTPSA id k15sm11354162pfi.0.2021.05.24.05.42.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 24 May 2021 05:42:56 -0700 (PDT) From: Arjun AK To: openwrt-devel@lists.openwrt.org Cc: Arjun AK Subject: [PATCH] Allow uci to work with symlinked config files Date: Mon, 24 May 2021 18:12:37 +0530 Message-Id: <20210524124237.9665-1-arjunak234@gmail.com> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210524_134408_154035_85C4452A X-CRM114-Status: GOOD ( 12.15 ) X-Spam-Score: -1.8 (-) X-Spam-Report: SpamAssassin version 3.4.6 on casper.infradead.org summary: Content analysis details: (-1.8 points, 5.0 required) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:631 listed in] [list.dnswl.org] -1.9 BAYES_00 BODY: Bayes spam probability is 0 to 1% [score: 0.0000] 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.0 SPF_PASS SPF: sender matches SPF record 0.2 FREEMAIL_ENVFROM_END_DIGIT Envelope-from freemail username ends in digit [arjunak234[at]gmail.com] 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [arjunak234[at]gmail.com] -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_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 X-BeenThere: openwrt-devel@lists.openwrt.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: OpenWrt Development List List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "openwrt-devel" Errors-To: openwrt-devel-bounces+incoming=patchwork.ozlabs.org@lists.openwrt.org Instead of creating the temp file in "/etc/config" it should be created where the config file actually exists (if the file is symlinked, it might be in another mount point and "rename()" will fail) Signed-off-by: Arjun AK --- file.c | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/file.c b/file.c index 93abfae..f7dfa2d 100644 --- a/file.c +++ b/file.c @@ -29,6 +29,7 @@ #include #include #include +#include #include "uci.h" #include "uci_internal.h" @@ -737,6 +738,7 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag char *volatile name = NULL; char *volatile path = NULL; char *filename = NULL; + char *conf_dir = NULL; struct stat statbuf; volatile bool do_rename = false; int fd, sz; @@ -748,9 +750,17 @@ static void uci_file_commit(struct uci_context *ctx, struct uci_package **packag UCI_THROW(ctx, UCI_ERR_INVAL); } - sz = snprintf(NULL, 0, "%s/.%s.uci-XXXXXX", ctx->confdir, p->e.name); + path = realpath(p->path, NULL); + if (path == NULL) { + UCI_THROW(ctx, UCI_ERR_INVAL); + } + conf_dir = dirname(path); + + sz = snprintf(NULL, 0, "%s/.%s.uci-XXXXXX", conf_dir, p->e.name); filename = alloca(sz + 1); - snprintf(filename, sz + 1, "%s/.%s.uci-XXXXXX", ctx->confdir, p->e.name); + snprintf(filename, sz + 1, "%s/.%s.uci-XXXXXX", conf_dir, p->e.name); + + free(path); /* open the config file for writing now, so that it is locked */ f1 = uci_open_stream(ctx, p->path, NULL, SEEK_SET, true, true);