diff --git a/src/plugins/LdapPlugin/ldapauth.c b/src/plugins/LdapPlugin/ldapauth.c index 3b3f3af..1572b4d 100644 --- a/src/plugins/LdapPlugin/ldapauth.c +++ b/src/plugins/LdapPlugin/ldapauth.c @@ -68,7 +68,7 @@ int savecounters(void) tc = tc->next; f=NULL; if(strcmp(tcd->comment,"ldapcounters")==0) { - tmpbuf=mypluginlink->malloc(strlen(pat_file)+strlen(ldap_dircount)+strlen(tcd->ace->users->user)); + tmpbuf=malloc(strlen(pat_file)+strlen(ldap_dircount)+strlen(tcd->ace->users->user)); sprintf(tmpbuf,pat_file,ldap_dircount,tcd->ace->users->user); f=fopen(tmpbuf,"w+b"); fseek(f,0,SEEK_SET); @@ -76,7 +76,7 @@ int savecounters(void) (unsigned long)tcd->cleared,(unsigned long)tcd->updated); fclose(f); - mypluginlink->free(tmpbuf); + free(tmpbuf); } } @@ -194,15 +194,15 @@ int h_ldapconnect(int argc, unsigned char ** argv) return 1; } - ldap_serv=mypluginlink->strdup(argv[1]); - ldap_user=mypluginlink->strdup(argv[2]); + ldap_serv=strdup(argv[1]); + ldap_user=strdup(argv[2]); ld = ldap_init( ldap_serv, 389 ); ldap_unbind_s(ld); if (argc == 4) { - ldap_pass= mypluginlink->strdup(argv[3]); + ldap_pass= strdup(argv[3]); } else { @@ -220,7 +220,7 @@ int h_access(int argc, unsigned char ** argv) fprintf(stderr, "Error in ldapaccess: See documentation of ldapauth plugin.\n"); return 1; } - ldap_access=mypluginlink->strdup(argv[1]); + ldap_access=strdup(argv[1]); return 0; } /* -------------------------------------------------------------------------- @@ -233,7 +233,7 @@ int h_sbase(int argc, unsigned char ** argv) fprintf(stderr, "Error in ldapsbase: See documentation of ldapauth plugin.\n"); return 1; } - ldap_sbase=mypluginlink->strdup(argv[1]); + ldap_sbase=strdup(argv[1]); return 0; } /* -------------------------------------------------------------------------- @@ -245,7 +245,7 @@ int h_userenv(int argc, unsigned char ** argv) fprintf(stderr, "Error in ldapsbase: See documentation of ldapauth plugin.\n"); return 1; } - ldap_userenv=mypluginlink->strdup(argv[1]); + ldap_userenv=strdup(argv[1]); return 0; } /* -------------------------------------------------------------------------- @@ -309,11 +309,11 @@ int h_trafgroup(int argc, unsigned char ** argv) bandwidth = atoi((char *)argv[4]); /* name ldap group */ - tmpbuf=mypluginlink->malloc(strlen(pat_group)+strlen(ldap_group_attr)+strlen(argv[1])); + tmpbuf=malloc(strlen(pat_group)+strlen(ldap_group_attr)+strlen(argv[1])); sprintf(tmpbuf,pat_group,ldap_group_attr,argv[1]); rc = ldap_search_s( ld, ldap_sbase, LDAP_SCOPE_SUBTREE, tmpbuf, attrs, 0, &res ); - mypluginlink->free(tmpbuf); + free(tmpbuf); rc=ldap_count_entries(ld,res); @@ -331,7 +331,7 @@ int h_trafgroup(int argc, unsigned char ** argv) /* -------------bandlim---------- create user list */ - newuserlist = (*mypluginlink->malloc)(sizeof (struct userlist)); + newuserlist = (*mypluginlink->mallocfunc)(sizeof (struct userlist)); if (usercaselow > 0) #ifdef _WIN32 { CharLower(vals[0]); } @@ -339,15 +339,15 @@ int h_trafgroup(int argc, unsigned char ** argv) { lower(vals[0]); } #endif - newuserlist->user = (*mypluginlink->strdup)(vals[0]); + newuserlist->user = (*mypluginlink->strdupfunc)(vals[0]); newuserlist->next = NULL; /*create user rule */ - newace = (*mypluginlink->malloc)(sizeof (struct ace)); + newace = (*mypluginlink->mallocfunc)(sizeof (struct ace)); memset(newace, 0, sizeof(struct ace)); newace->users = newuserlist; newace->action = BANDLIM; /*create user bandlim */ - newbandlim =(*mypluginlink->malloc)(sizeof (struct bandlim)); + newbandlim =(*mypluginlink->mallocfunc)(sizeof (struct bandlim)); memset(newbandlim, 0, sizeof(struct bandlim)); newbandlim->rate = bandwidth; newbandlim->ace = newace; @@ -356,29 +356,29 @@ int h_trafgroup(int argc, unsigned char ** argv) /* -------------counters---------- create user list */ - newuserlist = (*mypluginlink->malloc)(sizeof (struct userlist)); + newuserlist = (*mypluginlink->mallocfunc)(sizeof (struct userlist)); if (usercaselow > 0) #ifdef _WIN32 { CharLower(vals[0]); } #else { lower(vals[0]); } #endif - newuserlist->user = (*mypluginlink->strdup)(vals[0]); + newuserlist->user = (*mypluginlink->strdupfunc)(vals[0]); newuserlist->next = NULL; /*create user rule */ - newace = (*mypluginlink->malloc)(sizeof (struct ace)); + newace = (*mypluginlink->mallocfunc)(sizeof (struct ace)); memset(newace, 0, sizeof(struct ace)); newace->users = newuserlist; newace->action = COUNTIN; /*create user counter */ - newtrafcount =(*mypluginlink->malloc)(sizeof (struct trafcount)); + newtrafcount =(*mypluginlink->mallocfunc)(sizeof (struct trafcount)); memset(newtrafcount, 0, sizeof(struct trafcount)); newtrafcount->ace = newace; newtrafcount->type=rtype; newtrafcount->traflim64 = traflimit; - newtrafcount->comment=(*mypluginlink->strdup)("ldapcounters"); + newtrafcount->comment=(*mypluginlink->strdupfunc)("ldapcounters"); newtrafcount->number=0; - tmpbuf=(*mypluginlink->malloc)(strlen(pat_file)+strlen(ldap_dircount)+strlen(vals[0])); + tmpbuf=malloc(strlen(pat_file)+strlen(ldap_dircount)+strlen(vals[0])); sprintf(tmpbuf,pat_file,ldap_dircount,vals[0]); f=NULL; f=fopen(tmpbuf,"rb"); @@ -396,7 +396,7 @@ int h_trafgroup(int argc, unsigned char ** argv) newtrafcount->updated=rcounter.updated; fclose(f); } - mypluginlink->free(tmpbuf); + free(tmpbuf); newtrafcount->next = mypluginlink->conf->trafcounter; mypluginlink->conf->trafcounter = newtrafcount; @@ -422,8 +422,8 @@ int h_attrsgroup(int argc, unsigned char ** argv) fprintf(stderr, "Error in ldapattr: See documentation of ldapauth plugin.\n"); return 1; } - attrs[0]=mypluginlink->strdup(argv[1]); - ldap_group_attr=mypluginlink->strdup(argv[2]); + attrs[0]=strdup(argv[1]); + ldap_group_attr=strdup(argv[2]); if(argc == 4) { usercaselow=atoi(argv[3]); } @@ -439,7 +439,7 @@ int h_dircount(int argc, unsigned char ** argv) fprintf(stderr, "Error in ldapdircount: See documentation of ldapauth plugin.\n"); return 1; } - ldap_dircount=mypluginlink->strdup(argv[1]); + ldap_dircount=strdup(argv[1]); return 0; } @@ -460,15 +460,15 @@ PLUGINAPI int PLUGINCALL start(struct pluginlink * pluginlink, if (already_loaded != 0) { - pluginlink->free(ldap_access); - pluginlink->free(ldap_sbase); - pluginlink->free(ldap_serv); - pluginlink->free(ldap_user); - pluginlink->free(ldap_pass); - pluginlink->free(ldap_userenv); - pluginlink->free(ldap_dircount); - pluginlink->free(ldap_group_attr); - pluginlink->free(attrs[0]); + free(ldap_access); + free(ldap_sbase); + free(ldap_serv); + free(ldap_user); + free(ldap_pass); + free(ldap_userenv); + free(ldap_dircount); + free(ldap_group_attr); + free(attrs[0]); return (0); } diff --git a/src/plugins/PCREPlugin/pcre_plugin.c b/src/plugins/PCREPlugin/pcre_plugin.c index 30746a1..65a63aa 100644 --- a/src/plugins/PCREPlugin/pcre_plugin.c +++ b/src/plugins/PCREPlugin/pcre_plugin.c @@ -84,10 +84,10 @@ static void pcre_data_free(struct pcre_filter_data *pcrefd){ pthread_mutex_lock(&pcre_mutex); pcrefd->users--; if(!pcrefd->users){ - if(pcrefd->re) pl->free(pcrefd->re); + if(pcrefd->re) pl->freefunc(pcrefd->re); if(pcrefd->acl) pl->freeacl(pcrefd->acl); - if(pcrefd->replace) pl->free(pcrefd->replace); - pl->free(pcrefd); + if(pcrefd->replace) pl->freefunc(pcrefd->replace); + pl->freefunc(pcrefd); } pthread_mutex_unlock(&pcre_mutex); } @@ -167,7 +167,7 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns } } - tmpbuf = (*pl->malloc)(replen); + tmpbuf = pl->mallocfunc(replen); if(!tmpbuf) return CONTINUE; for(target = tmpbuf, replace = pcrefd->replace; *replace; ){ if(*replace == '\\' && *(replace +1)){ @@ -188,18 +188,18 @@ static FILTER_ACTION pcre_filter_buffer(void *fc, struct clientparam *param, uns } memcpy(target, *buf_p + ovector[1], *length_p - ovector[1]); if((ovector[0] + replen + 1) > *bufsize_p){ - newbuf = (*pl->malloc)(ovector[0] + replen + 1); + newbuf = pl->mallocfunc(ovector[0] + replen + 1); if(!newbuf){ - (*pl->free)(tmpbuf); + pl->freefunc(tmpbuf); return CONTINUE; } memcpy(newbuf, *buf_p, ovector[0]); - (*pl->free)(*buf_p); + pl->freefunc(*buf_p); *buf_p = (unsigned char *)newbuf; *bufsize_p = ovector[0] + replen + 1; } memcpy(*buf_p + ovector[0], tmpbuf, replen); - (*pl->free)(tmpbuf); + pl->freefunc(tmpbuf); (*buf_p)[ovector[0] + replen] = 0; *length_p = ovector[0] + replen; if(ovector[0] + replen <= offset){ @@ -237,7 +237,7 @@ static int h_pcre(int argc, unsigned char **argv){ if(!strncmp((char *)argv[0], "pcre_rewrite", 12)) { int i,j; offset = 5; - replace = pl->strdup((char *)argv[4]); + replace = pl->strdupfunc((char *)argv[4]); if(!replace) return 9; for(i=0, j=0; replace[i]; i++, j++){ if(replace[i] == '\\'){ @@ -270,19 +270,19 @@ static int h_pcre(int argc, unsigned char **argv){ if(*argv[3] && !(*argv[3] == '*' && !argv[3][1]) ){ re = pcre_compile((char *)argv[3], pcre_options, &errptr, &offset, NULL); if(!re) { - pl->free(acl); - if(replace) pl->free(replace); + pl->freefunc(acl); + if(replace) pl->freefunc(replace); return 3; } } - flt = pl->malloc(sizeof(struct pcre_filter_data)); - newf = pl->malloc(sizeof(struct filter)); + flt = pl->mallocfunc(sizeof(struct pcre_filter_data)); + newf = pl->mallocfunc(sizeof(struct filter)); if(!flt || !newf) { - pl->free(acl); - pl->free(re); - if(replace) pl->free(replace); - if(flt) pl->free(flt); + pl->freefunc(acl); + pl->freefunc(re); + if(replace) pl->freefunc(replace); + if(flt) pl->freefunc(flt); return 4; } memset(flt, 0, sizeof(struct pcre_filter_data)); @@ -367,11 +367,11 @@ PLUGINAPI int PLUGINCALL pcre_plugin (struct pluginlink * pluginlink, pl = pluginlink; pcre_options = 0; if(!pcre_loaded){ - pcre_malloc = pl->malloc; - pcre_free = pl->free; + pcre_malloc = pl->mallocfunc; + pcre_free = pl->freefunc; pcre_loaded = 1; pthread_mutex_init(&pcre_mutex, NULL); - regexp_symbols[6].value = pl->free; + regexp_symbols[6].value = pl->freefunc; regexp_symbols[6].next = pl->symbols.next; pl->symbols.next = regexp_symbols; pcre_commandhandlers[3].next = pl->commandhandlers->next; @@ -386,7 +386,7 @@ PLUGINAPI int PLUGINCALL pcre_plugin (struct pluginlink * pluginlink, tmpflt = flt->next; if(flt->data) pcre_data_free((struct pcre_filter_data *)flt->data); - pl->free(flt); + pl->freefunc(flt); if(flt == pcre_last_filter) break; } } diff --git a/src/plugins/PamAuth/pamauth.c b/src/plugins/PamAuth/pamauth.c index 3924289..da65ee9 100644 --- a/src/plugins/PamAuth/pamauth.c +++ b/src/plugins/PamAuth/pamauth.c @@ -131,8 +131,8 @@ PLUGINAPI int PLUGINCALL start(struct pluginlink * pluginlink, int argc, unsigne if(argc < 2) return 1; pl = pluginlink; - if(service) pl->free(service); - service=(unsigned char *)pl->strdup((char *)argv[1]); + if(service) free(service); + service=strdup((char *)argv[1]); if (already_loaded) { return (0); } diff --git a/src/plugins/StringsPlugin/StringsPlugin.c b/src/plugins/StringsPlugin/StringsPlugin.c index 4dc1326..e97098d 100644 --- a/src/plugins/StringsPlugin/StringsPlugin.c +++ b/src/plugins/StringsPlugin/StringsPlugin.c @@ -44,7 +44,7 @@ char **load_string(FILE *f,int max_count_str, int *countloadstr, /*create table for old strings */ - old_table=(char **)mypl->malloc(max_count_str*sizeof(char *)); + old_table=(char **)malloc(max_count_str*sizeof(char *)); memset(old_table,0,max_count_str*sizeof(char *)); /*load from file new strings */ @@ -77,13 +77,13 @@ char **load_string(FILE *f,int max_count_str, int *countloadstr, cstr=cstr+(int)strlen(tmpbuf1)+1; - p = (char *)mypl->malloc(cstr); + p = (char *)malloc(cstr); if (pt!=NULL) { strcpy(p, pt); strcat(p, tmpbuf1); - mypl->free(pt); + free(pt); } else { strcpy(p, tmpbuf1); } @@ -104,9 +104,9 @@ char **load_string(FILE *f,int max_count_str, int *countloadstr, } - if(pt)mypl->free(pt); + if(pt)free(pt); *countloadstr=i; - if (i==0) { mypl->free(old_table); old_table=NULL; } + if (i==0) { free(old_table); old_table=NULL; } return old_table; @@ -124,9 +124,9 @@ static int restore_old_table(void * v) for(i=0; i < count_str_proxy_in_3proxy; i++){ p=mypl->proxy_table[i]; mypl->proxy_table[i]=old_proxy_table[i]; - mypl->free(p); + free(p); } - mypl->free(old_proxy_table); + free(old_proxy_table); old_proxy_table = NULL; } @@ -140,9 +140,9 @@ static int restore_old_table(void * v) for(i=0; i < count_str_admin_in_3proxy; i++){ p=mypl->admin_table[i]; mypl->admin_table[i]=old_admin_table[i]; - mypl->free(p); + free(p); } - mypl->free(old_admin_table); + free(old_admin_table); old_admin_table = NULL; } /*return 1 delete job, 0 no delete!!! :)*/ diff --git a/src/plugins/TrafficPlugin/TrafficPlugin.c b/src/plugins/TrafficPlugin/TrafficPlugin.c index 4a3bed4..b721993 100644 --- a/src/plugins/TrafficPlugin/TrafficPlugin.c +++ b/src/plugins/TrafficPlugin/TrafficPlugin.c @@ -74,7 +74,7 @@ static void killtrafcorrect() { while (p) { d = p; p = p->next; - pl->free(d); + free(d); } } @@ -94,7 +94,7 @@ int h_trafcorrect(int argc, unsigned char ** argv) { } return 1; } - newitem = (struct trafcorrect *)pl->malloc(sizeof(struct trafcorrect)); + newitem = (struct trafcorrect *)malloc(sizeof(struct trafcorrect)); newitem->next = NULL; newitem->type = MULTIPLAY; @@ -112,7 +112,7 @@ int h_trafcorrect(int argc, unsigned char ** argv) { newitem->coeff = atof((char *)argv[4]); /* проверка на корректность ввода */ if ((newitem->port>65535) | (newitem->coeff<=0) | (newitem->coeff>100)) { - pl->free(newitem); + free(newitem); if(DBGLEVEL == 1)fprintf(stdout, "Port must be 0malloc(sizeof(struct trafcorrect)); + newitem = (struct trafcorrect *)malloc(sizeof(struct trafcorrect)); newitem->next = NULL; newitem->type = IPCORRECT; @@ -158,7 +158,7 @@ int h_trafcorrect(int argc, unsigned char ** argv) { } if ((newitem->port>65535) | (newitem->psize<=0)) { - pl->free(newitem); + free(newitem); if(DBGLEVEL == 1)fprintf(stdout, "Port must be 0sincl = param->srv->intsa; #endif pl->myinet_ntop(*SAFAMILY(¶m->req), SAADDR(¶m->req), (char *)addrbuf, sizeof(addrbuf)); - if(param->hostname) pl->free(param->hostname); - param->hostname = pl->strdup(addrbuf); + if(param->hostname) pl->freefunc(param->hostname); + param->hostname = pl->strdupfunc(addrbuf); param->sinsr = param->req; return PASS; } diff --git a/src/proxy.h b/src/proxy.h index 3577b40..34e29e2 100644 --- a/src/proxy.h +++ b/src/proxy.h @@ -138,6 +138,11 @@ void daemonize(void); #define DEFLOGFORMAT "G%y%m%d%H%M%S.%. %p %E %U %C:%c %R:%r %O %I %h %T" +#define myalloc malloc +#define myfree free +#define myrealloc realloc +#define mystrdup strdup + extern RESOLVFUNC resolvfunc; extern int wday; diff --git a/src/socks.c b/src/socks.c index f3c37be..899790a 100644 --- a/src/socks.c +++ b/src/socks.c @@ -237,7 +237,7 @@ CLEANRET: int repcode; sasize = sizeof(sin); - if(command != 3) so._getsockname(param->remsock, (struct sockaddr *)&sin, &sasize); + if(command != 3 && param->remsock != INVALID_SOCKET) so._getsockname(param->remsock, (struct sockaddr *)&sin, &sasize); else so._getsockname(param->clisock, (struct sockaddr *)&sin, &sasize); #if SOCKSTRACE > 0 fprintf(stderr, "Sending confirmation to client with code %d for %s with %s:%hu\n", diff --git a/src/structures.h b/src/structures.h index df5164a..36a76b5 100644 --- a/src/structures.h +++ b/src/structures.h @@ -197,11 +197,6 @@ typedef void * (*EXTENDFUNC) (struct node *node); typedef void (*CBFUNC)(void *cb, char * buf, int inbuf); typedef void (*PRINTFUNC) (struct node *node, CBFUNC cbf, void*cb); -#define myalloc malloc -#define myfree free -#define myrealloc realloc -#define mystrdup strdup - #ifdef WIN32 #define PLUGINAPI __declspec(dllexport) @@ -754,10 +749,10 @@ struct pluginlink { void (*decodeurl)(unsigned char *s, int allowcr); int (*parsestr) (unsigned char *str, unsigned char **argm, int nitems, unsigned char ** buff, int *inbuf, int *bufsize); struct ace * (*make_ace) (int argc, unsigned char ** argv); - void * (*malloc)(size_t size); - void (*free)(void *ptr); - void *(*realloc)(void *ptr, size_t size); - char * (*strdup)(const char *str); + void * (*mallocfunc)(size_t size); + void (*freefunc)(void *ptr); + void *(*reallocfunc)(void *ptr, size_t size); + char * (*strdupfunc)(const char *str); TRAFCOUNTFUNC trafcountfunc; char ** proxy_table; struct schedule ** schedule;