Package: nbd-client
Version: 1:3.2-2
Severity: normal
Tags: patch

Dear Maintainer,

When trying to connect to a new-style nbd server without
specfying an export name (which is required), the client issues
a cryptic message, and quits:
        nasc0:root ~ 134 # nbd-client nass0 10809 /dev/nbd0
        Negotiation: .Error: Not enough cliserv_magic
        Exiting.

The problem is, that, given an export name, nbd-client assumes
it is connecting to a new-style server. Without an export name,
it assumes it has an old-style server. In both cases, the magic
number does not match if the assumption was incorrect, resulting
in a cryptic error message.

I am attaching a patch relative to
902c07e75f12459c55d79f450a0fb9c1e7da02e5 that fixes the problem.

The patch reverses the checks: first the magic is checked to
determine the kind of server, then either the availability of
an export name is checked for new-style servers (and the client
complains if there is none), or nothing special is done for
old-style servers.

For old-style servers, this patch assumes a 'compatibility mode',
accepting the export name, but not using it. An alternative would
be for nbd-client to fail, complaining that an old-style server
does not support named exports. E.g.:

+               if (name) {
+                       fprintf(stderr, "\nE: Export names not supported by 
server\n");
+                       exit(EXIT_FAILURE);
+               }

Kind regards,

Rogier

----------------------------------------
diff --git a/nbd-client.c b/nbd-client.c
index 1445621..0ac0587 100644
--- a/nbd-client.c
+++ b/nbd-client.c
@@ -235,12 +235,15 @@ void negotiate(int sock, u64 *rsize64, u32 *flags, char* 
name, uint32_t needed_f
        if (read(sock, &magic, sizeof(magic)) < 0)
                err("Failed/2: %m");
        magic = ntohll(magic);
-       if(name) {
+       if(magic == opts_magic) {
                uint32_t opt;
                uint32_t namesize;
 
-               if (magic != opts_magic)
-                       err("Not enough opts_magic");
+               if (!name) {
+                       fprintf(stderr, "\nE: Server uses named exports - 
export name is required\n");
+                       exit(EXIT_FAILURE);
+               }
+
                printf(".");
                if(read(sock, &tmp, sizeof(uint16_t)) < 0) {
                        err("Failed reading flags: %m");
@@ -277,10 +280,10 @@ void negotiate(int sock, u64 *rsize64, u32 *flags, char* 
name, uint32_t needed_f
                        err("Failed/2.4: %m");
                if (write(sock, name, strlen(name)) < 0)
                        err("Failed/2.4: %m");
-       } else {
-               if (magic != cliserv_magic)
-                       err("Not enough cliserv_magic");
+       } else if (magic == cliserv_magic) {
                printf(".");
+       } else {
+               err("No opts_magic or cliserv_magic");
        }
 
        if (read(sock, &size64, sizeof(size64)) <= 0) {
----------------------------------------

-- System Information:
Debian Release: wheezy/sid
  APT prefers testing
  APT policy: (500, 'testing')
Architecture: i386 (x86_64)

Kernel: Linux 3.2.0-4-amd64 (SMP w/2 CPU cores)
Locale: LANG=en_US.UTF-8, LC_CTYPE=en_US.UTF-8 (charmap=UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages nbd-client depends on:
ii  debconf [debconf-2.0]  1.5.46
ii  initscripts            2.88dsf-34
ii  libc6                  2.13-37

nbd-client recommends no packages.

nbd-client suggests no packages.

-- debconf information excluded


-- 
To UNSUBSCRIBE, email to debian-bugs-dist-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org

Reply via email to