Don't force imap.host to be set when imap.tunnel is set
PATCH 1/1 Don't force imap.host to be set when imap.tunnel is set
The documentation for git-imap-send suggests a tunnel setting such as
Tunnel = "ssh -q [email protected] /usr/bin/imapd ./Maildir 2> /dev/null"
which works wonderfully and doesn't require a username, password or port setting.
However, git-imap-send currently requires that the imap.host variable be set in the config even when it was unused. This led me to have to put the following in my .gitconfig.
[imap]
host = dummy
This patch changes imap-send to only require that the imap.host setting is set if imap.tunnel is _not_ set.
--- imap-send.c | 2 +- 1 files changed, 1 insertions(+), 1 deletions(-)
imap-send.c +1 -1
@@ -1302,7 +1302,7 @@ main(int argc, char **argv)fprintf ( stderr,"no imap store specified\n" );return 1 ; } -if (!server.host) { +if (!server.host && !server.tunnel) {fprintf ( stderr,"no imap host specified\n" );return 1 ; }
Signature · 1 line
1.5.5.1.57.g5909c
Quoted 11 lines · Andy Parkins
The documentation for git-imap-send suggests a tunnel setting such as
Tunnel = "ssh -q [email protected]
/usr/bin/imapd./Maildir 2>/dev/null"which works wonderfully and doesn't require a username, password or port setting.
However, git-imap-send currently requires that the imap.host variable be set in the config even when it was unused. This led me to have to put the following in my .gitconfig.
Quoted 7 lines
[imap]
host = dummyThis patch changes imap-send to only require that the imap.host setting is set if imap.tunnel is _not_ set.
Signed-off-by Andy Parkins <[email protected]>
I am not an imap-send user myself, but is it the case that the use of imap.tunnel always makes imap.host useless/unnecessary and safe to be left as NULL?
My quick scan of imap-send.c suggests that
* imap_open_store() does not look at host/port when tunnel is defined while connecting at the socket level;
* however, when not preauth, "host" is used to issue error message when user is not set, and in prompt when pass needs to be asked. I suspect you do not want to leave "host" NULL in this case.
Driving imapd standalone like the "tunnel" example you quoted above would trigger preauth behaviour, so that should be safe, but I suspect there are other ways to use tunnel to just relay the connection over the firewall, while still requiring the client to authenticate the same way as usual.
Quoted 3 lines · Junio C Hamano
I am not an imap-send user myself, but is it the case that the use of imap.tunnel always makes imap.host useless/unnecessary and safe to be left as NULL?
You're right that it isn't guaranteed to be unnecessary, but equally it's not guaranteed to be necessary - which is just the situation that an optional configuration setting describes.
Quoted 4 lines
Driving imapd standalone like the "tunnel" example you quoted above would trigger preauth behaviour, so that should be safe, but I suspect there are other ways to use tunnel to just relay the connection over the firewall, while still requiring the client to authenticate the same way as usual.
I'm sure you are correct, but as I say - it's not guaranteed. Since git-imap-send can't know what this particular tunnel requires it shouldn't force the creation of a dummy option. If the tunnel does require a hostname then there is a place to put it, and the person writing the tunnel line can decide that.
Andy
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]
Quoted 5 lines · Andy Parkins
I'm sure you are correct, but as I say - it's not guaranteed. Since git-imap-send can't know what this particular tunnel requires it shouldn't force the creation of a dummy option. If the tunnel does require a hostname then there is a place to put it, and the person writing the tunnel line can decide that.
I think Junio's point is that it's easy to start dereferencing NULL, because later parts of the code assume that "host" is always set, even if only to use it for informational purposes. So those callsites either need to be fixed to handle a NULL host, or perhaps something like this instead (totally untested):
imap-send.c +5 -2
@@ -1303,8 +1303,11 @@ main(int argc, char **argv)return 1 ; }if (!server.host) { -fprintf ( stderr,"no imap host specified\n" ); -return 1 ; +if (!server.tunnel) { +fprintf ( stderr,"no imap host specified\n" ); +return 1 ; + } + server.host ="tunnel" ; }/* read the messages */
-Peff
Quoted 5 lines · Jeff King
I think Junio's point is that it's easy to start dereferencing NULL, because later parts of the code assume that "host" is always set, even if only to use it for informational purposes. So those callsites either need to be fixed to handle a NULL host, or perhaps something like this instead (totally untested):
Agreed. Yours is a much better solution.
Andy
Signature · 2 lines
Dr Andy Parkins, M Eng (hons), MIET [email protected]