pam-mount.scm 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2019 Guillaume Le Vaillant <glv@posteo.net>
  3. ;;;
  4. ;;; This file is part of GNU Guix.
  5. ;;;
  6. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  7. ;;; under the terms of the GNU General Public License as published by
  8. ;;; the Free Software Foundation; either version 3 of the License, or (at
  9. ;;; your option) any later version.
  10. ;;;
  11. ;;; GNU Guix is distributed in the hope that it will be useful, but
  12. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  13. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. ;;; GNU General Public License for more details.
  15. ;;;
  16. ;;; You should have received a copy of the GNU General Public License
  17. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  18. (define-module (gnu services pam-mount)
  19. #:use-module (gnu packages admin)
  20. #:use-module (gnu services)
  21. #:use-module (gnu services configuration)
  22. #:use-module (gnu system pam)
  23. #:use-module (guix gexp)
  24. #:use-module (guix records)
  25. #:export (pam-mount-configuration
  26. pam-mount-configuration?
  27. pam-mount-service-type))
  28. (define %pam-mount-default-configuration
  29. `((debug (@ (enable "0")))
  30. (mntoptions (@ (allow ,(string-join
  31. '("nosuid" "nodev" "loop"
  32. "encryption" "fsck" "nonempty"
  33. "allow_root" "allow_other")
  34. ","))))
  35. (mntoptions (@ (require "nosuid,nodev")))
  36. (logout (@ (wait "0")
  37. (hup "0")
  38. (term "no")
  39. (kill "no")))
  40. (mkmountpoint (@ (enable "1")
  41. (remove "true")))))
  42. (define (make-pam-mount-configuration-file config)
  43. (computed-file
  44. "pam_mount.conf.xml"
  45. #~(begin
  46. (use-modules (sxml simple))
  47. (call-with-output-file #$output
  48. (lambda (port)
  49. (sxml->xml
  50. '(*TOP*
  51. (*PI* xml "version='1.0' encoding='utf-8'")
  52. (pam_mount
  53. #$@(pam-mount-configuration-rules config)
  54. (pmvarrun
  55. #$(file-append pam-mount
  56. "/sbin/pmvarrun -u '%(USER)' -o '%(OPERATION)'"))
  57. (cryptmount
  58. #$(file-append pam-mount
  59. (string-append
  60. "/sbin/mount.crypt"
  61. " '%(if %(CIPHER),-ocipher=%(CIPHER))'"
  62. " '%(if %(FSKEYCIPHER),"
  63. "-ofsk_cipher=%(FSKEYCIPHER))'"
  64. " '%(if %(FSKEYHASH),-ofsk_hash=%(FSKEYHASH))'"
  65. " '%(if %(FSKEYPATH),-okeyfile=%(FSKEYPATH))'"
  66. " '%(if %(OPTIONS),-o%(OPTIONS))'"
  67. " '%(VOLUME)' '%(MNTPT)'")))
  68. (cryptumount
  69. #$(file-append pam-mount "/sbin/umount.crypt '%(MNTPT)'"))))
  70. port))))))
  71. (define-record-type* <pam-mount-configuration>
  72. pam-mount-configuration
  73. make-pam-mount-configuration
  74. pam-mount-configuration?
  75. (rules pam-mount-configuration-rules
  76. (default %pam-mount-default-configuration)))
  77. (define (pam-mount-etc-service config)
  78. `(("security/pam_mount.conf.xml"
  79. ,(make-pam-mount-configuration-file config))))
  80. (define (pam-mount-pam-service config)
  81. (define optional-pam-mount
  82. (pam-entry
  83. (control "optional")
  84. (module #~(string-append #$pam-mount "/lib/security/pam_mount.so"))))
  85. (list (lambda (pam)
  86. (if (member (pam-service-name pam)
  87. '("login" "su" "slim" "gdm-password" "sddm"))
  88. (pam-service
  89. (inherit pam)
  90. (auth (append (pam-service-auth pam)
  91. (list optional-pam-mount)))
  92. (session (append (pam-service-session pam)
  93. (list optional-pam-mount))))
  94. pam))))
  95. (define pam-mount-service-type
  96. (service-type
  97. (name 'pam-mount)
  98. (extensions (list (service-extension etc-service-type
  99. pam-mount-etc-service)
  100. (service-extension pam-root-service-type
  101. pam-mount-pam-service)))
  102. (default-value (pam-mount-configuration))
  103. (description "Activate PAM-Mount support. It allows mounting volumes for
  104. specific users when they log in.")))