@matheusbsbs / matheus-bagliano / commits / f80c7ae8fe
Fork 0

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>

Matthieu Moy committed Feb 22, 2010 at 23:32 UTC f80c7ae8fe9c0f3ce93c96a2dccaba34e456e33a
3 files changed +10 -20
builtin-pack-objects.c
+2 -16
@@ -464,9 +464,6 @@ static int write_one(struct sha1file *f,
464 return 1;
465 }
466
467 -/* forward declaration for write_pack_file */
468 -static int adjust_perm(const char *path, mode_t mode);
469 -
467 static void write_pack_file(void)
468 {
469 uint32_t i = 0, j;
@@ -523,21 +520,17 @@ static void write_pack_file(void)
520 }
521
522 if (!pack_to_stdout) {
526 - mode_t mode = umask(0);
523 struct stat st;
524 const char *idx_tmp_name;
525 char tmpname[PATH_MAX];
526
531 - umask(mode);
532 - mode = 0444 & ~mode;
533 -
527 idx_tmp_name = write_idx_file(NULL, written_list,
528 nr_written, sha1);
529
530 snprintf(tmpname, sizeof(tmpname), "%s-%s.pack",
531 base_name, sha1_to_hex(sha1));
532 free_pack_by_name(tmpname);
540 - if (adjust_perm(pack_tmp_name, mode))
533 + if (adjust_shared_perm(pack_tmp_name))
534 die_errno("unable to make temporary pack file readable");
535 if (rename(pack_tmp_name, tmpname))
536 die_errno("unable to rename temporary pack file");
@@ -565,7 +558,7 @@ static void write_pack_file(void)
558
559 snprintf(tmpname, sizeof(tmpname), "%s-%s.idx",
560 base_name, sha1_to_hex(sha1));
568 - if (adjust_perm(idx_tmp_name, mode))
561 + if (adjust_shared_perm(idx_tmp_name))
562 die_errno("unable to make temporary index file readable");
563 if (rename(idx_tmp_name, tmpname))
564 die_errno("unable to rename temporary index file");
@@ -2125,13 +2118,6 @@ static void get_object_list(int ac, const char **av)
2118 loosen_unused_packed_objects(&revs);
2119 }
2120
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 -
2121 int cmd_pack_objects(int argc, const char **argv, const char *prefix)
2122 {
2123 int use_internal_rev_list = 0;
t/t1304-default-acl.sh
+1 -1
@@ -59,7 +59,7 @@ test_expect_failure 'Objects creation does not break ACLs with restrictive umask
59 check_perms_and_acl .git/objects/e6/9de29bb2d1d6434b8b29ae775ad8c2e48c5391
60 '
61
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' '
63 git gc &&
64 check_perms_and_acl .git/objects/pack/*.pack
65 '
wrapper.c
+7 -3
@@ -277,10 +277,14 @@ int git_inflate(z_streamp strm, int flush)
277 int odb_mkstemp(char *template, size_t limit, const char *pattern)
278 {
279 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;
285 snprintf(template, limit, "%s/%s",
286 get_object_directory(), pattern);
283 - fd = mkstemp(template);
287 + fd = git_mkstemp_mode(template, mode);
288 if (0 <= fd)
289 return fd;
290
@@ -289,7 +293,7 @@ int odb_mkstemp(char *template, size_t limit, const char *pattern)
293 snprintf(template, limit, "%s/%s",
294 get_object_directory(), pattern);
295 safe_create_leading_directories(template);
292 - return xmkstemp(template);
296 + return xmkstemp_mode(template, mode);
297 }
298
299 int odb_pack_keep(char *name, size_t namesz, unsigned char *sha1)