From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mp1 ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by ms11 with LMTPS id SCzYEoGu9V89fgAA0tVLHw (envelope-from ) for ; Wed, 06 Jan 2021 12:35:13 +0000 Received: from aspmx1.migadu.com ([2001:41d0:2:4a6f::]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) by mp1 with LMTPS id SDTFDoGu9V85MAAAbx9fmQ (envelope-from ) for ; Wed, 06 Jan 2021 12:35:13 +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 98BC59404C8 for ; Wed, 6 Jan 2021 12:35:12 +0000 (UTC) Received: from localhost ([::1]:57264 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1kx81t-00075T-Nw for larch@yhetil.org; Wed, 06 Jan 2021 07:35:09 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:53782) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1kx81m-00075N-N9 for bug-guix@gnu.org; Wed, 06 Jan 2021 07:35:02 -0500 Received: from debbugs.gnu.org ([209.51.188.43]:60435) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1kx81m-00074X-Fv for bug-guix@gnu.org; Wed, 06 Jan 2021 07:35:02 -0500 Received: from Debian-debbugs by debbugs.gnu.org with local (Exim 4.84_2) (envelope-from ) id 1kx81m-0002gi-B3 for bug-guix@gnu.org; Wed, 06 Jan 2021 07:35:02 -0500 X-Loop: help-debbugs@gnu.org Subject: bug#45570: [PATCH] system: Assert, that user and group names are unique. Resent-From: Leo Prikler Original-Sender: "Debbugs-submit" Resent-CC: bug-guix@gnu.org Resent-Date: Wed, 06 Jan 2021 12:35:02 +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: Ludovic =?UTF-8?Q?Court=C3=A8s?= Received: via spool by 45570-submit@debbugs.gnu.org id=B45570.160993647210284 (code B ref 45570); Wed, 06 Jan 2021 12:35:02 +0000 Received: (at 45570) by debbugs.gnu.org; 6 Jan 2021 12:34:32 +0000 Received: from localhost ([127.0.0.1]:43748 helo=debbugs.gnu.org) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kx81H-0002fn-VJ for submit@debbugs.gnu.org; Wed, 06 Jan 2021 07:34:32 -0500 Received: from mailrelay.tugraz.at ([129.27.2.202]:24822) by debbugs.gnu.org with esmtp (Exim 4.84_2) (envelope-from ) id 1kx81F-0002fc-Tz for 45570@debbugs.gnu.org; Wed, 06 Jan 2021 07:34:31 -0500 Received: from nijino.local (217-149-174-13.nat.highway.telekom.at [217.149.174.13]) by mailrelay.tugraz.at (Postfix) with ESMTPSA id 4D9phg0rTTz1LWpD; Wed, 6 Jan 2021 13:34:26 +0100 (CET) DKIM-Filter: OpenDKIM Filter v2.11.0 mailrelay.tugraz.at 4D9phg0rTTz1LWpD DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=tugraz.at; s=mailrelay; t=1609936467; bh=fwZaYPT2fRErxwRO5PcrtDKtrJ0gGW/+OZFHQmGY6MU=; h=Subject:From:To:Cc:Date:In-Reply-To:References:From; b=PJ0N9hcao075RQsuw990cuMzgNX8EOM8x1D6Rg7jRzpp5I/N+KfPrfcNCHwJPKW+B c0d6O5e9uRdNOlptMJINz6+I8WrEs3jhCFxNwOr8b8XxC11wqNC+DbVH3yjPwJkPFQ arOOgMLiRrIxAC+Ha6KriMQVwluCUaHXQW+7h4XM= Message-ID: From: Leo Prikler Date: Wed, 06 Jan 2021 13:34:26 +0100 In-Reply-To: <87v9cao0c8.fsf@gnu.org> References: <20210102055728.22594-1-leo.prikler@student.tugraz.at> <87v9cao0c8.fsf@gnu.org> Content-Type: text/plain; charset="UTF-8" User-Agent: Evolution 3.34.2 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: 45570@debbugs.gnu.org, 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: -1.24 Authentication-Results: aspmx1.migadu.com; dkim=fail (headers rsa verify failed) header.d=tugraz.at header.s=mailrelay header.b=PJ0N9hca; 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: 98BC59404C8 X-Spam-Score: -1.24 X-Migadu-Scanner: scn0.migadu.com X-TUID: ZhATibcqQxxH Hi, Am Mittwoch, den 06.01.2021, 10:56 +0100 schrieb Ludovic Courtès: > Hi, > > Leo Prikler skribis: > > > *gnu/system/shadow.scm (find-duplicates): New variable. > > (assert-unique-account-names, assert-unique-group-names): New > > variables. > > (account-activation): Use them here. > > [...] > > > +(define (find-duplicates list =) > > + (match list > > + ('() '()) > > This should be: > > (match list > (() '()) > …) > > I’m surprised '() works as a pattern. I think it's because matching literals works, but you're right. > > + ((first . rest) > > + (if (member first rest =) ; (srfi srfi-1) member > > + (cons first (find-duplicates rest =)) > > + (find-duplicates rest =))))) > > Note that this is quadratic; it’s fine as long as we don’t have “too > many” users, which may be the case in general. It is indeed quadratic, but would there even be an n log n solution? I've once done an n log n sort+delete-duplicates!, perhaps that'd be a nicer solution here? > > +(define (assert-unique-account-names users) > > + (for-each > > + (lambda (account) > > + (raise (condition > > + (&message > > + (message > > + (format #f (G_ "account with name '~a' found > > twice.") > > + (user-account-name account))))))) > > + (find-duplicates users (lambda (alice bob) > > + (string=? (user-account-name alice) > > + (user-account-name bob)))))) > > ‘for-each’ looks awkward since we’ll stop on the first one. How > about > something like: > > (define (assert-unique-account-names users) > (match (find-duplicates things …) > (() #t) > (lst > (raise (formatted-message (G_ "the following accounts appear > more than once:~{ ~a~}~%" > lst)))))) > > ? That'd be weird for duplicate duplicates, hence just reporting the first. Of course we could always count occurrences by allocating a local hash table and then do some fancy hash-map->list conversion. If we do use hash-tables, perhaps this could even be a linear algorithm? Regards, Leo