From nobody Mon Apr 29 00:41:33 2024 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) client-ip=170.10.133.124; envelope-from=libvir-list-bounces@redhat.com; helo=us-smtp-delivery-124.mimecast.com; Authentication-Results: mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass(p=none dis=none) header.from=redhat.com ARC-Seal: i=1; a=rsa-sha256; t=1642412680; cv=none; d=zohomail.com; s=zohoarc; b=aRFb8Y1A97pxVw0L2hBZj9ra4jUDANOQwpXjGASnMXGpiKF9vDAKfKEtPq8AkKFzQvhPFPGhjLOnFImZVC8UszFzp8Qw8j1w9/a1nKgghAFzTO4AGxYqC/urh+PTTTd/iPdY0HQRwTgi7k4z9FWQc8DBTtC2ZTT3NVUVnysFisU= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1642412680; h=Content-Type:Content-Transfer-Encoding:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=Z+xFQdQMBLpstWXZpRi4CwwQisoQo3qFBXoR/btN400=; b=lgR4p/zyw0faAufIKcBLYUaTi/Z81O3abKdS1qHTqgZYqtm6t6PGYxrOvkSjnLY2bzsB4n9oJ5A9OB+CmFyqQb5u1Y87GEuB1HuMOqCWniCNK1KfaXEzpkObzSNhMWMbK4K1miI/9uR2d/8Zxy8DkbS1H7sEBPNAagd75mwBCmg= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; spf=pass (zohomail.com: domain of redhat.com designates 170.10.133.124 as permitted sender) smtp.mailfrom=libvir-list-bounces@redhat.com; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by mx.zohomail.com with SMTPS id 16424126800241016.8023705083649; Mon, 17 Jan 2022 01:44:40 -0800 (PST) Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-570-XDGAfYTGOdqvSTUovEJLCg-1; Mon, 17 Jan 2022 04:44:35 -0500 Received: from smtp.corp.redhat.com (int-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.11]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 272F11006AA3; Mon, 17 Jan 2022 09:44:30 +0000 (UTC) Received: from colo-mx.corp.redhat.com (colo-mx01.intmail.prod.int.phx2.redhat.com [10.5.11.20]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 967EE70D21; Mon, 17 Jan 2022 09:44:28 +0000 (UTC) Received: from lists01.pubmisc.prod.ext.phx2.redhat.com (lists01.pubmisc.prod.ext.phx2.redhat.com [10.5.19.33]) by colo-mx.corp.redhat.com (Postfix) with ESMTP id 93CA31809CB8; Mon, 17 Jan 2022 09:44:24 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx06.intmail.prod.int.phx2.redhat.com [10.5.11.16]) by lists01.pubmisc.prod.ext.phx2.redhat.com (8.13.8/8.13.8) with ESMTP id 20H9iNOA003917 for ; Mon, 17 Jan 2022 04:44:23 -0500 Received: by smtp.corp.redhat.com (Postfix) id 1F6BC7A234; Mon, 17 Jan 2022 09:44:23 +0000 (UTC) Received: from thinkpad-work.redhat.com (unknown [10.40.194.251]) by smtp.corp.redhat.com (Postfix) with ESMTP id 90DB07A231 for ; Mon, 17 Jan 2022 09:44:11 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1642412679; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:list-id:list-help: list-unsubscribe:list-subscribe:list-post; bh=Z+xFQdQMBLpstWXZpRi4CwwQisoQo3qFBXoR/btN400=; b=drvYS4Qw4I38r+3kBqsiMyGqfSd8DE7dRBa6gSll/hU/WlLHU0//6shryICV+3yH1sRspr I86PL7KFmOHZj2csjZ1d0myE2mtgYCqvyPeqjMAYmJUM3Xijm67xWigyIgzRJyxafB+YH2 odZFa9wHRHdeqHRVdT+bhEcwZbZw9G4= X-MC-Unique: XDGAfYTGOdqvSTUovEJLCg-1 From: Vit Mojzis To: libvir-list@redhat.com Subject: [PATCH v2] libselinux: Strip spaces before values in config Date: Mon, 17 Jan 2022 10:44:09 +0100 Message-Id: <20220117094409.1229007-1-vmojzis@redhat.com> In-Reply-To: References: MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.16 X-loop: libvir-list@redhat.com X-BeenThere: libvir-list@redhat.com X-Mailman-Version: 2.1.12 Precedence: junk List-Id: Development discussions about the libvirt library & tools List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: libvir-list-bounces@redhat.com Errors-To: libvir-list-bounces@redhat.com X-Scanned-By: MIMEDefang 2.79 on 10.5.11.11 Authentication-Results: relay.mimecast.com; auth=pass smtp.auth=CUSA124A263 smtp.mailfrom=libvir-list-bounces@redhat.com X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Transfer-Encoding: quoted-printable X-ZohoMail-DKIM: pass (identity @redhat.com) X-ZM-MESSAGEID: 1642412680483100001 Content-Type: text/plain; charset="utf-8" Spaces before values in /etc/selinux/config should be ignored just as spaces after them are. E.g. "SELINUXTYPE=3D targeted" should be a valid value. Fixes: # sed -i 's/^SELINUXTYPE=3D/SELINUXTYPE=3D /g' /etc/selinux/config # dnf install ... RPM: error: selabel_open: (/etc/selinux/ targeted/contexts/files/file_co= ntexts) No such file or directory RPM: error: Plugin selinux: hook tsm_pre failed ... Error: Could not run transaction. Signed-off-by: Vit Mojzis --- libselinux/src/selinux_config.c | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) diff --git a/libselinux/src/selinux_config.c b/libselinux/src/selinux_confi= g.c index 97f81a8b..d2e49ee1 100644 --- a/libselinux/src/selinux_config.c +++ b/libselinux/src/selinux_config.c @@ -92,6 +92,7 @@ int selinux_getenforcemode(int *enforce) FILE *cfg =3D fopen(SELINUXCONFIG, "re"); if (cfg) { char *buf; + char *tag; int len =3D sizeof(SELINUXTAG) - 1; buf =3D malloc(selinux_page_size); if (!buf) { @@ -101,21 +102,24 @@ int selinux_getenforcemode(int *enforce) while (fgets_unlocked(buf, selinux_page_size, cfg)) { if (strncmp(buf, SELINUXTAG, len)) continue; + tag =3D buf+len; + while (isspace(*tag)) + tag++; if (!strncasecmp - (buf + len, "enforcing", sizeof("enforcing") - 1)) { + (tag, "enforcing", sizeof("enforcing") - 1)) { *enforce =3D 1; ret =3D 0; break; } else if (!strncasecmp - (buf + len, "permissive", + (tag, "permissive", sizeof("permissive") - 1)) { *enforce =3D 0; ret =3D 0; break; } else if (!strncasecmp - (buf + len, "disabled", + (tag, "disabled", sizeof("disabled") - 1)) { *enforce =3D -1; ret =3D 0; @@ -176,7 +180,10 @@ static void init_selinux_config(void) =20 if (!strncasecmp(buf_p, SELINUXTYPETAG, sizeof(SELINUXTYPETAG) - 1)) { - type =3D strdup(buf_p + sizeof(SELINUXTYPETAG) - 1); + buf_p +=3D sizeof(SELINUXTYPETAG) - 1; + while (isspace(*buf_p)) + buf_p++; + type =3D strdup(buf_p); if (!type) { free(line_buf); fclose(fp); @@ -199,6 +206,8 @@ static void init_selinux_config(void) } else if (!strncmp(buf_p, REQUIRESEUSERS, sizeof(REQUIRESEUSERS) - 1)) { value =3D buf_p + sizeof(REQUIRESEUSERS) - 1; + while (isspace(*value)) + value++; intptr =3D &require_seusers; } else { continue; --=20 2.30.2