From: Johan Herland <johan@herland.net>
To: git@vger.kernel.org
Cc: Jeff King <peff@peff.net>, Junio C Hamano <gitster@pobox.com>
Subject: [PATCH 1/2] index-pack: Create .keep files with same permissions and .pack/.idx
Date: Fri, 01 Apr 2011 03:29:05 +0200 [thread overview]
Message-ID: <201104010329.05299.johan@herland.net> (raw)
In-Reply-To: <20110331190429.GC16981@sigill.intra.peff.net>
While pushing to a remote repo, Git transiently adds a .keep file for the
pack being pushed, to protect it from a concurrent "git gc". However, the
permissions on this .keep file are such that if a different user attempts
a local cross-filesystem clone ("git clone --no-hardlinks") on the server
while the .keep file is present (either because of a concurrent push, or
because of a prior failed push that left a stale .keep file), the clone
will fail because the second user cannot access the .keep file created by
the first user.
There's no reason why the permission mode of a .keep file should be any
different from the permission mode of the corresponding .pack/.idx files.
Therefore, adjust the permission of .keep files from 0600 to 0444 modulo
the shared_repository setting.
In the above scenario, the .keep file is now accessible to the second user,
and will not prevent the clone.
Signed-off-by: Johan Herland <johan@herland.net>
---
On Thursday 31 March 2011, Jeff King wrote:
> On Thu, Mar 31, 2011 at 12:46:25PM +0200, Johan Herland wrote:
> > 1. Why does the .keep file have 0600 permissions (preventing a local
> > clone by any other user)
>
> The relevant code is in 6e180cd (Make sure objects/pack exists before
> creating a new pack, 2009-02-24). I don't see anything particular about
> the mode, so I suspect it was simply habit to make tempfiles restricted.
>
> There is nothing secret in the contents, so I don't see any reason to
> loosen it to the same permissions as the packfiles themselves.
This patch attempts to fix the permissions on .keep files.
...Johan
builtin/index-pack.c | 9 ++++++---
environment.c | 4 ++--
2 files changed, 8 insertions(+), 5 deletions(-)
diff --git a/builtin/index-pack.c b/builtin/index-pack.c
index 5a67c81..586c9ac 100644
--- a/builtin/index-pack.c
+++ b/builtin/index-pack.c
@@ -792,10 +792,11 @@ static void final(const char *final_pack_name, const char
*curr_pack_name,
if (keep_msg) {
int keep_fd, keep_msg_len = strlen(keep_msg);
- if (!keep_name)
+ if (!keep_name) {
keep_fd = odb_pack_keep(name, sizeof(name), sha1);
- else
- keep_fd = open(keep_name, O_RDWR|O_CREAT|O_EXCL, 0600);
+ keep_name = name;
+ } else
+ keep_fd = open(keep_name, O_RDWR|O_CREAT|O_EXCL, 0444);
if (keep_fd < 0) {
if (errno != EEXIST)
@@ -811,6 +812,8 @@ static void final(const char *final_pack_name, const char *curr_pack_name,
keep_name);
report = "keep";
}
+ if (adjust_shared_perm(keep_name))
+ error("unable to set permission to '%s'", keep_name);
}
if (final_pack_name != curr_pack_name) {
diff --git a/environment.c b/environment.c
index f4549d3..86bf8f4 100644
--- a/environment.c
+++ b/environment.c
@@ -191,13 +191,13 @@ int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1)
snprintf(name, namesz, "%s/pack/pack-%s.keep",
get_object_directory(), sha1_to_hex(sha1));
- fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
+ fd = open(name, O_RDWR|O_CREAT|O_EXCL, 0444);
if (0 <= fd)
return fd;
/* slow path */
safe_create_leading_directories(name);
- return open(name, O_RDWR|O_CREAT|O_EXCL, 0600);
+ return open(name, O_RDWR|O_CREAT|O_EXCL, 0444);
}
char *get_index_file(void)
--
1.7.4
next prev parent reply other threads:[~2011-04-01 1:29 UTC|newest]
Thread overview: 14+ messages / expand[flat|nested] mbox.gz Atom feed top
2011-03-31 10:46 Problems with stale .keep files on git server Johan Herland
2011-03-31 19:04 ` Jeff King
2011-04-01 1:29 ` Johan Herland [this message]
2011-04-01 21:39 ` [PATCH 1/2] index-pack: Create .keep files with same permissions and .pack/.idx Junio C Hamano
2011-04-01 21:41 ` Jeff King
2011-04-01 21:49 ` Shawn Pearce
2011-04-01 22:21 ` Junio C Hamano
2011-04-01 23:27 ` Johan Herland
2011-04-02 4:21 ` Junio C Hamano
2011-04-03 1:01 ` Johan Herland
2011-04-01 23:37 ` Johan Herland
2011-04-01 1:34 ` [RFC/PATCH 2/2] repack: Remove stale .keep files before repacking Johan Herland
2011-04-01 1:41 ` Jeff King
2011-04-01 8:12 ` Johan Herland
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
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=201104010329.05299.johan@herland.net \
--to=johan@herland.net \
--cc=git@vger.kernel.org \
--cc=gitster@pobox.com \
--cc=peff@peff.net \
/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.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.