Skip to content

Commit f80c7ae

Browse files
moygitster
authored andcommitted
Use git_mkstemp_mode and xmkstemp_mode in odb_mkstemp, not chmod later.
We used to create 0600 files, and then use chmod to set the group and other permission bits to the umask. This usually has the same effect as a normal file creation with a umask. But in the presence of ACLs, the group permission plays the role of the ACL mask: the "g" bits of newly created files are chosen according to default ACL mask of the directory, not according to the umask, and doing a chmod() on these "g" bits affect the ACL's mask instead of actual group permission. In other words, creating files with 0600 and then doing a chmod to the umask creates files which are unreadable by users allowed in the default ACL. To create the files without breaking ACLs, we let the umask do it's job at the file's creation time, and get rid of the later chmod. Signed-off-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent b862b61 commit f80c7ae

File tree

3 files changed

+10
-20
lines changed

3 files changed

+10
-20
lines changed

builtin-pack-objects.c

Lines changed: 2 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -464,9 +464,6 @@ static int write_one(struct sha1file *f,
464464
return 1;
465465
}
466466

467-
/* forward declaration for write_pack_file */
468-
static int adjust_perm(const char *path, mode_t mode);
469-
470467
static void write_pack_file(void)
471468
{
472469
uint32_t i = 0, j;
@@ -523,21 +520,17 @@ static void write_pack_file(void)
523520
}
524521

525522
if (!pack_to_stdout) {
526-
mode_t mode = umask(0);
527523
struct stat st;
528524
const char *idx_tmp_name;
529525
char tmpname[PATH_MAX];
530526

531-
umask(mode);
532-
mode = 0444 & ~mode;
533-
534527
idx_tmp_name = write_idx_file(NULL, written_list,
535528
nr_written, sha1);
536529

537530
snprintf(tmpname, sizeof(tmpname), "%s-%s.pack",
538531
base_name, sha1_to_hex(sha1));
539532
free_pack_by_name(tmpname);
540-
if (adjust_perm(pack_tmp_name, mode))
533+
if (adjust_shared_perm(pack_tmp_name))
541534
die_errno("unable to make temporary pack file readable");
542535
if (rename(pack_tmp_name, tmpname))
543536
die_errno("unable to rename temporary pack file");
@@ -565,7 +558,7 @@ static void write_pack_file(void)
565558

566559
snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
567560
base_name, sha1_to_hex(sha1));
568-
if (adjust_perm(idx_tmp_name, mode))
561+
if (adjust_shared_perm(idx_tmp_name))
569562
die_errno("unable to make temporary index file readable");
570563
if (rename(idx_tmp_name, tmpname))
571564
die_errno("unable to rename temporary index file");
@@ -2125,13 +2118,6 @@ static void get_object_list(int ac, const char **av)
21252118
loosen_unused_packed_objects(&revs);
21262119
}
21272120

2128-
static int adjust_perm(const char *path, mode_t mode)
2129-
{
2130-
if (chmod(path, mode))
2131-
return -1;
2132-
return adjust_shared_perm(path);
2133-
}
2134-
21352121
int cmd_pack_objects(int argc, const char **argv, const char *prefix)
21362122
{
21372123
int use_internal_rev_list = 0;

t/t1304-default-acl.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ test_expect_failure 'Objects creation does not break ACLs with restrictive umask
5959
check_perms_and_acl .git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
6060
'
6161

62-
test_expect_failure 'git gc does not break ACLs with restrictive umask' '
62+
test_expect_success 'git gc does not break ACLs with restrictive umask' '
6363
git gc &&
6464
check_perms_and_acl .git/objects/pack/*.pack
6565
'

wrapper.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -277,10 +277,14 @@ int git_inflate(z_streamp strm, int flush)
277277
int odb_mkstemp(char *template, size_t limit, const char *pattern)
278278
{
279279
int fd;
280-
280+
/*
281+
* we let the umask do its job, don't try to be more
282+
* restrictive except to remove write permission.
283+
*/
284+
int mode = 0444;
281285
snprintf(template, limit, "%s/%s",
282286
get_object_directory(), pattern);
283-
fd = mkstemp(template);
287+
fd = git_mkstemp_mode(template, mode);
284288
if (0 <= fd)
285289
return fd;
286290

@@ -289,7 +293,7 @@ int odb_mkstemp(char *template, size_t limit, const char *pattern)
289293
snprintf(template, limit, "%s/%s",
290294
get_object_directory(), pattern);
291295
safe_create_leading_directories(template);
292-
return xmkstemp(template);
296+
return xmkstemp_mode(template, mode);
293297
}
294298

295299
int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1)

0 commit comments

Comments
 (0)