From owner-freebsd-current@FreeBSD.ORG Mon Nov 19 22:37:48 2012 Return-Path: Delivered-To: freebsd-current@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id BF01FE7A for ; Mon, 19 Nov 2012 22:37:48 +0000 (UTC) (envelope-from baptiste.daroussin@gmail.com) Received: from mail-wi0-f178.google.com (mail-wi0-f178.google.com [209.85.212.178]) by mx1.freebsd.org (Postfix) with ESMTP id 44BC38FC16 for ; Mon, 19 Nov 2012 22:37:47 +0000 (UTC) Received: by mail-wi0-f178.google.com with SMTP id hm6so371083wib.13 for ; Mon, 19 Nov 2012 14:37:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=sender:date:from:to:subject:message-id:references:mime-version :content-type:content-disposition:in-reply-to:user-agent; bh=IBe7lU1bY397xYrVcddT3apnW97mDtVu32B3GsEkOMk=; b=Z9uRrOFATPdwXgbMV64iictW1gmyiE6ywqV90puR78NUdXnNhnrwdM68bi5tFT6n6e dAS8yowlMiPLxHQygxa5vx2TRc0q146LDwNGfZaO2aRWg+/I7WRJS+NrsqLG4/e+RmZb ZjYhZD3j1eIEOAPNILTWR8aKBJgpAlZFNb7+M/4LYW3M/nFTvE+rJPGFB+MDOYluIadU gBJYxBTqnvgsrSnoj54KHofyiVN4rJ4OdnibHTR4KHIvaZRo4TSdP0sJCp8d/3h2RuLI 5z3K4kcXxIw7L3CKIJiTkSGhcZfU54uvtLQzhWxppLQGM0MetThmgkIyS/EUoIzOokRj I2NQ== Received: by 10.180.99.36 with SMTP id en4mr11253514wib.20.1353364667332; Mon, 19 Nov 2012 14:37:47 -0800 (PST) Received: from ithaqua.etoilebsd.net (ithaqua.etoilebsd.net. [37.59.37.188]) by mx.google.com with ESMTPS id ec3sm15367039wib.10.2012.11.19.14.37.46 (version=TLSv1/SSLv3 cipher=OTHER); Mon, 19 Nov 2012 14:37:46 -0800 (PST) Sender: Baptiste Daroussin Date: Mon, 19 Nov 2012 23:37:45 +0100 From: Baptiste Daroussin To: Mateusz Guzik , Ryan Stone , FreeBSD Current Subject: Re: pw keeps setting /etc/group to 0600 Message-ID: <20121119223745.GG71195@ithaqua.etoilebsd.net> References: <20121119222843.GB22292@dft-labs.eu> MIME-Version: 1.0 Content-Type: multipart/signed; micalg=pgp-sha1; protocol="application/pgp-signature"; boundary="+QwZB9vYiNIzNXIj" Content-Disposition: inline In-Reply-To: <20121119222843.GB22292@dft-labs.eu> User-Agent: Mutt/1.5.21 (2010-09-15) X-BeenThere: freebsd-current@freebsd.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Discussions about the use of FreeBSD-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 19 Nov 2012 22:37:48 -0000 --+QwZB9vYiNIzNXIj Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Mon, Nov 19, 2012 at 11:28:43PM +0100, Mateusz Guzik wrote: > On Sat, Nov 17, 2012 at 11:20:21AM -0500, Ryan Stone wrote: > > My original complaint that /etc/group gets permissions of 0600 is a res= ult > > of a bug in libutil, which bapt@ ported pw to use in r242349. The new > > group manipulation API using mktemp to create a temporary file, writes = the > > new group database to the temp file and then renames the temp file to > > /etc/group. The problem here is that mktemp creates a file with a mode= of > > 600, and libutil never chmods it. That should be pretty trivial to fix. >=20 > My additional 0,03$: >=20 > I took closer look to this and I think that problems are much broader > than this. I don't know if similar problems were present before. >=20 > First, pw should not fail if other instance is running, it should wait > instead (think of parallel batch scripts adding some users/groups). >=20 > Second, current code has a race: > lockfd =3D open(group_file, O_RDONLY, 0); > if (lockfd < 0 || fcntl(lockfd, F_SETFD, 1) =3D=3D -1) > err(1, "%s", group_file); > if (flock(lockfd, LOCK_EX|LOCK_NB) =3D=3D -1) { > [..] > gr_copy(pfd, tfd, gr, old_gr); /* copy from groupfile to tempfile */ > [..] > rename(tempfile,groupfile); >=20 > Now let's consider threads A and B: >=20 > A: open() > A: lock(); > A: gr_copy > B: open() >=20 > Now B has file descriptor to /etc/group that is about to be removed. >=20 > A: rename() > A: unlock() > B: lock() >=20 > Now B has a lock on unlinked file. >=20 > B: gr_copy() > B: rename() >=20 > ... and stores new content losing modifications done by A >=20 > Third, I don't like current api. > gr_lock and gr_tmp have no arguments (that matter anyway) > gr_copy operates on two descriptors given as arguments > gr_mkdb takes nothing and is expected to do The Right Thing gr_mkdb should chmod 0644 after renaming if rename worked. I should work on this soon. The API has been design to match the exact same api of pw_utils, I don't li= ke it either but at least this is consistent. regards, Bapt --+QwZB9vYiNIzNXIj Content-Type: application/pgp-signature -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (FreeBSD) iEYEARECAAYFAlCqtLkACgkQ8kTtMUmk6Ey/xgCdFhwC2X2HH7+SOki6QmTc7eBW sBYAn3nXdRkPnwoHVcFw61iUHdPgnNCz =lm2g -----END PGP SIGNATURE----- --+QwZB9vYiNIzNXIj--