From c2887bb4f72772484806c5d02b33d32957ffb6f2 Mon Sep 17 00:00:00 2001 From: "R. Steve McKown" Date: Mon, 24 Sep 2012 08:21:34 -0600 Subject: [PATCH] Misc cleanups --- repo_shell.c | 32 +++++++++++++++----------------- 1 file changed, 15 insertions(+), 17 deletions(-) diff --git a/repo_shell.c b/repo_shell.c index 7fb31d4..ebcb246 100644 --- a/repo_shell.c +++ b/repo_shell.c @@ -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"); } -- 2.39.2