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

Merge remote-tracking branch 'refs/remotes/origin/devel'

z3APA3A 10 лет назад
Родитель
Сommit
bf934201bb
2 измененных файлов с 0 добавлено и 379 удалено
  1. 0 145
      src/countersutil.c
  2. 0 234
      src/msnpr.c

+ 0 - 145
src/countersutil.c

@@ -1,145 +0,0 @@
-/*
-   3APA3A simpliest proxy server
-   (c) 2002-2008 by ZARAZA <3APA3A@security.nnov.ru>
-
-   please read License Agreement
-
-   $Id: common.c,v 1.81 2007/12/18 09:26:44 vlad Exp $
-*/
-
-#include "proxy.h"
-
-struct counter_header {
-	unsigned char sig[4];
-	time_t updated;
-} cheader = {"3CF", (time_t)0};
-
-
-struct counter_record {
-	unsigned long traf;
-	unsigned long trafgb;
-	time_t cleared;
-	time_t updated;
-} crecord;
-
-#ifdef _WIN32
-struct counter_header_old {
-	unsigned char sig[4];
-	DWORD updated;
-} cheader_old = {"3CF", (time_t)0};
-
-
-struct counter_record_old {
-	unsigned long traf;
-	unsigned long trafgb;
-	DWORD cleared;
-	DWORD updated;
-} crecord_old;
-#endif
-
-int main(int argc, char *argv[]){
-	FILE *txt;
-	int bin;
-	int i;
-	long unsigned lu1, lu2;
-	char buf[256];
-	if(argc!=4){
-		fprintf(stderr, "Usage: %s command binary_file text_file\n"
-				" commands are:\n"
-				"\texport - dump counterfile to text\n"
-#ifdef _WIN32
-				"\toldexport - export counterfile from older 3proxy version\n"
-#endif
-				"\timport- import counterfile from text\n"
-				"Examples:\n"
-#ifdef _WIN32
-				" %s oldexport counterfile.3cf tmpfile\n"
-#else
-				" %s export counterfilenew.3cf tmpfile\n"
-#endif
-				" %s import counterfilenew.3cf tmpfile\n"
-				"text file record format:\n"
-				"%%d %%10lu %%10lu %%lu %%lu\n"
-				" 1 - counter number\n"
-				" 2 - traffic (Bytes)\n"
-				" 3 - traffic (GB)\n"
-				" 4 - time counter reset (time_t)\n"
-				" 5 - time counter updated (time_t)\n"
-				,argv[0] , argv[0], argv[0]);
-		return 1;
-	}
-	if(!strcmp(argv[1], "export")){
-		bin = open((char *)argv[2], O_BINARY|O_RDONLY, 0660);
-		if(bin < 0){
-			fprintf(stderr, "Failed to open %s\n", argv[2]);
-			return 2;
-		}
-		if(read(bin, &cheader, sizeof(cheader)) != sizeof(cheader) ||
-		   memcmp(&cheader, "3CF", 4)){
-			fprintf(stderr, "Invalid counter file\n");
-			return 3;
-		}
-		txt = fopen(argv[3], "w");
-		if(!txt) txt = stdout;
-		for(i=1; read(bin, &crecord, sizeof(crecord))==sizeof(crecord); i++)
-			fprintf(txt,"%d %10lu %10lu %lu %lu\n", i, 
-				crecord.trafgb,
-				crecord.traf,
-				(unsigned long) crecord.cleared,
-				(unsigned long) crecord.updated);
-	}
-#ifdef _WIN32
-	else if(!strcmp(argv[1], "oldexport")){
-		bin = open((char *)argv[2], O_BINARY|O_RDONLY, 0660);
-		if(bin < 0){
-			fprintf(stderr, "Failed to open %s\n", argv[2]);
-			return 2;
-		}
-		if(read(bin, &cheader_old, sizeof(cheader_old)) != sizeof(cheader_old) ||
-		   memcmp(&cheader, "3CF", 4)){
-			fprintf(stderr, "Invalid counter file\n");
-			return 3;
-		}
-		txt = fopen(argv[3], "w");
-		if(!txt) txt = stdout;
-		for(i=1; read(bin, &crecord_old, sizeof(crecord_old))==sizeof(crecord_old); i++)
-			fprintf(txt, "%d %10lu %10lu %lu %lu\n", i, 
-				crecord_old.trafgb,
-				crecord_old.traf,
-				(unsigned long) crecord_old.cleared,
-				(unsigned long) crecord_old.updated);
-	}
-#endif
-	else if(!strcmp(argv[1], "import")){
-		bin = open((char *)argv[2], O_BINARY|O_WRONLY|O_CREAT|O_EXCL, 0660);
-		if(bin < 0){
-			fprintf(stderr, "Failed to open %s\n", argv[2]);
-			return 2;
-		}
-		txt = fopen(argv[3], "r");
-		if(!txt) {
-			fprintf(stderr, "Failed to open %s\n", argv[3]);
-			return 3;
-		}
-		cheader.updated = time(0);
-		write(bin, &cheader, sizeof(cheader));
-		while(fgets(buf, 256, txt) &&
-			sscanf(buf, "%d %10lu %10lu %lu %lu\n",
-				&i, &crecord.trafgb, &crecord.traf,
-				&lu1, &lu2) == 5){
-
-			crecord.cleared = (time_t) lu1;
-			crecord.updated = (time_t) lu1;
-			lseek(bin,
-			 sizeof(struct counter_header) + (i-1) * sizeof(crecord),
-			 SEEK_SET);
-			write(bin, &crecord, sizeof(crecord));
-
-		}
-	}
-	else {
-		fprintf(stderr, "Unknown command: %s\n", argv[1]);
-		return 5;
-	}
-	return 0;
-}

