cherrypicking delmasce's changes (appended) from the master nbd repo fixes the
issue and makes nbd-server allow working as expected in jessie's 3.8 version,
so please apply.

Thanks,
 greetings
  Hermann

-- 
Netzwerkadministration/Zentrale Dienste, Interdiziplinaeres 
Zentrum fuer wissenschaftliches Rechnen der Universitaet Heidelberg
IWR; INF 368; 69120 Heidelberg; Tel: (06221)54-8236 Fax: -5224
Email: hermann.la...@iwr.uni-heidelberg.de
# HG changeset patch
# User delmasce <delma...@users.noreply.github.com>
# Date 1410731631 -7200
#      Sun Sep 14 23:53:51 2014 +0200
# Node ID 212c52fc4eab5644d7bfbe744ab3e1d26bab0c5f
# Parent  cd20ba144612f68193db3ae3ff0b9bccf60a26e0
Pass whole struct sockaddr to function address_matches() and use it to
compare against the masks defined in auth file.

diff --git a/nbdsrv.c b/nbdsrv.c
--- a/nbdsrv.c
+++ b/nbdsrv.c
@@ -21,14 +21,14 @@
 
 #include <cliserv.h>
 
-bool address_matches(const char* mask, const void* addr, int af, GError** err) {
+bool address_matches(const char* mask, const struct sockaddr* addr, GError** err) {
 	struct addrinfo *res, *aitmp, hints;
 	char *masksep;
 	char privmask[strlen(mask)+1];
 	int masklen;
-	int addrlen = af == AF_INET ? 4 : 16;
+	int addrlen = addr->sa_family == AF_INET ? 4 : 16;
 
-	assert(af == AF_INET || af == AF_INET6);
+	assert(addr->sa_family == AF_INET || addr->sa_family == AF_INET6);
 
 	strcpy(privmask, mask);
 
@@ -50,18 +50,20 @@
 	}
 	aitmp = res;
 	while(res) {
-		const uint8_t* byte_s = addr;
+		const uint8_t* byte_s;
 		uint8_t* byte_t;
 		uint8_t mask = 0;
 		int len_left = masklen;
-		if(res->ai_family != af) {
+		if(res->ai_family != addr->sa_family) {
 			goto next;
 		}
-		switch(af) {
+		switch(addr->sa_family) {
 			case AF_INET:
+				byte_s = (const uint8_t*)(&(((struct sockaddr_in*)addr)->sin_addr));
 				byte_t = (uint8_t*)(&(((struct sockaddr_in*)(res->ai_addr))->sin_addr));
 				break;
 			case AF_INET6:
+				byte_s = (const uint8_t*)(&(((struct sockaddr_in6*)addr)->sin6_addr));
 				byte_t = (uint8_t*)(&(((struct sockaddr_in6*)(res->ai_addr))->sin6_addr));
 				break;
 		}
@@ -134,8 +136,7 @@
 		if(!(*pos)) {
 			continue;
 		}
-		struct sockaddr* sa = (struct sockaddr*)&opts->clientaddr;
-		if(address_matches(line, sa->sa_data, sa->sa_family, NULL)) {
+		if(address_matches(line, (struct sockaddr*)&opts->clientaddr, NULL)) {
 			fclose(f);
 			return 1;
 		}
diff --git a/nbdsrv.h b/nbdsrv.h
--- a/nbdsrv.h
+++ b/nbdsrv.h
@@ -123,14 +123,13 @@
   * Check whether a given address matches a given netmask.
   *
   * @param mask the address or netmask to check against, in ASCII representation
-  * @param addr the address to check, in network byte order
-  * @param af the address family of the passed address (AF_INET or AF_INET6)
+  * @param addr the address to check
   *
   * @return true if the address matches the mask, false otherwise; in case of
   * failure to parse netmask, returns false with err set appropriately.
   * @todo decide what to do with v6-mapped IPv4 addresses.
   */
-bool address_matches(const char* mask, const void* addr, int af, GError** err);
+bool address_matches(const char* mask, const struct sockaddr* addr, GError** err);
 
 /**
   * Gets a byte to allow for address masking.
# HG changeset patch
# User delmasce <delma...@users.noreply.github.com>
# Date 1410733851 -7200
#      Mon Sep 15 00:30:51 2014 +0200
# Node ID b1049b0860629ff2d23cfabf5099ec7ceff4fd35
# Parent  212c52fc4eab5644d7bfbe744ab3e1d26bab0c5f
Update clientacl.c

Update test code with new prototype of address_matches()

diff --git a/tests/code/clientacl.c b/tests/code/clientacl.c
--- a/tests/code/clientacl.c
+++ b/tests/code/clientacl.c
@@ -31,7 +31,7 @@
 					   &(((struct sockaddr_in*)res->ai_addr)->sin_addr),
 					       buf,
 					       res->ai_addrlen));
-		if(address_matches(netmask, &(((struct sockaddr_in*)res->ai_addr)->sin_addr), res->ai_family, NULL)) {
+		if(address_matches(netmask, (struct sockaddr_in*)res->ai_addr, NULL)) {
 			printf("Yes!\n");
 			freeaddrinfo(tmp);
 			return true;

Reply via email to