git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Junio C Hamano <gitster@pobox.com>
To: Christian Couder <christian.couder@gmail.com>
Cc: git@vger.kernel.org, "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Michael Haggerty" <mhagger@alum.mit.edu>,
	"Nguyen Thai Ngoc Duy" <pclouds@gmail.com>,
	"Ramsay Jones" <ramsay@ramsayjones.plus.com>,
	"Christian Couder" <chriscool@tuxfamily.org>
Subject: Re: [PATCH v2 1/3] read-cache: use shared perms when writing shared index
Date: Fri, 23 Jun 2017 15:02:49 -0700	[thread overview]
Message-ID: <xmqq60fmcqgm.fsf@gitster.mtv.corp.google.com> (raw)
In-Reply-To: <20170623151640.24082-1-chriscool@tuxfamily.org> (Christian Couder's message of "Fri, 23 Jun 2017 17:16:38 +0200")

Christian Couder <christian.couder@gmail.com> writes:

> Since f6ecc62dbf (write_shared_index(): use tempfile module, 2015-08-10)
> write_shared_index() has been using mks_tempfile() to create the
> temporary file that will become the shared index.
>
> But even before that, it looks like the functions used to create this
> file didn't call adjust_shared_perm(), which means that the shared
> index file has always been created with 600 permissions regardless
> of the shared permission settings.
>
> Because of that, on repositories created with `git init --shared=all`
> and using the split index feature, one gets an error like:
>
> fatal: .git/sharedindex.a52f910b489bc462f187ab572ba0086f7b5157de: index file open failed: Permission denied
>
> when another user performs any operation that reads the shared index.
>
> We could use create_tempfile() that calls adjust_shared_perm(), but
> unfortunately create_tempfile() doesn't replace the XXXXXX at the end
> of the path it is passed. So let's just call adjust_shared_perm() by
> ourselves.

Because create_tempfile() is not even a viable alternative, the
above sounds just as silly as saying "We could use X, but
unfortunately that X doesn't create a temporary file and return its
file descriptor" with X replaced with any one of about a dozen
functions that happen to call adjust_shared_perm().

	Call adjust_shared_perm() on the temporary file created by
	mks_tempfile() ourselves to adjust the permission bits.

should be sufficient.

Thanks.

>
> Signed-off-by: Christian Couder <chriscool@tuxfamily.org>
> ---
>  read-cache.c | 8 ++++++++
>  1 file changed, 8 insertions(+)
>
> diff --git a/read-cache.c b/read-cache.c
> index bc156a133e..66f85f8d58 100644
> --- a/read-cache.c
> +++ b/read-cache.c
> @@ -2425,6 +2425,14 @@ static int write_shared_index(struct index_state *istate,
>  		delete_tempfile(&temporary_sharedindex);
>  		return ret;
>  	}
> +	ret = adjust_shared_perm(temporary_sharedindex.filename.buf);
> +	if (ret) {
> +		int save_errno = errno;
> +		error("cannot fix permission bits on %s", temporary_sharedindex.filename.buf);
> +		delete_tempfile(&temporary_sharedindex);
> +		errno = save_errno;
> +		return ret;
> +	}
>  	ret = rename_tempfile(&temporary_sharedindex,
>  			      git_path("sharedindex.%s", sha1_to_hex(si->base->sha1)));
>  	if (!ret) {

  parent reply	other threads:[~2017-06-23 22:02 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2017-06-23 15:16 [PATCH v2 1/3] read-cache: use shared perms when writing shared index Christian Couder
2017-06-23 15:16 ` [PATCH v2 2/3] t1301: move modebits() to test-lib-functions.sh Christian Couder
2017-06-23 15:16 ` [PATCH v2 3/3] t1700: make sure split-index respects core.sharedrepository Christian Couder
2017-06-23 22:20   ` Junio C Hamano
2017-06-25  4:39     ` Christian Couder
2017-06-23 21:55 ` [PATCH v2 1/3] read-cache: use shared perms when writing shared index Junio C Hamano
2017-06-23 22:02 ` Junio C Hamano [this message]
2017-06-25  4:42   ` Christian Couder

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=xmqq60fmcqgm.fsf@gitster.mtv.corp.google.com \
    --to=gitster@pobox.com \
    --cc=avarab@gmail.com \
    --cc=chriscool@tuxfamily.org \
    --cc=christian.couder@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=mhagger@alum.mit.edu \
    --cc=pclouds@gmail.com \
    --cc=ramsay@ramsayjones.plus.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).