From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp12.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms5.migadu.com with LMTPS id kE26NU4k8WKLGgAAbAwnHQ (envelope-from ) for ; Mon, 08 Aug 2022 16:57:18 +0200 Received: from aspmx1.migadu.com ([2001:41d0:8:6d80::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp12.migadu.com with LMTPS id YN+jNU4k8WKZEAEAauVa8A (envelope-from ) for ; Mon, 08 Aug 2022 16:57:18 +0200 Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id 5C3C8A670 for ; Mon, 8 Aug 2022 16:57:18 +0200 (CEST) Received: from localhost ([::1]:41664 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1oL4Bx-0007GT-44 for larch@yhetil.org; Mon, 08 Aug 2022 10:57:17 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:50766) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1oL4Bj-0007CR-Kd for guix-patches@gnu.org; Mon, 08 Aug 2022 10:57:03 -0400 Received: from debbugs.gnu.org ([209.51.188.43]:51754) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1oL4Bj-0005Hw-Ba for guix-patches@gnu.org; Mon, 08 Aug 2022 10:57:03 -0400 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1oL4Bj-0004fl-7j for guix-patches@gnu.org; Mon, 08 Aug 2022 10:57:03 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#54561] [PATCH v3 2/4] services: Add samba service. Resent-From: simon@netpanic.org Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Mon, 08 Aug 2022 14:57:03 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 54561 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: patch To: 54561@debbugs.gnu.org Cc: Simon Streit Received: via spool by 54561-submit@debbugs.gnu.org id=B54561.165997062017926 (code B ref 54561); Mon, 08 Aug 2022 14:57:03 +0000 Received: (at 54561) by debbugs.gnu.org; 8 Aug 2022 14:57:00 +0000 Received: from localhost ([127.0.0.1]:41497 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oL4Bf-0004f3-1i for submit@debbugs.gnu.org; Mon, 08 Aug 2022 10:57:00 -0400 Received: from smtprelay01.ispgateway.de ([80.67.31.35]:7767) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1oL4Bb-0004eU-4i for 54561@debbugs.gnu.org; Mon, 08 Aug 2022 10:56:56 -0400 Received: from [79.252.144.136] (helo=motorball.wh6.home.arpa) by smtprelay01.ispgateway.de with esmtpsa (TLS1.2) tls TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256 (Exim 4.94.2) (envelope-from ) id 1oL4Ca-000256-Gl; Mon, 08 Aug 2022 16:57:56 +0200 From: simon@netpanic.org Date: Mon, 8 Aug 2022 16:56:41 +0200 Message-Id: <20220808145643.3445-3-simon@netpanic.org> X-Mailer: git-send-email 2.37.1 In-Reply-To: <20220808145643.3445-1-simon@netpanic.org> References: <20220808145643.3445-1-simon@netpanic.org> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Df-Sender: c2ltb25AbmV0cGFuaWMub3Jn 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+larch=yhetil.org@gnu.org Sender: "Guix-patches" X-Migadu-Flow: FLOW_IN X-Migadu-To: larch@yhetil.org X-Migadu-Country: US ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1659970638; h=from:from:sender:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post; bh=226Jf+PHeegrmgHI7/1r4nNMvmVfXj3eenFiHa/EJAw=; b=dGcQ1o0FkP1yrApNBsnkFjga0dhE20olSQgFdF+W/DaElc6fww2RG8xR8EcA8uZChQUlDV i3/6MOXlpLTZ51+ckxSOfSoQNAorV0OVHhadXbxtLGQMWDMJKQ3SKwzunoR11OB7piYq+P wMLJckjfEU/o0JU/WGLt8uvZiLLByWzk1iLFzhemjnXVIjkGukoYWuBJsYZ3yAaMKDZVqf v2sgANhhhVV+dVpuNc6o506wlzHnh+g42l4G9/aKUfGcERAVRIYo0bywDxg2Gsx/LrlFDU rY77T9XcSeLfWL9jYRO1zfCed7LVWosehKg4AIjExPvc3pUt9d51FPvbUB0HlA== ARC-Seal: i=1; s=key1; d=yhetil.org; t=1659970638; a=rsa-sha256; cv=none; b=SbeAVgN49cYLui9Q5Q6OeaeHt08J8i8jS9W2/d/pffapM2sMuE0MhmIn8XKJbx7/tBss1X nCfcsplrEUO3b/j/kbo3MpDnbPZjWOTp2YzMSgq9PD7v4u+ZA9/3yPoTV6r/PS9jYkjniu Hd796G+wRBJr+fqeMAY5Th1iFTPv4sKRlfGiblgzrFZW7RVggmwY4elVy6L5/aFV/uo6Hs 5Vyv6txNJ3uwgFdAFgAG72EubxUtxUmtWmgKnNHTN5Pm+CrFVACChlRTpomcWwH0grFv79 8q6RTJ1MvMaKjLre3pvVm+V2rGGu8EwaSiNeYBYwoDfarTm0oadAw1/wEyW4LA== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Spam-Score: -2.99 Authentication-Results: aspmx1.migadu.com; dkim=none; dmarc=none; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org" X-Migadu-Queue-Id: 5C3C8A670 X-Spam-Score: -2.99 X-Migadu-Scanner: scn0.migadu.com X-TUID: /i1j77K77tWS From: Simon Streit * doc/guix.texi: Document it. * gnu/local.mk (GNU_SYSTEM_MODULES): Add it. * gnu/local.mk (samba.scm): Add it. * gnu/services/samba.scm: New file. * gnu/tests/samba.scm: New file. * po/guix/POTFILES.in Add it. --- doc/guix.texi | 53 ++++++++++++ gnu/local.mk | 2 + gnu/services/samba.scm | 182 +++++++++++++++++++++++++++++++++++++++++ gnu/tests/samba.scm | 158 +++++++++++++++++++++++++++++++++++ po/guix/POTFILES.in | 1 + 5 files changed, 396 insertions(+) create mode 100644 gnu/services/samba.scm create mode 100644 gnu/tests/samba.scm diff --git a/doc/guix.texi b/doc/guix.texi index 12ecc1b952..614d0a0e03 100644 --- a/doc/guix.texi +++ b/doc/guix.texi @@ -106,6 +106,7 @@ Copyright @copyright{} 2022 Philip M@sup{c}Grath@* Copyright @copyright{} 2022 Karl Hallsby@* Copyright @copyright{} 2022 Justin Veilleux@* Copyright @copyright{} 2022 Reily Siegel@* +Copyright @copyright{} 2022 Simon Streit@* Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.3 or @@ -385,6 +386,7 @@ Services * DNS Services:: DNS daemons. * VPN Services:: VPN daemons. * Network File System:: NFS related services. +* Samba Services:: Samba services. * Continuous Integration:: Cuirass and Laminar services. * Power Management Services:: Extending battery life. * Audio Services:: The MPD. @@ -17451,6 +17453,7 @@ declaration. * DNS Services:: DNS daemons. * VPN Services:: VPN daemons. * Network File System:: NFS related services. +* Samba Services:: Samba services. * Continuous Integration:: Cuirass and Laminar services. * Power Management Services:: Extending battery life. * Audio Services:: The MPD. @@ -31194,6 +31197,56 @@ The verbosity level of the daemon. @end table @end deftp +@node Samba Services, Continuous Integration, Network File System, Services +@subsection Samba Services + +@cindex Samba +@cindex SMB +The @code{(gnu services samba)} module provides service definitions for +Samba as well as additional helper services. Currently it provides the +following services. + +@subsubheading Samba + +@uref{https://www.samba.org, Samba} provides network shares for folders +and printers using the SMB/CIFS protocol commonly used on Windows. It +can also act as an Active Directory Domain Controller (AD DC) for other +hosts in an heterougenious network with different types of Computer +systems. + +@defvar {Scheme variable} samba-service-type + +The service type to enable the samba services @code{samba}, @code{nmbd}, +@code{smbd} and @code{winbindd}. By default this service type does not +run as an AD DC, hence @code{samba} remains disabled. + +@end defvar + +@deftp{Data Type} samba-service-configuration +Configuration record for the Samba suite. + +@table @asis +@item @code{package} (default: @code{samba}) +The samba package to use. + +@item @code{config-file} (default: @code{#f}) +The config file to use. + +@item @code{enable-samba?} (default: @code{#f}) +Manually enable the @code{samba} daemon. + +@item @code{enable-smbd?} (default: @code{#f}) +Manually enable the @code{smbd} daemon. + +@item @code{enable-nmbd?} (default: @code{#f}) +Manually enable the @code{nmbd} daemon. + +@item @code{enable-winbindd?} (default: @code{#f}) +Manually enable the @code{winbindd} daemon. + +@end table +@end deftp + @node Continuous Integration @subsection Continuous Integration diff --git a/gnu/local.mk b/gnu/local.mk index 72637761d5..9c1f5ff5b8 100644 --- a/gnu/local.mk +++ b/gnu/local.mk @@ -676,6 +676,7 @@ GNU_SYSTEM_MODULES = \ %D%/services/herd.scm \ %D%/services/pm.scm \ %D%/services/rsync.scm \ + %D%/services/samba.scm \ %D%/services/sddm.scm \ %D%/services/spice.scm \ %D%/services/ssh.scm \ @@ -754,6 +755,7 @@ GNU_SYSTEM_MODULES = \ %D%/tests/package-management.scm \ %D%/tests/reconfigure.scm \ %D%/tests/rsync.scm \ + %D%/tests/samba.scm \ %D%/tests/security-token.scm \ %D%/tests/singularity.scm \ %D%/tests/ssh.scm \ diff --git a/gnu/services/samba.scm b/gnu/services/samba.scm new file mode 100644 index 0000000000..2c9e52a0b0 --- /dev/null +++ b/gnu/services/samba.scm @@ -0,0 +1,182 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2022 Simon Streit +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu services samba) + + #:use-module (gnu packages) + #:use-module (gnu packages base) + #:use-module (gnu packages admin) + #:use-module (gnu packages samba) + + #:use-module (gnu services) + #:use-module (gnu services configuration) + #:use-module (gnu services shepherd) + #:use-module (gnu services base) + #:use-module (gnu system shadow) + + #:use-module (guix gexp) + #:use-module (guix packages) + #:use-module (guix modules) + #:use-module (guix records) + + #:use-module (ice-9 format) + #:use-module (ice-9 match) + #:use-module (ice-9 textual-ports) + #:use-module (srfi srfi-1) + + #:export (samba-service-type + samba-configuration + samba-smb-conf)) + +(define %smb-conf + (plain-file "smb.conf" "[global] + workgroup = WORKGROUP + server string = Samba Server + server role = standalone server + log file = /var/log/samba/log.%m + logging = file +")) + +(define-record-type* + samba-configuration + make-samba-configuration + samba-configuration? + (package samba-configuration-package + (default samba)) + (config-file samba-configuration-config-file + (default #f)) + (enable-samba? samba-configuration-enable-samba? + (default #f)) + (enable-smbd? samba-configuration-enable-smbd? + (default #t)) + (enable-nmbd? samba-configuration-enable-nmbd? + (default #t)) + (enable-winbindd? samba-configuration-enable-winbindd? + (default #t))) + +(define (samba-activation config) + (let ((package (samba-configuration-package config)) + (config-file (samba-configuration-config-file config))) + (with-imported-modules '((guix build utils)) + (let ((lib-dir "/var/lib/samba") + (log-dir "/var/log/samba") + (run-dir "/var/run/samba") + (lock-dir "/var/lock/samba") + (cache-dir "/var/cache/samba") + (etc-dir "/etc/samba") + (smb.conf "/etc/samba/smb.conf")) + #~(begin + (use-modules (guix build utils)) + (mkdir-p #$etc-dir) + (mkdir-p #$lib-dir) + (mkdir-p/perms (string-append #$lib-dir "/private") + (getpwnam "root") #o700) + (mkdir-p #$log-dir) + (mkdir-p #$run-dir) + (mkdir-p #$lock-dir) + (mkdir-p #$cache-dir) + (copy-file #$config-file #$smb.conf) + (invoke #$(file-append package "/bin/testparm") + "--suppress-prompt" #$smb.conf)))))) + +(define (samba-samba-shepherd-service config) + (let ((package (samba-configuration-package config)) + (config-file (samba-configuration-config-file config))) + (list (shepherd-service + (documentation "Run Samba") + (provision '(samba-samba)) + (requirement '(networking)) + (start #~(make-forkexec-constructor + (list #$(file-append package "/sbin/samba") + (string-append "--configfile=" #$config-file) + "--foreground" + "--no-process-group"))) + (stop #~(make-kill-destructor)))))) + +(define (samba-nmbd-shepherd-service config) + (let ((package (samba-configuration-package config)) + (config-file (samba-configuration-config-file config))) + (list (shepherd-service + (documentation "Run NMBD") + (provision '(samba-nmbd)) + (requirement '(networking)) + (start #~(make-forkexec-constructor + (list #$(file-append package "/sbin/nmbd") + (string-append "--configfile=" #$config-file) + "--foreground" + "--no-process-group"))) + (stop #~(make-kill-destructor)))))) + +(define (samba-smbd-shepherd-service config) + (let ((package (samba-configuration-package config)) + (config-file (samba-configuration-config-file config))) + (list (shepherd-service + (documentation "Run SMBD") + (provision '(samba-smbd)) + (requirement '(networking)) + (start #~(make-forkexec-constructor + (list #$(file-append package "/sbin/smbd") + (string-append "--configfile=" #$config-file) + "--foreground" + "--no-process-group"))) + (stop #~(make-kill-destructor)))))) + +(define (samba-winbindd-shepherd-service config) + (let ((package (samba-configuration-package config)) + (config-file (samba-configuration-config-file config))) + (list (shepherd-service + (documentation "Run Winnbindd for Name Service Switch") + (provision '(samba-winbindd)) + (requirement '(networking)) + (start #~(make-forkexec-constructor + (list #$(file-append package "/sbin/winbindd") + (string-append "--configfile=" #$config-file) + "--foreground" + "--no-process-group"))) + (stop #~(make-kill-destructor)))))) + +(define (samba-shepherd-services config) + (append (if (samba-configuration-enable-samba? config) + (samba-samba-shepherd-service config) + '()) + (if (samba-configuration-enable-nmbd? config) + (samba-nmbd-shepherd-service config) + '()) + (if (samba-configuration-enable-smbd? config) + (samba-smbd-shepherd-service config) + '()) + (if (samba-configuration-enable-winbindd? config) + (samba-winbindd-shepherd-service config) + '()))) + +(define samba-service-type + (service-type + (name 'samba) + (description "Run @uref{https://www.samba.org/, Samba}, a network file and +print service for all clients using the SMB/CIFS protocol. Samba is an +important component to seamlessly integrate Linux/Unix Servers and Desktops +into Active Directory environments. It can function both as a domain +controller or as a regular domain member.") + (extensions + (list (service-extension shepherd-root-service-type + samba-shepherd-services) + (service-extension activation-service-type + samba-activation) + (service-extension profile-service-type + (compose list samba-configuration-package)))) + (default-value (samba-configuration)))) diff --git a/gnu/tests/samba.scm b/gnu/tests/samba.scm new file mode 100644 index 0000000000..27d7ea49c3 --- /dev/null +++ b/gnu/tests/samba.scm @@ -0,0 +1,158 @@ +;;; GNU Guix --- Functional package management for GNU +;;; Copyright © 2022 Simon Streit +;;; +;;; This file is part of GNU Guix. +;;; +;;; GNU Guix is free software; you can redistribute it and/or modify it +;;; under the terms of the GNU General Public License as published by +;;; the Free Software Foundation; either version 3 of the License, or (at +;;; your option) any later version. +;;; +;;; GNU Guix is distributed in the hope that it will be useful, but +;;; WITHOUT ANY WARRANTY; without even the implied warranty of +;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +;;; GNU General Public License for more details. +;;; +;;; You should have received a copy of the GNU General Public License +;;; along with GNU Guix. If not, see . + +(define-module (gnu tests samba) + #:use-module (gnu tests) + #:use-module (gnu system) + #:use-module (gnu system vm) + #:use-module (gnu services) + #:use-module (gnu services networking) + #:use-module (gnu services samba) + #:use-module (gnu packages samba) + #:use-module (guix gexp) + #:use-module (guix store) + #:export (%test-samba)) + + +;;; +;;; The Samba service. +;;; + +(define %samba-os + (let ((base-os (simple-operating-system + (simple-service 'create-target-directory activation-service-type + #~(begin + (mkdir-p "/srv/samba/guest") + (chown "/srv/samba/guest" + (passwd:uid (getpw "nobody")) + (passwd:gid (getpw "nobody"))))) + (service dhcp-client-service-type) + (service samba-service-type + (samba-configuration + (config-file (plain-file "smb.conf" " +[global] + workgroup = WORKGROUP + server string = Samba Server + server role = standalone server + log file = /var/log/samba/log.%m + logging = file + +[guest] + path = /srv/samba/guest + read only = no + guest ok = yes + guest only = yes +"))))))) + (operating-system + (inherit base-os) + (packages (cons samba (operating-system-packages base-os)))))) + +(define* (run-samba-test) + "Return a test of an OS running Samba service." + + (define vm + (virtual-machine + (operating-system (marionette-operating-system + %samba-os + #:imported-modules '((gnu services herd)))) + (port-forwardings '((8135 . 135) + (8137 . 137) + (8138 . 138) + (8445 . 445))))) + + (define test + (with-imported-modules '((gnu build marionette)) + #~(begin + (use-modules (gnu build marionette) + (srfi srfi-26) + (srfi srfi-64)) + + (define marionette + (make-marionette '(#$vm))) + + (test-runner-current (system-test-runner #$output)) + (test-begin "samba") + + (test-assert "samba-smbd running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'samba-smbd)) + marionette)) + + (test-assert "samba-nmbd running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'samba-nmbd)) + marionette)) + + (test-assert "samba-winbindd running" + (marionette-eval + '(begin + (use-modules (gnu services herd)) + (start-service 'samba-winbindd)) + marionette)) + + (test-assert "smbd service process id" + (let ((pid + (number->string (wait-for-file "/var/run/samba/smbd.pid" + marionette)))) + (marionette-eval `(file-exists? (string-append "/proc/" ,pid)) + marionette))) + + (test-assert "nmbd service process id" + (let ((pid + (number->string (wait-for-file "/var/run/samba/nmbd.pid" + marionette)))) + (marionette-eval `(file-exists? (string-append "/proc/" ,pid)) + marionette))) + + (test-assert "winbindd service process id" + (let ((pid + (number->string (wait-for-file "/var/run/samba/winbindd.pid" + marionette)))) + (marionette-eval `(file-exists? (string-append "/proc/" ,pid)) + marionette))) + + (test-assert "samba-smbd is listening for peers" + (wait-for-tcp-port 445 marionette)) + + (test-equal "smbclient connect" + 0 + (marionette-eval + '(system* #$(file-append samba "/bin/smbclient") + "--list=localhost" "--no-pass") + marionette)) + + (test-equal "smbclient connect" + 0 + (marionette-eval + '(system* #$(file-append samba "/bin/smbclient") + "--list=localhost" "--no-pass") + marionette)) + + (test-end)))) + + (gexp->derivation "samba-test" test)) + +(define %test-samba + (system-test + (name "samba") + (description "Connect to a running Samba daemon.") + (value (run-samba-test)))) diff --git a/po/guix/POTFILES.in b/po/guix/POTFILES.in index f50dd00422..9088a627ff 100644 --- a/po/guix/POTFILES.in +++ b/po/guix/POTFILES.in @@ -6,6 +6,7 @@ gnu/services.scm gnu/system.scm gnu/services/configuration.scm gnu/services/shepherd.scm +gnu/services/samba.scm gnu/home/services.scm gnu/home/services/ssh.scm gnu/home/services/symlink-manager.scm -- 2.37.1