unofficial mirror of guix-patches@gnu.org 
 help / color / mirror / code / Atom feed
From: Nicolas Graves via Guix-patches via <guix-patches@gnu.org>
To: 62461@debbugs.gnu.org
Cc: ngraves@ngraves.fr
Subject: [bug#62461] [PATCH 1/3] gnu: home-openssh-configuration: Add field add-keys-to-agent.
Date: Sun, 26 Mar 2023 16:07:04 +0200	[thread overview]
Message-ID: <20230326140706.32412-1-ngraves@ngraves.fr> (raw)
In-Reply-To: <87bkkfaa2x.fsf@ngraves.fr>

---
 gnu/home/services/ssh.scm | 44 +++++++++++++++++++++++++++++++--------
 1 file changed, 35 insertions(+), 9 deletions(-)

diff --git a/gnu/home/services/ssh.scm b/gnu/home/services/ssh.scm
index 01917a29cd..4ab2adb292 100644
--- a/gnu/home/services/ssh.scm
+++ b/gnu/home/services/ssh.scm
@@ -1,6 +1,7 @@
 ;;; GNU Guix --- Functional package management for GNU
 ;;; Copyright © 2022 Ludovic Courtès <ludo@gnu.org>
 ;;; Copyright © 2023 Janneke Nieuwenhuizen <janneke@gnu.org>
+;;; Copyright © 2023 Nicolas Graves <ngraves@ngraves.fr>
 ;;;
 ;;; This file is part of GNU Guix.
 ;;;
@@ -39,6 +40,7 @@ (define-module (gnu home services ssh)
             home-openssh-configuration-authorized-keys
             home-openssh-configuration-known-hosts
             home-openssh-configuration-hosts
+            home-openssh-configuration-add-keys-to-agent
             home-ssh-agent-configuration
 
             openssh-host
@@ -185,17 +187,41 @@ (define (openssh-host-name-field? field)
 (define-record-type* <home-openssh-configuration>
   home-openssh-configuration make-home-openssh-configuration
   home-openssh-configuration?
-  (authorized-keys home-openssh-configuration-authorized-keys ;list of file-like
-                   (default '()))
-  (known-hosts     home-openssh-configuration-known-hosts ;unspec | list of file-like
-                   (default *unspecified*))
-  (hosts           home-openssh-configuration-hosts   ;list of <openssh-host>
-                   (default '())))
+  (authorized-keys   home-openssh-configuration-authorized-keys ;list of file-like
+                     (default '()))
+  (known-hosts       home-openssh-configuration-known-hosts ;unspec | list of file-like
+                     (default *unspecified*))
+  (hosts             home-openssh-configuration-hosts   ;list of <openssh-host>
+                     (default '()))
+  (add-keys-to-agent home-openssh-configuration-add-keys-to-agent ;string with limited values
+                     (default "no")))
+
+(define (serialize-add-keys-to-agent value)
+  (define (is-valid-time-string? str)
+    (and (> (string-length str) 0)
+         (eq?
+          (cdr (vector-ref
+                (string-match "\
+[0-9]+|([0-9]+[Ww])?([0-9]+[Dd])?([0-9]+[Hh])?([0-9]+[Mm])?([0-9]+[Ss])?" str)
+                1))
+          (string-length str))))
+
+  (string-append "AddKeysToAgent "
+                 (cond ((member value '("yes" "no" "confirm" "ask")) value)
+                       ((is-valid-time-string? value) value)
+                       ((and (string-prefix? "confirm" value)
+                             (is-valid-time-string?
+                              (cdr (string-split value #\ )))) value)
+                       ;; The 'else' branch is unreachable.
+                       (else (raise (condition (&error)))))))
 
 (define (openssh-configuration->string config)
-  (string-join (map serialize-openssh-host
-                    (home-openssh-configuration-hosts config))
-               "\n"))
+  (string-join
+   (cons* (serialize-add-keys-to-agent
+           (home-openssh-configuration-add-keys-to-agent config))
+          (map serialize-openssh-host
+               (home-openssh-configuration-hosts config)))
+   "\n"))
 
 (define* (file-join name files #:optional (delimiter " "))
   "Return a file in the store called @var{name} that is the concatenation
-- 
2.39.2





  reply	other threads:[~2023-03-26 14:08 UTC|newest]

Thread overview: 20+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-03-26 13:58 [bug#62461] Additional ssh configuration options Nicolas Graves via Guix-patches via
2023-03-26 14:07 ` Nicolas Graves via Guix-patches via [this message]
2023-03-26 14:07   ` [bug#62461] [PATCH 2/3] gnu: openssh-host: Add option match-criteria Nicolas Graves via Guix-patches via
2023-04-01  7:59     ` [bug#62461] Additional ssh configuration options Ludovic Courtès
2023-04-17 15:08       ` Nicolas Graves via Guix-patches via
2023-03-26 14:07   ` [bug#62461] [PATCH 3/3] gnu: ssh: Export configuration predicates Nicolas Graves via Guix-patches via
2023-04-01  8:00     ` [bug#62461] Additional ssh configuration options Ludovic Courtès
2023-04-01  7:45   ` Ludovic Courtès
2023-04-20  8:30 ` [bug#62461] [PATCH v2 1/4] gnu: home-openssh-configuration: Add field add-keys-to-agent Nicolas Graves via Guix-patches via
2023-04-20  8:30   ` [bug#62461] [PATCH v2 2/4] gnu: openssh-host: Add option match-criteria Nicolas Graves via Guix-patches via
2023-04-20  8:30   ` [bug#62461] [PATCH v2 3/4] gnu: ssh: Export configuration predicates Nicolas Graves via Guix-patches via
2023-04-20  8:30   ` [bug#62461] [PATCH v2 4/4] gnu: ssh: Export home-ssh-agent variables Nicolas Graves via Guix-patches via
2023-05-14 21:11   ` [bug#62461] Additional ssh configuration options Ludovic Courtès
2023-06-05 12:34 ` [bug#62461] [PATCH v3 1/4] gnu: home-openssh-configuration: Add field add-keys-to-agent Nicolas Graves via Guix-patches via
2023-06-05 12:34   ` [bug#62461] [PATCH v3 2/4] gnu: openssh-host: Add option match-criteria Nicolas Graves via Guix-patches via
2023-06-05 12:34   ` [bug#62461] [PATCH v3 3/4] gnu: ssh: Export configuration predicates Nicolas Graves via Guix-patches via
2023-06-05 12:34   ` [bug#62461] [PATCH v3 4/4] gnu: ssh: Export home-ssh-agent variables Nicolas Graves via Guix-patches via
2023-06-09 21:43   ` bug#62461: Additional ssh configuration options Ludovic Courtès
2023-07-04 20:17     ` [bug#62461] " Josselin Poiret via Guix-patches via
2023-07-21 20:23       ` Nicolas Graves via Guix-patches via

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://guix.gnu.org/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230326140706.32412-1-ngraves@ngraves.fr \
    --to=guix-patches@gnu.org \
    --cc=62461@debbugs.gnu.org \
    --cc=ngraves@ngraves.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/guix.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).