summaryrefslogtreecommitdiff
path: root/gnu/system
diff options
context:
space:
mode:
authorGiacomo Leidi <goodoldpaul@autistici.org>2024-10-08 00:40:27 +0200
committerLudovic Courtès <ludo@gnu.org>2024-12-18 18:32:40 +0100
commit337037d22cfcc7764c1ce87127166c351a91369d (patch)
treeaaa67b2d13770e5b0daa8cad0d00f64fa40b5fdd /gnu/system
parent58f430f69e71f95cedab9912c1c9f2cc8660fad9 (diff)
accounts: Add /etc/subid and /etc/subgid allocation logic.
This commit adds allocation logic for subid ranges. Subid ranges are ranges of contiguous subids that are mapped to a user in the host system. This patch implements a flexible allocation algorithm allowing users that do not want (or need) to specify details of the subid ranges that they are requesting to avoid doing so, while upholding requests of users that need to have specific ranges. * gnu/build/accounts.scm (%subordinate-id-min): New variable; (%subordinate-id-max): new variable; (%subordinate-id-count): new variable; (subordinate-id?): new variable; (&subordinate-id-error): new variable; (&subordinate-id-overflow-error): new variable; (&illegal-subid-range-error): new variable; (&specific-subid-range-expected-error): new variable; (&generic-subid-range-expected-error): new variable; (within-interval?): new variable; (allocate-unused-range): new variable; (allocate-generic-range): new variable; (allocate-specific-range): new variable; (reserve-subids): new variable; (range->entry): new variable; (entry->range): new variable; (allocate-subids): new variable; (subuid+subgid-databases): new variable. * gnu/system/accounts.scm (subid-range-end): New variable; (subid-range-has-start?): new variable; (subid-range-less): new variable. * test/accounts.scm: Test them. Change-Id: I8de1fd7cfe508b9c76408064d6f498471da0752d Co-Authored-By: Ludovic Courtès <ludo@gnu.org> Signed-off-by: Giacomo Leidi <goodoldpaul@autistici.org> Signed-off-by: Ludovic Courtès <ludo@gnu.org>
Diffstat (limited to 'gnu/system')
-rw-r--r--gnu/system/accounts.scm30
1 files changed, 30 insertions, 0 deletions
diff --git a/gnu/system/accounts.scm b/gnu/system/accounts.scm
index 9a006c188db..1b88ca301fc 100644
--- a/gnu/system/accounts.scm
+++ b/gnu/system/accounts.scm
@@ -45,6 +45,9 @@
45 subid-range-name 45 subid-range-name
46 subid-range-start 46 subid-range-start
47 subid-range-count 47 subid-range-count
48 subid-range-end
49 subid-range-has-start?
50 subid-range-less
48 51
49 sexp->user-account 52 sexp->user-account
50 sexp->user-group 53 sexp->user-group
@@ -102,6 +105,33 @@
102 ; find_new_sub_uids.c 105 ; find_new_sub_uids.c
103 (default 65536))) 106 (default 65536)))
104 107
108(define (subid-range-end range)
109 "Returns the last subid referenced in RANGE."
110 (and
111 (subid-range-has-start? range)
112 (+ (subid-range-start range)
113 (subid-range-count range)
114 -1)))
115
116(define (subid-range-has-start? range)
117 "Returns #t when RANGE's start is a number."
118 (number? (subid-range-start range)))
119
120(define (subid-range-less a b)
121 "Returns #t when subid range A either starts before, or is more specific
122than B. When it is not possible to determine whether a range is more specific
123w.r.t. another range their names are compared alphabetically."
124 (define start-a (subid-range-start a))
125 (define start-b (subid-range-start b))
126 (cond ((and (not start-a) (not start-b))
127 (string< (subid-range-name a)
128 (subid-range-name b)))
129 ((and start-a start-b)
130 (< start-a start-b))
131 (else
132 (and start-a
133 (not start-b)))))
134
105(define (default-home-directory account) 135(define (default-home-directory account)
106 "Return the default home directory for ACCOUNT." 136 "Return the default home directory for ACCOUNT."
107 (string-append "/home/" (user-account-name account))) 137 (string-append "/home/" (user-account-name account)))