2013-09-11 22:36:50 +02:00
|
|
|
;;; GNU Guix --- Functional package management for GNU
|
2014-04-28 23:07:08 +02:00
|
|
|
;;; Copyright © 2013, 2014 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
|
|
|
|
(use-modules (ice-9 match))
|
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))))
|
|
|
|
'#$(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
|
|
|
|
should be the name of a file 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)))
|
|
|
|
(password (list unix))
|
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-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."
|
system: Make accounts and groups at activation time.
* gnu/services/base.scm (guix-build-accounts): Remove #:gid parameter;
add #:group. Remove 'password' and 'gid' fields in 'user-account'
form, and add 'group'.
(guix-service): Remove #:build-user-gid parameter. Remove 'id' field
in 'user-group' form.
* gnu/system.scm (etc-directory): Remove #:groups and #:accounts. No
longer produce files "passwd", "shadow", and "group". Adjust caller
accordingly.
(%root-account): New variable.
(operating-system-accounts): Add 'users' variable. Add %ROOT-ACCOUNT
only of 'operating-system-users' doesn't already contain a root
account.
(user-group->gexp, user-account->gexp): New procedures.
(operating-system-boot-script): Add calls to 'setenv' and
'activate-users+groups' in gexp.
* gnu/system/linux.scm (base-pam-services): Add PAM services for
"user{add,del,mode}" and "group{add,del,mod}".
* gnu/system/shadow.scm (<user-account>)[gid]: Rename to...
[group]: ... this.
[supplementary-groups]: New field.
[uid, password]: Default to #f.
(<user-group>)[id]: Default to #f.
(group-file, passwd-file): Remove.
* gnu/system/vm.scm (operating-system-default-contents)[user-directories]:
Remove. Add "/home" to the directives.
* guix/build/activation.scm (add-group, add-user,
activate-users+groups): New procedures.
2014-05-11 22:41:01 +02:00
|
|
|
(cons %pam-other-services
|
|
|
|
(map (cut unix-pam-service <>
|
|
|
|
#:allow-empty-passwords? allow-empty-passwords?)
|
|
|
|
'("su" "passwd" "sudo"
|
|
|
|
"useradd" "userdel" "usermod"
|
|
|
|
"groupadd" "groupdel" "groupmod"
|
|
|
|
;; TODO: Add other Shadow programs?
|
|
|
|
))))
|
2014-04-30 22:17:56 +02:00
|
|
|
|
2013-09-11 22:36:50 +02:00
|
|
|
;;; linux.scm ends here
|