From patchwork Tue Dec 21 14:23:36 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 35517 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 6500E27BBE9; Tue, 21 Dec 2021 14:24:37 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,URIBL_BLOCKED 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 0A0E427BBEA for ; Tue, 21 Dec 2021 14:24:31 +0000 (GMT) Received: from localhost ([::1]:46726 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzg46-00038d-2l for patchwork@mira.cbaines.net; Tue, 21 Dec 2021 09:24:30 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59698) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzg3s-00037v-30 for guix-patches@gnu.org; Tue, 21 Dec 2021 09:24:17 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:41264) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzg3f-0000ce-0H for guix-patches@gnu.org; Tue, 21 Dec 2021 09:24:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mzg3e-0005eZ-UG for guix-patches@gnu.org; Tue, 21 Dec 2021 09:24:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#52703] [PATCH 1/2] services: rsync: Allow configuring several rsync "modules". References: <20211221141858.3668-1-ludo@gnu.org> In-Reply-To: <20211221141858.3668-1-ludo@gnu.org> Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 21 Dec 2021 14:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52703 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 52703@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 52703-submit@debbugs.gnu.org id=B52703.164009664021716 (code B ref 52703); Tue, 21 Dec 2021 14:24:02 +0000 Received: (at 52703) by debbugs.gnu.org; 21 Dec 2021 14:24:00 +0000 Received: from localhost ([127.0.0.1]:52809 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mzg3b-0005e5-FS for submit@debbugs.gnu.org; Tue, 21 Dec 2021 09:24:00 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58858) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mzg3Z-0005df-In for 52703@debbugs.gnu.org; Tue, 21 Dec 2021 09:23:58 -0500 Received: from [2001:470:142:3::e] (port=50922 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzg3N-0000am-Hq; Tue, 21 Dec 2021 09:23:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:Date:Subject:To:From:in-reply-to: references; bh=1sbX2oXFXFiGPh5pzLbzJVeXTKn06XmLz8f+9Wt4xD8=; b=eMf0xYrcithPrs sx+tIsG2FW3jHRBEJqQf/X75sZ4Tl6fgeDa35N/wxTCeKFnbsN5lzvySq8oF6l2nAfxYYlpePRwpi rKkAEJYSyqi5AyRSrbsOYIKfWZZxRR4rxjLvPPoxdJVvM+OZKAtADWH2KDW9qZeRQH2YX1iR6kknJ JSRUW4GfZ66Y8i3BxkoDpvjoSbeROeYo9clcKAG2xmiP/iTjJ3B58GOcy44Nv0L0ofeHhvTrbz5hQ 6r4iDh4nSO26u2HGlR3HiDIxwJGziwJM9KYmMAFLMCRgaoqiCLOSG4Acl8WszNGuhrYU+ur4NxepI 3QcJ97t3hv1QNeM30XIQ==; Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=35168 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzg3N-00066P-GX; Tue, 21 Dec 2021 09:23:45 -0500 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Tue, 21 Dec 2021 15:23:36 +0100 Message-Id: <20211221142337.3811-1-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 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: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches Until now the rsync service would export a single module, named "files". This allows users to specify as many modules as they want, in line with rsyncd.conf(5). * gnu/services/rsync.scm (warn-share-field-deprecation): New procedure. ()[modules]: New field. [share-path, share-comment, read-only?, timeout]: Mark as deprecated. (): New record type. (%default-modules): New variable. (rsync-configuration-modules): New procedure. (rsync-activation): Create the directory of each module. (rsync-config-file): Generate configuration for each module. (rsync-service-type)[description]: New field. * doc/guix.texi (Networking Services): Adjust documentation. Augment example. --- doc/guix.texi | 71 ++++++++++++----- gnu/services/rsync.scm | 170 +++++++++++++++++++++++++++++------------ 2 files changed, 174 insertions(+), 67 deletions(-) diff --git a/doc/guix.texi b/doc/guix.texi index 333cb4117a..34e75156eb 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -18059,7 +18059,17 @@ The value for this service type is a @command{rsync-configuration} record as in this example: @lisp -(service rsync-service-type) +;; Export two directories over rsync. By default rsync listens on +;; all the network interfaces. +(service rsync-service-type + (rsync-configuration + (modules (list (rsync-module + (name "music") + (file-name "/srv/zik") + (read-only? #f)) + (rsync-module + (name "movies") + (file-name "/home/charlie/movies")))))) @end lisp See below for details about @code{rsync-configuration}. @@ -18090,34 +18100,55 @@ Name of the file where @command{rsync} writes its lock file. @item @code{log-file} (default: @code{"/var/log/rsyncd.log"}) Name of the file where @command{rsync} writes its log file. -@item @code{use-chroot?} (default: @var{#t}) -Whether to use chroot for @command{rsync} shared directory. - -@item @code{share-path} (default: @file{/srv/rsync}) -Location of the @command{rsync} shared directory. - -@item @code{share-comment} (default: @code{"Rsync share"}) -Comment of the @command{rsync} shared directory. - -@item @code{read-only?} (default: @var{#f}) -Read-write permissions to shared directory. - -@item @code{timeout} (default: @code{300}) -I/O timeout in seconds. - -@item @code{user} (default: @var{"root"}) +@item @code{user} (default: @code{"root"}) Owner of the @code{rsync} process. -@item @code{group} (default: @var{"root"}) +@item @code{group} (default: @code{"root"}) Group of the @code{rsync} process. -@item @code{uid} (default: @var{"rsyncd"}) +@item @code{uid} (default: @code{"rsyncd"}) User name or user ID that file transfers to and from that module should take place as when the daemon was run as @code{root}. -@item @code{gid} (default: @var{"rsyncd"}) +@item @code{gid} (default: @code{"rsyncd"}) Group name or group ID that will be used when accessing the module. +@item @code{modules} (default: @code{%default-modules}) +List of ``modules''---i.e., directories exported over rsync. Each +element must be a @code{rsync-module} record, as described below. +@end table +@end deftp + +@deftp {Data Type} rsync-module +This is the data type for rsync ``modules''. A module is a directory +exported over the rsync protocol. The available fields are as follows: + +@table @asis +@item @code{name} +The module name. This is the name that shows up in URLs. For example, +if the module is called @code{music}, the corresponding URL will be +@code{rsync://host.example.org/music}. + +@item @code{file-name} +Name of the directory being exported. + +@item @code{comment} (default: @code{""}) +Comment associated with the module. Client user interfaces may display +it when they obtain the list of available modules. + +@item @code{read-only?} (default: @code{#t}) +Whether or not client will be able to upload files. If this is false, +the uploads will be authorized if permissions on the daemon side permit +it. + +@item @code{chroot?} (default: @code{#t}) +When this is true, the rsync daemon changes root to the module's +directory before starting file transfers with the client. This improves +security, but requires rsync to run as root. + +@item @code{timeout} (default: @code{300}) +Idle time in seconds after which the daemon closes a connection with the +client. @end table @end deftp diff --git a/gnu/services/rsync.scm b/gnu/services/rsync.scm index 6e27edde25..d456911563 100644 --- a/gnu/services/rsync.scm +++ b/gnu/services/rsync.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017 Oleg Pykhalov +;;; Copyright © 2021 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -25,11 +26,23 @@ (define-module (gnu services rsync) #:use-module (gnu packages admin) #:use-module (guix records) #:use-module (guix gexp) + #:use-module (guix diagnostics) + #:use-module (guix i18n) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (ice-9 match) #:export (rsync-configuration rsync-configuration? + rsync-configuration-modules + + rsync-module + rsync-module? + rsync-module-name + rsync-module-file-name + rsync-module-comment + rsync-module-read-only + rsync-module-timeout + rsync-service-type)) ;;;; Commentary: @@ -39,6 +52,13 @@ (define-module (gnu services rsync) ;;; ;;;; Code: +(define-with-syntax-properties (warn-share-field-deprecation (value properties)) + (unless (unspecified? value) + (warning (source-properties->location properties) + (G_ "the 'share-path' and 'share-comment' fields is deprecated, \ +please use 'modules' instead~%"))) + value) + (define-record-type* rsync-configuration make-rsync-configuration @@ -56,15 +76,22 @@ (define-record-type* (log-file rsync-configuration-log-file ; string (default "/var/log/rsyncd.log")) (use-chroot? rsync-configuration-use-chroot? ; boolean - (default #t)) + (sanitize warn-share-field-deprecation) + (default *unspecified*)) + (modules rsync-configuration-actual-modules ;list of + (default %default-modules)) ;TODO: eventually remove default (share-path rsync-configuration-share-path ; string - (default "/srv/rsyncd")) + (sanitize warn-share-field-deprecation) + (default *unspecified*)) (share-comment rsync-configuration-share-comment ; string - (default "Rsync share")) + (sanitize warn-share-field-deprecation) + (default *unspecified*)) (read-only? rsync-configuration-read-only? ; boolean - (default #f)) + (sanitize warn-share-field-deprecation) + (default *unspecified*)) (timeout rsync-configuration-timeout ; integer - (default 300)) + (sanitize warn-share-field-deprecation) + (default *unspecified*)) (user rsync-configuration-user ; string (default "root")) (group rsync-configuration-group ; string @@ -74,6 +101,45 @@ (define-record-type* (gid rsync-configuration-gid ; string (default "rsyncd"))) +;; Rsync "module": a directory exported the rsync protocol. +(define-record-type* + rsync-module make-rsync-module + rsync-module? + (name rsync-module-name) ;string + (file-name rsync-module-file-name) ;string + (comment rsync-module-comment ;string + (default "")) + (read-only? rsync-module-read-only? ;boolean + (default #t)) + (chroot? rsync-module-chroot? ;boolean + (default #t)) + (timeout rsync-module-timeout ;integer + (default 300))) + +(define %default-modules + ;; Default modules, provided for backward compatibility. + (list (rsync-module (name "files") + (file-name "/srv/rsyncd") + (comment "Rsync share") + (read-only? #f)))) ;yes, that was the default + +(define (rsync-configuration-modules config) + (match-record config + (modules + share-path share-comment use-chroot? read-only? timeout) ;deprecated + (if (unspecified? share-path) + (rsync-configuration-actual-modules config) + (list (rsync-module ;backward compatibility + (name "files") + (file-name share-path) + (comment "Rsync share") + (chroot? + (if (unspecified? use-chroot?) #t use-chroot?)) + (read-only? + (if (unspecified? read-only?) #f read-only?)) + (timeout + (if (unspecified? timeout) 300 timeout))))))) + (define (rsync-account config) "Return the user accounts and user groups for CONFIG." (let ((rsync-user (if (rsync-configuration-uid config) @@ -96,55 +162,62 @@ (define (rsync-activation config) "Return the activation GEXP for CONFIG." (with-imported-modules '((guix build utils)) #~(begin - (let ((share-directory #$(rsync-configuration-share-path config)) - (user (getpw (if #$(rsync-configuration-uid config) + (let ((user (getpw (if #$(rsync-configuration-uid config) #$(rsync-configuration-uid config) #$(rsync-configuration-user config)))) (group (getpw (if #$(rsync-configuration-gid config) #$(rsync-configuration-gid config) #$(rsync-configuration-group config))))) (mkdir-p (dirname #$(rsync-configuration-pid-file config))) - (and=> share-directory mkdir-p) - (chown share-directory - (passwd:uid user) - (group:gid group)))))) + (for-each (lambda (directory) + (mkdir-p directory) + (chown directory (passwd:uid user) (group:gid group))) + '#$(map rsync-module-file-name + (rsync-configuration-modules config))))))) -(define rsync-config-file +(define (rsync-config-file config) ;; Return the rsync configuration file corresponding to CONFIG. - (match-lambda - (($ package address port-number pid-file lock-file log-file - use-chroot? share-path share-comment read-only? - timeout user group uid gid) - (if (not (string=? user "root")) - (cond - ((<= port-number 1024) - (error (string-append "rsync-service: to run on port " - (number->string port-number) - ", user must be root."))) - (use-chroot? - (error (string-append "rsync-service: to run in a chroot" - ", user must be root."))) - (uid - (error "rsync-service: to use uid, user must be root.")) - (gid - (error "rsync-service: to use gid, user must be root.")))) - (mixed-text-file - "rsync.conf" - "# Generated by 'rsync-service'.\n\n" - "pid file = " pid-file "\n" - "lock file = " lock-file "\n" - "log file = " log-file "\n" - (if address (string-append "address = " address "\n") "") - "port = " (number->string port-number) "\n" - "use chroot = " (if use-chroot? "true" "false") "\n" - (if uid (string-append "uid = " uid "\n") "") - "gid = " (if gid gid "nogroup") "\n" ; no group nobody - "\n" - "[files]\n" - "path = " share-path "\n" - "comment = " share-comment "\n" - "read only = " (if read-only? "true" "false") "\n" - "timeout = " (number->string timeout) "\n")))) + (define (module-config module) + (match-record module + (name file-name comment chroot? read-only? timeout) + (list "[" name "]\n" + " path = " file-name "\n" + " use chroot = " (if chroot? "true" "false") "\n" + " comment = " comment "\n" + " read only = " (if read-only? "true" "false") "\n" + " timeout = " (number->string timeout) "\n"))) + + (define modules + (rsync-configuration-modules config)) + + (match-record config + (package address port-number pid-file lock-file log-file + user group uid gid) + (unless (string=? user "root") + (cond + ((<= port-number 1024) + (error (string-append "rsync-service: to run on port " + (number->string port-number) + ", user must be root."))) + ((find rsync-module-chroot? modules) + (error (string-append "rsync-service: to run in a chroot" + ", user must be root."))) + (uid + (error "rsync-service: to use uid, user must be root.")) + (gid + (error "rsync-service: to use gid, user must be root.")))) + + (apply mixed-text-file "rsync.conf" + "# Generated by 'rsync-service'.\n\n" + "pid file = " pid-file "\n" + "lock file = " lock-file "\n" + "log file = " log-file "\n" + (if address (string-append "address = " address "\n") "") + "port = " (number->string port-number) "\n" + (if uid (string-append "uid = " uid "\n") "") + "gid = " (if gid gid "nogroup") "\n" ; no group nobody + "\n\n" + (append-map module-config modules)))) (define (rsync-shepherd-service config) "Return a for rsync with CONFIG." @@ -172,4 +245,7 @@ (define rsync-service-type (list (service-extension shepherd-root-service-type rsync-shepherd-service) (service-extension account-service-type rsync-account) (service-extension activation-service-type rsync-activation))) - (default-value (rsync-configuration)))) + (default-value (rsync-configuration)) + (description + "Run the rsync file copying tool in daemon mode. This allows remote hosts +to keep synchronized copies of the files exported by rsync."))) From patchwork Tue Dec 21 14:23:37 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ludovic_Court=C3=A8s?= X-Patchwork-Id: 35518 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 C5D1527BBE9; Tue, 21 Dec 2021 14:24:37 +0000 (GMT) X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on mira.cbaines.net X-Spam-Level: X-Spam-Status: No, score=-2.7 required=5.0 tests=BAYES_00,DKIM_INVALID, DKIM_SIGNED,MAILING_LIST_MULTI,RCVD_IN_MSPIKE_H3,RCVD_IN_MSPIKE_WL, SPF_HELO_PASS,URIBL_BLOCKED autolearn=ham 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 C1FF927BBEC for ; Tue, 21 Dec 2021 14:24:32 +0000 (GMT) Received: from localhost ([::1]:46850 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1mzg48-0003DN-0L for patchwork@mira.cbaines.net; Tue, 21 Dec 2021 09:24:32 -0500 Received: from eggs.gnu.org ([209.51.188.92]:59704) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzg3s-00037w-3R for guix-patches@gnu.org; Tue, 21 Dec 2021 09:24:17 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:41263) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzg3e-0000cc-KQ for guix-patches@gnu.org; Tue, 21 Dec 2021 09:24:05 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1mzg3e-0005eS-Hf for guix-patches@gnu.org; Tue, 21 Dec 2021 09:24:02 -0500 X-Loop: help-debbugs@gnu.org Subject: [bug#52703] [PATCH 2/2] tests: rsync: Define several modules. Resent-From: Ludovic =?utf-8?q?Court=C3=A8s?= Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Tue, 21 Dec 2021 14:24:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 52703 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 52703@debbugs.gnu.org Cc: Ludovic =?utf-8?q?Court=C3=A8s?= Received: via spool by 52703-submit@debbugs.gnu.org id=B52703.164009663921708 (code B ref 52703); Tue, 21 Dec 2021 14:24:02 +0000 Received: (at 52703) by debbugs.gnu.org; 21 Dec 2021 14:23:59 +0000 Received: from localhost ([127.0.0.1]:52807 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mzg3b-0005e3-5g for submit@debbugs.gnu.org; Tue, 21 Dec 2021 09:23:59 -0500 Received: from eggs.gnu.org ([209.51.188.92]:58866) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1mzg3Z-0005dg-J3 for 52703@debbugs.gnu.org; Tue, 21 Dec 2021 09:23:58 -0500 Received: from [2001:470:142:3::e] (port=50924 helo=fencepost.gnu.org) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1mzg3O-0000bK-Ug; Tue, 21 Dec 2021 09:23:51 -0500 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=gnu.org; s=fencepost-gnu-org; h=MIME-Version:References:In-Reply-To:Date:Subject:To: From; bh=pWJMfJJ2A6WOmuIGTv0vCLWwEYHMzg/AOLAvZUQ2Raw=; b=lSs+Ti1U202ee9fOAce5 qTAFj4u0BHsLM1eBoabZgrcCdl8rCnH2YlqOMr+93EjT1ByVBS933mb0y3V7x/pGAJjhMa0pPmtQs SElUXUcu4ewllL/YA9othirHePxt5yxjTCWO28/SxyUTL3Msc4085Vq4R5TSY6sMyokpx/wNcfpyS Rvy9GoOPix1N4GOJvqzglGuRPxkTAwTphewuSj3zVpQorDB4Tdsi+CNll6s9ksKcZXG1R+vmCVBpF s7ydr7ttNv1FrWpOCkc5+CRrms7n4Rk6IhD6bOQBDD0hoxXNfHf9WgDhfOzbkor8eDlLkkIPZdXXz s+3kNItfSZ+IeQ==; Received: from [2001:660:6102:320:e120:2c8f:8909:cdfe] (port=35168 helo=gnu.org) by fencepost.gnu.org with esmtpsa (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1mzg3O-00066P-6h; Tue, 21 Dec 2021 09:23:46 -0500 From: Ludovic =?utf-8?q?Court=C3=A8s?= Date: Tue, 21 Dec 2021 15:23:37 +0100 Message-Id: <20211221142337.3811-2-ludo@gnu.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211221142337.3811-1-ludo@gnu.org> References: <20211221142337.3811-1-ludo@gnu.org> MIME-Version: 1.0 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: , Errors-To: guix-patches-bounces+patchwork=mira.cbaines.net@gnu.org Sender: "Guix-patches" X-getmail-retrieved-from-mailbox: Patches * gnu/tests/rsync.scm (run-rsync-test)["Test file not copied to read-only share", "Test file correctly received from read-only share"]: New tests. (%rsync-os): Define two modules. --- gnu/tests/rsync.scm | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/gnu/tests/rsync.scm b/gnu/tests/rsync.scm index 91f2b41cec..079a898cdc 100644 --- a/gnu/tests/rsync.scm +++ b/gnu/tests/rsync.scm @@ -1,6 +1,7 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2017 Christopher Baines ;;; Copyright © 2018 Clément Lassieur +;;; Copyright © 2021 Ludovic Courtès ;;; ;;; This file is part of GNU Guix. ;;; @@ -104,6 +105,35 @@ (define marionette (read-line port)))) marionette)) + (test-equal "Test file not copied to read-only share" + 10 ;see "EXIT VALUES" in rsync(1) + (marionette-eval + '(status:exit-val + (system* "rsync" "/tmp/input" + (string-append "rsync://localhost:" + (number->string #$rsync-port) + "/read-only/input"))) + marionette)) + + (test-equal "Test file correctly received from read-only share" + "\"Hi!\" from the read-only share." + (marionette-eval + '(begin + (use-modules (ice-9 rdelim)) + + (call-with-output-file "/srv/read-only/the-file" + (lambda (port) + (display "\"Hi!\" from the read-only share." port))) + + (zero? + (system* "rsync" + (string-append "rsync://localhost:" + (number->string #$rsync-port) + "/read-only/the-file") + "/tmp/output")) + (call-with-input-file "/tmp/output" read-line)) + marionette)) + (test-end)))) (gexp->derivation "rsync-test" test)) @@ -113,7 +143,15 @@ (define* %rsync-os (let ((base-os (simple-operating-system (service dhcp-client-service-type) - (service rsync-service-type)))) + (service rsync-service-type + (rsync-configuration + (modules (list (rsync-module + (name "read-only") + (file-name "/srv/read-only")) + (rsync-module + (name "files") + (file-name "/srv/read-write") + (read-only? #f))))))))) (operating-system (inherit base-os) (packages (cons* rsync