diff mbox

[2/2] services: Add 'dropbear-service'.

Message ID 20160713161312.20282-3-david@craven.ch
State New
Headers show

Commit Message

David Craven July 13, 2016, 4:13 p.m. UTC
* gnu/services/ssh.scm (dropbear-service, ...): New variables.
* doc/guix.texi: New node.
---
 doc/guix.texi        | 18 +++++++++++-
 gnu/services/ssh.scm | 83 +++++++++++++++++++++++++++++++++++++++++++++++++---
 2 files changed, 96 insertions(+), 5 deletions(-)

Comments

Ludovic Courtès July 15, 2016, 4 p.m. UTC | #1
David Craven <david@craven.ch> skribis:

> * gnu/services/ssh.scm (dropbear-service, ...): New variables.
> * doc/guix.texi: New node.

Applied with these modifications:

  • I exposed and documented ‘dropbear-configuration’ (we should do the
    same with ‘lsh-configuration’ eventually);

  • I used the #:pid-file option of ‘make-forkexec-constructor’;

  • Turned ‘dropbear-command’ into a gexp (instead of a list);

  • Fixed indentation of a few things;

  • Added a comment for “-R”.

  • Added a copyright line for you;

  • Added a full commit log.

Thanks!

Ludo’.
diff mbox

Patch

diff --git a/doc/guix.texi b/doc/guix.texi
index 67ece1d..5c501bf 100644
--- a/doc/guix.texi
+++ b/doc/guix.texi
@@ -7738,7 +7738,7 @@  In addition, @var{extra-settings} specifies a string to append to the
 configuration file.
 @end deffn
 
-Furthermore, @code{(gnu services ssh)} provides the following service.
+Furthermore, @code{(gnu services ssh)} provides the following services.
 
 @deffn {Scheme Procedure} lsh-service [#:host-key "/etc/lsh/host-key"] @
        [#:daemonic? #t] [#:interfaces '()] [#:port-number 22] @
@@ -7776,6 +7776,22 @@  root.
 The other options should be self-descriptive.
 @end deffn
 
+@deffn {Scheme Procedure} dropbear-service @
+       [#:port-number 22] [#:root-login? #f] @
+       [#:allow-empty-passwords? #f] @
+       [#:password-authentication? #t] @
+       [#:syslog-output? #t]
+Run the @command{dropbear} program from @var{dropbear} to listen on port @var{port-number}.
+
+By default dropbear logs its output to syslogd, unless @var{syslog-output?} is
+set to false. This also makes dropbear-service depend on existence of syslogd
+service.
+
+@var{allow-empty-passwords?} specifies whether to accept connections to accounts
+with empty passwords, and @var{root-login?} specifies whether to accept logging in
+with the root account.
+@end deffn
+
 @defvr {Scheme Variable} %facebook-host-aliases
 This variable contains a string for use in @file{/etc/hosts}
 (@pxref{Host Names,,, libc, The GNU C Library Reference Manual}).  Each
diff --git a/gnu/services/ssh.scm b/gnu/services/ssh.scm
index 1eb9382..bf7a5e2 100644
--- a/gnu/services/ssh.scm
+++ b/gnu/services/ssh.scm
@@ -17,14 +17,15 @@ 
 ;;; along with GNU Guix.  If not, see <http://www.gnu.org/licenses/>.
 
 (define-module (gnu services ssh)
-  #:use-module (guix gexp)
-  #:use-module (guix records)
+  #:use-module (gnu packages ssh)
   #:use-module (gnu services)
   #:use-module (gnu services shepherd)
   #:use-module (gnu system pam)
-  #:use-module (gnu packages ssh)
+  #:use-module (guix gexp)
+  #:use-module (guix records)
   #:use-module (srfi srfi-26)
-  #:export (lsh-service))
+  #:export (dropbear-service
+            lsh-service))
 
 ;;; Commentary:
 ;;;
@@ -235,4 +236,78 @@  The other options should be self-descriptive."
                                public-key-authentication?)
                               (initialize? initialize?))))
 
+;;;
+;;; Dropbear ssh server
+;;;
+
+(define-record-type* <dropbear-configuration>
+  dropbear-configuration make-dropbear-configuration
+  dropbear-configuration?
+  (dropbear dropbear-configuration-dropbear
+            (default dropbear))
+  (port-number dropbear-configuration-port-number)
+  (syslog-output? dropbear-configuration-syslog-output?)
+  (pid-file dropbear-configuration-pid-file)
+  (root-login? dropbear-configuration-root-login?)
+  (allow-empty-passwords? dropbear-configuration-allow-empty-passwords?)
+  (password-authentication? dropbear-configuration-password-authentication?))
+
+(define (dropbear-activation config)
+  "Return the activation gexp for CONFIG."
+  #~(begin
+      (mkdir-p "/etc/dropbear")))
+
+(define (dropbear-shepherd-service config)
+  "Return a <shepherd-service> for dropbear with CONFIG."
+  (define dropbear (dropbear-configuration-dropbear config))
+
+  (define dropbear-command
+    (append
+      (list
+        #~(string-append #$dropbear "/sbin/dropbear") "-F" "-R"
+        "-p" (number->string (dropbear-configuration-port-number config))
+        "-P" (dropbear-configuration-pid-file config))
+      (if (dropbear-configuration-syslog-output? config) '() '("-E"))
+      (if (dropbear-configuration-root-login? config) '() '("-w"))
+      (if (dropbear-configuration-password-authentication? config) '() '("-s" "-g"))
+      (if (dropbear-configuration-allow-empty-passwords? config) '("-B") '())))
+
+  (define requires
+    (if (dropbear-configuration-syslog-output? config)
+        '(networking syslogd) '(networking)))
+
+  (list (shepherd-service
+    (documentation "Dropbear ssh server")
+    (requirement requires)
+    (provision '(ssh-daemon))
+    (start #~(make-forkexec-constructor #$@dropbear-command))
+    (stop #~(make-kill-destructor)))))
+
+(define dropbear-service-type
+  (service-type (name 'dropbear)
+    (extensions
+      (list (service-extension shepherd-root-service-type
+                               dropbear-shepherd-service)
+            (service-extension activation-service-type
+                               dropbear-activation)))))
+
+(define* (dropbear-service #:key
+  (dropbear dropbear)
+  (port-number 22)
+  (allow-empty-passwords? #f)
+  (root-login? #f)
+  (syslog-output? #t)
+  (pid-file "/var/run/dropbear.pid")
+  (password-authentication? #t))
+  "Run the @command{dropbear} daemon from @var{dropbear} to start a ssh server."
+  (service dropbear-service-type
+    (dropbear-configuration
+      (dropbear dropbear)
+      (port-number port-number)
+      (allow-empty-passwords? allow-empty-passwords?)
+      (root-login? root-login?)
+      (syslog-output? syslog-output?)
+      (pid-file pid-file)
+      (password-authentication? password-authentication?))))
+
 ;;; ssh.scm ends here