Skip to content

Commit 2c98b82

Browse files
committed
server: When --tls is used, set captive $uri variable to nbds://...
We didn't set the $uri shell variable correctly when TLS is enabled. Although this is a rare corner case because using TLS over a loopback connection is not very useful, we should try to get the URI right. Simple example that did not work and gave a weird error: $ nbdkit --tls=require --tls-certificates=$PWD/tests/pki null \ --run 'nbdinfo "$uri"' nbdkit: null[1]: error: unknown option version 30003, expecting 49484156454f5054 nbdinfo: : nbd_opt_go: recv: Connection reset by peer protocol: newstyle-fixed without TLS
1 parent 7e4c646 commit 2c98b82

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

server/captive.c

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,21 @@ run_command (void)
7777

7878
/* Construct $uri. */
7979
fprintf (fp, "uri=");
80+
if (tls == 2) /* --tls=require */
81+
fprintf (fp, "nbds");
82+
else
83+
fprintf (fp, "nbd");
8084
if (port) {
8185
if (!vsock) {
82-
fprintf (fp, "nbd://localhost:");
86+
fprintf (fp, "://localhost:");
8387
shell_quote (port, fp);
8488
if (strcmp (export_name, "") != 0) {
8589
putc ('/', fp);
8690
uri_quote (export_name, fp);
8791
}
8892
}
8993
else {
90-
fprintf (fp, "nbd+vsock://1:"); /* 1 = VMADDR_CID_LOCAL */
94+
fprintf (fp, "+vsock://1:"); /* 1 = VMADDR_CID_LOCAL */
9195
shell_quote (port, fp);
9296
if (strcmp (export_name, "") != 0) {
9397
putc ('/', fp);
@@ -96,7 +100,7 @@ run_command (void)
96100
}
97101
}
98102
else if (unixsocket) {
99-
fprintf (fp, "nbd+unix://");
103+
fprintf (fp, "+unix://");
100104
if (strcmp (export_name, "") != 0) {
101105
putc ('/', fp);
102106
uri_quote (export_name, fp);

0 commit comments

Comments
 (0)