+ 0 - 234
src/msnpr.c

@@ -1,234 +0,0 @@
-/*
-   3APA3A simpliest proxy server
-   (c) 2002-2008 by ZARAZA <3APA3A@security.nnov.ru>
-
-   please read License Agreement
-
-   $Id: msnpr.c,v 1.3 2012-04-11 23:01:19 vlad Exp $
-*/
-
-#include "proxy.h"
-
-#ifndef PORTMAP
-#define PORTMAP
-#endif
-#define RETURN(xxx) { param->res = xxx; goto CLEANRET; }
-
-struct msn_cookie {
-	struct msn_cookie *next;
-	unsigned char *userid;
-	char * connectstring;
-};
-
-static struct msn_cookie *msn_cookies = NULL;
-pthread_mutex_t msn_cookie_mutex;
-int msn_cookie_mutex_init = 0;
-
-static void msn_clear(void *fo){
-};
-
-static FILTER_ACTION msn_srv(void *fc, struct clientparam * param, unsigned char ** buf_p, int * bufsize_p, int offset, int * length_p){
-	unsigned char *data = *buf_p + offset;
-	int len = (int)(*length_p - offset);
-	struct sockaddr_in sa;
-	SASIZETYPE size = sizeof(sa);
-	struct msn_cookie *cookie;
-	char tmpbuf[256];
-	char *sp1, *sp2, *sp3;
-
-
-	if(*bufsize_p - *length_p < 32) return CONTINUE;
-	if(len < 10 || len > 220) return CONTINUE;
-
-	data[len] = 0;
-	
-
-	sp1 = data + 3;
-	if(data[0] == 'X' && data[1] == 'F' && data[2] == 'R' && data[3] == ' '){
-		if(!(sp2 = strchr(sp1 + 1, ' ')) || !(sp2 = strchr(sp2 + 1, ' '))|| !(sp3 = strchr(sp2 + 1, ' '))) return CONTINUE;
-	}
-	else if(data[0] == 'R' && data[1] == 'N' && data[2] == 'G' && data[3] == ' '){
-		if(!(sp2 = strchr(sp1 + 1, ' ')) || !(sp3 = strchr(sp2 + 1, ' '))) return CONTINUE;
-	}
-	else return CONTINUE;
-
- 	*sp2 = 0;
- 	*sp3 = 0;
-	if(getsockname(param->clisock, (struct sockaddr *)&sa, &size)==-1) {
-		return CONTINUE;
-	};
-	cookie = myalloc(sizeof(struct msn_cookie));
-	cookie->connectstring = mystrdup(sp2 + 1);
-	cookie->userid = mystrdup(param->username);
-
-	pthread_mutex_lock(&msn_cookie_mutex);
-	cookie->next = msn_cookies;
-	msn_cookies = cookie;
-	pthread_mutex_unlock(&msn_cookie_mutex);
-
-	strcpy(tmpbuf, data);
-	len = (int)strlen(tmpbuf);
-	tmpbuf[len++] = ' ';
-
-	len+=myinet_ntoa(sa.sin_addr, tmpbuf+len);
-	sprintf(tmpbuf+len, ":%hu %s", ntohs(sa.sin_port), sp3 + 1);
-	len = (int)strlen(tmpbuf);
-	memcpy(*buf_p + offset, tmpbuf, len);
-	*length_p = offset + len;
-
-	return CONTINUE;
-}
-
-
-static struct filter msnfilter = {
-	NULL,
-	"msnfilter",
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	NULL,
-	*msn_srv,
-	*msn_clear,
-	NULL
-};
-
-
-void * msnprchild(struct clientparam* param) {
- int res, len;
- unsigned char *buf;
- int buflen = 256;
- char *sp1, *sp2, *sp3;
- char *verstr = NULL;
- int id;
- struct msn_cookie *cookie, *prevcookie=NULL;
- int sec = 0; 
- struct filterp  **newfilters;
- int skip = 0;
- struct filterp msnfilterp = {
-	&msnfilter,
-	(void *)&skip
- };
-
-
- if(!msn_cookie_mutex_init){
-	msn_cookie_mutex_init = 1;
-	pthread_mutex_init(&msn_cookie_mutex, NULL);
- }
-
- buf = myalloc(buflen); 
- res = sockgetlinebuf(param, CLIENT, buf, 240, '\n', conf.timeouts[STRING_S]);
- if(res < 10) RETURN(1201);
- buf[res] = 0;
- if(!(sp1 = strchr(buf, ' ')) || !(sp2 = strchr(sp1 + 1, ' ')) || !(sp3 = strchr(sp2 + 1, ' ')) || ((int)(sp3-sp2)) < 6) RETURN(1202);
- if((buf[0] == 'U' && buf[1] == 'S' && buf[2] == 'R') ||
-    (buf[0] == 'A' && buf[1] == 'N' && buf[2] == 'S')){
-        len = 1 + (int)(sp3 - sp2);
- 	param->username = myalloc(len - 1);
- 	memcpy(param->username, sp2 + 1, len - 2);
-	sec = 1;
-
- }
- else if(buf[0] != 'V' || buf[1] != 'E' || buf[2] != 'R') {RETURN(1203);}
- else {
-	id = atoi(sp1 + 1);
-	verstr = mystrdup(buf);
-
-	if(socksend(param->clisock, buf, res, conf.timeouts[STRING_S])!=res) {RETURN (1204);}
-
-	res = sockgetlinebuf(param, CLIENT, buf, 240, '\n', conf.timeouts[STRING_S]);
-	if(res < 10) RETURN(1205);
- 	buf[res] = 0;
- 	if(buf[0] != 'C' || buf[1] != 'V' || buf[2] != 'R' || !(sp1=strrchr(buf,' ')) || (len = (int)strlen(sp1+1)) < 3) RETURN(1206);
- 	param->username = myalloc(len - 1);
- 	memcpy(param->username, sp1 + 1, len - 2);
- }
- param->username[len - 2] = 0;
- param->operation = CONNECT;
-
- pthread_mutex_lock(&msn_cookie_mutex);
- for(cookie = msn_cookies; cookie; cookie = cookie->next){
-	if(!strcmp(param->username, cookie->userid)){
-		parsehostname(cookie->connectstring, param, ntohs(param->srv->targetport));
-		if(prevcookie)prevcookie->next = cookie->next;
-		else msn_cookies = cookie->next;
-		myfree(cookie->connectstring);
-		myfree(cookie->userid);
-		myfree(cookie);
-		break;
-	}
-	prevcookie = cookie;
- }
- pthread_mutex_unlock(&msn_cookie_mutex);
- if(!cookie) {
-	if(sec) RETURN(1233);
-	parsehostname((char *)param->srv->target, param, ntohs(param->srv->targetport));
- }
- res = (*param->srv->authfunc)(param);
- if(res) {RETURN(res);}
-
- if(!sec){
-	len = (int)strlen(verstr);
-	if(socksend(param->remsock, verstr, len, conf.timeouts[STRING_S])!= len) {RETURN (1207);}
-	param->statscli += len;
-
-
-	myfree(verstr);
-	verstr = mystrdup(buf);
-
-	len = sockgetlinebuf(param, SERVER, buf, 240, '\n', conf.timeouts[STRING_S]);
-	if(len < 10) RETURN(1208);
-	param->statssrv += len;
-
-	strcpy(buf, verstr);
- }
-
- len = (int)strlen(buf);
- if((res=handledatfltcli(param,  &buf, &buflen, 0, &len))!=PASS) RETURN(res);
- if(socksend(param->remsock, buf, len, conf.timeouts[STRING_S])!= len) {RETURN (1207);}
-
-
- param->statscli += len;
-
- if(sec){
-	RETURN(sockmap(param, conf.timeouts[CONNECTION_L]));
- }
-
- param->ndatfilterssrv++;
- newfilters = myalloc(param->ndatfilterssrv * sizeof(struct filterp *));
- if(param->ndatfilterssrv > 1){
-	memcpy(newfilters, param->datfilterssrv, (param->ndatfilterssrv - 1) * sizeof(struct filterp *));
-	myfree(param->datfilterssrv);
- }
- param->datfilterssrv = newfilters;
- newfilters[param->ndatfilterssrv - 1] = &msnfilterp;
-
- param->res = sockmap(param, conf.timeouts[CONNECTION_L]);
-
- param->ndatfilterssrv--;
-
-
-
-CLEANRET:
- 
- 
- if(verstr)myfree(verstr);
- if(buf)myfree(buf);
- (*param->srv->logfunc)(param, NULL);
- freeparam(param);
- return (NULL);
-}
-
-#ifdef WITHMAIN
-struct proxydef childdef = {
-	msnprchild,
-	0,
-	0,
-	S_MSNPR,
-	""
-};
-#include "proxymain.c"
-#endif