guix-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

01/04: accounts: Delete duplicate entries.


From: guix-commits
Subject: 01/04: accounts: Delete duplicate entries.
Date: Tue, 27 Aug 2019 18:27:24 -0400 (EDT)

civodul pushed a commit to branch master
in repository guix.

commit dd4e46edda6c255ca170a6650c6f92b16ff50a3f
Author: Ludovic Courtès <address@hidden>
Date:   Tue Aug 27 22:38:04 2019 +0200

    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.
---
 gnu/build/accounts.scm |  2 +-
 tests/accounts.scm     | 19 +++++++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)

diff --git a/gnu/build/accounts.scm b/gnu/build/accounts.scm
index 5094456..f60d68d 100644
--- a/gnu/build/accounts.scm
+++ b/gnu/build/accounts.scm
@@ -238,7 +238,7 @@ to it atomically and set the appropriate permissions."
       (for-each (lambda (entry)
                   (display (entry->string entry) port)
                   (newline port))
-                entries))
+                (delete-duplicates entries)))
 
     (if (port? file-or-port)
         (write-entries file-or-port)
diff --git a/tests/accounts.scm b/tests/accounts.scm
index 673dd42..7813639 100644
--- a/tests/accounts.scm
+++ b/tests/accounts.scm
@@ -62,6 +62,25 @@ nobody:!:0::::::\n"))
                            (shell "/bin/sh")))
                     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"
   %passwd-sample
   (call-with-output-string



reply via email to

[Prev in Thread] Current Thread [Next in Thread]