[pbs-devel] [PATCH proxmox-backup] client/http_client: add necessary brackets

Wolfgang Bumiller w.bumiller at proxmox.com
Tue May 4 13:17:18 CEST 2021


On Fri, Apr 09, 2021 at 10:14:56AM +0200, Dominik Csapak wrote:
> if we are given a 'naked' ipv6 without square brackets around it,
> we need to add them ourselves, since the address is ambigious otherwise
> when we add the port.
> 
> e.g. giving 'fe80::1' as address we arrive at the url (with the default port)
> 'https://fe80::1:8007/'
> 
> Signed-off-by: Dominik Csapak <d.csapak at proxmox.com>
> ---
> we could also only add it to the actual request if wanted, should not
> make much of a difference though

^ That would definitely be the better approach, because with the current
patch you're also changing the address for *everything* else
(load_fingerprint, store_fingerprint, store_ticket_info, ...)

The address is supposed to be just that, an address. The brackets are
part of the URL syntax and should therefore be limited to that and that
alone.

> 
>  src/client/http_client.rs | 16 ++++++++++++++--
>  1 file changed, 14 insertions(+), 2 deletions(-)
> 
> diff --git a/src/client/http_client.rs b/src/client/http_client.rs
> index 76ab0391..07e8cd83 100644
> --- a/src/client/http_client.rs
> +++ b/src/client/http_client.rs
> @@ -273,6 +273,16 @@ fn load_ticket_info(prefix: &str, server: &str, userid: &Userid) -> Option<(Stri
>      }
>  }
>  
> +fn map_ipv6(server: &str) -> String {
> +    let bytes = server.as_bytes();
> +    let len = bytes.len();
> +    if len > 3 && bytes.contains(&b':') && bytes[0] != b'[' && bytes[len-1] != b']' {
> +        format!("[{}]", server)
> +    } else {
> +        server.to_string()
> +    }
> +}
> +
>  impl HttpClient {
>      pub fn new(
>          server: &str,
> @@ -285,11 +295,13 @@ impl HttpClient {
>  
>          let mut fingerprint = options.fingerprint.take();
>  
> +        let server = map_ipv6(server);
> +
>          if fingerprint.is_some() {
>              // do not store fingerprints passed via options in cache
>              options.fingerprint_cache = false;
>          } else if options.fingerprint_cache && options.prefix.is_some() {
> -            fingerprint = load_fingerprint(options.prefix.as_ref().unwrap(), server);
> +            fingerprint = load_fingerprint(options.prefix.as_ref().unwrap(), &server);
>          }
>  
>          let mut ssl_connector_builder = SslConnector::builder(SslMethod::tls()).unwrap();
> @@ -344,7 +356,7 @@ impl HttpClient {
>              };
>              let mut ticket_info = None;
>              if use_ticket_cache {
> -                ticket_info = load_ticket_info(options.prefix.as_ref().unwrap(), server, userid);
> +                ticket_info = load_ticket_info(options.prefix.as_ref().unwrap(), &server, userid);
>              }
>              if let Some((ticket, _token)) = ticket_info {
>                  ticket
> -- 
> 2.20.1





More information about the pbs-devel mailing list