{"thread":{"id":"48827","subject":"RUNTIME_PREFIX references in gitconfig variable paths","startedAt":"2018-07-04T06:43:52Z","lastAt":"2018-10-02T14:28:29Z","messageCount":4,"participants":["Paul Smith","Johannes Schindelin"],"isPatch":false,"patchVersion":null,"patchTotal":null},"messages":[{"id":"351679","messageId":"e9d5bbec6242e47b1f4141ffd99b276eb6a41347.camel@mad-scientist.net","threadId":"48827","inReplyTo":null,"subject":"RUNTIME_PREFIX references in gitconfig variable paths","fromName":"Paul Smith","fromEmail":"paul@mad-scientist.net","sentAt":"2018-07-04T06:08:46Z","receivedAt":"2018-07-04T06:43:52Z","isPatch":false,"sender":{"key":"paul@mad-scientist.net","avatar":"https://avatars.githubusercontent.com/u/109636?v=4"},"body":"One thing I wanted to do was provide a default ca-bundle.crt file along\nwith my local build of Git.  I need my installation to be relocatable\nand I'm using RUNTIME_PREFIX with Git 2.18.0 (on GNU/Linux).\n\nI can provide a system gitconfig file with a setting for http.sslCAInfo\nbut the problem is I can't create a relocatable path here so I don't\nknow how to set it:\n\n  $ cat $prefix/etc/gitconfig\n  [http]\n      sslCAInfo = <prefix>/etc/ca-bundle.crt\n\nWhat do I use for <prefix> above since I want it to be relocatable? \nBasically I want this to be in the same directory as the relocatable\nsysconfdir (I don't actually care much but that seems like a good\nplace).\n\nIs there some way to create a reference to a path relative to the\ninstallation directory?\n\nFor example \"~\" is accepted as the users $HOME path; is there some\nsyntax which refers to the Git installation directory?\n\nIf not this seems like something that would be very useful.\n\n\nI can use a wrapper script and set GIT_SSL_CAINFO, but that will also\noverride any user's setting of http.sslCAInfo in their local gitconfig\nwhich I don't really want.\n"},{"id":"351689","messageId":"nycvar.QRO.7.76.6.1807041323490.75@tvgsbejvaqbjf.bet","threadId":"48827","inReplyTo":"e9d5bbec6242e47b1f4141ffd99b276eb6a41347.camel@mad-scientist.net","subject":"Re: RUNTIME_PREFIX references in gitconfig variable paths","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-07-04T11:26:54Z","receivedAt":"2018-07-04T11:27:16Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Paul,\n\nOn Wed, 4 Jul 2018, Paul Smith wrote:\n\n> One thing I wanted to do was provide a default ca-bundle.crt file along\n> with my local build of Git.  I need my installation to be relocatable\n> and I'm using RUNTIME_PREFIX with Git 2.18.0 (on GNU/Linux).\n\nUnderstandable. We do this all the time in Git for Windows. Our config\nentry has this form:\n\n\t[http]\n\t\tsslCAinfo = /ssl/certs/ca-bundle.crt\n\nand in the RUNTIME_PREFIX mode, this will be made relative to the runtime\nprefix. It is my understanding that bf9acba (http: treat config options\nsslCAPath and sslCAInfo as paths, 2015-11-23) makes this work.\n\n> I can provide a system gitconfig file with a setting for http.sslCAInfo\n> but the problem is I can't create a relocatable path here so I don't\n> know how to set it:\n> \n>   $ cat $prefix/etc/gitconfig\n>   [http]\n>       sslCAInfo = <prefix>/etc/ca-bundle.crt\n> \n> What do I use for <prefix> above since I want it to be relocatable? \n> Basically I want this to be in the same directory as the relocatable\n> sysconfdir (I don't actually care much but that seems like a good\n> place).\n> \n> Is there some way to create a reference to a path relative to the\n> installation directory?\n> \n> For example \"~\" is accepted as the users $HOME path; is there some\n> syntax which refers to the Git installation directory?\n> \n> If not this seems like something that would be very useful.\n> \n> \n> I can use a wrapper script and set GIT_SSL_CAINFO, but that will also\n> override any user's setting of http.sslCAInfo in their local gitconfig\n> which I don't really want.\n\nI think if you simply delete `<prefix>`, it will start working.\n\nCiao,\nJohannes\n"},{"id":"351693","messageId":"55733da67095123ced63095aa554970053bef321.camel@mad-scientist.net","threadId":"48827","inReplyTo":"nycvar.QRO.7.76.6.1807041323490.75@tvgsbejvaqbjf.bet","subject":"Re: RUNTIME_PREFIX references in gitconfig variable paths","fromName":"Paul Smith","fromEmail":"paul@mad-scientist.net","sentAt":"2018-07-04T13:56:56Z","receivedAt":"2018-07-04T14:32:02Z","isPatch":false,"sender":{"key":"paul@mad-scientist.net","avatar":"https://avatars.githubusercontent.com/u/109636?v=4"},"body":"On Wed, 2018-07-04 at 13:26 +0200, Johannes Schindelin wrote:\n> On Wed, 4 Jul 2018, Paul Smith wrote:\n> \n> > One thing I wanted to do was provide a default ca-bundle.crt file\n> > along with my local build of Git.  I need my installation to be\n> > relocatable and I'm using RUNTIME_PREFIX with Git 2.18.0 (on\n> > GNU/Linux).\n> \n> Understandable. We do this all the time in Git for Windows. Our\n> config entry has this form:\n> \n>         [http]\n>                 sslCAinfo = /ssl/certs/ca-bundle.crt\n> \n> and in the RUNTIME_PREFIX mode, this will be made relative to the\n> runtime prefix. It is my understanding that bf9acba (http: treat\n> config options sslCAPath and sslCAInfo as paths, 2015-11-23) makes\n> this work.\n\nHm.  Unless I'm missing something this doesn't happen (and indeed, it\ndoes not work for me; with:\n\n  [http]\n      sslcainfo = /etc/ca-bundle.crt\n\nI get:\n\n  fatal: unable to access 'https://github.com/myrepo.git/': error\nsetting certificate verify locations:\n    CAfile: /etc/ca-bundle.crt\n    CApath: none\n\nalthough it works if I use a fully-qualified pathname, and using strace\nI find the process never attempted to access any other path for ca-\nbundle.crt).\n\nIn http.c we see how this path is treated in http_options():\n\n        if (!strcmp(\"http.sslcainfo\", var))\n                return git_config_pathname(&ssl_cainfo, var, value);\n\nI can't tell exactly how this function is invoked, but the result\n(ssl_cainfo) is used here without further modification:\n\n        curl_easy_setopt(result, CURLOPT_CAINFO, ssl_cainfo);\n\nIn config.c we find get_config_pathname() which does this:\n\n        *dest = expand_user_path(value, 0);\n\nIn path.c we find expand_user_path() which does this:\n\n        if (path == NULL)\n                goto return_null;\n        if (path[0] == '~') {\n            ...\n        }\n        strbuf_addstr(&user_path, to_copy);\n        return strbuf_detach(&user_path, NULL);\n\nI don't see any reference to system_prefix(), system_path(), etc. which\nwould be needed to RUNTIME_PREFIX-ize things.\n"},{"id":"359416","messageId":"nycvar.QRO.7.76.6.1810021611040.2034@tvgsbejvaqbjf.bet","threadId":"48827","inReplyTo":"55733da67095123ced63095aa554970053bef321.camel@mad-scientist.net","subject":"Re: RUNTIME_PREFIX references in gitconfig variable paths","fromName":"Johannes Schindelin","fromEmail":"johannes.schindelin@gmx.de","sentAt":"2018-10-02T14:28:26Z","receivedAt":"2018-10-02T14:28:29Z","isPatch":false,"sender":{"key":"johannes.schindelin@gmx.de","avatar":"https://avatars.githubusercontent.com/u/127790?v=4"},"body":"Hi Paul,\n\n[late reply, I know, sorry about that!]\n\nOn Wed, 4 Jul 2018, Paul Smith wrote:\n\n> On Wed, 2018-07-04 at 13:26 +0200, Johannes Schindelin wrote:\n> > On Wed, 4 Jul 2018, Paul Smith wrote:\n> > \n> > > One thing I wanted to do was provide a default ca-bundle.crt file\n> > > along with my local build of Git.  I need my installation to be\n> > > relocatable and I'm using RUNTIME_PREFIX with Git 2.18.0 (on\n> > > GNU/Linux).\n> > \n> > Understandable. We do this all the time in Git for Windows. Our\n> > config entry has this form:\n> > \n> >         [http]\n> >                 sslCAinfo = /ssl/certs/ca-bundle.crt\n> > \n> > and in the RUNTIME_PREFIX mode, this will be made relative to the\n> > runtime prefix. It is my understanding that bf9acba (http: treat\n> > config options sslCAPath and sslCAInfo as paths, 2015-11-23) makes\n> > this work.\n> \n> Hm.  Unless I'm missing something this doesn't happen (and indeed, it\n> does not work for me; with:\n> \n>   [http]\n>       sslcainfo = /etc/ca-bundle.crt\n> \n> I get:\n> \n>   fatal: unable to access 'https://github.com/myrepo.git/': error\n> setting certificate verify locations:\n>     CAfile: /etc/ca-bundle.crt\n>     CApath: none\n> \n> although it works if I use a fully-qualified pathname, and using strace\n> I find the process never attempted to access any other path for ca-\n> bundle.crt).\n> \n> In http.c we see how this path is treated in http_options():\n> \n>         if (!strcmp(\"http.sslcainfo\", var))\n>                 return git_config_pathname(&ssl_cainfo, var, value);\n> \n> I can't tell exactly how this function is invoked, but the result\n> (ssl_cainfo) is used here without further modification:\n> \n>         curl_easy_setopt(result, CURLOPT_CAINFO, ssl_cainfo);\n> \n> In config.c we find get_config_pathname() which does this:\n> \n>         *dest = expand_user_path(value, 0);\n> \n> In path.c we find expand_user_path() which does this:\n> \n>         if (path == NULL)\n>                 goto return_null;\n>         if (path[0] == '~') {\n>             ...\n>         }\n>         strbuf_addstr(&user_path, to_copy);\n>         return strbuf_detach(&user_path, NULL);\n> \n> I don't see any reference to system_prefix(), system_path(), etc. which\n> would be needed to RUNTIME_PREFIX-ize things.\n\nI finally got around to dig into this, and found out what is\nhappening: in https://github.com/git/git/blob/v2.19.0/http.c#L295-L296,\nthe http.sslcainfo setting is handled by calling git_config_pathname(),\nwhich in turn calls expand_user_path() to handle special cases\n(https://github.com/git/git/blob/v2.19.0/config.c#L1067-L1075). And it\nis this function which has a specific, special handling on Windows\n(which, like so many other changes that are waiting patiently for the\nslow upstreaming process, has not made it into any *Git* version yet),\nsee https://github.com/git-for-windows/git/commit/434b76522de1:\n\n@@ -709,6 +710,10 @@ char *expand_user_path(const char *path, int real_home)\n\n        if (path == NULL)\n\t\tgoto return_null;\n+#ifdef __MINGW32__\n+       if (path[0] == '/')\n+               return system_path(path + 1);\n+#endif\n        if (path[0] == '~') {\n                const char *first_slash = strchrnul(path, '/');\n                const char *username = path + 1;\n\nThis explains why it works on Windows, but not elsewhere...\n\nNow, I could imagine that this special handling makes a ton of sense not\nfor *Git for Windows*, but rather for RUNTIME_PREFIX.\n\nSo maybe we should replace that `__MINGW32__` condition by\n`RUNTIME_PREFIX`? What do you think?\n\nCiao,\nJohannes\n"}]}