lix/src/libutil
Maximilian Bosch 93a8a005de
libstore/openStore: fix stores with IPv6 addresses
In `nixStable` (2.3.7 to be precise) it's possible to connect to stores
using an IPv6 address:

  nix ping-store --store ssh://root@2001:db8::1

This is also useful for `nixops(1)` where you could specify an IPv6
address in `deployment.targetHost`.

However, this behavior is broken on `nixUnstable` and fails with the
following error:

  $ nix store ping --store ssh://root@2001:db8::1
  don't know how to open Nix store 'ssh://root@2001:db8::1'

This happened because `openStore` from `libstore` uses the `parseURL`
function from `libfetchers` which expects a valid URL as defined in
RFC2732. However, this is unsupported by `ssh(1)`:

  $ nix store ping --store 'ssh://root@[2001:db8::1]'
  cannot connect to 'root@[2001:db8::1]'

This patch now allows both ways of specifying a store (`root@2001:db8::1`) and
also `root@[2001:db8::1]` since the latter one is useful to pass query
parameters to the remote store.

In order to achieve this, the following changes were made:

* The URL regex from `url-parts.hh` now allows an IPv6 address in the
  form `2001:db8::1` and also `[2001:db8::1]`.

* In `libstore`, a new function named `extractConnStr` ensures that a
  proper URL is passed to e.g. `ssh(1)`:

  * If a URL looks like either `[2001:db8::1]` or `root@[2001:db8::1]`,
    the brackets will be removed using a regex. No additional validation
    is done here as only strings parsed by `parseURL` are expected.

  * In any other case, the string will be left untouched.

* The rules above only apply for `LegacySSHStore` and `SSHStore` (a.k.a
  `ssh://` and `ssh-ng://`).

Unresolved questions:

* I'm not really sure whether we want to allow both variants of IPv6
  addresses in the URL parser. However it should be noted that both seem
  to be possible according to RFC2732:

  > This document incudes an update to the generic syntax for Uniform
  > Resource Identifiers defined in RFC 2396 [URL].  It defines a syntax
  > for IPv6 addresses and allows the use of "[" and "]" within a URI
  > explicitly for this reserved purpose.

* Currently, it's not supported to specify a port number behind the
  hostname, however it seems as this is not really supported by the URL
  parser. Hence, this is probably out of scope here.
2020-12-09 12:23:29 +01:00
..
tests filterANSIEscapes(): Handle UTF-8 characters 2020-11-16 16:41:53 +01:00
abstract-setting-to-json.hh abstractsettingtojson.hh -> abstract-setting-to-json.hh 2020-09-21 18:49:43 +02:00
affinity.cc affinity operator<< 2020-05-04 14:44:00 -06:00
affinity.hh Run the daemon worker on the same CPU as the client 2013-08-07 14:02:04 +02:00
ansicolor.hh Fix ANSI color constants 2020-07-12 16:52:20 +02:00
archive.cc read(): Use char * instead of unsigned char * 2020-12-02 14:17:27 +01:00
archive.hh Add forgotten override annotation 2020-12-02 14:23:38 +01:00
args.cc Add deprecated aliases for renamed commands 2020-12-03 22:45:44 +01:00
args.hh Add deprecated aliases for renamed commands 2020-12-03 22:45:44 +01:00
callback.hh Move Callback into its own header 2020-09-21 18:42:21 +02:00
compression.cc Sink: Use std::string_view 2020-12-02 14:17:27 +01:00
compression.hh Fix Brotli decompression in 'nix log' 2018-08-06 15:40:29 +02:00
config.cc Fix appending to Setting<StringSet> 2020-11-09 15:04:34 +01:00
config.hh Generalize extra-* settings 2020-10-29 18:17:39 +01:00
error.cc Formatting 2020-10-07 16:33:19 +02:00
error.hh Formatting 2020-10-07 16:33:19 +02:00
finally.hh Add missing #include 2016-11-07 14:35:47 +01:00
fmt.hh Formatting 2020-10-07 16:33:19 +02:00
hash.cc Sink: Use std::string_view 2020-12-02 14:17:27 +01:00
hash.hh Sink: Use std::string_view 2020-12-02 14:17:27 +01:00
json.cc Fix build 2020-07-30 15:27:28 +02:00
json.hh Make std::uncaught_exception warning less noisy 2019-10-09 23:04:11 +02:00
local.mk StorePath: Rewrite in C++ 2020-06-16 14:28:41 +02:00
logging.cc Capitalize JSON for consistency 2020-10-28 17:54:28 -05:00
logging.hh Macro hygiene 2020-12-01 13:45:06 +01:00
lru-cache.hh Missing #include <cassert> in lru-cache.hh (#3654) 2020-06-03 10:15:22 +00:00
monitor-fd.hh monitor-fds: Fix on macOS. 2018-02-14 18:26:37 -05:00
pool.hh RemoteStore: Close connection if an exception occurs 2018-10-16 23:36:15 +02:00
ref.hh Allow setting the state directory as a store parameter 2016-06-02 16:02:48 +02:00
rust-ffi.cc StorePath: Rewrite in C++ 2020-06-16 14:28:41 +02:00
rust-ffi.hh StorePath: Rewrite in C++ 2020-06-16 14:28:41 +02:00
serialise.cc read(): Use char * instead of unsigned char * 2020-12-02 14:17:27 +01:00
serialise.hh read(): Use char * instead of unsigned char * 2020-12-02 14:17:27 +01:00
split.hh Typo 2020-09-17 20:21:04 +02:00
sync.hh sync.hh: return cv_status instead of dropping it, in case useful. 2018-06-18 17:31:00 -05:00
tarfile.cc read(): Use char * instead of unsigned char * 2020-12-02 14:17:27 +01:00
tarfile.hh libarchive proof of concept 2019-12-07 22:35:14 +07:00
thread-pool.cc Fix a hang in ThreadPool 2017-10-09 15:41:09 +02:00
thread-pool.hh Fix extra ; warnings involving MakeError 2019-11-10 11:24:47 -05:00
topo-sort.hh Add missing #pragma once 2020-10-06 10:40:07 +02:00
types.hh Move Explicit 2020-10-26 17:01:20 +01:00
url-parts.hh libstore/openStore: fix stores with IPv6 addresses 2020-12-09 12:23:29 +01:00
url.cc Don't include <regex> in header files 2020-09-21 18:22:45 +02:00
url.hh Don't include <regex> in header files 2020-09-21 18:22:45 +02:00
util.cc read(): Use char * instead of unsigned char * 2020-12-02 14:17:27 +01:00
util.hh read(): Use char * instead of unsigned char * 2020-12-02 14:17:27 +01:00
xml-writer.cc Cleanup 2019-11-06 16:53:02 +01:00
xml-writer.hh Fix some random -Wconversion warnings 2018-05-02 13:56:34 +02:00