X-Git-Url: https://git.tokkee.org/?a=blobdiff_plain;f=path.c;h=db8905f3c352592124b2f0bda18fc0ccd048528e;hb=17a10f3709c211769c9fada79bd1608aa64f6080;hp=334b2bd195f56ac6aaf9f9b8a36fe59115cd758c;hpb=1a17ee22a2fbd85a893ab36fd53168d03554c2dd;p=git.git diff --git a/path.c b/path.c index 334b2bd19..db8905f3c 100644 --- a/path.c +++ b/path.c @@ -77,20 +77,12 @@ int git_mkstemp(char *path, size_t len, const char *template) pch += n; } - safe_strncpy(pch, template, len); + strlcpy(pch, template, len); return mkstemp(path); } -char *safe_strncpy(char *dest, const char *src, size_t n) -{ - strncpy(dest, src, n); - dest[n - 1] = '\0'; - - return dest; -} - int validate_symref(const char *path) { struct stat st; @@ -250,3 +242,36 @@ char *enter_repo(char *path, int strict) return NULL; } + +int adjust_shared_perm(const char *path) +{ + struct stat st; + int mode; + + if (!shared_repository) + return 0; + if (lstat(path, &st) < 0) + return -1; + mode = st.st_mode; + if (mode & S_IRUSR) + mode |= (shared_repository == PERM_GROUP + ? S_IRGRP + : (shared_repository == PERM_EVERYBODY + ? (S_IRGRP|S_IROTH) + : 0)); + + if (mode & S_IWUSR) + mode |= S_IWGRP; + + if (mode & S_IXUSR) + mode |= (shared_repository == PERM_GROUP + ? S_IXGRP + : (shared_repository == PERM_EVERYBODY + ? (S_IXGRP|S_IXOTH) + : 0)); + if (S_ISDIR(mode)) + mode |= S_ISGID; + if (chmod(path, mode) < 0) + return -2; + return 0; +}