system: pam: Add #:login-uid? parameter to 'unix-pam-service'.
[jackhill/guix/guix.git] / gnu / services / ssh.scm
CommitLineData
f33e2d78 1;;; GNU Guix --- Functional package management for GNU
56a93cb9 2;;; Copyright © 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès <ludo@gnu.org>
71b0601a 3;;; Copyright © 2016 David Craven <david@craven.ch>
86d8f6d3 4;;; Copyright © 2016 Julien Lepiller <julien@lepiller.eu>
e57bd0be 5;;; Copyright © 2017 Clément Lassieur <clement@lassieur.org>
65cd70ce 6;;; Copyright © 2019 Ricardo Wurmus <rekado@elephly.net>
f33e2d78
LC
7;;;
8;;; This file is part of GNU Guix.
9;;;
10;;; GNU Guix is free software; you can redistribute it and/or modify it
11;;; under the terms of the GNU General Public License as published by
12;;; the Free Software Foundation; either version 3 of the License, or (at
13;;; your option) any later version.
14;;;
15;;; GNU Guix is distributed in the hope that it will be useful, but
16;;; WITHOUT ANY WARRANTY; without even the implied warranty of
17;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18;;; GNU General Public License for more details.
19;;;
20;;; You should have received a copy of the GNU General Public License
21;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
22
23(define-module (gnu services ssh)
71b0601a 24 #:use-module (gnu packages ssh)
86d8f6d3 25 #:use-module (gnu packages admin)
f33e2d78 26 #:use-module (gnu services)
0190c1c0 27 #:use-module (gnu services shepherd)
6e828634 28 #:use-module (gnu system pam)
86d8f6d3 29 #:use-module (gnu system shadow)
71b0601a
DC
30 #:use-module (guix gexp)
31 #:use-module (guix records)
4892eb7c 32 #:use-module (guix modules)
1398a438 33 #:use-module (srfi srfi-1)
fde40c98 34 #:use-module (srfi srfi-26)
86d8f6d3 35 #:use-module (ice-9 match)
24e96431
36 #:export (lsh-configuration
37 lsh-configuration?
38 lsh-service
39 lsh-service-type
71b0601a 40
86d8f6d3
JL
41 openssh-configuration
42 openssh-configuration?
43 openssh-service-type
86d8f6d3 44
71b0601a
DC
45 dropbear-configuration
46 dropbear-configuration?
47 dropbear-service-type
48 dropbear-service))
f33e2d78
LC
49
50;;; Commentary:
51;;;
52;;; This module implements secure shell (SSH) services.
53;;;
54;;; Code:
55
0adfe95a
LC
56(define-record-type* <lsh-configuration>
57 lsh-configuration make-lsh-configuration
58 lsh-configuration?
59 (lsh lsh-configuration-lsh
60 (default lsh))
61 (daemonic? lsh-configuration-daemonic?)
62 (host-key lsh-configuration-host-key)
63 (interfaces lsh-configuration-interfaces)
64 (port-number lsh-configuration-port-number)
65 (allow-empty-passwords? lsh-configuration-allow-empty-passwords?)
66 (root-login? lsh-configuration-root-login?)
67 (syslog-output? lsh-configuration-syslog-output?)
68 (pid-file? lsh-configuration-pid-file?)
69 (pid-file lsh-configuration-pid-file)
70 (x11-forwarding? lsh-configuration-x11-forwarding?)
71 (tcp/ip-forwarding? lsh-configuration-tcp/ip-forwarding?)
72 (password-authentication? lsh-configuration-password-authentication?)
73 (public-key-authentication? lsh-configuration-public-key-authentication?)
74 (initialize? lsh-configuration-initialize?))
75
f33e2d78
LC
76(define %yarrow-seed
77 "/var/spool/lsh/yarrow-seed-file")
78
0adfe95a
LC
79(define (lsh-initialization lsh host-key)
80 "Return the gexp to initialize the LSH service for HOST-KEY."
f33e2d78
LC
81 #~(begin
82 (unless (file-exists? #$%yarrow-seed)
83 (system* (string-append #$lsh "/bin/lsh-make-seed")
84 "--sloppy" "-o" #$%yarrow-seed))
85
86 (unless (file-exists? #$host-key)
87 (mkdir-p (dirname #$host-key))
88 (format #t "creating SSH host key '~a'...~%" #$host-key)
89
90 ;; FIXME: We're just doing a simple pipeline, but 'system' cannot be
91 ;; used yet because /bin/sh might be dangling; factorize this somehow.
92 (let* ((in+out (pipe))
93 (keygen (primitive-fork)))
94 (case keygen
95 ((0)
96 (close-port (car in+out))
97 (close-fdes 1)
98 (dup2 (fileno (cdr in+out)) 1)
99 (execl (string-append #$lsh "/bin/lsh-keygen")
100 "lsh-keygen" "--server"))
101 (else
102 (let ((write-key (primitive-fork)))
103 (case write-key
104 ((0)
105 (close-port (cdr in+out))
106 (close-fdes 0)
107 (dup2 (fileno (car in+out)) 0)
108 (execl (string-append #$lsh "/bin/lsh-writekey")
109 "lsh-writekey" "--server" "-o" #$host-key))
110 (else
111 (close-port (car in+out))
112 (close-port (cdr in+out))
113 (waitpid keygen)
114 (waitpid write-key))))))))))
115
0adfe95a
LC
116(define (lsh-activation config)
117 "Return the activation gexp for CONFIG."
118 #~(begin
119 (use-modules (guix build utils))
120 (mkdir-p "/var/spool/lsh")
121 #$(if (lsh-configuration-initialize? config)
122 (lsh-initialization (lsh-configuration-lsh config)
123 (lsh-configuration-host-key config))
124 #t)))
125
d4053c71
AK
126(define (lsh-shepherd-service config)
127 "Return a <shepherd-service> for lsh with CONFIG."
0adfe95a
LC
128 (define lsh (lsh-configuration-lsh config))
129 (define pid-file (lsh-configuration-pid-file config))
130 (define pid-file? (lsh-configuration-pid-file? config))
131 (define daemonic? (lsh-configuration-daemonic? config))
132 (define interfaces (lsh-configuration-interfaces config))
133
134 (define lsh-command
135 (append
9e41130b 136 (cons (file-append lsh "/sbin/lshd")
0adfe95a
LC
137 (if daemonic?
138 (let ((syslog (if (lsh-configuration-syslog-output? config)
139 '()
140 (list "--no-syslog"))))
141 (cons "--daemonic"
142 (if pid-file?
143 (cons #~(string-append "--pid-file=" #$pid-file)
144 syslog)
145 (cons "--no-pid-file" syslog))))
146 (if pid-file?
147 (list #~(string-append "--pid-file=" #$pid-file))
148 '())))
149 (cons* #~(string-append "--host-key="
150 #$(lsh-configuration-host-key config))
151 #~(string-append "--password-helper=" #$lsh "/sbin/lsh-pam-checkpw")
152 #~(string-append "--subsystems=sftp=" #$lsh "/sbin/sftp-server")
153 "-p" (number->string (lsh-configuration-port-number config))
154 (if (lsh-configuration-password-authentication? config)
155 "--password" "--no-password")
156 (if (lsh-configuration-public-key-authentication? config)
157 "--publickey" "--no-publickey")
158 (if (lsh-configuration-root-login? config)
159 "--root-login" "--no-root-login")
160 (if (lsh-configuration-x11-forwarding? config)
161 "--x11-forward" "--no-x11-forward")
162 (if (lsh-configuration-tcp/ip-forwarding? config)
163 "--tcpip-forward" "--no-tcpip-forward")
164 (if (null? interfaces)
165 '()
fde40c98
LC
166 (map (cut string-append "--interface=" <>)
167 interfaces)))))
0adfe95a
LC
168
169 (define requires
170 (if (and daemonic? (lsh-configuration-syslog-output? config))
171 '(networking syslogd)
172 '(networking)))
173
d4053c71 174 (list (shepherd-service
0adfe95a
LC
175 (documentation "GNU lsh SSH server")
176 (provision '(ssh-daemon))
177 (requirement requires)
178 (start #~(make-forkexec-constructor (list #$@lsh-command)))
179 (stop #~(make-kill-destructor)))))
180
181(define (lsh-pam-services config)
182 "Return a list of <pam-services> for lshd with CONFIG."
183 (list (unix-pam-service
184 "lshd"
185 #:allow-empty-passwords?
186 (lsh-configuration-allow-empty-passwords? config))))
187
188(define lsh-service-type
189 (service-type (name 'lsh)
21b71b01
LC
190 (description
191 "Run the GNU@tie{}lsh secure shell (SSH) daemon,
192@command{lshd}.")
0adfe95a 193 (extensions
d4053c71
AK
194 (list (service-extension shepherd-root-service-type
195 lsh-shepherd-service)
0adfe95a
LC
196 (service-extension pam-root-service-type
197 lsh-pam-services)
198 (service-extension activation-service-type
199 lsh-activation)))))
200
f33e2d78
LC
201(define* (lsh-service #:key
202 (lsh lsh)
5833bf33 203 (daemonic? #t)
f33e2d78
LC
204 (host-key "/etc/lsh/host-key")
205 (interfaces '())
206 (port-number 22)
207 (allow-empty-passwords? #f)
208 (root-login? #f)
209 (syslog-output? #t)
5833bf33
DP
210 (pid-file? #f)
211 (pid-file "/var/run/lshd.pid")
f33e2d78
LC
212 (x11-forwarding? #t)
213 (tcp/ip-forwarding? #t)
214 (password-authentication? #t)
215 (public-key-authentication? #t)
21cc905a 216 (initialize? #t))
f33e2d78
LC
217 "Run the @command{lshd} program from @var{lsh} to listen on port @var{port-number}.
218@var{host-key} must designate a file containing the host key, and readable
219only by root.
220
5833bf33
DP
221When @var{daemonic?} is true, @command{lshd} will detach from the
222controlling terminal and log its output to syslogd, unless one sets
223@var{syslog-output?} to false. Obviously, it also makes lsh-service
224depend on existence of syslogd service. When @var{pid-file?} is true,
225@command{lshd} writes its PID to the file called @var{pid-file}.
226
f33e2d78
LC
227When @var{initialize?} is true, automatically create the seed and host key
228upon service activation if they do not exist yet. This may take long and
229require interaction.
230
20dd519c
LC
231When @var{initialize?} is false, it is up to the user to initialize the
232randomness generator (@pxref{lsh-make-seed,,, lsh, LSH Manual}), and to create
233a key pair with the private key stored in file @var{host-key} (@pxref{lshd
234basics,,, lsh, LSH Manual}).
235
f33e2d78
LC
236When @var{interfaces} is empty, lshd listens for connections on all the
237network interfaces; otherwise, @var{interfaces} must be a list of host names
238or addresses.
239
20dd519c
LC
240@var{allow-empty-passwords?} specifies whether to accept log-ins with empty
241passwords, and @var{root-login?} specifies whether to accept log-ins as
f33e2d78
LC
242root.
243
244The other options should be self-descriptive."
0adfe95a
LC
245 (service lsh-service-type
246 (lsh-configuration (lsh lsh) (daemonic? daemonic?)
247 (host-key host-key) (interfaces interfaces)
248 (port-number port-number)
249 (allow-empty-passwords? allow-empty-passwords?)
250 (root-login? root-login?)
251 (syslog-output? syslog-output?)
252 (pid-file? pid-file?) (pid-file pid-file)
253 (x11-forwarding? x11-forwarding?)
254 (tcp/ip-forwarding? tcp/ip-forwarding?)
255 (password-authentication?
256 password-authentication?)
257 (public-key-authentication?
258 public-key-authentication?)
259 (initialize? initialize?))))
f33e2d78 260
71b0601a 261\f
86d8f6d3
JL
262;;;
263;;; OpenSSH.
264;;;
265
266(define-record-type* <openssh-configuration>
267 openssh-configuration make-openssh-configuration
268 openssh-configuration?
4ca3e9b7
CL
269 ;; <package>
270 (openssh openssh-configuration-openssh
23f22ba8 271 (default openssh))
4ca3e9b7 272 ;; string
d8f31281
LC
273 (pid-file openssh-configuration-pid-file
274 (default "/var/run/sshd.pid"))
4ca3e9b7
CL
275 ;; integer
276 (port-number openssh-configuration-port-number
d8f31281 277 (default 22))
4ca3e9b7
CL
278 ;; Boolean | 'without-password
279 (permit-root-login openssh-configuration-permit-root-login
d8f31281 280 (default #f))
4ca3e9b7
CL
281 ;; Boolean
282 (allow-empty-passwords? openssh-configuration-allow-empty-passwords?
d8f31281 283 (default #f))
4ca3e9b7
CL
284 ;; Boolean
285 (password-authentication? openssh-configuration-password-authentication?
d8f31281 286 (default #t))
4ca3e9b7 287 ;; Boolean
d8f31281 288 (public-key-authentication? openssh-configuration-public-key-authentication?
4ca3e9b7
CL
289 (default #t))
290 ;; Boolean
291 (x11-forwarding? openssh-configuration-x11-forwarding?
d8f31281 292 (default #f))
5b682390
EB
293
294 ;; Boolean
295 (allow-agent-forwarding? openssh-configuration-allow-agent-forwarding?
296 (default #t))
297
298 ;; Boolean
299 (allow-tcp-forwarding? openssh-configuration-allow-tcp-forwarding?
300 (default #t))
301
302 ;; Boolean
303 (gateway-ports? openssh-configuration-gateway-ports?
304 (default #f))
305
4ca3e9b7 306 ;; Boolean
563c5d42 307 (challenge-response-authentication? openssh-challenge-response-authentication?
4ca3e9b7
CL
308 (default #f))
309 ;; Boolean
563c5d42 310 (use-pam? openssh-configuration-use-pam?
4ca3e9b7
CL
311 (default #t))
312 ;; Boolean
f895dce4 313 (print-last-log? openssh-configuration-print-last-log?
12723370
CL
314 (default #t))
315 ;; list of two-element lists
316 (subsystems openssh-configuration-subsystems
4892eb7c
LC
317 (default '(("sftp" "internal-sftp"))))
318
985934cb
MC
319 ;; list of strings
320 (accepted-environment openssh-configuration-accepted-environment
321 (default '()))
322
6772ed1e
LC
323 ;; symbol
324 (log-level openssh-configuration-log-level
325 (default 'info))
326
65cd70ce
RW
327 ;; String
328 ;; This is an "escape hatch" to provide configuration that isn't yet
329 ;; supported by this configuration record.
330 (extra-content openssh-configuration-extra-content
331 (default ""))
332
4892eb7c
LC
333 ;; list of user-name/file-like tuples
334 (authorized-keys openssh-authorized-keys
aab322d9
LC
335 (default '()))
336
337 ;; Boolean
338 ;; XXX: This should really be handled in an orthogonal way, for instance as
339 ;; proposed in <https://bugs.gnu.org/27155>. Keep it internal/undocumented
340 ;; for now.
341 (%auto-start? openssh-auto-start?
342 (default #t)))
86d8f6d3
JL
343
344(define %openssh-accounts
345 (list (user-group (name "sshd") (system? #t))
346 (user-account
347 (name "sshd")
348 (group "sshd")
349 (system? #t)
350 (comment "sshd privilege separation user")
351 (home-directory "/var/run/sshd")
56a93cb9 352 (shell (file-append shadow "/sbin/nologin")))))
86d8f6d3
JL
353
354(define (openssh-activation config)
355 "Return the activation GEXP for CONFIG."
4892eb7c
LC
356 (with-imported-modules '((guix build utils))
357 #~(begin
358 (use-modules (guix build utils))
359
360 (define (touch file-name)
361 (call-with-output-file file-name (const #t)))
362
363 ;; Make sure /etc/ssh can be read by the 'sshd' user.
364 (mkdir-p "/etc/ssh")
365 (chmod "/etc/ssh" #o755)
366 (mkdir-p (dirname #$(openssh-configuration-pid-file config)))
367
368 ;; 'sshd' complains if the authorized-key directory and its parents
369 ;; are group-writable, which rules out /gnu/store. Thus we copy the
370 ;; authorized-key directory to /etc.
371 (catch 'system-error
372 (lambda ()
373 (delete-file-recursively "/etc/authorized_keys.d"))
374 (lambda args
375 (unless (= ENOENT (system-error-errno args))
376 (apply throw args))))
377 (copy-recursively #$(authorized-key-directory
378 (openssh-authorized-keys config))
379 "/etc/ssh/authorized_keys.d")
380
381 (chmod "/etc/ssh/authorized_keys.d" #o555)
382
383 (let ((lastlog "/var/log/lastlog"))
384 (when #$(openssh-configuration-print-last-log? config)
385 (unless (file-exists? lastlog)
386 (touch lastlog))))
387
388 ;; Generate missing host keys.
389 (system* (string-append #$(openssh-configuration-openssh config)
390 "/bin/ssh-keygen") "-A"))))
391
392(define (authorized-key-directory keys)
393 "Return a directory containing the authorized keys specified in KEYS, a list
394of user-name/file-like tuples."
395 (define build
396 (with-imported-modules (source-module-closure '((guix build utils)))
397 #~(begin
398 (use-modules (ice-9 match) (srfi srfi-26)
399 (guix build utils))
400
401 (mkdir #$output)
402 (for-each (match-lambda
403 ((user keys ...)
404 (let ((file (string-append #$output "/" user)))
405 (call-with-output-file file
406 (lambda (port)
407 (for-each (lambda (key)
408 (call-with-input-file key
409 (cut dump-port <> port)))
410 keys))))))
411 '#$keys))))
412
413 (computed-file "openssh-authorized-keys" build))
86d8f6d3
JL
414
415(define (openssh-config-file config)
416 "Return the sshd configuration file corresponding to CONFIG."
417 (computed-file
418 "sshd_config"
12723370
CL
419 #~(begin
420 (use-modules (ice-9 match))
421 (call-with-output-file #$output
422 (lambda (port)
423 (display "# Generated by 'openssh-service'.\n" port)
424 (format port "Port ~a\n"
425 #$(number->string
426 (openssh-configuration-port-number config)))
427 (format port "PermitRootLogin ~a\n"
428 #$(match (openssh-configuration-permit-root-login config)
429 (#t "yes")
430 (#f "no")
431 ('without-password "without-password")))
432 (format port "PermitEmptyPasswords ~a\n"
433 #$(if (openssh-configuration-allow-empty-passwords? config)
434 "yes" "no"))
435 (format port "PasswordAuthentication ~a\n"
436 #$(if (openssh-configuration-password-authentication? config)
437 "yes" "no"))
438 (format port "PubkeyAuthentication ~a\n"
439 #$(if (openssh-configuration-public-key-authentication?
440 config)
441 "yes" "no"))
442 (format port "X11Forwarding ~a\n"
443 #$(if (openssh-configuration-x11-forwarding? config)
444 "yes" "no"))
5b682390
EB
445 (format port "AllowAgentForwarding ~a\n"
446 #$(if (openssh-configuration-allow-agent-forwarding? config)
447 "yes" "no"))
448 (format port "AllowTcpForwarding ~a\n"
449 #$(if (openssh-configuration-allow-tcp-forwarding? config)
450 "yes" "no"))
451 (format port "GatewayPorts ~a\n"
452 #$(if (openssh-configuration-gateway-ports? config)
453 "yes" "no"))
12723370
CL
454 (format port "PidFile ~a\n"
455 #$(openssh-configuration-pid-file config))
456 (format port "ChallengeResponseAuthentication ~a\n"
457 #$(if (openssh-challenge-response-authentication? config)
458 "yes" "no"))
459 (format port "UsePAM ~a\n"
460 #$(if (openssh-configuration-use-pam? config)
461 "yes" "no"))
462 (format port "PrintLastLog ~a\n"
463 #$(if (openssh-configuration-print-last-log? config)
464 "yes" "no"))
6772ed1e
LC
465 (format port "LogLevel ~a\n"
466 #$(string-upcase
467 (symbol->string
468 (openssh-configuration-log-level config))))
4892eb7c
LC
469
470 ;; Add '/etc/authorized_keys.d/%u', which we populate.
471 (format port "AuthorizedKeysFile \
472 .ssh/authorized_keys .ssh/authorized_keys2 /etc/ssh/authorized_keys.d/%u\n")
473
985934cb
MC
474 (for-each (lambda (s) (format port "AcceptEnv ~a\n" s))
475 '#$(openssh-configuration-accepted-environment config))
476
12723370
CL
477 (for-each
478 (match-lambda
479 ((name command) (format port "Subsystem\t~a\t~a\n" name command)))
480 '#$(openssh-configuration-subsystems config))
65cd70ce
RW
481
482 (format port "~a\n"
483 #$(openssh-configuration-extra-content config))
12723370 484 #t)))))
86d8f6d3
JL
485
486(define (openssh-shepherd-service config)
487 "Return a <shepherd-service> for openssh with CONFIG."
488
489 (define pid-file
490 (openssh-configuration-pid-file config))
491
492 (define openssh-command
23f22ba8 493 #~(list (string-append #$(openssh-configuration-openssh config) "/sbin/sshd")
86d8f6d3
JL
494 "-D" "-f" #$(openssh-config-file config)))
495
496 (list (shepherd-service
497 (documentation "OpenSSH server.")
363c946b 498 (requirement '(syslogd loopback))
86d8f6d3
JL
499 (provision '(ssh-daemon))
500 (start #~(make-forkexec-constructor #$openssh-command
501 #:pid-file #$pid-file))
aab322d9
LC
502 (stop #~(make-kill-destructor))
503 (auto-start? (openssh-auto-start? config)))))
86d8f6d3 504
563c5d42
CL
505(define (openssh-pam-services config)
506 "Return a list of <pam-services> for sshd with CONFIG."
507 (list (unix-pam-service
508 "sshd"
509 #:allow-empty-passwords?
510 (openssh-configuration-allow-empty-passwords? config))))
511
1398a438
LC
512(define (extend-openssh-authorized-keys config keys)
513 "Extend CONFIG with the extra authorized keys listed in KEYS."
514 (openssh-configuration
515 (inherit config)
516 (authorized-keys
517 (append (openssh-authorized-keys config) keys))))
518
86d8f6d3
JL
519(define openssh-service-type
520 (service-type (name 'openssh)
21b71b01
LC
521 (description
522 "Run the OpenSSH secure shell (SSH) server, @command{sshd}.")
86d8f6d3
JL
523 (extensions
524 (list (service-extension shepherd-root-service-type
525 openssh-shepherd-service)
563c5d42
CL
526 (service-extension pam-root-service-type
527 openssh-pam-services)
86d8f6d3
JL
528 (service-extension activation-service-type
529 openssh-activation)
530 (service-extension account-service-type
0c17f720
LC
531 (const %openssh-accounts))
532
533 ;; Install OpenSSH in the system profile. That way,
534 ;; 'scp' is found when someone tries to copy to or from
535 ;; this machine.
536 (service-extension profile-service-type
537 (lambda (config)
538 (list (openssh-configuration-openssh
539 config))))))
1398a438
LC
540 (compose concatenate)
541 (extend extend-openssh-authorized-keys)
3d3c5650 542 (default-value (openssh-configuration))))
86d8f6d3 543
86d8f6d3 544\f
71b0601a
DC
545;;;
546;;; Dropbear.
547;;;
548
549(define-record-type* <dropbear-configuration>
550 dropbear-configuration make-dropbear-configuration
551 dropbear-configuration?
552 (dropbear dropbear-configuration-dropbear
553 (default dropbear))
554 (port-number dropbear-configuration-port-number
555 (default 22))
556 (syslog-output? dropbear-configuration-syslog-output?
557 (default #t))
558 (pid-file dropbear-configuration-pid-file
559 (default "/var/run/dropbear.pid"))
560 (root-login? dropbear-configuration-root-login?
561 (default #f))
562 (allow-empty-passwords? dropbear-configuration-allow-empty-passwords?
563 (default #f))
564 (password-authentication? dropbear-configuration-password-authentication?
565 (default #t)))
566
567(define (dropbear-activation config)
568 "Return the activation gexp for CONFIG."
569 #~(begin
e57bd0be 570 (use-modules (guix build utils))
71b0601a
DC
571 (mkdir-p "/etc/dropbear")))
572
573(define (dropbear-shepherd-service config)
574 "Return a <shepherd-service> for dropbear with CONFIG."
575 (define dropbear
576 (dropbear-configuration-dropbear config))
577
578 (define pid-file
579 (dropbear-configuration-pid-file config))
580
581 (define dropbear-command
582 #~(list (string-append #$dropbear "/sbin/dropbear")
583
584 ;; '-R' allows host keys to be automatically generated upon first
585 ;; connection, at a time when /dev/urandom is more likely securely
586 ;; seeded.
587 "-F" "-R"
588
589 "-p" #$(number->string (dropbear-configuration-port-number config))
590 "-P" #$pid-file
591 #$@(if (dropbear-configuration-syslog-output? config) '() '("-E"))
592 #$@(if (dropbear-configuration-root-login? config) '() '("-w"))
593 #$@(if (dropbear-configuration-password-authentication? config)
594 '()
595 '("-s" "-g"))
596 #$@(if (dropbear-configuration-allow-empty-passwords? config)
597 '("-B")
598 '())))
599
600 (define requires
601 (if (dropbear-configuration-syslog-output? config)
602 '(networking syslogd) '(networking)))
603
604 (list (shepherd-service
605 (documentation "Dropbear SSH server.")
606 (requirement requires)
607 (provision '(ssh-daemon))
608 (start #~(make-forkexec-constructor #$dropbear-command
609 #:pid-file #$pid-file))
610 (stop #~(make-kill-destructor)))))
611
612(define dropbear-service-type
613 (service-type (name 'dropbear)
21b71b01
LC
614 (description
615 "Run the Dropbear secure shell (SSH) server.")
71b0601a
DC
616 (extensions
617 (list (service-extension shepherd-root-service-type
618 dropbear-shepherd-service)
619 (service-extension activation-service-type
3613ce46
LC
620 dropbear-activation)))
621 (default-value (dropbear-configuration))))
71b0601a
DC
622
623(define* (dropbear-service #:optional (config (dropbear-configuration)))
624 "Run the @uref{https://matt.ucc.asn.au/dropbear/dropbear.html,Dropbear SSH
625daemon} with the given @var{config}, a @code{<dropbear-configuration>}
626object."
627 (service dropbear-service-type config))
628
f33e2d78 629;;; ssh.scm ends here