|
ru.unix.bsd- RU.UNIX.BSD ------------------------------------------------------------------ From : Roman Korolyov 2:5095/1.128 11 Nov 2005 01:52:51 To : All Subject : ziproxy -------------------------------------------------------------------------------- .RFC-X-Complaints-To: usenet@gate.inetcomm.net .RFC-NNTP-Posting-Date: Thu, 10 Nov 2005 21:52:52 +0000 (UTC) .RFC-X-Priority: 3 .RFC-X-MSMail-Priority: Normal .RFC-X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.2180 .RFC-X-RFC2646: Format=Flowed; Original From: "Roman Korolyov" <rk@inetcomm.net> Тут наткнулся случайно (http://ziproxy.sourceforge.net/), повертел, понял, что с GPRS'а довольно приятно будет воспользоваться. Hо огорчился, что не умеет HTTP auth (а всему билайну не хочется доступ давать ;) Прикрутил простейшую авторизацию. Может кому ещё пригодится: Hе ругайте, если криво, лучше поправьте ;) diff -ruN ziproxy-1.5.1.orig/etc/ziproxy.conf ziproxy-1.5.1/etc/ziproxy.conf - --- ziproxy-1.5.1.orig/etc/ziproxy.conf Mon Jul 18 18:01:50 2005 +++ ziproxy-1.5.1/etc/ziproxy.conf Fri Nov 11 00:35:39 2005 @@ -24,6 +24,11 @@ # Ziproxy options # ################### +## HTTP auth file +## Should contain user:pass pairs, lines no longer that 128 chars +## Pass is unencrypted +# PasswdFile="/usr/local/ziproxy/ziproxy.passwd" + ## Forward everything to another proxy server. ## Modifications/compression is still applied. # NextProxy="host.name" diff -ruN ziproxy-1.5.1.orig/src/cfgfile.c ziproxy-1.5.1/src/cfgfile.c - --- ziproxy-1.5.1.orig/src/cfgfile.c Sun Jul 17 01:38:28 2005 +++ ziproxy-1.5.1/src/cfgfile.c Fri Nov 11 00:34:55 2005 @@ -29,6 +29,9 @@ char *WhereZiproxy, *ServHost, *OnlyFrom, *LogFileName, *NextProxy, *ServUrl; char **LogPipe, **Compressible; char *CustomError400, *CustomError404, *CustomError408, *CustomError500, *CustomError503; +char *PasswdFile; +char **PasswdEntries; +unsigned long PasswdNumEntries; #ifndef DefaultCfgLocation char DefaultCfgLocation[] = "./ziproxy.conf"; @@ -69,6 +72,7 @@ CFG_SIMPLE_STR("CustomError408", &CustomError408), CFG_SIMPLE_STR("CustomError500", &CustomError500), CFG_SIMPLE_STR("CustomError503", &CustomError503), + CFG_SIMPLE_STR("PasswdFile", &PasswdFile), #ifdef JP2K CFG_BOOL("ModifySuffixes", cfg_true, 0), #else @@ -108,7 +112,8 @@ WhereZiproxy = ServHost = ServUrl = OnlyFrom = LogFileName = NextProxy = NULL; LogPipe = Compressible = NULL; CustomError400 = CustomError404 = CustomError408 = CustomError500 = CustomError503 = NULL; - + PasswdFile = NULL; + cfg = cfg_init(opts, CFGF_NOCASE); status = cfg_parse(cfg, cfg_file); if(!status){ @@ -169,6 +174,9 @@ Continuing with default values.\n"); DoGzip=cfg_getbool(cfg,"Gzip"); ModifySuffixes=cfg_getbool(cfg,"ModifySuffixes"); + if ( !ReadPasswdFile(PasswdFile) ) + PasswdFile=NULL; + } cfg_free(cfg); return status; @@ -194,4 +202,31 @@ *rate = JP2Rate[try]; *quality = ImageQ[try]; return try; +} + +int ReadPasswdFile(char * pswd_file) { + FILE *txtfile; + unsigned long txtfilesize; + PasswdNumEntries=0; + char *line; + + line = malloc(129); + if (pswd_file != NULL){ + if (txtfile = fopen (pswd_file, "r")){ + fseek (txtfile, 0, SEEK_END); + txtfilesize = ftell (txtfile); + fseek (txtfile, 0, SEEK_SET); + PasswdEntries = malloc (txtfilesize + 1); + while ( fgets(line,128,txtfile) ) { + line[strlen(line)-1]=0; + if (strlen(line)>3) { + PasswdEntries[PasswdNumEntries]=strdup(line); + PasswdNumEntries++; + } + } + fclose (txtfile); + } + } + free(line); + return(PasswdNumEntries); } diff -ruN ziproxy-1.5.1.orig/src/cfgfile.h ziproxy-1.5.1/src/cfgfile.h - --- ziproxy-1.5.1.orig/src/cfgfile.h Sun Jul 17 01:38:28 2005 +++ ziproxy-1.5.1/src/cfgfile.h Fri Nov 11 00:23:21 2005 @@ -38,8 +38,12 @@ extern char *WhereZiproxy, *ServHost, *ServUrl, *OnlyFrom, *LogFileName, *NextProxy; extern char **LogPipe, **Compressible; extern char *CustomError400, *CustomError404, *CustomError408, *CustomError500, *CustomError503; +extern char *PasswdFile; +extern char **PasswdEntries; +extern unsigned long PasswdNumEntries; extern int ReadCfgFile(char * cfg_file); +extern int ReadPasswdFile(char * pswd_file); #ifndef DefaultCfgLocation extern char DefaultCfgLocation[]; diff -ruN ziproxy-1.5.1.orig/src/http.c ziproxy-1.5.1/src/http.c - --- ziproxy-1.5.1.orig/src/http.c Sun Sep 4 08:36:59 2005 +++ ziproxy-1.5.1/src/http.c Fri Nov 11 00:34:13 2005 @@ -34,6 +34,9 @@ static void read_content(http_headers *hdr, FILE *sockrfp, char ** inbuf, int *inlen); static void clean_hdr(char* ln); +static const char cd64[]="|$$$}rstuvwxyz{$$$$$$$>?@ABCDEFGHIJKLMNOPQRSTUVW$$$$$$XYZ[\\]^_`abcdefgh ijklmnopq"; +char *base64_decode(char *instr); + void proxy_http(http_headers *client_hdr, FILE* sockrfp, FILE* sockwfp ) { http_headers *serv_hdr; @@ -484,7 +487,8 @@ static void get_client_headers(http_headers * hdr){ int was_via=0, was_keepalive=0; int linelen; - + int was_auth=0; + int unsigned long i; logputs("Headers from client:"); @@ -505,7 +509,16 @@ if (strncasecmp(line,"Proxy-Connection:",17) == 0) continue; - + + if (strncasecmp(line,"Proxy-Authorization:",20) == 0) { + for (i=0; i<PasswdNumEntries; i++ ) { + if (strncasecmp( base64_decode(&(line[27])), PasswdEntries[i], strlen(base64_decode(&(line[27]))) ) == 0 ) { + was_auth=1; + continue; + } + } + } + if (strncasecmp(line,"Keep-Alive:",11) == 0) continue; @@ -552,6 +565,10 @@ add_header(hdr, line); } + if(PasswdFile && !was_auth) { + logputs("Requesting HTTP auth from client"); + send_error( 407, "Proxy Authentication Required", "Proxy-Authenticate: Basic realm=", "You have to be registered before using this proxy."); + } }//get_client_headers /*Does not release the headers ! Rather use special function?*/ @@ -914,3 +931,44 @@ if (spaces > 1) memmove(colon+2,i,strlen(ln)-(colon-ln) - 2); } +// Decode login:pass pair for HTTP authorization +char *base64_decode(char *input) { + unsigned char in[4], out[3], v; + int r, i, len, str_len; + char *outstr; + int outpos=0; + + outstr=(char *)malloc(132); + str_len = strlen(input); + + r = 0; + while (input[r] && outpos < 128 ) { + for (len = 0, i=0; i<4 && input[r]; i++) { + v = 0; + while(input[r] && v == 0 ) { + v = (unsigned char) input[r++]; + v = (unsigned char) ((v < 43 || v > 122) ? 0 : cd64[ v - 43 ]); + if(v) + v = (unsigned char) ((v == '$') ? 0 : v - 61); + } + if (input[r] || ( (str_len % 4) == 0 && input[str_len-1] != '=' ) ) { + len++; + if (v) + in[i] = (unsigned char) (v - 1); + } else { + in[i] = 0; + } + } + + if(len) { + out[0] = (unsigned char) (in[0] << 2 | in[1] >> 4); + out[1] = (unsigned char) (in[1] << 4 | in[2] >> 2); + out[2] = (unsigned char) (((in[2] << 6) & 0xc0) | in[3]); + for (i=0; i<len-1; i++) + outstr[outpos++] = out[i]; + + } + } + outstr[outpos]=0; + return(outstr); +} --- Microsoft Outlook Express 6.00.2900.2180 * Origin: INETCOMM (2:5095/1.128@fidonet) Вернуться к списку тем, сортированных по: возрастание даты уменьшение даты тема автор
Архивное /ru.unix.bsd/13653accbde6e.html, оценка из 5, голосов 16
|