pam.scm 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106
  1. ;;; GNU Guix --- Functional package management for GNU
  2. ;;; Copyright © 2023 Bruno Victal <mirai@makinata.eu>
  3. ;;; Copyright © 2023 Felix Lechner <felix.lechner@lease-up.com>
  4. ;;;
  5. ;;; This file is part of GNU Guix.
  6. ;;;
  7. ;;; GNU Guix is free software; you can redistribute it and/or modify it
  8. ;;; under the terms of the GNU General Public License as published by
  9. ;;; the Free Software Foundation; either version 3 of the License, or (at
  10. ;;; your option) any later version.
  11. ;;;
  12. ;;; GNU Guix is distributed in the hope that it will be useful, but
  13. ;;; WITHOUT ANY WARRANTY; without even the implied warranty of
  14. ;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. ;;; GNU General Public License for more details.
  16. ;;;
  17. ;;; You should have received a copy of the GNU General Public License
  18. ;;; along with GNU Guix. If not, see <http://www.gnu.org/licenses/>.
  19. (define-module (gnu tests pam)
  20. #:use-module (gnu tests)
  21. #:use-module (gnu services)
  22. #:use-module (gnu services base)
  23. #:use-module (gnu system)
  24. #:use-module (gnu system pam)
  25. #:use-module (gnu system vm)
  26. #:use-module (guix gexp)
  27. #:use-module (ice-9 format)
  28. #:export (%test-pam-limits))
  29. ;;;
  30. ;;; pam-limits-service-type
  31. ;;;
  32. (define pam-limit-entries
  33. (list
  34. ;; make sure the limits apply to root (uid 0)
  35. (pam-limits-entry ":0" 'both 'rtprio 99) ;default is 0
  36. (pam-limits-entry ":0" 'both 'memlock 'unlimited))) ;default is 8192 kbytes
  37. (define (run-test-pam-limits config)
  38. "Run tests in a os with pam-limits-service-type configured."
  39. (define os
  40. (marionette-operating-system
  41. (simple-operating-system
  42. (service pam-limits-service-type config))
  43. #:imported-modules '((gnu services herd))))
  44. (define vm
  45. (virtual-machine os))
  46. (define name "pam-limits-service")
  47. (define test
  48. (with-imported-modules '((gnu build marionette)
  49. (guix build syscalls))
  50. #~(begin
  51. (use-modules (gnu build marionette)
  52. (guix build syscalls)
  53. (srfi srfi-64))
  54. (let ((marionette (make-marionette (list #$vm))))
  55. (test-runner-current (system-test-runner #$output))
  56. (test-begin #$name)
  57. (test-equal "log in on tty1 and read limits"
  58. '(("99") ;real-time priority
  59. ("unlimited")) ;max locked memory
  60. (begin
  61. ;; Wait for tty1.
  62. (marionette-eval '(begin
  63. (use-modules (gnu services herd))
  64. (start-service 'term-tty1))
  65. marionette)
  66. (marionette-control "sendkey ctrl-alt-f1" marionette)
  67. ;; Now we can type.
  68. (marionette-type "root\n" marionette)
  69. (marionette-type "ulimit -r > real-time-priority\n" marionette)
  70. (marionette-type "ulimit -l > max-locked-memory\n" marionette)
  71. ;; Read the two files.
  72. (marionette-eval '(use-modules (rnrs io ports)) marionette)
  73. (let ((guest-file (lambda (file)
  74. (string-tokenize
  75. (wait-for-file file marionette
  76. #:read 'get-string-all)))))
  77. (list (guest-file "/root/real-time-priority")
  78. (guest-file "/root/max-locked-memory")))))
  79. (test-end)))))
  80. (gexp->derivation (string-append name "-test") test))
  81. (define %test-pam-limits
  82. (system-test
  83. (name "pam-limits-service")
  84. (description "Test that pam-limits-service actually sets the limits as
  85. configured.")
  86. (value (run-test-pam-limits pam-limit-entries))))