@matheusbsbs / matheus-bagliano / commits / 138086a725
Fork 0

shared repository - add a few missing calls to adjust_shared_perm().

There were a few calls to adjust_shared_perm() that were missing: - init-db creates refs, refs/heads, and refs/tags before reading from templates that could specify sharedrepository in the config file; - updating config file created it under user's umask without adjusting; - updating refs created it under user's umask without adjusting; - switching branches created .git/HEAD under user's umask without adjusting. This moves adjust_shared_perm() from sha1_file.c to path.c, since a few SIMPLE_PROGRAM need to call repository configuration functions which in turn need to call adjust_shared_perm(). sha1_file.c needs to link with SHA1 computation library which is usually not linked to SIMPLE_PROGRAM. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jun 9, 2006 at 22:07 UTC 138086a72582620e0b3ec0aa60a78da208e89a2a
6 files changed +54 -29
builtin-init-db.c
+15
@@ -198,6 +198,21 @@ static void create_default_files(const char *git_dir, const char *template_path)
198
199 git_config(git_default_config);
200
201 + /*
202 + * We would have created the above under user's umask -- under
203 + * shared-repository settings, we would need to fix them up.
204 + */
205 + if (shared_repository) {
206 + path[len] = 0;
207 + adjust_shared_perm(path);
208 + strcpy(path + len, "refs");
209 + adjust_shared_perm(path);
210 + strcpy(path + len, "refs/heads");
211 + adjust_shared_perm(path);
212 + strcpy(path + len, "refs/tags");
213 + adjust_shared_perm(path);
214 + }
215 +
216 /*
217 * Create the default symlink from ".git/HEAD" to the "master"
218 * branch, if it does not exist yet.
config.c
+1 -1
@@ -536,7 +536,7 @@ int git_config_set_multivar(const char* key, const char* value,
536 * contents of .git/config will be written into it.
537 */
538 fd = open(lock_file, O_WRONLY | O_CREAT | O_EXCL, 0666);
539 - if (fd < 0) {
539 + if (fd < 0 || adjust_shared_perm(lock_file)) {
540 fprintf(stderr, "could not lock config file\n");
541 free(store.key);
542 ret = -1;
lockfile.c
+10 -5
@@ -27,11 +27,16 @@ int hold_lock_file_for_update(struct lock_file *lk, const char *path)
27 int fd;
28 sprintf(lk->filename, "%s.lock", path);
29 fd = open(lk->filename, O_RDWR | O_CREAT | O_EXCL, 0666);
30 - if (fd >=0 && !lk->next) {
31 - lk->next = lock_file_list;
32 - lock_file_list = lk;
33 - signal(SIGINT, remove_lock_file_on_signal);
34 - atexit(remove_lock_file);
30 + if (0 <= fd) {
31 + if (!lk->next) {
32 + lk->next = lock_file_list;
33 + lock_file_list = lk;
34 + signal(SIGINT, remove_lock_file_on_signal);
35 + atexit(remove_lock_file);
36 + }
37 + if (adjust_shared_perm(lk->filename))
38 + return error("cannot fix permission bits on %s",
39 + lk->filename);
40 }
41 return fd;
42 }
path.c
+23
@@ -250,3 +250,26 @@ char *enter_repo(char *path, int strict)
250
251 return NULL;
252 }
253 +
254 +int adjust_shared_perm(const char *path)
255 +{
256 + struct stat st;
257 + int mode;
258 +
259 + if (!shared_repository)
260 + return 0;
261 + if (lstat(path, &st) < 0)
262 + return -1;
263 + mode = st.st_mode;
264 + if (mode & S_IRUSR)
265 + mode |= S_IRGRP;
266 + if (mode & S_IWUSR)
267 + mode |= S_IWGRP;
268 + if (mode & S_IXUSR)
269 + mode |= S_IXGRP;
270 + if (S_ISDIR(mode))
271 + mode |= S_ISGID;
272 + if (chmod(path, mode) < 0)
273 + return -2;
274 + return 0;
275 +}
refs.c
+5
@@ -104,6 +104,11 @@ int create_symref(const char *git_HEAD, const char *refs_heads_master)
104 error("Unable to create %s", git_HEAD);
105 return -3;
106 }
107 + if (adjust_shared_perm(git_HEAD)) {
108 + unlink(lockpath);
109 + error("Unable to fix permissions on %s", lockpath);
110 + return -4;
111 + }
112 return 0;
113 }
114
sha1_file.c
-23
@@ -50,29 +50,6 @@ int get_sha1_hex(const char *hex, unsigned char *sha1)
50 return 0;
51 }
52
53 -int adjust_shared_perm(const char *path)
54 -{
55 - struct stat st;
56 - int mode;
57 -
58 - if (!shared_repository)
59 - return 0;
60 - if (lstat(path, &st) < 0)
61 - return -1;
62 - mode = st.st_mode;
63 - if (mode & S_IRUSR)
64 - mode |= S_IRGRP;
65 - if (mode & S_IWUSR)
66 - mode |= S_IWGRP;
67 - if (mode & S_IXUSR)
68 - mode |= S_IXGRP;
69 - if (S_ISDIR(mode))
70 - mode |= S_ISGID;
71 - if (chmod(path, mode) < 0)
72 - return -2;
73 - return 0;
74 -}
75 -
53 int safe_create_leading_directories(char *path)
54 {
55 char *pos = path;