activation: Lock /etc/.pwd.lock before accessing databases.
Suggested by Florian Pelz <pelzflorian@pelzflorian.de> in <http://bugs.gnu.org/35996>. * gnu/build/accounts.scm (%password-lock-file): New variable. * gnu/build/activation.scm (activate-users+groups): Wrap calls to 'user+group-databases', 'write-group', etc. into 'with-file-lock'.
This commit is contained in:
parent
5f0cf1df71
commit
d497b6ab39
|
@ -51,6 +51,7 @@
|
||||||
group-entry-gid
|
group-entry-gid
|
||||||
group-entry-members
|
group-entry-members
|
||||||
|
|
||||||
|
%password-lock-file
|
||||||
write-group
|
write-group
|
||||||
write-passwd
|
write-passwd
|
||||||
write-shadow
|
write-shadow
|
||||||
|
@ -224,6 +225,11 @@ each field."
|
||||||
(serialization list->comma-separated comma-separated->list)
|
(serialization list->comma-separated comma-separated->list)
|
||||||
(default '())))
|
(default '())))
|
||||||
|
|
||||||
|
(define %password-lock-file
|
||||||
|
;; The password database lock file used by libc's 'lckpwdf'. Users should
|
||||||
|
;; grab this lock with 'with-file-lock' when they access the databases.
|
||||||
|
"/etc/.pwd.lock")
|
||||||
|
|
||||||
(define (database-writer file mode entry->string)
|
(define (database-writer file mode entry->string)
|
||||||
(lambda* (entries #:optional (file-or-port file))
|
(lambda* (entries #:optional (file-or-port file))
|
||||||
"Write ENTRIES to FILE-OR-PORT. When FILE-OR-PORT is a file name, write
|
"Write ENTRIES to FILE-OR-PORT. When FILE-OR-PORT is a file name, write
|
||||||
|
|
|
@ -22,6 +22,7 @@
|
||||||
#:use-module (gnu build accounts)
|
#:use-module (gnu build accounts)
|
||||||
#:use-module (gnu build linux-boot)
|
#:use-module (gnu build linux-boot)
|
||||||
#:use-module (guix build utils)
|
#:use-module (guix build utils)
|
||||||
|
#:use-module ((guix build syscalls) #:select (with-file-lock))
|
||||||
#:use-module (ice-9 ftw)
|
#:use-module (ice-9 ftw)
|
||||||
#:use-module (ice-9 match)
|
#:use-module (ice-9 match)
|
||||||
#:use-module (ice-9 vlist)
|
#:use-module (ice-9 vlist)
|
||||||
|
@ -129,11 +130,15 @@ group records) are all available."
|
||||||
;; Allow home directories to be created under /var/lib.
|
;; Allow home directories to be created under /var/lib.
|
||||||
(mkdir-p "/var/lib")
|
(mkdir-p "/var/lib")
|
||||||
|
|
||||||
|
;; Take same lock as libc's 'lckpwdf' (but without a timeout) while we read
|
||||||
|
;; and write the databases. This ensures there's no race condition with
|
||||||
|
;; other tools that might be accessing it at the same time.
|
||||||
|
(with-file-lock %password-lock-file
|
||||||
(let-values (((groups passwd shadow)
|
(let-values (((groups passwd shadow)
|
||||||
(user+group-databases users groups)))
|
(user+group-databases users groups)))
|
||||||
(write-group groups)
|
(write-group groups)
|
||||||
(write-passwd passwd)
|
(write-passwd passwd)
|
||||||
(write-shadow shadow)
|
(write-shadow shadow)))
|
||||||
|
|
||||||
;; Home directories of non-system accounts are created by
|
;; Home directories of non-system accounts are created by
|
||||||
;; 'activate-user-home'.
|
;; 'activate-user-home'.
|
||||||
|
@ -144,7 +149,7 @@ group records) are all available."
|
||||||
(for-each (lambda (directory)
|
(for-each (lambda (directory)
|
||||||
(chown directory 0 0)
|
(chown directory 0 0)
|
||||||
(chmod directory #o555))
|
(chmod directory #o555))
|
||||||
(duplicates (map user-account-home-directory system-accounts)))))
|
(duplicates (map user-account-home-directory system-accounts))))
|
||||||
|
|
||||||
(define (activate-user-home users)
|
(define (activate-user-home users)
|
||||||
"Create and populate the home directory of USERS, a list of tuples, unless
|
"Create and populate the home directory of USERS, a list of tuples, unless
|
||||||
|
|
Loading…
Reference in New Issue