From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms13.migadu.com with LMTPS id IKyoEk293GZmdwAA62LTzQ:P1 (envelope-from ) for ; Sat, 07 Sep 2024 20:53:33 +0000 Received: from aspmx1.migadu.com ([2001:41d0:303:e16b::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1.migadu.com with LMTPS id IKyoEk293GZmdwAA62LTzQ (envelope-from ) for ; Sat, 07 Sep 2024 22:53:33 +0200 X-Envelope-To: larch@yhetil.org Authentication-Results: aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=EZuF4Slb; dkim=fail ("body hash did not verify") header.d=autistici.org header.s=stigmate header.b=jA7HTGnS; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=yhetil.org; s=key1; t=1725742413; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding:resent-cc: resent-from:resent-sender:resent-message-id:in-reply-to:in-reply-to: references:references:list-id:list-help:list-unsubscribe: list-subscribe:list-post:dkim-signature; bh=PY0LDNsvZ0e8jIuAvqins280d32mkqGs6YSQIdUgVjw=; b=kuzv6vsbCqeZ6jvGhLQRFsyaC4vkuyjE80HiKQ7eE7tXZkSMlHrmcf2h+2KPE4AKIz5L+e RHtZBSfwaWcKgF+cefwV278J8asHqNaasf/RqHtM1GDKGDZ0YbcgEAA+GBJXPrDxZ4keYl yYr33UW3sDK0/2q15J2eV/W5ACV3g+j8Yqf4bnEEr/54AUIpvVkNjibQXmnDJKJDDZjOVA xKk5cGv7GszuulJdw/UfYFBtXU6vQfA/0H0pjpcamsGLBjsW57ii33xd/e80+D5EMRGlAX RNhZ6Iv5NnXsX5MmhV63YwJaiYBJmSiiTi82ZERemz8swetkLAoTtY0wbHNoTw== ARC-Authentication-Results: i=1; aspmx1.migadu.com; dkim=fail ("body hash did not verify") header.d=debbugs.gnu.org header.s=debbugs-gnu-org header.b=EZuF4Slb; dkim=fail ("body hash did not verify") header.d=autistici.org header.s=stigmate header.b=jA7HTGnS; spf=pass (aspmx1.migadu.com: domain of "guix-patches-bounces+larch=yhetil.org@gnu.org" designates 209.51.188.17 as permitted sender) smtp.mailfrom="guix-patches-bounces+larch=yhetil.org@gnu.org"; dmarc=pass (policy=none) header.from=gnu.org ARC-Seal: i=1; s=key1; d=yhetil.org; t=1725742413; a=rsa-sha256; cv=none; b=c+AH3YXkL4t0NLQsmOVOCnKFX6d9qO2LnkZ5RQdfHFZz2/wBeaAFQ7fbfwDAQFegr3r0Fd 124rMivei0ofkvM8y6m/vlDpI0OXOchqu88lv5SI5b6HllqDZNb7+CDLPhETaknSu1Mna+ h40bUsFP8OYtFpjMlOysIKdUzBl0ktXOEESvgNhNcIVriTo2+/Sch7fkUB5VlfjIyCOnjU YF1Yp/PZk7nZ7jDBaGwAL+JxW9RdLA6Lf0K6d5x5Y+m8LhugkKkSNRKyhfK5DBG001O6u6 Mzny72PJkvxGlOe/yaV3sUJcitCpOWnMrfPTg7PpIJCO/qzWNYAZdoknahrrfw== Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by aspmx1.migadu.com (Postfix) with ESMTPS id E139E70C7C for ; Sat, 07 Sep 2024 22:53:32 +0200 (CEST) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sn2QY-0004bz-QA; Sat, 07 Sep 2024 16:53:02 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sn2QX-0004be-G5 for guix-patches@gnu.org; Sat, 07 Sep 2024 16:53:01 -0400 Received: from debbugs.gnu.org ([2001:470:142:5::43]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1sn2QX-0001wQ-6q for guix-patches@gnu.org; Sat, 07 Sep 2024 16:53:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=debbugs.gnu.org; s=debbugs-gnu-org; h=MIME-Version:Date:From:To:In-Reply-To:References:Subject; bh=eb+5clUKO/1jGXfV4k9QcgTp8DbrUa9GLwE/7rDoo10=; b=EZuF4SlbYFZUb67lTjqbqq73euFdLIIurS4vk/cyMdDh9Y5hf+0IiA9poY6A7gxAWWaMjymD8ossBevcQ/AxUoC1Mi7v7gHcTrDLAdfBqvzyd1VmDranESlMbGzDWzZbTDRoU82ITm2TvUKnNlWohUFsXCKnCNi1wsUJUPv4IfQ/ukw2sg/p3nVvtwxkzTCzIqGt+zb+0SV0LM0oLd064Wl5BYexNaFdPmju5f80PkuQoZVCR2QKFf6wo6OnBcB+dhJ7ZfOxJMLE+9iOwDNOMQzaChhyTGRiLWs8DjrQj/PLCWInxukqG0uI389QZZncvSETlsR6pPWo+BGdfTUcNQ==; Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1sn2QY-0003gH-Cn for guix-patches@gnu.org; Sat, 07 Sep 2024 16:53:02 -0400 X-Loop: help-debbugs@gnu.org Subject: [bug#72337] [PATCH v4 1/3] accounts: Add /etc/subuid and /etc/subgid support. References: In-Reply-To: Resent-From: Giacomo Leidi Original-Sender: "Debbugs-submit" Resent-CC: guix-patches@gnu.org Resent-Date: Sat, 07 Sep 2024 20:53:02 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 72337 X-GNU-PR-Package: guix-patches X-GNU-PR-Keywords: To: 72337@debbugs.gnu.org Cc: Giacomo Leidi Received: via spool by 72337-submit@debbugs.gnu.org id=B72337.172574232714048 (code B ref 72337); Sat, 07 Sep 2024 20:53:02 +0000 Received: (at 72337) by debbugs.gnu.org; 7 Sep 2024 20:52:07 +0000 Received: from localhost ([127.0.0.1]:57679 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sn2Pe-0003eT-Nd for submit@debbugs.gnu.org; Sat, 07 Sep 2024 16:52:07 -0400 Received: from confino.investici.org ([93.190.126.19]:62493) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1sn2Pc-0003eF-Jt for 72337@debbugs.gnu.org; Sat, 07 Sep 2024 16:52:05 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1725742322; bh=eb+5clUKO/1jGXfV4k9QcgTp8DbrUa9GLwE/7rDoo10=; h=From:To:Cc:Subject:Date:From; b=jA7HTGnSdygI48ICJZgxgJP6M3zSBF35XvS7Sz8MgDhi+vHZwLkI0FSREUzBf/ggA 0HtTDBDFVAOGx4Hw8smllHxY2eOwO8Bkm+erqhyK+s+0g5tMyOgF+5rK2fqJSY+jWc VwGT/pppo2aeQj+1wabHALIJLvOaVcxSHH7kEre8= Received: from mx1.investici.org (unknown [127.0.0.1]) by confino.investici.org (Postfix) with ESMTP id 4X1QJL5wT6z11Fd; Sat, 7 Sep 2024 20:52:02 +0000 (UTC) Received: from [93.190.126.19] (mx1.investici.org [93.190.126.19]) (Authenticated sender: goodoldpaul@autistici.org) by localhost (Postfix) with ESMTPSA id 4X1QJL537Fz11FW; Sat, 7 Sep 2024 20:52:02 +0000 (UTC) Date: Sat, 7 Sep 2024 22:51:47 +0200 Message-ID: <8737329a065c5436643c6e5e7d52ec760f069725.1725742309.git.goodoldpaul@autistici.org> X-Mailer: git-send-email 2.45.2 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: guix-patches@gnu.org List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-to: Giacomo Leidi X-ACL-Warn: , Giacomo Leidi via Guix-patches From: Giacomo Leidi via Guix-patches via Errors-To: guix-patches-bounces+larch=yhetil.org@gnu.org Sender: guix-patches-bounces+larch=yhetil.org@gnu.org X-Migadu-Country: US X-Migadu-Flow: FLOW_IN X-Migadu-Queue-Id: E139E70C7C X-Migadu-Scanner: mx13.migadu.com X-Migadu-Spam-Score: -7.09 X-Spam-Score: -7.09 X-TUID: cPmv1A1wJCxu This commit adds a new record type, and serializers and deserializers for it in (gnu build accounts). Each instance of this record represents one line in either /etc/subuid or /etc/subgid. Since Shadow uses the same representation for both files, it should be ok if we do it as well. This commit adds also , a user facing representation of . It is supposed to be usable directly in OS configurations. * gnu/build/accounts.scm (subid-entry): New record; (write-subgid): add serializer for subgids; (write-subuid): add serializer for subuids; (read-subgid): add serializer for subgids; (read-subuid): add serializer for subuids. * gnu/system/accounts.scm (subid-range): New record. * test/accounts.scm: Test them. Change-Id: I6b037e40e354c069bf556412bb5b626bd3ea1b2c Signed-off-by: Giacomo Leidi --- gnu/build/accounts.scm | 37 ++++++++++++++++++++++++--- gnu/system/accounts.scm | 17 +++++++++++++ tests/accounts.scm | 55 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 106 insertions(+), 3 deletions(-) diff --git a/gnu/build/accounts.scm b/gnu/build/accounts.scm index fa6f454b5e..ea8c69f205 100644 --- a/gnu/build/accounts.scm +++ b/gnu/build/accounts.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2019, 2021, 2023 Ludovic Courtès +;;; Copyright © 2024 Giacomo Leidi ;;; ;;; This file is part of GNU Guix. ;;; @@ -51,13 +52,23 @@ (define-module (gnu build accounts) group-entry-gid group-entry-members + subid-entry + subid-entry? + subid-entry-name + subid-entry-start + subid-entry-count + %password-lock-file write-group write-passwd write-shadow + write-subgid + write-subuid read-group read-passwd read-shadow + read-subgid + read-subuid %id-min %id-max @@ -68,11 +79,12 @@ (define-module (gnu build accounts) ;;; Commentary: ;;; -;;; This modules provides functionality equivalent to the C library's +;;; This module provides functionality equivalent to the C library's ;;; , , and routines, as well as a subset of the ;;; functionality of the Shadow command-line tools. It can parse and write -;;; /etc/passwd, /etc/shadow, and /etc/group. It can also take care of UID -;;; and GID allocation in a way similar to what 'useradd' does. +;;; /etc/passwd, /etc/shadow, /etc/group, /etc/subuid and /etc/subgid. It can +;;; also take care of UID and GID allocation in a way similar to what 'useradd' +;;; does. The same goes for sub UID and sub GID allocation. ;;; ;;; The benefit is twofold: less code is involved, and the ID allocation ;;; strategy and state preservation is made explicit. @@ -225,6 +237,17 @@ (define-database-entry ; (serialization list->comma-separated comma-separated->list) (default '()))) +(define-database-entry ; + subid-entry make-subid-entry + subid-entry? + (serialization #\: subid-entry->string string->subid-entry) + + (name subid-entry-name) + (start subid-entry-start + (serialization number->string string->number)) + (count subid-entry-count + (serialization number->string string->number))) + (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. @@ -265,6 +288,10 @@ (define write-shadow (database-writer "/etc/shadow" #o600 shadow-entry->string)) (define write-group (database-writer "/etc/group" #o644 group-entry->string)) +(define write-subuid + (database-writer "/etc/subuid" #o644 subid-entry->string)) +(define write-subgid + (database-writer "/etc/subgid" #o644 subid-entry->string)) (define (database-reader file string->entry) (lambda* (#:optional (file-or-port file)) @@ -287,6 +314,10 @@ (define read-shadow (database-reader "/etc/shadow" string->shadow-entry)) (define read-group (database-reader "/etc/group" string->group-entry)) +(define read-subuid + (database-reader "/etc/subuid" string->subid-entry)) +(define read-subgid + (database-reader "/etc/subgid" string->subid-entry)) ;;; diff --git a/gnu/system/accounts.scm b/gnu/system/accounts.scm index 586cff1842..9a006c188d 100644 --- a/gnu/system/accounts.scm +++ b/gnu/system/accounts.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2013, 2014, 2015, 2016, 2017, 2018, 2019 Ludovic Courtès +;;; Copyright © 2024 Giacomo Leidi ;;; ;;; This file is part of GNU Guix. ;;; @@ -39,6 +40,12 @@ (define-module (gnu system accounts) user-group-id user-group-system? + subid-range + subid-range? + subid-range-name + subid-range-start + subid-range-count + sexp->user-account sexp->user-group @@ -85,6 +92,16 @@ (define-record-type* (system? user-group-system? ; Boolean (default #f))) +(define-record-type* + subid-range make-subid-range + subid-range? + (name subid-range-name) + (start subid-range-start (default #f)) ; number + (count subid-range-count ; number + ; from find_new_sub_gids.c and + ; find_new_sub_uids.c + (default 65536))) + (define (default-home-directory account) "Return the default home directory for ACCOUNT." (string-append "/home/" (user-account-name account))) diff --git a/tests/accounts.scm b/tests/accounts.scm index 78136390bb..4944c22f49 100644 --- a/tests/accounts.scm +++ b/tests/accounts.scm @@ -1,5 +1,6 @@ ;;; GNU Guix --- Functional package management for GNU ;;; Copyright © 2019 Ludovic Courtès +;;; Copyright © 2024 Giacomo Leidi ;;; ;;; This file is part of GNU Guix. ;;; @@ -41,6 +42,16 @@ (define %shadow-sample charlie:" (crypt "hey!" "$6$abc") ":17169:::::: nobody:!:0::::::\n")) +(define %subuid-sample + "\ +root:100000:300 +ada:100300:300\n") + +(define %subgid-sample + "\ +root:100000:600 +ada:100600:300\n") + (test-begin "accounts") @@ -135,6 +146,50 @@ (define %shadow-sample read-shadow) port)))) +(test-equal "write-subuid" + %subuid-sample + (call-with-output-string + (lambda (port) + (write-subuid (list (subid-entry + (name "root") + (start 100000) + (count 300)) + (subid-entry + (name "ada") + (start 100300) + (count 300))) + port)))) + +(test-equal "read-subuid + write-subuid" + %subuid-sample + (call-with-output-string + (lambda (port) + (write-subuid (call-with-input-string %subuid-sample + read-subuid) + port)))) + +(test-equal "write-subgid" + %subgid-sample + (call-with-output-string + (lambda (port) + (write-subgid (list (subid-entry + (name "root") + (start 100000) + (count 600)) + (subid-entry + (name "ada") + (start 100600) + (count 300))) + port)))) + +(test-equal "read-subgid + write-subgid" + %subgid-sample + (call-with-output-string + (lambda (port) + (write-subgid (call-with-input-string %subgid-sample + read-subgid) + port)))) + (define allocate-groups (@@ (gnu build accounts) allocate-groups)) (define allocate-passwd (@@ (gnu build accounts) allocate-passwd)) base-commit: 4ba9f3e0f1484524f91ca1f7ec3a4ce7cb8873ff -- 2.45.2