]> oss.titaniummirror.com Git - repo_shell.git/commitdiff
Misc cleanups
authorR. Steve McKown <rsmckown@gmail.com>
Mon, 24 Sep 2012 14:21:34 +0000 (08:21 -0600)
committerR. Steve McKown <rsmckown@gmail.com>
Mon, 24 Sep 2012 14:21:34 +0000 (08:21 -0600)
repo_shell.c

index 7fb31d4c9f6340efff9bfde16c2979deb0a25b49..ebcb246dbb315422655ab6c60cfac035e20358ff 100644 (file)
@@ -95,17 +95,16 @@ static char *dequote(char *arg)
 
 static char *add_prefix(char *prefix, char* arg)
 {
-       int size;
-
-       if (arg && prefix && strlen(prefix)) {
-               char *n = xmalloc(sizeof(char *) *
-                       (strlen(prefix) + strlen(arg) + 2));
-               strcpy(n, prefix);
-               strcat(n, "/");
-               strcat(n, arg);
-               arg = n;
+       char *narg = arg;
+        int i;
+
+       if (arg && prefix && (i = strlen(prefix))) {
+               narg = xmalloc(sizeof(char *) * (i + strlen(arg) + 2));
+               strcpy(narg, prefix);
+               strcpy(narg + i++, "/");
+               strcpy(narg + i, arg);
        }
-       return arg;
+       return narg;
 }
 
 static int check_ssh_interactive(uid_t uid)
@@ -143,12 +142,11 @@ static int git_acl(const char *user, const char *repo)
 
 static int git_check_access(const char *cmd, const char *repo, const char *user)
 {
-       int rw = 1; /* 0=no access, 1=read only, 2=read/write */
-
-       /* What access is required per the incoming command? */
-       if (!strcmp(cmd, "git-upload-pack") ||
-                       !strcmp(cmd, "git-upload-archive"))
-               rw = 2;
+       /* What access is required per the incoming command?
+        * 0=none, 1=read-only, 2=read-write
+        */
+       int rw = (!strcmp(cmd, "git-upload-pack") ||
+                       !strcmp(cmd, "git-upload-archive")) ? 2 : 1;
 
        /* Return true (1) if the user permissions >= those required */
        return (git_acl(user, repo) >= rw) ? 1 : 0;
@@ -194,7 +192,7 @@ static void cd_to_homedir(void)
 {
        const char *home = getenv("HOME");
        if (!home)
-               die("could not determine user's home directory; HOME is unset");
+               die("user variable HOME is unset");
        if (chdir(home) == -1)
                die("could not chdir to user's home directory");
 }