{"thread":{"id":"28573","subject":"[PATCH 2/4] Learn to handle gitfiles in enter_repo","startedAt":"2011-10-04T20:05:17Z","lastAt":"2011-10-04T20:13:59Z","messageCount":2,"participants":["Phil Hord"],"isPatch":true,"patchVersion":1,"patchTotal":4},"messages":[{"id":"176868","messageId":"CABURp0r7o8Mq4RyjEac18syU3HwCXWm7FOe+Mu0PshVXddJwuA@mail.gmail.com","threadId":"28573","inReplyTo":null,"subject":"[PATCH 2/4] Learn to handle gitfiles in enter_repo","fromName":"Phil Hord","fromEmail":"phil.hord@gmail.com","sentAt":"2011-10-04T20:05:17Z","receivedAt":"2011-10-04T20:05:17Z","isPatch":true,"sender":{"key":"phil.hord@gmail.com","avatar":"https://avatars.githubusercontent.com/u/123908?v=4"},"body":"The enter_repo() function is used to navigate into a .git\ndirectory.  It knows how to find standard alternatives (DWIM) but\nit doesn't handle gitfiles created by git init --separate-git-dir.\nThis means that git-fetch and others do not work with repositories\nusing the separate-git-dir mechanism.\n\nTeach enter_repo() to deal with the gitfile mechanism by resolving\nthe path to the redirected path and continuing tests on that path\ninstead of the found file.\n\nSigned-off-by: Phil Hord <hordp@cisco.com>\n---\n\nThis change allows enter_repo to work with gitfiles, but another change\nis required to teach transport.c to recognize gitfiles as git-dirs.\n\ndiff --git a/path.c b/path.c\nindex 01028f2..b6f71d1 100644\n--- a/path.c\n+++ b/path.c\n@@ -295,6 +295,7 @@ const char *enter_repo(const char *path, int strict)\n \t\tstatic const char *suffix[] = {\n \t\t\t\".git/.git\", \"/.git\", \".git\", \"\", NULL,\n \t\t};\n+\t\tconst char *gitfile;\n \t\tint len = strlen(path);\n \t\tint i;\n \t\twhile ((1 < len) && (path[len-1] == '/'))\n@@ -329,7 +330,12 @@ const char *enter_repo(const char *path, int strict)\n \t\t\t\tbreak;\n \t\t\t}\n \t\t}\n-\t\tif (!suffix[i] || chdir(used_path))\n+\t\tif (!suffix[i])\n+\t\t\treturn NULL;\n+\t\tgitfile = read_gitfile(used_path) ;\n+\t\tif (gitfile)\n+\t\t\tstrcpy(used_path, gitfile);\n+\t\tif (chdir(used_path))\n \t\t\treturn NULL;\n \t\tpath = validated_path;\n \t}\n-- \n1.7.7.503.g26392.dirty\n"},{"id":"176874","messageId":"CABURp0p1kcccrAfTpyjOyZit0b+-0VWVCLyhK5B9SXksmy1riQ@mail.gmail.com","threadId":"28573","inReplyTo":"CABURp0r7o8Mq4RyjEac18syU3HwCXWm7FOe+Mu0PshVXddJwuA@mail.gmail.com","subject":"Re: [PATCH 2/4] Learn to handle gitfiles in enter_repo","fromName":"Phil Hord","fromEmail":"phil.hord@gmail.com","sentAt":"2011-10-04T20:13:59Z","receivedAt":"2011-10-04T20:13:59Z","isPatch":true,"sender":{"key":"phil.hord@gmail.com","avatar":"https://avatars.githubusercontent.com/u/123908?v=4"},"body":"On Tue, Oct 4, 2011 at 4:05 PM, Phil Hord <phil.hord@gmail.com> wrote:\n> The enter_repo() function is used to navigate into a .git\n> directory.  It knows how to find standard alternatives (DWIM) but\n> it doesn't handle gitfiles created by git init --separate-git-dir.\n> This means that git-fetch and others do not work with repositories\n> using the separate-git-dir mechanism.\n>\n> Teach enter_repo() to deal with the gitfile mechanism by resolving\n> the path to the redirected path and continuing tests on that path\n> instead of the found file.\n>\n> Signed-off-by: Phil Hord <hordp@cisco.com>\n> ---\n>\n\n\nI meant to include this note on this patch.  Maybe I should have added\nan RFC, too.\n\nI'm not sure how to resolve this change for the 'strict' case.\n\nThe actual path followed may be different than the version spelled\nout on the input path because of resolved symlinks and whatnot.\nThis function normally returns the unmolested \"original\" path\nthat was validated.  In case of a gitfile, I think that means\nwe should return the url resolved from the gitfile contents.\n\nBut should we?\n\nThe returned path is only used in git-daemon where it gets\nfurther checks for path restrictions.\n\nA. If we return the gitfile-resolved path, this may cause these\n   path restrictions to fail since the path gets canonicalized\n   when the gitfile is created by git.\n\nB. If we do not return the gitfile-resolved path, this can create\n   a security-hole by allowing remote users to access files they\n   would otherwise have been restricted from.  In effect it creates\n   an alternate symlink mechanism of which the administrator might\n   not be aware.\n"}]}