Просмотр исходного кода

Fix compatibility issues

! avoid errno usage due to compatibility issues (and never use errno as
a lvalue). socks changed to use internal error codes instead.
! NOIPV6 compilation issues solved
! -lite version is switched to NOIPV6
z3APA3A 11 лет назад
Родитель
Сommit
085b47d64e
4 измененных файлов с 14 добавлено и 29 удалено
  1. 1 1
      Makefile.win
  2. 11 26
      src/socks.c
  3. 0 2
      src/structures.h
  4. 2 0
      src/version.h

+ 1 - 1
Makefile.win

@@ -11,7 +11,7 @@
 
 
 BUILDDIR = ../bin/
 BUILDDIR = ../bin/
 CC = gcc
 CC = gcc
-CFLAGS = -O2 -s -c -mthreads -DWITH_STD_MALLOC
+CFLAGS = -O2 -s -c -mthreads -DWITH_STD_MALLOC -DNOIPV6
 COUT = -o 
 COUT = -o 
 LN = gcc
 LN = gcc
 LDFLAGS = -O2 -s  -mthreads
 LDFLAGS = -O2 -s  -mthreads

+ 11 - 26
src/socks.c

@@ -161,31 +161,7 @@ void * sockschild(struct clientparam* param) {
 	 RETURN(997);
 	 RETURN(997);
  }
  }
 
 
- errno = 0;
  if((res = (*param->srv->authfunc)(param))) {
  if((res = (*param->srv->authfunc)(param))) {
-	res *= 10;
-	switch (errno) {
-		/* If authfunc failed but errno stays intacts we assume ACL denied the access,
-		 * otherwise we do our best to pick a good error code for SOCKSv5. */
-		case 0:
-			res += 2; /* connection not allowed by ruleset */
-			break;
-		case ENETUNREACH:
-			res += 3; /* Network unreachable */
-			break;
-		case EHOSTUNREACH:
-			res += 4; /* Host unreachable */
-			break;
-		case ECONNREFUSED:
-			res += 5; /* Connection refused */
-			break;
-		case EPFNOSUPPORT:
-		case EAFNOSUPPORT:
-			res += 8; /* Address type not supported */
-			break;
-		default:
-			res += 1;
-	}
 	RETURN(res);
 	RETURN(res);
  }
  }
 
 
@@ -223,6 +199,8 @@ fflush(stderr);
 CLEANRET:
 CLEANRET:
 
 
  if(param->clisock != INVALID_SOCKET){
  if(param->clisock != INVALID_SOCKET){
+	int repcode;
+
 	sasize = sizeof(sin);
 	sasize = sizeof(sin);
 	if(command != 3) so._getsockname(param->remsock, (struct sockaddr *)&sin,  &sasize);
 	if(command != 3) so._getsockname(param->remsock, (struct sockaddr *)&sin,  &sasize);
 	else so._getsockname(param->clisock, (struct sockaddr *)&sin,  &sasize);
 	else so._getsockname(param->clisock, (struct sockaddr *)&sin,  &sasize);
@@ -235,9 +213,16 @@ fprintf(stderr, "Sending confirmation to client with code %d for %s with %s:%hu\
 	);
 	);
 fflush(stderr);
 fflush(stderr);
 #endif
 #endif
+	if(!param->res) repcode = 0;
+	else if(param->res <= 10) repcode = 2;
+	else if (param->res < 20) repcode = 5;
+	else if (param->res < 30) repcode = 1;
+	else if (param->res < 100) repcode = 4;
+	else repcode = param->res%10;
+
 	if(ver == 5){
 	if(ver == 5){
 		buf[0] = 5;
 		buf[0] = 5;
-		buf[1] = param->res%10;
+		buf[1] = repcode;
 		buf[2] = 0;
 		buf[2] = 0;
 		buf[3] = 1;
 		buf[3] = 1;
 		memcpy(buf+4, SAADDR(&sin), 4);
 		memcpy(buf+4, SAADDR(&sin), 4);
@@ -246,7 +231,7 @@ fflush(stderr);
 	}
 	}
 	else{
 	else{
 		buf[0] = 0;
 		buf[0] = 0;
-		buf[1] = 90 + !!(param->res%10);
+		buf[1] = 90 + !!(repcode);
 		memcpy(buf+2, SAPORT(&sin), 2);
 		memcpy(buf+2, SAPORT(&sin), 2);
 		memcpy(buf+4, SAADDR(&sin), 4);
 		memcpy(buf+4, SAADDR(&sin), 4);
 		socksend(param->clisock, buf, 8, conf.timeouts[STRING_S]);
 		socksend(param->clisock, buf, 8, conf.timeouts[STRING_S]);

+ 0 - 2
src/structures.h

@@ -28,9 +28,7 @@ extern "C" {
 #define INVALID_SOCKET  (-1)
 #define INVALID_SOCKET  (-1)
 #else
 #else
 #include <winsock2.h>
 #include <winsock2.h>
-#ifndef NOIPV6
 #include <Ws2tcpip.h>
 #include <Ws2tcpip.h>
-#endif
 #define pthread_mutex_t CRITICAL_SECTION
 #define pthread_mutex_t CRITICAL_SECTION
 #define pthread_mutex_init(x, y) InitializeCriticalSection(x)
 #define pthread_mutex_init(x, y) InitializeCriticalSection(x)
 #define pthread_mutex_lock(x) EnterCriticalSection(x)
 #define pthread_mutex_lock(x) EnterCriticalSection(x)

+ 2 - 0
src/version.h

@@ -0,0 +1,2 @@
+#define VERSION "3proxy-0.8b-devel"
+#define BUILDDATE "140703033508"