From patchwork Fri Apr 30 09:51:29 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guillaume Benoit X-Patchwork-Id: 1915 Return-Path: Delivered-To: patchwork@archlinux.org Received: from mail.archlinux.org [95.216.189.61] by patchwork.archlinux.org with IMAP (fetchmail-6.4.18) for (single-drop); Fri, 30 Apr 2021 09:51:38 +0000 (UTC) Received: from mail.archlinux.org by mail.archlinux.org with LMTP id eBqAGirTi2C8ZgoAK+/4rw (envelope-from ) for ; Fri, 30 Apr 2021 09:51:38 +0000 Received: from luna.archlinux.org (luna.archlinux.org [5.9.250.164]) (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) by mail.archlinux.org (Postfix) with ESMTPS id B1B1554BDD3; Fri, 30 Apr 2021 09:51:37 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 596DD2C732; Fri, 30 Apr 2021 09:51:37 +0000 (UTC) Received: from luna.archlinux.org (luna.archlinux.org [127.0.0.1]) by luna.archlinux.org (Postfix) with ESMTP id 384DC2C72F for ; Fri, 30 Apr 2021 09:51:34 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.5 (2021-03-20) on luna.archlinux.org X-Spam-Level: X-Spam-Status: No, score=-2.3 required=5.0 tests=RCVD_IN_DNSWL_MED=-2.3, T_DMARC_TESTS_FAIL=0.01 autolearn=failed autolearn_force=no version=3.4.5 X-Spam-BL-Results: [127.0.9.2] Received: from mail.archlinux.org (mail.archlinux.org [IPv6:2a01:4f9:c010:3052::1]) by luna.archlinux.org (Postfix) with ESMTPS for ; Fri, 30 Apr 2021 09:51:34 +0000 (UTC) Received: from mail.manjaro.org (mail.manjaro.org [IPv6:2a01:4f8:150:448b::1]) (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 mail.archlinux.org (Postfix) with ESMTPS id 53EC954BDD2 for ; Fri, 30 Apr 2021 09:51:33 +0000 (UTC) Received: from localhost (localhost [127.0.0.1]) by mail.manjaro.org (Postfix) with ESMTP id B74CA220AE0 for ; Fri, 30 Apr 2021 11:51:32 +0200 (CEST) X-Virus-Scanned: Debian amavisd-new at manjaro.org Received: from mail.manjaro.org ([127.0.0.1]) by localhost (manjaro.org [127.0.0.1]) (amavisd-new, port 10024) with ESMTP id zi6of0Ios1Io for ; Fri, 30 Apr 2021 11:51:30 +0200 (CEST) From: Guillaume Benoit To: pacman-dev@archlinux.org Message-ID: <1eb71e41-5bb1-19eb-4426-609c7a61cf1f@manjaro.org> Date: Fri, 30 Apr 2021 11:51:29 +0200 MIME-Version: 1.0 Content-Language: en-US Subject: [pacman-dev] [PATCH] libalpm: download signatures with a fetch callback X-BeenThere: pacman-dev@lists.archlinux.org X-Mailman-Version: 2.1.34 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@lists.archlinux.org Sender: "pacman-dev" Authentication-Results: mail.archlinux.org; dkim=none; dmarc=none; spf=pass (mail.archlinux.org: domain of pacman-dev-bounces@lists.archlinux.org designates 5.9.250.164 as permitted sender) smtp.mailfrom=pacman-dev-bounces@lists.archlinux.org X-Rspamd-Queue-Id: B1B1554BDD3 X-Spamd-Result: default: False [-0.91 / 15.00]; HAS_REPLYTO(0.00)[pacman-dev@lists.archlinux.org]; ARC_NA(0.00)[]; MID_RHS_MATCH_FROM(0.00)[]; FROM_HAS_DN(0.00)[]; R_SPF_ALLOW(-0.20)[+ip4:5.9.250.164]; FORGED_SENDER_MAILLIST(0.00)[]; MIME_GOOD(-0.10)[text/plain]; REPLYTO_DOM_NEQ_FROM_DOM(0.00)[]; TO_DN_NONE(0.00)[]; HAS_LIST_UNSUB(-0.01)[]; RCPT_COUNT_ONE(0.00)[1]; RCVD_TLS_LAST(0.00)[]; RCVD_IN_DNSWL_MED(-0.40)[2a01:4f9:c010:3052::1:received,5.9.250.164:from]; DMARC_NA(0.00)[manjaro.org]; NEURAL_HAM(-0.00)[-1.000]; MAILLIST(-0.20)[mailman]; R_DKIM_NA(0.00)[]; MIME_TRACE(0.00)[0:+]; ASN(0.00)[asn:24940, ipnet:5.9.0.0/16, country:DE]; FROM_NEQ_ENVFROM(0.00)[guillaume@manjaro.org,pacman-dev-bounces@lists.archlinux.org]; RCVD_COUNT_SEVEN(0.00)[7] X-Rspamd-Server: mail.archlinux.org Remove an unwanted break and download signatures when using a custom fetch callback. --- lib/libalpm/dload.c | 43 +++++++++++++++++++++++++++++++++++++------ 1 file changed, 37 insertions(+), 6 deletions(-) snprintf(fileurl, len, "%s/%s", server, payload->filepath); ret = handle->fetchcb(fileurl, localpath, payload->force); - free(fileurl); if (ret != -1) { - success = 1; - break; + /* Let's check if client requested downloading accompanion *.sig file */ + if(payload->download_signature) { + char *sig_fileurl; + + size_t sig_len = strlen(fileurl) + 5; + MALLOC(sig_fileurl, sig_len, RET_ERR(handle, ALPM_ERR_MEMORY, -1)); + snprintf(sig_fileurl, sig_len, "%s.sig", fileurl); + + ret = handle->fetchcb(sig_fileurl, localpath, payload->force); + + free(sig_fileurl); + } + if (ret != -1) { + success = 1; + break; + } } + free(fileurl); } } if(!success && !payload->errors_ok) { diff --git a/lib/libalpm/dload.c b/lib/libalpm/dload.c index a4c42f8d..6f33451a 100644 --- a/lib/libalpm/dload.c +++ b/lib/libalpm/dload.c @@ -877,9 +877,26 @@ int _alpm_download(alpm_handle_t *handle, int success = 0; if(payload->fileurl) { - if (handle->fetchcb(payload->fileurl, localpath, payload->force) != -1) { - success = 1; - break; + int ret; + + ret = handle->fetchcb(payload->fileurl, localpath, payload->force); + + if (ret != -1) { + /* Let's check if client requested downloading accompanion *.sig file */ + if(payload->download_signature) { + char *sig_fileurl; + + size_t sig_len = strlen(payload->fileurl) + 5; + MALLOC(sig_fileurl, sig_len, RET_ERR(handle, ALPM_ERR_MEMORY, -1)); + snprintf(sig_fileurl, sig_len, "%s.sig", payload->fileurl); + + ret = handle->fetchcb(sig_fileurl, localpath, payload->force); + + free(sig_fileurl); + } + if (ret != -1) { + success = 1; + } } } else { for(s = payload->servers; s; s = s->next) { @@ -892,12 +909,26 @@ int _alpm_download(alpm_handle_t *handle,