From patchwork Wed Nov 27 20:40:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Gonzalez X-Patchwork-Id: 1400 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id 9BBD715503AF0 for ; Wed, 27 Nov 2019 20:41:31 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on apollo.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-0.9 required=5.0 tests=DKIM_ADSP_CUSTOM_MED=0.001, DKIM_INVALID=1,DKIM_SIGNED=0.1,FREEMAIL_FROM=0.5,MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,SPF_HELO_NONE=0.001,SUBJ_OBFU_PUNCT_FEW=0.75, T_DMARC_POLICY_NONE=0.01,T_DMARC_SIMPLE_DKIM=0.01 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Wed, 27 Nov 2019 20:41:31 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 434D016EDE2887; Wed, 27 Nov 2019 20:41:21 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: luna) by orion.archlinux.org (Postfix) with ESMTPSA id 81CC516EDE2865; Wed, 27 Nov 2019 20:41:18 +0000 (UTC) Authentication-Results: orion.archlinux.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZeI/dR1W Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 6718D2B791; Wed, 27 Nov 2019 20:41:18 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZeI/dR1W Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id CE3772B78A for ; Wed, 27 Nov 2019 20:41:12 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [IPv6:2a01:4f8:160:6087::1]) by luna.archlinux.org (Postfix) with ESMTPS for ; Wed, 27 Nov 2019 20:41:12 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 457E916EDE2842 for ; Wed, 27 Nov 2019 20:41:08 +0000 (UTC) Received: from mail-yw1-xc44.google.com (mail-yw1-xc44.google.com [IPv6:2607:f8b0:4864:20::c44]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS for ; Wed, 27 Nov 2019 20:41:08 +0000 (UTC) Received: by mail-yw1-xc44.google.com with SMTP id 10so1053572ywv.5 for ; Wed, 27 Nov 2019 12:41:08 -0800 (PST) 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=+JTvyc0DJJuCKvlncxVWTEnEJNV0Q1VttpxXu6fAuQs=; b=ZeI/dR1W5YujUn0SeZVui3FdAyqZRs7lj5CRuVl9VaWhw4qQB4iR8/AtmHHxWQfcE2 kmuQe+VXnYKH9T8JCQ9TPAoxIip+AL9Zi6vJYdXleyUvUrb6cGoSXAh511tB9CLAUELi TM16PVhuSqjbOxpl3Epib/Agv65V/bs8qGXl+BXnPlWXqRutTr2Tqybe/mPQNYI4dXPm 9io26fjLXfxA7hoOnk1OcF1/OvZE1LtuP4d8hrWw9DbmuovFovN95NQiNMChM3R3gHZj AHIeh3kQnDLsu86tYk7mKLWIb0xJYHTlS4dI1YH5zObGlq4Z3mAOEz0KLzqYQMG3LJ/V 9osw== 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=+JTvyc0DJJuCKvlncxVWTEnEJNV0Q1VttpxXu6fAuQs=; b=XY0IIHZOM6M2n/NWELyIN/pgjZg01nSIrOoZNVwOZg2WR2/DU3n5lzuNlp/OMIYTTs 7ckmdOM6eMmn+2M80VrpYCa5a0LDy00zCu3Pyjyn/8eq7v9dQIOh0HCAkRBoN+FlPwS2 TrdCPsk9lJDsFnBXsjJ+OyQOOR7qMFcgfLnDpxJ5DR6BGFv98U7o+lnppQaCFPHET1Q4 fI4gGFw4JSMfTeNKQAUdzQei5KouwCtQPX4xNRI9ScVop+ZURtQWQIqpQL/zd9p0XkRJ BhxfEfHFjzSGHfW7M9vrNSMrRIQKTfzE1BDupAayJkOZfNzGB3WHzOb+49eoOE+pCYF4 eWRQ== X-Gm-Message-State: APjAAAU33Oi66vKecL9gqDYSSmiTozgoVHxHdB7bFcQpD0pkCIU86lWe nD2NHIlHfX9Ej+JsAm7Bwqxa4l5bXkw= X-Google-Smtp-Source: APXvYqzQ89xVMSyEmc1fbxihXoRHiUpybfGOFRmBiQAXHO3FbmkNMZs5Vq0brTvtJ7Qvyjf6tgsktQ== X-Received: by 2002:a81:704b:: with SMTP id l72mr4581131ywc.115.1574887266472; Wed, 27 Nov 2019 12:41:06 -0800 (PST) Received: from toolbox.localdomain ([2600:1700:2ab0:1b80::66c]) by smtp.gmail.com with ESMTPSA id q131sm7553186ywh.22.2019.11.27.12.41.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 12:41:05 -0800 (PST) From: Ryan Gonzalez To: pacman-dev@archlinux.org Date: Wed, 27 Nov 2019 14:40:50 -0600 Message-Id: <20191127204051.782-1-rymg19@gmail.com> X-Mailer: git-send-email 2.23.0 MIME-Version: 1.0 Subject: [pacman-dev] [PATCH 1/2] util: Add _alpm_access_flags X-BeenThere: pacman-dev@archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for pacman development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Discussion list for pacman development Errors-To: pacman-dev-bounces@archlinux.org Sender: "pacman-dev" This changes _alpm_access* to use faccessat, which allows behavior flags to be passed. Signed-off-by: Ryan Gonzalez --- lib/libalpm/util.c | 18 ++++++++++++------ lib/libalpm/util.h | 2 ++ 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/lib/libalpm/util.c b/lib/libalpm/util.c index a4d62c7c..8d653b16 100644 --- a/lib/libalpm/util.c +++ b/lib/libalpm/util.c @@ -1333,16 +1333,22 @@ alpm_time_t _alpm_parsedate(const char *line) return (alpm_time_t)result; } -/** Wrapper around access() which takes a dir and file argument +int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int amode) { + return _alpm_access_flags(handle, dir, file, amode, 0); +} + +/** Wrapper around faccessat() which takes a dir and file argument * separately and generates an appropriate error message. * If dir is NULL file will be treated as the whole path. * @param handle an alpm handle * @param dir directory path ending with and slash * @param file filename - * @param amode access mode as described in access() - * @return int value returned by access() + * @param amode access mode as described in faccessat() + * @param flags flags to pass as described in faccessat() + * @return int value returned by faccessat() */ -int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int amode) +int _alpm_access_flags(alpm_handle_t *handle, const char *dir, const char *file, int amode, + int flags) { size_t len = 0; int ret = 0; @@ -1354,11 +1360,11 @@ int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int a CALLOC(check_path, len, sizeof(char), RET_ERR(handle, ALPM_ERR_MEMORY, -1)); snprintf(check_path, len, "%s%s", dir, file); - ret = access(check_path, amode); + ret = faccessat(AT_FDCWD, check_path, amode, flags); free(check_path); } else { dir = ""; - ret = access(file, amode); + ret = faccessat(AT_FDCWD, file, amode, flags); } if(ret != 0) { diff --git a/lib/libalpm/util.h b/lib/libalpm/util.h index 71dadc2c..1af79571 100644 --- a/lib/libalpm/util.h +++ b/lib/libalpm/util.h @@ -143,6 +143,8 @@ alpm_time_t _alpm_parsedate(const char *line); int _alpm_raw_cmp(const char *first, const char *second); int _alpm_raw_ncmp(const char *first, const char *second, size_t max); int _alpm_access(alpm_handle_t *handle, const char *dir, const char *file, int amode); +int _alpm_access_flags(alpm_handle_t *handle, const char *dir, const char *file, int amode, + int flags); int _alpm_fnmatch_patterns(alpm_list_t *patterns, const char *string); int _alpm_fnmatch(const void *pattern, const void *string); void *_alpm_realloc(void **data, size_t *current, const size_t required); From patchwork Wed Nov 27 20:40:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ryan Gonzalez X-Patchwork-Id: 1399 Return-Path: Delivered-To: patchwork@archlinux.org Received: from apollo.archlinux.org (localhost [127.0.0.1]) by apollo.archlinux.org (Postfix) with ESMTP id 5DC1515503ACD for ; Wed, 27 Nov 2019 20:41:24 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on apollo.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-1.7 required=5.0 tests=DKIM_ADSP_CUSTOM_MED=0.001, DKIM_INVALID=1,DKIM_SIGNED=0.1,FREEMAIL_FROM=0.5,MAILING_LIST_MULTI=-1, RCVD_IN_DNSWL_MED=-2.3,SPF_HELO_NONE=0.001,T_DMARC_POLICY_NONE=0.01, T_DMARC_SIMPLE_DKIM=0.01 autolearn=ham autolearn_force=no version=3.4.2 X-Spam-BL-Results: [127.0.9.2] Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by apollo.archlinux.org (Postfix) with ESMTPS for ; Wed, 27 Nov 2019 20:41:24 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id D37D916EDE2858; Wed, 27 Nov 2019 20:41:16 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [IPv6:2a01:4f8:160:3033::2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits)) (No client certificate requested) (Authenticated sender: luna) by orion.archlinux.org (Postfix) with ESMTPSA id 598D316EDE2850; Wed, 27 Nov 2019 20:41:16 +0000 (UTC) Authentication-Results: orion.archlinux.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pTHCXrkw Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 42E392B791; Wed, 27 Nov 2019 20:41:16 +0000 (UTC) Authentication-Results: luna.archlinux.org; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=pTHCXrkw Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 733882B78F for ; Wed, 27 Nov 2019 20:41:13 +0000 (UTC) Received: from orion.archlinux.org (orion.archlinux.org [88.198.91.70]) by luna.archlinux.org (Postfix) with ESMTPS for ; Wed, 27 Nov 2019 20:41:13 +0000 (UTC) Received: from orion.archlinux.org (localhost [127.0.0.1]) by orion.archlinux.org (Postfix) with ESMTP id 0F79116EDE2849 for ; Wed, 27 Nov 2019 20:41:12 +0000 (UTC) Received: from mail-yb1-xb43.google.com (mail-yb1-xb43.google.com [IPv6:2607:f8b0:4864:20::b43]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by orion.archlinux.org (Postfix) with ESMTPS for ; Wed, 27 Nov 2019 20:41:12 +0000 (UTC) Received: by mail-yb1-xb43.google.com with SMTP id i3so9507864ybe.12 for ; Wed, 27 Nov 2019 12:41:11 -0800 (PST) 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 :mime-version:content-transfer-encoding; bh=TXz8pcaq/+Ys6jFZHjdXkg2RrjOMnbwbvK7vaasZdus=; b=pTHCXrkw87WizA1dEmlgyurlxXJ8QYaAymxjniQ8bgD+DyhDlJ1UNAQ3bQBjZmpn+6 YHTs200ot0UzdNm16dVBeT0YmzK2qYhkgrkJQy/zvhpPwRvKOU529wVQ6eVQ3jDK5S2G xE3VFArkk37gR8LB3sulycYtCLWuHPNae2nTcpVxzfAGVLh5BhcurJ+EOefY+ZArg+Tg FQQ0GEE+L8Zf0tOXfABXYj0Tn9wHGualpTMz7Rf9jJmuRJhfkohOAvFepkrexfgCF4BN LvaAzjA7TuEMdoXJt1khachFqUgCFXJKzaYjJ6i/13ISU/RMnRqUCTaG7B1vWNHugeb+ EEBA== 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:mime-version:content-transfer-encoding; bh=TXz8pcaq/+Ys6jFZHjdXkg2RrjOMnbwbvK7vaasZdus=; b=TFHagG4sgcT3qhqxJNR6Haa//AzZb3EPKOeP+jr/CnrcsQYl4pmu73ld6gJfg8FE1+ Vv6aT7oejAkSegogQ0qFWnF3M4D0v8dzSHzDcUJJ/goVSbyxzmHLTG7qYWx7ZJBrld6P 2ck0cnGrdCnLdUhgthr6Y6/NqOexBRTFNW/7h0mDeEvvjYtdkCoTnbpFF7I67/zmdKFu mEhLCJ8R6q99aPtidhEpm0zzvmvpxqy2OpKJfoS/YdJLO+ZzK6bh+3Se2kO6DnikwSXz qyDBkpICJNL+9M9s1K2Sq3v9qALSdK2nXz4zVLFD6XgZCbWgRcBLjR46/RjuiOGv7YxG PjUA== X-Gm-Message-State: APjAAAU7LAvepmk7U2X7x1SNYkJOkUadelE6dSU3p4c05IV8jiA1HOwg oNoq0zoSuy870TKG9zn+LOPmI9dtsU4= X-Google-Smtp-Source: APXvYqxlwe+dkmXeLoadC0ohur8PFRatKkvzuKUG/gLpgsFdwpo75tinPaNLjubb9jJKnfARh1+eEQ== X-Received: by 2002:a25:d805:: with SMTP id p5mr32497805ybg.424.1574887270418; Wed, 27 Nov 2019 12:41:10 -0800 (PST) Received: from toolbox.localdomain ([2600:1700:2ab0:1b80::66c]) by smtp.gmail.com with ESMTPSA id q131sm7553186ywh.22.2019.11.27.12.41.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 27 Nov 2019 12:41:10 -0800 (PST) From: Ryan Gonzalez To: pacman-dev@archlinux.org Date: Wed, 27 Nov 2019 14:40:51 -0600 Message-Id: <20191127204051.782-2-rymg19@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191127204051.782-1-rymg19@gmail.com> References: <20191127204051.782-1-rymg19@gmail.com> MIME-Version: 1.0 Subject: [pacman-dev] [PATCH 2/2] remove: Don't follow symlinks in checking if a file can be removed X-BeenThere: pacman-dev@archlinux.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Discussion list for pacman development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: Discussion list for pacman development Errors-To: pacman-dev-bounces@archlinux.org Sender: "pacman-dev" Otherwise, symlinks to non-removable files will be logged as unable to be removed. Signed-off-by: Ryan Gonzalez --- lib/libalpm/remove.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/libalpm/remove.c b/lib/libalpm/remove.c index 9030bfee..bb980e7d 100644 --- a/lib/libalpm/remove.c +++ b/lib/libalpm/remove.c @@ -339,7 +339,7 @@ static int can_remove_file(alpm_handle_t *handle, const alpm_file_t *file) /* If we fail write permissions due to a read-only filesystem, abort. * Assume all other possible failures are covered somewhere else */ - if(_alpm_access(handle, NULL, filepath, W_OK) == -1) { + if(_alpm_access_flags(handle, NULL, filepath, W_OK, AT_SYMLINK_NOFOLLOW) == -1) { if(errno != EACCES && errno != ETXTBSY && access(filepath, F_OK) == 0) { /* only return failure if the file ACTUALLY exists and we can't write to * it - ignore "chmod -w" simple permission failures */