From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms0.migadu.com with LMTPS id aMTGDDMWvmGYbwAAgWs5BA (envelope-from ) for ; Sat, 18 Dec 2021 18:11:15 +0100 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id IK1SCDMWvmEHFQAAbx9fmQ (envelope-from ) for ; Sat, 18 Dec 2021 17:11:15 +0000 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id BC72C822A for ; Sat, 18 Dec 2021 18:11:14 +0100 (CET) Received: from localhost ([::1]:51288 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mydEn-0003OL-WE for larch@yhetil.org; Sat, 18 Dec 2021 12:11:14 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38784) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mydEc-0003O5-SS for guix-patches@gnu.org; Sat, 18 Dec 2021 12:11:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:60402) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mydEc-0000Ko-Ix for guix-patches@gnu.org; Sat, 18 Dec 2021 12:11:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mydEc-0005BG-El for guix-patches@gnu.org; Sat, 18 Dec 2021 12:11:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#52603] [PATCH 2/2] services: static-networking: Sanitize values. Resent-From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 18 Dec 2021 17:11:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52603 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 52603@debbugs.gnu.org Cc: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 52603-submit@debbugs.gnu.org id=B52603.163984746019899 (code B ref 52603); Sat, 18 Dec 2021 17:11:02 +0000 Received: (at 52603) by debbugs.gnu.org; 18 Dec 2021 17:11:00 +0000 Received: from localhost ([127.0.0.1]:43714 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mydEZ-0005At-O2 for submit@debbugs.gnu.org; Sat, 18 Dec 2021 12:11:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:38014) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mydEW-0005AQ-J2 for 52603@debbugs.gnu.org; Sat, 18 Dec 2021 12:10:56 -0500 Received: from [2001:470:142:3::e] (port=59258 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mydER-0000G4-E0; Sat, 18 Dec 2021 12:10:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=WlH2OKxELK+nlVYdV+ZepBgfo/88NxY8B+bHKGcvdcE=; b=kV4Ns5J5qCrXnqD8JtYg U7keJiTYhGPP2zHoR/wkW319HyuTGKP+AMbUTdSi7KPYaqGw4CFLXA2yKMM+JT6zhyHobR3A0E361 W51ivYD+H6EyEBpFgu3e8IivrZatVha+qXBoMzvqWlakh8749oTFT0M2ru8vsGZAB1KUm/5IyiYzq YSe6/V2xvXbq/k0nnYIttpz1KMSNWPgivtLkZmCRdVqgFmjGXxTe3b+jy10xZKIlPnQDpCSyKJFws HsjXWiQQQFy0xWYGtIu1LQHh9Z4e/wOM0tGpIcUllDc5agqvsoMBuQYKTJ5PxKt4QDtVw5ID9uqCu OSXWZxwPG/AQ9w==; Received: from 91-160-117-201.subs.proxad.net ([91.160.117.201]:51822 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mydER-0007OB-Be; Sat, 18 Dec 2021 12:10:51 -0500 From: Ludovic =?UTF-8?Q?Court=C3=A8s?= Date: Sat, 18 Dec 2021 18:10:40 +0100 Message-Id: <20211218171040.20268-2-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211218171040.20268-1-ludo@gnu.org> References: <20211218171040.20268-1-ludo@gnu.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1639847474; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=WlH2OKxELK+nlVYdV+ZepBgfo/88NxY8B+bHKGcvdcE=; b=KBfYLW6vOA2DXcsEjWAyL9Vwz9Hqx4pWzIxx7k2BQmMba1PZ0llSKgKSIjPBa6SnmqWkeU OAdmchaRJMxP1NG0xgX7SC41poeVx7nN89rF36Y3knz3vhRoXhsew2uWUjbI1oB9NWZA7e tedt67u/srRU79sRLGI/5AuDh53MUYoS7zK45YJgEUpmIrBZfyyotUzwjx7+vSYlz5icKU VL8zHtkNuSeG756TxF4l2ShgtYwkaE+ttGQT9vjCjb/BiqPH/IFPuqby4cQ0KG5v3eGAjC NHehkqPcgbd5UGEY1xbTqT2FzJRShmS/pl4XZY3mEHljbSOsqzSu9jtEN7Vjvg== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1639847474; a=rsa-sha256; cv=none; b=r4YfLvFjdi5Tb8b0Z6ZPPYvc9rOZSpfyfrsYPO0Of4MxkLNh70TaygLkjEpS0cdh8kp4ts 08+fl7Yq2Kj78w3yJPESC0nuSdBTMu1wKm3D5QSL8E8k65rD8HUQhGmWehbOFiumuBHIj3 JaKzqdIZsMiriGSYACtuLWjrknpCVo5hndpkklEnDqiZ8xp/8iPGv0v6fwi/MEtZa8Q2el AqZLS5U+e14JuuNpcWgxK68NqaaW0pfUWID3YpPXn+SMkTx9NnDXmj6aLewq48nIAxf66Z glMlpNV5XaP5EsxmkMG3x9wUrD2PJFo37/d+NmJ+kwoQ3zDG2EGnZPHSFFQedw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=kV4Ns5J5; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.71 Authentication-Results: aspmx1.migadu.com; dkim=fail ("headers rsa verify failed") header.d=gnu.org header.s=fencepost-gnu-org header.b=kV4Ns5J5; dmarc=pass (policy=none) header.from=gnu.org; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: BC72C822A X-Spam-Score: -2.71 X-Migadu-Scanner: scn0.migadu.com X-TUID: t6W8d8Hs3mrl This makes sure users do not mistakenly configuring a network with "/0" as its netmask. * gnu/services/base.scm (assert-valid-address): New procedure. ()[value]: Add it as 'sanitize'. --- gnu/services/base.scm | 28 ++++++++++++++++++++++++++-- 1 file changed, 26 insertions(+), 2 deletions(-) diff --git a/gnu/services/base.scm b/gnu/services/base.scm index 5f93483dda..49ec856de4 100644 --- a/gnu/services/base.scm +++ b/gnu/services/base.scm @@ -35,8 +35,9 @@ (define-module (gnu services base) #:use-module (guix store) #:use-module (guix deprecation) - #:autoload (guix diagnostics) (warning) + #:autoload (guix diagnostics) (warning &fix-hint) #:autoload (guix i18n) (G_) + #:use-module (guix combinators) #:use-module (gnu services) #:use-module (gnu services admin) #:use-module (gnu services shepherd) @@ -72,6 +73,8 @@ (define-module (gnu services base) #:use-module (guix i18n) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) + #:use-module (srfi srfi-34) + #:use-module (srfi srfi-35) #:use-module (ice-9 match) #:use-module (ice-9 format) #:re-export (user-processes-service-type ;backwards compatibility @@ -2388,6 +2391,26 @@ (define (ipv6-address? str) "Return true if STR denotes an IPv6 address." (false-if-exception (->bool (inet-pton AF_INET6 str)))) +(define-compile-time-procedure (assert-valid-address (address string?)) + "Ensure ADDRESS has a valid netmask." + (unless (or (cidr->netmask address) + (and=> (false-if-exception (inet-pton AF_INET address)) + (cut = INADDR_LOOPBACK <>)) + (and=> (false-if-exception (inet-pton AF_INET6 address)) + (cut = 1 <>))) + (raise + (make-compound-condition + (formatted-message (G_ "address '~a' lacks a network mask") + address) + (condition (&error-location + (location + (source-properties->location procedure-call-location)))) + (condition (&fix-hint + (hint (format #f (G_ "\ +Write, say, @samp{\"~a/24\"} for a 24-bit network mask.") + address))))))) + address) + (define-record-type* static-networking make-static-networking static-networking? @@ -2405,7 +2428,8 @@ (define-record-type* network-address make-network-address network-address? (device network-address-device) ;string--e.g., "en01" - (value network-address-value) ;string--CIDR notation + (value network-address-value ;string--CIDR notation + (sanitize assert-valid-address)) (ipv6? network-address-ipv6? ;Boolean (thunked) (default -- 2.33.0