contrib: better support symbolic port names in git-credential-netrc

To improve support for symbolic port names in netrc files, this
changes does the following:

 - Treat symbolic port names as ports, not protocols in git-credential-netrc
 - Validate the SMTP server port provided to send-email
 - Convert the above symbolic port names to their numerical values.

Before this change, it was not possible to have a SMTP server port set
to "smtps" in a netrc file (e.g. Emacs' ~/.authinfo.gpg), as it would
be registered as a protocol and break the match for a "smtp" protocol
host, as queried for by git-send-email.

Signed-off-by: Maxim Cournoyer <maxim@guixotic.coop>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:
Maxim Cournoyer
2025-06-25 23:25:11 +09:00
committed by Junio C Hamano
parent 53ca38298d
commit 1926d9b6da
5 changed files with 42 additions and 8 deletions

View File

@@ -1061,6 +1061,19 @@ sub _close_cat_blob {
delete @$self{@vars};
}
# Given PORT, a port number or service name, return its numerical
# value else undef.
sub port_num {
my ($port) = @_;
# Port can be either a positive integer within the 16-bit range...
if ($port =~ /^\d+$/ && $port > 0 && $port <= (2**16 - 1)) {
return $port;
}
# ... or a symbolic port (service name).
return scalar getservbyname($port, '');
}
=item credential_read( FILEHANDLE )