{"thread":{"id":"19450","subject":"patch for git-daemon base-path trailing '/' problem","startedAt":"2009-05-23T15:33:18Z","lastAt":"2009-05-23T15:33:18Z","messageCount":1,"participants":["Aneesh Bhasin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"114514","messageId":"f662f0210905230833p781d8e7ck77a40b4cd58a799d@mail.gmail.com","threadId":"19450","inReplyTo":null,"subject":"patch for git-daemon base-path trailing '/' problem","fromName":"Aneesh Bhasin","fromEmail":"contact.aneesh@gmail.com","sentAt":"2009-05-23T15:33:18Z","receivedAt":"2009-05-23T15:33:18Z","isPatch":false,"sender":{"key":"contact.aneesh@gmail.com","avatar":null},"body":"Hi All,\n\nI was trying to setup git-daemon on our server with the following args :\n\ngit-daemon --base-path=/git_repo/ --export-all --syslog --inetd\n--verbose /git_repo/external_repos/\n\nThere are two git repos in /git_repo/external_repos/ :-\nlinux-test/.git and linux-release/.git\n\nWhen I try to clone the linux-test/.git repo using :\ngit clone 192.168.1.100/external_repos/linux-test\n\nI get an error at the server side from git-daemon saying that\n\"/git_repo//external/repos/linux-test/.git not in whitelist\".\n\nThe problem is because fo the trailing '/' in base-path in git-daemon\nargs. I think it might be fairly common that a person might add a '/'\nat the end of base-path. The following patch takes care of this\ntrailing patch :\n\n\ndiff --git a/daemon.c b/daemon.c\nindex daa4c8e..cd4dfed 100644\n--- a/daemon.c\n+++ b/daemon.c\n@@ -209,11 +209,15 @@ static char *path_ok(char *directory)\n                dir = interp_path;\n        }\n        else if (base_path) {\n+    int base_pathlen;\n                if (*dir != '/') {\n                        /* Allow only absolute */\n                        logerror(\"'%s': Non-absolute path denied (base-path acti\n                        return NULL;\n                }\n+    base_pathlen = strlen(base_path);\n+    if(base_path[base_pathlen-1]=='/')\n+      base_path[base_pathlen-1]='\\0';\n                snprintf(rpath, PATH_MAX, \"%s%s\", base_path, dir);\n                dir = rpath;\n        }\n@@ -229,7 +233,7 @@ static char *path_ok(char *directory)\n        }\n\n\n---------------------------------------\nRegards,\nAneesh Bhasin\n"}]}