Explorar o código

"limit" support in authcache to bind sessions to ip

z3APA3A %!s(int64=6) %!d(string=hai) anos
pai
achega
e7e7d2fddf
Modificáronse 5 ficheiros con 33 adicións e 8 borrados
  1. 6 1
      doc/html/howtoe.html
  2. 7 0
      doc/html/howtor.html
  3. 2 0
      man/3proxy.cfg.3
  4. 17 7
      src/auth.c
  5. 1 0
      src/conf.c

+ 6 - 1
doc/html/howtoe.html

@@ -461,7 +461,12 @@ proxy -n
 </p>
 </p>
 Please note, that caching affects security. Never use caching for access to
 Please note, that caching affects security. Never use caching for access to
 critical resources, such as web administration.
 critical resources, such as web administration.
-
+  <p>authcache can be used to bind user's sessions to ip with 'limit' option, with
+  <pre>
+  autchcache ip,user,pass,limit 120
+  auth cache strong</pre>
+  user will not be able to use more than a single IP during cache time (120 sec).
+  </p>
 		<li><A NAME="USERS">How to create user list</A>
 		<li><A NAME="USERS">How to create user list</A>
 <p>
 <p>
 Userslist is created with 'users' command.
 Userslist is created with 'users' command.

+ 7 - 0
doc/html/howtor.html

@@ -469,6 +469,13 @@
   использовать кэширование для доступа к критичным ресурсам, в частности к
   использовать кэширование для доступа к критичным ресурсам, в частности к
   интерфейсу администрирования.
   интерфейсу администрирования.
   </p>
   </p>
+  <p>authcache так же может использоваться для привязки сессий пользователя к ip с
+  с помощью опции limit
+  <pre>
+  autchcache ip,user,pass,limit 120
+  auth cache strong</pre>
+  запретит пользователю использовать более одного адреса в течении времени кеширования.
+  </p>
   <li><a name="USERS"><i>Как создать список пользователей</i></a>
   <li><a name="USERS"><i>Как создать список пользователей</i></a>
   <p>
   <p>
   Список пользователей задается с помощью команды users. 
   Список пользователей задается с помощью команды users. 

+ 2 - 0
man/3proxy.cfg.3

@@ -519,6 +519,8 @@ assigned to the same user without actual authentication.
  user - same as above, but IP is not checked. 
  user - same as above, but IP is not checked. 
 .br
 .br
  user,password - both username and password are checked against cached ones.
  user,password - both username and password are checked against cached ones.
+.br
+ limit - limit user to use only one ip, \'ip\' and \'user\' are required
 .br
 .br
 Use auth type \'cache\' for cached authentication
 Use auth type \'cache\' for cached authentication
 
 

+ 17 - 7
src/auth.c

@@ -721,15 +721,24 @@ int cacheauth(struct clientparam * param){
 			continue;
 			continue;
 			
 			
 		}
 		}
-		if(((!(conf.authcachetype&2)) || (param->username && ac->username && !strcmp(ac->username, (char *)param->username))) &&
-		   ((!(conf.authcachetype&1)) || (*SAFAMILY(&ac->sa) ==  *SAFAMILY(&param->sincr) && !memcmp(SAADDR(&ac->sa), SAADDR(&param->sincr), SAADDRLEN(&ac->sa)))) && 
+		if((!(conf.authcachetype&2) || (param->username && ac->username && !strcmp(ac->username, (char *)param->username))) &&
 		   (!(conf.authcachetype&4) || (ac->password && param->password && !strcmp(ac->password, (char *)param->password)))) {
 		   (!(conf.authcachetype&4) || (ac->password && param->password && !strcmp(ac->password, (char *)param->password)))) {
-			if(param->username){
-				myfree(param->username);
+
+			if(!(conf.authcachetype&1)
+				|| ((*SAFAMILY(&ac->sa) ==  *SAFAMILY(&param->sincr) 
+				   && !memcmp(SAADDR(&ac->sa), SAADDR(&param->sincr), SAADDRLEN(&ac->sa))))){
+
+				if(param->username){
+					myfree(param->username);
+				}
+				param->username = (unsigned char *)mystrdup(ac->username);
+				pthread_mutex_unlock(&hash_mutex);
+				return 0;
+			}
+			else if ((conf.authcachetype&1) && (conf.authcachetype&8)) {
+				pthread_mutex_unlock(&hash_mutex);
+				return 10;
 			}
 			}
-			param->username = (unsigned char *)mystrdup(ac->username);
-			pthread_mutex_unlock(&hash_mutex);
-			return 0;
 		}
 		}
 		last = ac;
 		last = ac;
 		ac = ac->next;
 		ac = ac->next;
@@ -790,6 +799,7 @@ int doauth(struct clientparam * param){
 			break;
 			break;
 		}
 		}
 		if(res > ret) ret = res;
 		if(res > ret) ret = res;
+		if(ret > 9) return ret;
 	}
 	}
 	if(!res){
 	if(!res){
 		return alwaysauth(param);
 		return alwaysauth(param);

+ 1 - 0
src/conf.c

@@ -1338,6 +1338,7 @@ static int h_authcache(int argc, unsigned char **argv){
 	if(strstr((char *) *(argv + 1), "ip")) conf.authcachetype |= 1;
 	if(strstr((char *) *(argv + 1), "ip")) conf.authcachetype |= 1;
 	if(strstr((char *) *(argv + 1), "user")) conf.authcachetype |= 2;
 	if(strstr((char *) *(argv + 1), "user")) conf.authcachetype |= 2;
 	if(strstr((char *) *(argv + 1), "pass")) conf.authcachetype |= 4;
 	if(strstr((char *) *(argv + 1), "pass")) conf.authcachetype |= 4;
+	if(strstr((char *) *(argv + 1), "limit")) conf.authcachetype |= 8;
 	if(argc > 2) conf.authcachetime = (unsigned) atoi((char *) *(argv + 2));
 	if(argc > 2) conf.authcachetime = (unsigned) atoi((char *) *(argv + 2));
 	if(!conf.authcachetype) conf.authcachetype = 6;
 	if(!conf.authcachetype) conf.authcachetype = 6;
 	if(!conf.authcachetime) conf.authcachetime = 600;
 	if(!conf.authcachetime) conf.authcachetime = 600;