accounts: Delete duplicate entries.

When adding multiple instances of a service requiring some user
account/group, we could end up with multiple entries for that account or
group in /etc/passwd or /etc/group.

* gnu/build/accounts.scm (database-writer)[write-entries]: Add call to
'delete-duplicates'.
* tests/accounts.scm ("write-passwd with duplicate entry"): New test.
This commit is contained in:
Ludovic Courtès 2019-08-27 22:38:04 +02:00
parent 114f02bac4
commit dd4e46edda
No known key found for this signature in database
GPG Key ID: 090B11993D9AEBB5
2 changed files with 20 additions and 1 deletions

View File

@ -238,7 +238,7 @@ to it atomically and set the appropriate permissions."
(for-each (lambda (entry) (for-each (lambda (entry)
(display (entry->string entry) port) (display (entry->string entry) port)
(newline port)) (newline port))
entries)) (delete-duplicates entries)))
(if (port? file-or-port) (if (port? file-or-port)
(write-entries file-or-port) (write-entries file-or-port)

View File

@ -62,6 +62,25 @@ nobody:!:0::::::\n"))
(shell "/bin/sh"))) (shell "/bin/sh")))
port)))) port))))
(test-equal "write-passwd with duplicate entry"
%passwd-sample
(call-with-output-string
(lambda (port)
(let ((charlie (password-entry
(name "charlie")
(uid 1000) (gid 998)
(real-name "Charlie")
(directory "/home/charlie")
(shell "/bin/sh"))))
(write-passwd (list (password-entry
(name "root")
(uid 0) (gid 0)
(real-name "Admin")
(directory "/root")
(shell "/bin/sh"))
charlie charlie)
port)))))
(test-equal "read-passwd + write-passwd" (test-equal "read-passwd + write-passwd"
%passwd-sample %passwd-sample
(call-with-output-string (call-with-output-string