@matheusbsbs / matheus-bagliano / commits / 94df2506ed
Fork 0

shared repository: optionally allow reading to "others".

This enhances core.sharedrepository to have additionally specify that read and exec permissions to be given to others as well. It is useful when serving a repository via gitweb and git-daemon that runs as a user outside the project group. The configuration item can take the following values: [core] sharedrepository ; the same as "group" sharedrepository = true ; ditto sharedrepository = 1 ; ditto sharedrepository = group ; allow rwx to group sharedrepository = all ; allow rwx to group, allow rx to other sharedrepository = umask ; not shared - use umask It also extends "git init-db" to take "--shared=all" and friends from the command line. Signed-off-by: Junio C Hamano <junkio@cox.net>

Junio C Hamano committed Jun 9, 2006 at 23:09 UTC 94df2506edd76a886a1044376f8c99349b2f226e
5 files changed +47 -7
builtin-init-db.c
+12 -3
@@ -263,7 +263,9 @@ int cmd_init_db(int argc, const char **argv, char **envp)
263 if (!strncmp(arg, "--template=", 11))
264 template_dir = arg+11;
265 else if (!strcmp(arg, "--shared"))
266 - shared_repository = 1;
266 + shared_repository = PERM_GROUP;
267 + else if (!strncmp(arg, "--shared=", 9))
268 + shared_repository = git_config_perm("arg", arg+9);
269 else
270 die(init_db_usage);
271 }
@@ -301,8 +303,15 @@ int cmd_init_db(int argc, const char **argv, char **envp)
303 strcpy(path+len, "/info");
304 safe_create_dir(path, 1);
305
304 - if (shared_repository)
305 - git_config_set("core.sharedrepository", "true");
306 + if (shared_repository) {
307 + char buf[10];
308 + /* We do not spell "group" and such, so that
309 + * the configuration can be read by older version
310 + * of git.
311 + */
312 + sprintf(buf, "%d", shared_repository);
313 + git_config_set("core.sharedrepository", buf);
314 + }
315
316 return 0;
317 }
cache.h
+6
@@ -208,6 +208,12 @@ extern const unsigned char null_sha1[20];
208
209 int git_mkstemp(char *path, size_t n, const char *template);
210
211 +enum sharedrepo {
212 + PERM_UMASK = 0,
213 + PERM_GROUP,
214 + PERM_EVERYBODY
215 +};
216 +int git_config_perm(const char *var, const char *value);
217 int adjust_shared_perm(const char *path);
218 int safe_create_leading_directories(char *path);
219 char *safe_strncpy(char *, const char *, size_t);
environment.c
+1 -1
@@ -18,7 +18,7 @@ int log_all_ref_updates = 0;
18 int warn_ambiguous_refs = 1;
19 int repository_format_version = 0;
20 char git_commit_encoding[MAX_ENCODING_LENGTH] = "utf-8";
21 -int shared_repository = 0;
21 +int shared_repository = PERM_UMASK;
22 const char *apply_default_whitespace = NULL;
23
24 static char *git_dir, *git_object_dir, *git_index_file, *git_refs_dir,
path.c
+12 -2
@@ -262,11 +262,21 @@ int adjust_shared_perm(const char *path)
262 return -1;
263 mode = st.st_mode;
264 if (mode & S_IRUSR)
265 - mode |= S_IRGRP;
265 + mode |= (shared_repository == PERM_GROUP
266 + ? S_IRGRP
267 + : (shared_repository == PERM_EVERYBODY
268 + ? (S_IRGRP|S_IROTH)
269 + : 0));
270 +
271 if (mode & S_IWUSR)
272 mode |= S_IWGRP;
273 +
274 if (mode & S_IXUSR)
269 - mode |= S_IXGRP;
275 + mode |= (shared_repository == PERM_GROUP
276 + ? S_IXGRP
277 + : (shared_repository == PERM_EVERYBODY
278 + ? (S_IXGRP|S_IXOTH)
279 + : 0));
280 if (S_ISDIR(mode))
281 mode |= S_ISGID;
282 if (chmod(path, mode) < 0)
setup.c
+16 -1
@@ -219,12 +219,27 @@ const char *setup_git_directory_gently(int *nongit_ok)
219 return cwd + offset;
220 }
221
222 +int git_config_perm(const char *var, const char *value)
223 +{
224 + if (value) {
225 + if (!strcmp(value, "umask"))
226 + return PERM_UMASK;
227 + if (!strcmp(value, "group"))
228 + return PERM_GROUP;
229 + if (!strcmp(value, "all") ||
230 + !strcmp(value, "world") ||
231 + !strcmp(value, "everybody"))
232 + return PERM_EVERYBODY;
233 + }
234 + return git_config_bool(var, value);
235 +}
236 +
237 int check_repository_format_version(const char *var, const char *value)
238 {
239 if (strcmp(var, "core.repositoryformatversion") == 0)
240 repository_format_version = git_config_int(var, value);
241 else if (strcmp(var, "core.sharedrepository") == 0)
227 - shared_repository = git_config_bool(var, value);
242 + shared_repository = git_config_perm(var, value);
243 return 0;
244 }
245