2013-09-11 22:36:50 +02:00
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2015-09-07 22:44:26 +02:00
|
|
|
;;; Copyright © 2013, 2014, 2015 Ludovic Courtès <ludo@gnu.org>
|
2013-09-11 22:36:50 +02:00
|
|
|
;;;
|
|
|
|
;;; 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 <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
(define-module (gnu system linux)
|
|
|
|
#:use-module (guix store)
|
|
|
|
#:use-module (guix records)
|
|
|
|
#:use-module (guix derivations)
|
gnu: vm: Rewrite helper functions as monadic functions.
* gnu/system/dmd.scm (host-name-service, nscd-service, mingetty-service,
syslog-service, guix-service, static-networking-service): Rewrite as
monadic functions.
(dmd-configuration-file): Use 'text-file' instead of
'add-text-to-store'.
* gnu/system/grub.scm (grub-configuration-file): Rewrite as a monadic
function.
* gnu/system/linux.scm (pam-services->directory): Likewise.
* gnu/system/shadow.scm (group-file, passwd-file, guix-build-accounts):
Likewise.
* gnu/system/vm.scm (expression->derivation-in-linux-vm, qemu-image,
union, system-qemu-image): Likewise.
2013-10-03 21:30:30 +02:00
|
|
|
#:use-module (guix monads)
|
2014-04-28 23:07:08 +02:00
|
|
|
#:use-module (guix gexp)
|
2013-09-11 22:36:50 +02:00
|
|
|
#:use-module (ice-9 match)
|
|
|
|
#:use-module (srfi srfi-1)
|
|
|
|
#:use-module (srfi srfi-26)
|
|
|
|
#:use-module ((guix utils) #:select (%current-system))
|
|
|
|
#:export (pam-service
|
|
|
|
pam-entry
|
|
|
|
pam-services->directory
|
2014-04-30 22:17:56 +02:00
|
|
|
unix-pam-service
|
|
|
|
base-pam-services))
|
2013-09-11 22:36:50 +02:00
|
|
|
|
|
|
|
;;; Commentary:
|
|
|
|
;;;
|
|
|
|
;;; Configuration of Linux-related things, including pluggable authentication
|
|
|
|
;;; modules (PAM).
|
|
|
|
;;;
|
|
|
|
;;; Code:
|
|
|
|
|
|
|
|
;; PAM services (see
|
|
|
|
;; <http://www.linux-pam.org/Linux-PAM-html/sag-configuration-file.html>.)
|
|
|
|
(define-record-type* <pam-service> pam-service
|
|
|
|
make-pam-service
|
|
|
|
pam-service?
|
|
|
|
(name pam-service-name) ; string
|
|
|
|
|
|
|
|
;; The four "management groups".
|
|
|
|
(account pam-service-account ; list of <pam-entry>
|
|
|
|
(default '()))
|
|
|
|
(auth pam-service-auth
|
|
|
|
(default '()))
|
|
|
|
(password pam-service-password
|
|
|
|
(default '()))
|
|
|
|
(session pam-service-session
|
|
|
|
(default '())))
|
|
|
|
|
|
|
|
(define-record-type* <pam-entry> pam-entry
|
|
|
|
make-pam-entry
|
|
|
|
pam-entry?
|
2014-04-28 23:07:08 +02:00
|
|
|
(control pam-entry-control) ; string
|
|
|
|
(module pam-entry-module) ; file name
|
|
|
|
(arguments pam-entry-arguments ; list of string-valued g-expressions
|
2013-09-11 22:36:50 +02:00
|
|
|
(default '())))
|
|
|
|
|
|
|
|
(define (pam-service->configuration service)
|
2014-04-28 23:07:08 +02:00
|
|
|
"Return the derivation building the configuration file for SERVICE, to be
|
|
|
|
dumped in /etc/pam.d/NAME, where NAME is the name of SERVICE."
|
|
|
|
(define (entry->gexp type entry)
|
2013-09-11 22:36:50 +02:00
|
|
|
(match entry
|
|
|
|
(($ <pam-entry> control module (arguments ...))
|
2014-04-28 23:07:08 +02:00
|
|
|
#~(format #t "~a ~a ~a ~a~%"
|
|
|
|
#$type #$control #$module
|
|
|
|
(string-join (list #$@arguments))))))
|
2013-09-11 22:36:50 +02:00
|
|
|
|
|
|
|
(match service
|
|
|
|
(($ <pam-service> name account auth password session)
|
2014-04-28 23:07:08 +02:00
|
|
|
(define builder
|
|
|
|
#~(begin
|
|
|
|
(with-output-to-file #$output
|
|
|
|
(lambda ()
|
|
|
|
#$@(append (map (cut entry->gexp "account" <>) account)
|
|
|
|
(map (cut entry->gexp "auth" <>) auth)
|
|
|
|
(map (cut entry->gexp "password" <>) password)
|
|
|
|
(map (cut entry->gexp "session" <>) session))
|
|
|
|
#t))))
|
|
|
|
|
|
|
|
(gexp->derivation name builder))))
|
2013-09-11 22:36:50 +02:00
|
|
|
|
gnu: vm: Rewrite helper functions as monadic functions.
* gnu/system/dmd.scm (host-name-service, nscd-service, mingetty-service,
syslog-service, guix-service, static-networking-service): Rewrite as
monadic functions.
(dmd-configuration-file): Use 'text-file' instead of
'add-text-to-store'.
* gnu/system/grub.scm (grub-configuration-file): Rewrite as a monadic
function.
* gnu/system/linux.scm (pam-services->directory): Likewise.
* gnu/system/shadow.scm (group-file, passwd-file, guix-build-accounts):
Likewise.
* gnu/system/vm.scm (expression->derivation-in-linux-vm, qemu-image,
union, system-qemu-image): Likewise.
2013-10-03 21:30:30 +02:00
|
|
|
(define (pam-services->directory services)
|
2013-09-11 22:36:50 +02:00
|
|
|
"Return the derivation to build the configuration directory to be used as
|
|
|
|
/etc/pam.d for SERVICES."
|
gnu: vm: Rewrite helper functions as monadic functions.
* gnu/system/dmd.scm (host-name-service, nscd-service, mingetty-service,
syslog-service, guix-service, static-networking-service): Rewrite as
monadic functions.
(dmd-configuration-file): Use 'text-file' instead of
'add-text-to-store'.
* gnu/system/grub.scm (grub-configuration-file): Rewrite as a monadic
function.
* gnu/system/linux.scm (pam-services->directory): Likewise.
* gnu/system/shadow.scm (group-file, passwd-file, guix-build-accounts):
Likewise.
* gnu/system/vm.scm (expression->derivation-in-linux-vm, qemu-image,
union, system-qemu-image): Likewise.
2013-10-03 21:30:30 +02:00
|
|
|
(mlet %store-monad
|
|
|
|
((names -> (map pam-service-name services))
|
2014-04-28 23:07:08 +02:00
|
|
|
(files (sequence %store-monad
|
|
|
|
(map pam-service->configuration
|
|
|
|
;; XXX: Eventually, SERVICES may be a list of
|
|
|
|
;; monadic values instead of plain values.
|
|
|
|
services))))
|
2013-09-11 22:36:50 +02:00
|
|
|
(define builder
|
2014-04-28 23:07:08 +02:00
|
|
|
#~(begin
|
2015-03-10 18:07:48 +01:00
|
|
|
(use-modules (ice-9 match)
|
|
|
|
(srfi srfi-1))
|
2013-09-11 22:36:50 +02:00
|
|
|
|
2014-04-28 23:07:08 +02:00
|
|
|
(mkdir #$output)
|
|
|
|
(for-each (match-lambda
|
|
|
|
((name file)
|
|
|
|
(symlink file (string-append #$output "/" name))))
|
2015-03-10 18:07:48 +01:00
|
|
|
|
|
|
|
;; Since <pam-service> objects cannot be compared with
|
|
|
|
;; 'equal?' since they contain gexps, which contain
|
|
|
|
;; closures, use 'delete-duplicates' on the build-side
|
|
|
|
;; instead. See <http://bugs.gnu.org/20037>.
|
|
|
|
(delete-duplicates '#$(zip names files)))))
|
2013-09-11 22:36:50 +02:00
|
|
|
|
2014-04-28 23:07:08 +02:00
|
|
|
(gexp->derivation "pam.d" builder)))
|
2013-09-11 22:36:50 +02:00
|
|
|
|
|
|
|
(define %pam-other-services
|
|
|
|
;; The "other" PAM configuration, which denies everything (see
|
|
|
|
;; <http://www.linux-pam.org/Linux-PAM-html/sag-configuration-example.html>.)
|
|
|
|
(let ((deny (pam-entry
|
|
|
|
(control "required")
|
|
|
|
(module "pam_deny.so"))))
|
|
|
|
(pam-service
|
|
|
|
(name "other")
|
|
|
|
(account (list deny))
|
|
|
|
(auth (list deny))
|
|
|
|
(password (list deny))
|
|
|
|
(session (list deny)))))
|
|
|
|
|
|
|
|
(define unix-pam-service
|
|
|
|
(let ((unix (pam-entry
|
|
|
|
(control "required")
|
|
|
|
(module "pam_unix.so"))))
|
2013-09-25 21:47:10 +02:00
|
|
|
(lambda* (name #:key allow-empty-passwords? motd)
|
2013-09-11 22:36:50 +02:00
|
|
|
"Return a standard Unix-style PAM service for NAME. When
|
2013-09-25 21:47:10 +02:00
|
|
|
ALLOW-EMPTY-PASSWORDS? is true, allow empty passwords. When MOTD is true, it
|
2015-09-07 22:44:26 +02:00
|
|
|
should be a file-like object used as the message-of-the-day."
|
2013-09-11 22:36:50 +02:00
|
|
|
;; See <http://www.linux-pam.org/Linux-PAM-html/sag-configuration-example.html>.
|
|
|
|
(let ((name* name))
|
|
|
|
(pam-service
|
|
|
|
(name name*)
|
|
|
|
(account (list unix))
|
|
|
|
(auth (list (if allow-empty-passwords?
|
|
|
|
(pam-entry
|
|
|
|
(control "required")
|
|
|
|
(module "pam_unix.so")
|
|
|
|
(arguments '("nullok")))
|
|
|
|
unix)))
|
2015-08-23 00:33:59 +02:00
|
|
|
(password (list (pam-entry
|
|
|
|
(control "required")
|
|
|
|
(module "pam_unix.so")
|
|
|
|
;; Store SHA-512 encrypted passwords in /etc/shadow.
|
|
|
|
(arguments '("sha512" "shadow")))))
|
2013-09-25 21:47:10 +02:00
|
|
|
(session (if motd
|
|
|
|
(list unix
|
|
|
|
(pam-entry
|
|
|
|
(control "optional")
|
|
|
|
(module "pam_motd.so")
|
2014-04-28 23:07:08 +02:00
|
|
|
(arguments
|
|
|
|
(list #~(string-append "motd=" #$motd)))))
|
2013-09-25 21:47:10 +02:00
|
|
|
(list unix))))))))
|
2013-09-11 22:36:50 +02:00
|
|
|
|
2014-07-11 14:02:44 +02:00
|
|
|
(define (rootok-pam-service command)
|
|
|
|
"Return a PAM service for COMMAND such that 'root' does not need to
|
|
|
|
authenticate to run COMMAND."
|
|
|
|
(let ((unix (pam-entry
|
|
|
|
(control "required")
|
|
|
|
(module "pam_unix.so"))))
|
|
|
|
(pam-service
|
|
|
|
(name command)
|
|
|
|
(account (list unix))
|
|
|
|
(auth (list (pam-entry
|
|
|
|
(control "sufficient")
|
|
|
|
(module "pam_rootok.so"))))
|
|
|
|
(password (list unix))
|
|
|
|
(session (list unix)))))
|
|
|
|
|
2014-04-30 22:17:56 +02:00
|
|
|
(define* (base-pam-services #:key allow-empty-passwords?)
|
|
|
|
"Return the list of basic PAM services everyone would want."
|
2014-07-11 14:02:44 +02:00
|
|
|
;; TODO: Add other Shadow programs?
|
|
|
|
(append (list %pam-other-services)
|
|
|
|
|
|
|
|
;; These programs are setuid-root.
|
|
|
|
(map (cut unix-pam-service <>
|
|
|
|
#:allow-empty-passwords? allow-empty-passwords?)
|
2014-09-11 21:53:20 +02:00
|
|
|
'("su" "passwd" "sudo"
|
|
|
|
"xlock" "xscreensaver"))
|
2014-07-11 14:02:44 +02:00
|
|
|
|
|
|
|
;; These programs are not setuid-root, and we want root to be able
|
|
|
|
;; to run them without having to authenticate (notably because
|
|
|
|
;; 'useradd' and 'groupadd' are run during system activation.)
|
|
|
|
(map rootok-pam-service
|
|
|
|
'("useradd" "userdel" "usermod"
|
|
|
|
"groupadd" "groupdel" "groupmod"))))
|
2014-04-30 22:17:56 +02:00
|
|
|
|
2013-09-11 22:36:50 +02:00
|
|
|
;;; linux.scm ends here
|