Skip site navigation (1)Skip section navigation (2)
Date:      Sun, 23 Jun 2002 17:07:40 -0700
From:      Terry Lambert <tlambert2@mindspring.com>
To:        Paul Herman <pherman@frenchfries.net>
Cc:        "Matthew D. Fuller" <fullermd@over-yonder.net>, "Geoffrey C. Speicher" <geoff@sea-incorporated.com>, freebsd-hackers@FreeBSD.ORG
Subject:   Re: bug in pw, -STABLE [patch]
Message-ID:  <3D1662CC.FE6F6D49@mindspring.com>
References:  <20020623111412.V38509-100000@mammoth.eat.frenchfries.net>

next in thread | previous in thread | raw e-mail | index | archive | help
Paul Herman wrote:
> Fine, then lock them both, and use rename().  Patch attached.
> 
> In fact, if you look at fileupdate(), you see that it already gains
> an exclusive lock on the temp file, but not the original
> "/etc/master.passwd" (if you will.)  I think this is a bug, because
> the original is getting modified (at least in name space), so that
> should be locked while pw(8) is operating.
> 
> What do you think?

Don't use an exclusive open.  Use a standard lock file lock
mechanism.

The problem with your proposed patch is that it breaks the
ability to allow authentication against the database while
it is undergoing modification, which may be a prolonged period.

The correct way to deal with this is to make a hard link against
the file, verify that the link count is exactly 2, and if it's
not, back off and fail.

You are only permitted to write the file if you are the one that
made the second link.

Since both rename and link are atomic operations in the directory,
you are safe.

-- Terry

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-hackers" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?3D1662CC.FE6F6D49>