From patchwork Sun Mar 26 14:07:05 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicolas Graves X-Patchwork-Id: 48709 Return-Path: X-Original-To: patchwork@mira.cbaines.net Delivered-To: patchwork@mira.cbaines.net Received: by mira.cbaines.net (Postfix, from userid 113) id 4095916FFB; Sun, 26 Mar 2023 15:08:32 +0100 (BST) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_MSPIKE_H2,SPF_HELO_PASS autolearn=unavailable autolearn_force=no version=3.4.6 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mira.cbaines.net (Postfix) with ESMTPS id E734E16F60 for ; Sun, 26 Mar 2023 15:08:28 +0100 (BST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1pgR2U-0005xZ-7d; Sun, 26 Mar 2023 10:08:06 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1pgR2Q-0005wH-Tw for guix-patches@gnu.org; Sun, 26 Mar 2023 10:08:02 -0400 Received: from debbugs.gnu.org ([209.51.188.43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1pgR2Q-0001T5-3z for guix-patches@gnu.org; Sun, 26 Mar 2023 10:08:02 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1pgR2P-0004YC-VC for guix-patches@gnu.org; Sun, 26 Mar 2023 10:08:01 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#62461] [PATCH 2/3] gnu: openssh-host: Add option match-criteria. Resent-From: Nicolas Graves Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sun, 26 Mar 2023 14:08:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 62461 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 62461@debbugs.gnu.org Cc: ngraves@ngraves.fr Received: via spool by 62461-submit@debbugs.gnu.org id=B62461.167983963717418 (code B ref 62461); Sun, 26 Mar 2023 14:08:01 +0000 Received: (at 62461) by debbugs.gnu.org; 26 Mar 2023 14:07:17 +0000 Received: from localhost ([127.0.0.1]:45616 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pgR1g-0004Wr-P2 for submit@debbugs.gnu.org; Sun, 26 Mar 2023 10:07:17 -0400 Received: from 15.mo584.mail-out.ovh.net ([91.121.62.11]:36651) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1pgR1b-0004WJ-Dh for 62461@debbugs.gnu.org; Sun, 26 Mar 2023 10:07:12 -0400 Received: from director6.ghost.mail-out.ovh.net (unknown [10.108.20.107]) by mo584.mail-out.ovh.net (Postfix) with ESMTP id 25A99237EC for <62461@debbugs.gnu.org>; Sun, 26 Mar 2023 14:07:10 +0000 (UTC) Received: from ghost-submission-6684bf9d7b-2mcdt (unknown [10.108.16.127]) by director6.ghost.mail-out.ovh.net (Postfix) with ESMTPS id DC0341FD15; Sun, 26 Mar 2023 14:07:09 +0000 (UTC) Received: from ngraves.fr ([37.59.142.103]) by ghost-submission-6684bf9d7b-2mcdt with ESMTPSA id 9z59Mo1RIGSmzgEAym7gpQ (envelope-from ); Sun, 26 Mar 2023 14:07:09 +0000 Authentication-Results: garm.ovh; auth=pass (GARM-103G005d596d08f-2918-4ae8-83a0-b0a6a8f5cc18, 7E234574D634A6AB9E7E21F50CF4BBEA9FF18F38) smtp.auth=ngraves@ngraves.fr X-OVh-ClientIp: 90.45.24.108 Date: Sun, 26 Mar 2023 16:07:05 +0200 Message-Id: <20230326140706.32412-2-ngraves@ngraves.fr> X-Mailer: git-send-email 2.39.2 In-Reply-To: <20230326140706.32412-1-ngraves@ngraves.fr> References: <20230326140706.32412-1-ngraves@ngraves.fr> MIME-Version: 1.0 X-Ovh-Tracer-Id: 5876634564319634146 X-VR-SPAMSTATE: OK X-VR-SPAMSCORE: 0 X-VR-SPAMCAUSE: gggruggvucftvghtrhhoucdtuddrgedvhedrvdehtddgjeefucetufdoteggodetrfdotffvucfrrhhofhhilhgvmecuqfggjfdpvefjgfevmfevgfenuceurghilhhouhhtmecuhedttdenucenucfjughrpefhvfevufffkffojghfggfgsedtkeertdertddtnecuhfhrohhmpefpihgtohhlrghsucfirhgrvhgvshcuoehnghhrrghvvghssehnghhrrghvvghsrdhfrheqnecuggftrfgrthhtvghrnhepiedtteetteekfeetheethfduvedvgeevkeeljedvleeigeeuuedtgedvheetieejnecuffhomhgrihhnpegvgigrmhhplhgvrdhorhhgnecukfhppeduvdejrddtrddtrddupdefjedrheelrddugedvrddutdefnecuvehluhhsthgvrhfuihiivgeptdenucfrrghrrghmpehinhgvthepuddvjedrtddrtddruddpmhgrihhlfhhrohhmpeeonhhgrhgrvhgvshesnhhgrhgrvhgvshdrfhhrqedpnhgspghrtghpthhtohepuddprhgtphhtthhopeeivdegieduseguvggssghughhsrdhgnhhurdhorhhgpdfovfetjfhoshhtpehmohehkeegpdhmohguvgepshhmthhpohhuth 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: , Reply-to: Nicolas Graves X-ACL-Warn: , Nicolas Graves via Guix-patches X-Patchwork-Original-From: Nicolas Graves via Guix-patches via From: Nicolas Graves Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org X-getmail-retrieved-from-mailbox: Patches --- gnu/home/services/ssh.scm | 49 ++++++++++++++++++++++++++++++++++----- 1 file changed, 43 insertions(+), 6 deletions(-) diff --git a/gnu/home/services/ssh.scm b/gnu/home/services/ssh.scm index 4ab2adb292..0bd79e4322 100644 --- a/gnu/home/services/ssh.scm +++ b/gnu/home/services/ssh.scm @@ -45,6 +45,7 @@ (define-module (gnu home services ssh) openssh-host openssh-host-host-name + openssh-host-match-criteria openssh-host-identity-file openssh-host-name openssh-host-port @@ -116,13 +117,39 @@ (define (serialize-string-list field lst) (define-maybe string-list) +(define ssh-match-keywords + '("canonical" "final" "exec" "host" "originalhost" "user" "localuser")) + +(define (match-criteria? str) + ;; Rule out the case of "all" keyword. + (if (member str '("all" + "canonical all" + "final all")) + #t + (let* ((first (string-take str (string-index str #\ ))) + (keyword (if (string-prefix? "!" first) + (string-drop first 1) + first))) + (member keyword ssh-match-keywords)))) + +(define-maybe match-criteria) + (define-configuration openssh-host (name - (string) - "Name of this host declaration.") + maybe-string + "Name of this host declaration. A @code{openssh-host} must define only +@code{name} or @code{match-criteria}. Use host-name \"*\" for top-level +options.") (host-name maybe-string "Host name---e.g., @code{\"foo.example.org\"} or @code{\"192.168.1.2\"}.") + (match-criteria ;TODO implement stricter match-criteria rules + maybe-match-criteria + "A string where the first element is all or one of +@code{ssh-match-keywords}. The rest of the elements are arguments for the +keyword, or other criteria. A @code{openssh-host} must define only +@code{name} or @code{match-criteria}. Other host configuration options will +apply to all hosts matching @code{match-criteria}.") (address-family maybe-address-family "Address family to use when connecting to this host: one of @@ -171,17 +198,27 @@ (define-configuration openssh-host @file{~/.ssh/config}.")) (define (serialize-openssh-host config) - (define (openssh-host-name-field? field) - (eq? (configuration-field-name field) 'name)) + (define (openssh-host-name-or-match-field? field) + (or (eq? (configuration-field-name field) 'name) + (eq? (configuration-field-name field) 'match-criteria))) (string-append - "Host " (openssh-host-name config) "\n" + (if (maybe-value-set? (openssh-host-name config)) + (if (maybe-value-set? (openssh-host-match-criteria config)) + (error + "You must either define name or match-criteria, not both.") + (string-append "Host " (openssh-host-name config) "\n")) + (if (maybe-value-set? (openssh-host-match-criteria config)) + (string-append + "Match " (string-join (openssh-host-match-criteria config) " ") "\n") + (error + "You must either define name or match-criteria once."))) (string-concatenate (map (lambda (field) ((configuration-field-serializer field) (configuration-field-name field) ((configuration-field-getter field) config))) - (remove openssh-host-name-field? + (remove openssh-host-name-or-match-field? openssh-host-fields))))) (define-record-type*