diff options
| author | Ludovic Courtès <ludo@gnu.org> | 2022-11-17 12:35:07 +0100 |
|---|---|---|
| committer | Ludovic Courtès <ludo@gnu.org> | 2022-11-17 22:27:39 +0100 |
| commit | 17b01d546306885ff3c07e7b6aaffb541a8b9043 (patch) | |
| tree | a2498d72ed07147aec3384a892ccc3bdd871c038 /gnu/machine | |
| parent | 983906ab72307a5b848a54233b30d9744356de07 (diff) | |
machine: ssh: Validate 'system' field.
* gnu/machine/ssh.scm (<machine-ssh-configuration>)[system]: Add
'sanitize' property.
(validate-system-type): New macro.
Diffstat (limited to 'gnu/machine')
| -rw-r--r-- | gnu/machine/ssh.scm | 30 |
1 files changed, 29 insertions, 1 deletions
diff --git a/gnu/machine/ssh.scm b/gnu/machine/ssh.scm index 1230b1ec0dd..343cf747484 100644 --- a/gnu/machine/ssh.scm +++ b/gnu/machine/ssh.scm | |||
| @@ -42,6 +42,7 @@ | |||
| 42 | #:use-module ((guix inferior) | 42 | #:use-module ((guix inferior) |
| 43 | #:select (inferior-exception? | 43 | #:select (inferior-exception? |
| 44 | inferior-exception-arguments)) | 44 | inferior-exception-arguments)) |
| 45 | #:use-module ((guix platform) #:select (systems)) | ||
| 45 | #:use-module (gcrypt pk-crypto) | 46 | #:use-module (gcrypt pk-crypto) |
| 46 | #:use-module (ice-9 format) | 47 | #:use-module (ice-9 format) |
| 47 | #:use-module (ice-9 match) | 48 | #:use-module (ice-9 match) |
| @@ -86,7 +87,8 @@ | |||
| 86 | machine-ssh-configuration? | 87 | machine-ssh-configuration? |
| 87 | this-machine-ssh-configuration | 88 | this-machine-ssh-configuration |
| 88 | (host-name machine-ssh-configuration-host-name) ; string | 89 | (host-name machine-ssh-configuration-host-name) ; string |
| 89 | (system machine-ssh-configuration-system) ; string | 90 | (system machine-ssh-configuration-system ; string |
| 91 | (sanitize validate-system-type)) | ||
| 90 | (build-locally? machine-ssh-configuration-build-locally? ; boolean | 92 | (build-locally? machine-ssh-configuration-build-locally? ; boolean |
| 91 | (default #t)) | 93 | (default #t)) |
| 92 | (authorize? machine-ssh-configuration-authorize? ; boolean | 94 | (authorize? machine-ssh-configuration-authorize? ; boolean |
| @@ -109,6 +111,32 @@ | |||
| 109 | (host-key machine-ssh-configuration-host-key ; #f | string | 111 | (host-key machine-ssh-configuration-host-key ; #f | string |
| 110 | (default #f))) | 112 | (default #f))) |
| 111 | 113 | ||
| 114 | (define-with-syntax-properties (validate-system-type (value properties)) | ||
| 115 | ;; Raise an error if VALUE is not a valid system type. | ||
| 116 | (unless (string? value) | ||
| 117 | (raise (make-compound-condition | ||
| 118 | (condition | ||
| 119 | (&error-location | ||
| 120 | (location (source-properties->location properties)))) | ||
| 121 | (formatted-message | ||
| 122 | (G_ "~a: invalid system type; must be a string") | ||
| 123 | value)))) | ||
| 124 | (unless (member value (systems)) | ||
| 125 | (raise (apply make-compound-condition | ||
| 126 | (condition | ||
| 127 | (&error-location | ||
| 128 | (location (source-properties->location properties)))) | ||
| 129 | (formatted-message (G_ "~a: unknown system type") value) | ||
| 130 | (let ((closest (string-closest value (systems) | ||
| 131 | #:threshold 5))) | ||
| 132 | (if closest | ||
| 133 | (list (condition | ||
| 134 | (&fix-hint | ||
| 135 | (hint (format #f (G_ "Did you mean @code{~a}?") | ||
| 136 | closest))))) | ||
| 137 | '()))))) | ||
| 138 | value) | ||
| 139 | |||
| 112 | (define (open-machine-ssh-session config) | 140 | (define (open-machine-ssh-session config) |
| 113 | "Open an SSH session for CONFIG, a <machine-ssh-configuration> record." | 141 | "Open an SSH session for CONFIG, a <machine-ssh-configuration> record." |
| 114 | (let ((host-name (machine-ssh-configuration-host-name config)) | 142 | (let ((host-name (machine-ssh-configuration-host-name config)) |
