From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp2 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id EJI2Nj4q9l8uBQAA0tVLHw (envelope-from ) for ; Wed, 06 Jan 2021 21:23:10 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp2 with LMTPS id cCwJMj4q9l/3BwAAB5/wlQ (envelope-from ) for ; Wed, 06 Jan 2021 21:23:10 +0000 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 6E2C3940149 for ; Wed, 6 Jan 2021 21:23:10 +0000 (UTC) Received: from localhost ([::1]:33026 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kxGGq-0008UG-SC for larch@yhetil.org; Wed, 06 Jan 2021 16:23:08 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56696) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kxGGk-0008U7-1h for bug-guix@gnu.org; Wed, 06 Jan 2021 16:23:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:34208) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kxGGj-0008JE-Pa for bug-guix@gnu.org; Wed, 06 Jan 2021 16:23:01 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kxGGj-0003ov-Lw for bug-guix@gnu.org; Wed, 06 Jan 2021 16:23:01 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#45570: [PATCH v2] system: Assert, that user and group names are unique. References: In-Reply-To: Resent-From: Leo Prikler Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Wed, 06 Jan 2021 21:23:01 +0000 Resent-Message-ID: Resent-Sender: help-debbugs@gnu.org X-GNU-PR-Message: followup 45570 X-GNU-PR-Package: guix X-GNU-PR-Keywords: To: 45570@debbugs.gnu.org Received: via spool by 45570-submit@debbugs.gnu.org id=B45570.160996817914675 (code B ref 45570); Wed, 06 Jan 2021 21:23:01 +0000 Received: (at 45570) by debbugs.gnu.org; 6 Jan 2021 21:22:59 +0000 Received: from localhost ([127.0.0.1]:45754 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxGGh-0003od-1o for submit@debbugs.gnu.org; Wed, 06 Jan 2021 16:22:59 -0500 Received: from mailrelay.tugraz.at ([129.27.2.202]:11803) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kxGGf-0003oS-AG for 45570@debbugs.gnu.org; Wed, 06 Jan 2021 16:22:58 -0500 Received: from localhost.localdomain (217-149-174-13.nat.highway.telekom.at [217.149.174.13]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4DB2QQ1QFGz3wFK; Wed, 6 Jan 2021 22:22:54 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1609968174; bh=H/AW1y/aX8KMSGdzhYVMv9f4WP7gUpE7pZfG+aZBrC8=; h=From:To:Cc:Subject:Date; b=shbPZCUV4AxOnNXFu6aGcrx2F2rXrmOd2rvxJEzh4+ba7idQ5kA/bGft3T4FYl5Q+ WjNQGrqHJrioLUD8vt6ScIyKTGOqS67J1tzSPRaMEfkMU9TXU4uwS41V+ZIoSwA1JE RQuQaAkYsewMUwS1zzKWU9cIR7oTmQbPCKdaRaUQ= From: Leo Prikler Date: Wed, 6 Jan 2021 22:21:49 +0100 Message-Id: <20210106212148.28720-1-leo.prikler@student.tugraz.at> X-Mailer: git-send-email 2.30.0 MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-TUG-Backscatter-control: bt4lQm5Tva3SBgCuw0EnZw X-Spam-Scanner: SpamAssassin 3.003001 X-Spam-Score-relay: -1.9 X-Scanned-By: MIMEDefang 2.74 on 129.27.10.116 X-BeenThere: debbugs-submit@debbugs.gnu.org X-Mailman-Version: 2.1.18 Precedence: list X-BeenThere: bug-guix@gnu.org List-Id: Bug reports for GNU Guix List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: conjaroy@gmail.com Errors-To: bug-guix-bounces+larch=yhetil.org@gnu.org Sender: "bug-Guix" X-Migadu-Flow: FLOW_IN X-Migadu-Spam-Score: 3.76 Authentication-Results: aspmx1.migadu.com; dkim=fail (headers rsa verify failed) header.d=tugraz.at header.s=mailrelay header.b=shbPZCUV; dmarc=fail reason="SPF not aligned (relaxed)" header.from=student.tugraz.at (policy=none); spf=pass (aspmx1.migadu.com: domain of bug-guix-bounces@gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=bug-guix-bounces@gnu.org X-Migadu-Queue-Id: 6E2C3940149 X-Spam-Score: 3.76 X-Migadu-Scanner: scn0.migadu.com X-TUID: o3YpUm2tghY5 *gnu/system/shadow.scm (find-duplicates): New variable. (assert-unique-account-names, assert-unique-group-names): New variables. (account-activation): Use them here. --- gnu/system/shadow.scm | 38 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/gnu/system/shadow.scm b/gnu/system/shadow.scm index a69339bc07..4dbd578e1e 100644 --- a/gnu/system/shadow.scm +++ b/gnu/system/shadow.scm @@ -20,6 +20,7 @@ ;;; along with GNU Guix. If not, see . (define-module (gnu system shadow) + #:use-module ((guix diagnostics) #:select (formatted-message)) #:use-module (guix records) #:use-module (guix gexp) #:use-module (guix store) @@ -34,6 +35,7 @@ #:use-module ((gnu packages admin) #:select (shadow)) #:use-module (gnu packages bash) + #:use-module (ice-9 match) #:use-module (srfi srfi-1) #:use-module (srfi srfi-26) #:use-module (srfi srfi-34) @@ -222,6 +224,40 @@ for a colorful Guile experience.\\n\\n\"))))\n")) (rename-file ".nanorc" ".config/nano/nanorc")) #t)))) +(define (find-duplicates list) + (let loop ((table (make-hash-table)) + (list list)) + (match list + (() + (hash-fold (lambda (key value seed) + (if (> value 1) + (cons key seed) + seed)) + '() + table)) + ((first . rest) + (hash-set! table first + (1+ (hash-ref table first 0))) + (loop table rest))))) + +(define (assert-unique-account-names users) + (match (find-duplicates (map user-account-name users)) + (() *unspecified*) + (duplicates + (raise + (formatted-message + (G_ "the following accounts appear more than once:~{ ~a~}~%") + duplicates))))) + +(define (assert-unique-group-names groups) + (match (find-duplicates (map user-group-name groups)) + (() *unspecified*) + (duplicates + (raise + (formatted-message + (G_ "the following groups appear more than once:~{ ~a~}~%") + duplicates))))) + (define (assert-valid-users/groups users groups) "Raise an error if USERS refer to groups not listed in GROUPS." (let ((groups (list->set (map user-group-name groups)))) @@ -292,6 +328,8 @@ group." (define group-specs (map user-group->gexp groups)) + (assert-unique-account-names accounts) + (assert-unique-group-names groups) (assert-valid-users/groups accounts groups) ;; Add users and user groups. -- 2.30.0