Compare commits

...

3 Commits

Author SHA1 Message Date
Vladimir Dubrovin
830b2d39d1 Use standard malloc functions
Some checks are pending
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI Linux / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI MacOS / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI Windows / ${{ matrix.target }} (windows-2022) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (macos-15) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-24.04-arm) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (ubuntu-latest) (push) Waiting to run
C/C++ CI cmake / ${{ matrix.target }} (windows-2022) (push) Waiting to run
2026-05-04 18:50:02 +03:00
Vladimir Dubrovin
a338a0c689 Speedup passwords lists 2026-05-04 18:37:18 +03:00
Vladimir Dubrovin
af8a6e0b91 minimize blake2 usage for hashing 2026-05-04 16:48:07 +03:00
26 changed files with 394 additions and 393 deletions

View File

@ -489,7 +489,7 @@ int WinMain(HINSTANCE hInstance, HINSTANCE hPrevInstance, LPWSTR lpCmdLine, int
} }
#endif #endif
#endif #endif
conf.conffile = mystrdup((argc==2)?argv[1]:(char*)DEFAULTCONFIG); conf.conffile = strdup((argc==2)?argv[1]:(char*)DEFAULTCONFIG);
if(conf.conffile && *conf.conffile != '-') { if(conf.conffile && *conf.conffile != '-') {
fp = confopen(); fp = confopen();
#ifndef _WIN32 #ifndef _WIN32

View File

@ -7,6 +7,7 @@
*/ */
#include "proxy.h" #include "proxy.h"
#include "blake2_compat.h"
void initbandlims(struct clientparam *param); void initbandlims(struct clientparam *param);
@ -92,8 +93,8 @@ int cacheauth(struct clientparam * param){
} }
if(!(conf.authcachetype&2) && *ac.username){ if(!(conf.authcachetype&2) && *ac.username){
if(param->username) myfree(param->username); if(param->username) free(param->username);
param->username = (unsigned char *)mystrdup((char *)ac.username); param->username = (unsigned char *)strdup((char *)ac.username);
} }
if((conf.authcachetype & 32)){ if((conf.authcachetype & 32)){
memset(&param->sinsl, 0, sizeof(param->sinsl)); memset(&param->sinsl, 0, sizeof(param->sinsl));
@ -217,23 +218,43 @@ int dnsauth(struct clientparam * param){
int strongauth(struct clientparam * param){ int strongauth(struct clientparam * param){
static char dummy; static char dummy;
unsigned char buf[256]; unsigned char buf[256];
char cryptpw[65] = {0}; char pass[256] = {0};
if (!param->username) return 4; if (!param->username) return 4;
if (!param->pwtype && param->password) { if (!param->pwtype && param->password) {
if (pw_table.ihashtable && hashresolv(&pw_table, param, &dummy, NULL)) if (pwl_table.ihashtable && hashresolv(&pwl_table, param->username, pass, NULL)) {
return 0; switch(pass[0]){
case CL: {
int pwlen = strlen((char *)param->password);
if(pwlen > 255) pwlen = 255;
if((unsigned)pwlen < pwl_table.recsize) {
if(!strncmp(pass + 1, (char *)param->password, pwl_table.recsize - 1)) return 0;
} else {
blake2b_state S;
unsigned hashsz;
hashsz = pwl_table.recsize - 1 < 64 ? pwl_table.recsize - 1 : 64;
memset(buf, 0, pwl_table.recsize - 1);
blake2b_init(&S, hashsz);
blake2b_update(&S, param->password, pwlen + 1);
blake2b_final(&S, buf, hashsz);
if(!memcmp(pass + 1, buf, pwl_table.recsize - 1)) return 0;
}
return 6;
}
case CR:
if (!strcmp(pass + 1, (char *)mycrypt(param->password, (unsigned char *)pass, buf)))
return 0;
else return 7;
#ifdef WITH_SSL #ifdef WITH_SSL
if (pwnt_table.ihashtable && hashresolv(&pwnt_table, param, &dummy, NULL)) case NT:
return 0; ntpwdhash(buf, param->password, 1);
if(!strcmp(pass + 1, (char *)buf)) return 0;
else return 8;
#endif #endif
#ifndef NOCRYPT default:
if (pwcr_table.ihashtable && hashresolv(&pwcr_table, param, cryptpw, NULL)) { break;
if (!strcmp(cryptpw, (char *)mycrypt(param->password, (unsigned char *)cryptpw, buf))) }
return 0;
return 7;
} }
#endif
} }
return 5; return 5;
} }

View File

@ -13,7 +13,7 @@ void * autochild(struct clientparam* param) {
int len; int len;
if(!param->clibuf){ if(!param->clibuf){
if(!(param->clibuf = myalloc(SRVBUFSIZE))) return 0; if(!(param->clibuf = malloc(SRVBUFSIZE))) return 0;
param->clibufsize = SRVBUFSIZE; param->clibufsize = SRVBUFSIZE;
param->clioffset = param->cliinbuf = 0; param->clioffset = param->cliinbuf = 0;
} }

View File

@ -463,8 +463,8 @@ int parsehostname(char *hostname, struct clientparam *param, uint16_t port){
*se = 0; *se = 0;
} }
if(hostname != (char *)param->hostname){ if(hostname != (char *)param->hostname){
if(param->hostname) myfree(param->hostname); if(param->hostname) free(param->hostname);
param->hostname = (unsigned char *)mystrdup(hostname + (se!=0)); param->hostname = (unsigned char *)strdup(hostname + (se!=0));
} }
if(sp){ if(sp){
port = atoi(sp+1); port = atoi(sp+1);
@ -486,12 +486,12 @@ int parseusername(char *username, struct clientparam *param, int extpasswd){
*se = 0; *se = 0;
if(sp) *sp = 0; if(sp) *sp = 0;
if(*(sb+1)) { if(*(sb+1)) {
if(param->password) myfree(param->password); if(param->password) free(param->password);
param->password = (unsigned char *)mystrdup(sb+1); param->password = (unsigned char *)strdup(sb+1);
} }
if(*username) { if(*username) {
if(param->username) myfree(param->username); if(param->username) free(param->username);
param->username = (unsigned char *)mystrdup(username); param->username = (unsigned char *)strdup(username);
} }
username = se+1; username = se+1;
} }
@ -499,12 +499,12 @@ int parseusername(char *username, struct clientparam *param, int extpasswd){
if(!sp) sp = strchr(username, ':'); if(!sp) sp = strchr(username, ':');
if(sp){ if(sp){
*sp = 0; *sp = 0;
if(param->extpassword) myfree(param->extpassword); if(param->extpassword) free(param->extpassword);
param->extpassword = (unsigned char *) mystrdup(sp+1); param->extpassword = (unsigned char *) strdup(sp+1);
} }
} }
if(param->extusername) myfree(param->extusername); if(param->extusername) free(param->extusername);
param->extusername = (unsigned char *)mystrdup(username); param->extusername = (unsigned char *)strdup(username);
if(sb) *sb = ':'; if(sb) *sb = ':';
if(se) *se = ':'; if(se) *se = ':';
if(sp) *sp = ':'; if(sp) *sp = ':';

View File

@ -7,6 +7,7 @@
*/ */
#include "proxy.h" #include "proxy.h"
#include "blake2_compat.h"
#ifdef WITH_SSL #ifdef WITH_SSL
void ssl_install(void); void ssl_install(void);
#endif #endif
@ -319,7 +320,7 @@ static int h_log(int argc, unsigned char ** argv){
notchanged = 1; notchanged = 1;
} }
if(!notchanged && conf.logtarget){ if(!notchanged && conf.logtarget){
myfree(conf.logtarget); free(conf.logtarget);
conf.logtarget = NULL; conf.logtarget = NULL;
} }
if(argc > 1) { if(argc > 1) {
@ -327,7 +328,7 @@ static int h_log(int argc, unsigned char ** argv){
conf.logfunc = lognone; conf.logfunc = lognone;
return 0; return 0;
} }
if(!notchanged) conf.logtarget = (unsigned char *)mystrdup((char *)argv[1]); if(!notchanged) conf.logtarget = (unsigned char *)strdup((char *)argv[1]);
if(*argv[1]=='@'){ if(*argv[1]=='@'){
#ifndef _WIN32 #ifndef _WIN32
conf.logfunc = logsyslog; conf.logfunc = logsyslog;
@ -357,8 +358,8 @@ static int h_log(int argc, unsigned char ** argv){
conf.logfunc = logstdout; conf.logfunc = logstdout;
if(notchanged) return 0; if(notchanged) return 0;
conf.logtime = time(0); conf.logtime = time(0);
if(conf.logname)myfree(conf.logname); if(conf.logname)free(conf.logname);
conf.logname = (unsigned char *)mystrdup((char *)argv[1]); conf.logname = (unsigned char *)strdup((char *)argv[1]);
if(conf.stdlog) conf.stdlog = freopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.logtime), "a", conf.stdlog); if(conf.stdlog) conf.stdlog = freopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.logtime), "a", conf.stdlog);
else conf.stdlog = fopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.logtime), "a"); else conf.stdlog = fopen((char *)dologname (tmpbuf, conf.logname, NULL, conf.logtype, conf.logtime), "a");
if(!conf.stdlog){ if(!conf.stdlog){
@ -399,8 +400,8 @@ static int h_daemon(int argc, unsigned char **argv){
} }
static int h_config(int argc, unsigned char **argv){ static int h_config(int argc, unsigned char **argv){
if(conf.conffile)myfree(conf.conffile); if(conf.conffile)free(conf.conffile);
conf.conffile = mystrdup((char *)argv[1]); conf.conffile = strdup((char *)argv[1]);
if(!conf.conffile) return 21; if(!conf.conffile) return 21;
return 0; return 0;
} }
@ -422,10 +423,10 @@ static int h_include(int argc, unsigned char **argv){
static int h_archiver(int argc, unsigned char **argv){ static int h_archiver(int argc, unsigned char **argv){
int j; int j;
conf.archiver = myalloc(argc * sizeof(char *)); conf.archiver = malloc(argc * sizeof(char *));
if(conf.archiver) { if(conf.archiver) {
conf.archiverc = argc; conf.archiverc = argc;
for(j = 0; j < conf.archiverc; j++) conf.archiver[j] = (unsigned char *)mystrdup((char *)argv[j]); for(j = 0; j < conf.archiverc; j++) conf.archiver[j] = (unsigned char *)strdup((char *)argv[j]);
} }
return 0; return 0;
} }
@ -451,8 +452,8 @@ static int h_counter(int argc, unsigned char **argv){
} }
if(argc >=4) { if(argc >=4) {
conf.countertype = getrotate(*argv[2]); conf.countertype = getrotate(*argv[2]);
if(conf.counterfile) myfree(conf.counterfile); if(conf.counterfile) free(conf.counterfile);
conf.counterfile = mystrdup((char *)argv[3]); conf.counterfile = strdup((char *)argv[3]);
} }
return 0; return 0;
} }
@ -469,8 +470,8 @@ static int h_maxseg(int argc, unsigned char **argv){
static int h_logformat(int argc, unsigned char **argv){ static int h_logformat(int argc, unsigned char **argv){
unsigned char * old = conf.logformat; unsigned char * old = conf.logformat;
conf.logformat = (unsigned char *)mystrdup((char *)argv[1]); conf.logformat = (unsigned char *)strdup((char *)argv[1]);
if(old) myfree(old); if(old) free(old);
return 0; return 0;
} }
@ -499,7 +500,7 @@ static int h_auth(int argc, unsigned char **argv){
for(argc--; argc; argc--){ for(argc--; argc; argc--){
for(au = authfuncs; au; au=au->next){ for(au = authfuncs; au; au=au->next){
if(!strcmp((char *)argv[argc], au->desc)){ if(!strcmp((char *)argv[argc], au->desc)){
newau = myalloc(sizeof(struct auth)); newau = malloc(sizeof(struct auth));
if(!newau) { if(!newau) {
return 21; return 21;
} }
@ -522,6 +523,8 @@ static int h_users(int argc, unsigned char **argv){
int j; int j;
unsigned char *arg; unsigned char *arg;
char *pw[2]; char *pw[2];
char pass[256];
int l;
for (j = 1; j < argc; j++) { for (j = 1; j < argc; j++) {
arg = (unsigned char *)strchr((char *)argv[j], ':'); arg = (unsigned char *)strchr((char *)argv[j], ':');
@ -529,34 +532,44 @@ static int h_users(int argc, unsigned char **argv){
*arg = 0; *arg = 0;
pw[0] = (char *)argv[j]; pw[0] = (char *)argv[j];
if (!pwl_table.ihashtable && inithashtable(&pwl_table, 16, 32, 1048576))
return 3;
memset(pass, 0, sizeof(pass));
if (arg[1] && arg[2] && arg[3] == ':') { if (arg[1] && arg[2] && arg[3] == ':') {
pw[1] = (char *)(arg + 4); pw[1] = (char *)(arg + 4);
if (arg[1] == 'N' && arg[2] == 'T') { if (arg[1] == 'N' && arg[2] == 'T') {
#ifdef WITH_SSL #ifdef WITH_SSL
if (!pwnt_table.ihashtable && inithashtable(&pwnt_table, 16, 32, 1048576)) *pass = NT;
return 3; #else
hashadd(&pwnt_table, pw, &dummy, MAX_COUNTER_TIME); continue;
#endif #endif
continue;
} }
if (arg[1] == 'C' && arg[2] == 'R') { else if (arg[1] == 'C' && arg[2] == 'R') {
if (!pwcr_table.ihashtable && inithashtable(&pwcr_table, 16, 32, 1048576)) *pass = CR;
return 3;
hashadd(&pwcr_table, pw[0], pw[1], MAX_COUNTER_TIME);
continue;
} }
if (arg[1] == 'C' && arg[2] == 'L') { else if (arg[1] == 'C' && arg[2] == 'L') {
/* fall through to CL handling below */ *pass = CL;
} else { } else {
continue; continue;
} }
} else { } else {
*pass = CL;
pw[1] = (char *)(arg + 1); pw[1] = (char *)(arg + 1);
} }
l = strlen(pw[1]);
if (!pw_table.ihashtable && inithashtable(&pw_table, 16, 32, 1048576)) if(l > 255) l = 255;
return 3; if((unsigned)l >= pwl_table.recsize) {
hashadd(&pw_table, pw, &dummy, MAX_COUNTER_TIME); if(*pass != CL) continue;
blake2b_state S;
unsigned hashsz;
hashsz = pwl_table.recsize - 1 < 64 ? pwl_table.recsize - 1 : 64;
blake2b_init(&S, hashsz);
blake2b_update(&S, pw[1], l + 1);
blake2b_final(&S, (uint8_t *)(pass + 1), hashsz);
} else {
memcpy(pass + 1, pw[1], l);
}
hashadd(&pwl_table, pw[0], pass, MAX_COUNTER_TIME);
} }
return 0; return 0;
} }
@ -689,8 +702,8 @@ static int h_nsrecord(int argc, unsigned char **argv){
} }
static int h_dialer(int argc, unsigned char **argv){ static int h_dialer(int argc, unsigned char **argv){
if(conf.demanddialprog) myfree(conf.demanddialprog); if(conf.demanddialprog) free(conf.demanddialprog);
conf.demanddialprog = mystrdup((char *)argv[1]); conf.demanddialprog = strdup((char *)argv[1]);
return 0; return 0;
} }
@ -719,14 +732,14 @@ static int h_pidfile(int argc, unsigned char **argv){
static int h_monitor(int argc, unsigned char **argv){ static int h_monitor(int argc, unsigned char **argv){
struct filemon * fm; struct filemon * fm;
fm = myalloc(sizeof (struct filemon)); fm = malloc(sizeof (struct filemon));
if(!fm) return 21; if(!fm) return 21;
if(stat((char *)argv[1], &fm->sb)){ if(stat((char *)argv[1], &fm->sb)){
myfree(fm); free(fm);
fprintf(stderr, "Warning: file %s doesn't exist on line %d\n", argv[1], linenum); fprintf(stderr, "Warning: file %s doesn't exist on line %d\n", argv[1], linenum);
} }
else { else {
fm->path = mystrdup((char *)argv[1]); fm->path = strdup((char *)argv[1]);
if(!fm->path) return 21; if(!fm->path) return 21;
fm->next = conf.fmon; fm->next = conf.fmon;
conf.fmon = fm; conf.fmon = fm;
@ -771,7 +784,7 @@ static int h_parent(int argc, unsigned char **argv){
} }
acl->action = 2; acl->action = 2;
chains = myalloc(sizeof(struct chain)); chains = malloc(sizeof(struct chain));
if(!chains){ if(!chains){
return(21); return(21);
} }
@ -779,7 +792,7 @@ static int h_parent(int argc, unsigned char **argv){
chains->weight = (unsigned)atoi((char *)argv[1]); chains->weight = (unsigned)atoi((char *)argv[1]);
if(chains->weight == 0 || chains->weight >1000) { if(chains->weight == 0 || chains->weight >1000) {
fprintf(stderr, "Chaining error: bad chain weight %u line %d\n", chains->weight, linenum); fprintf(stderr, "Chaining error: bad chain weight %u line %d\n", chains->weight, linenum);
myfree(chains); free(chains);
return(3); return(3);
} }
for(i = 0; redirs[i].name ; i++){ for(i = 0; redirs[i].name ; i++){
@ -795,7 +808,7 @@ static int h_parent(int argc, unsigned char **argv){
} }
if(!redirs[i].name) { if(!redirs[i].name) {
fprintf(stderr, "Chaining error: bad chain type (%s)\n", argv[2]); fprintf(stderr, "Chaining error: bad chain type (%s)\n", argv[2]);
myfree(chains); free(chains);
return(4); return(4);
} }
#ifdef WITH_UN #ifdef WITH_UN
@ -807,15 +820,15 @@ static int h_parent(int argc, unsigned char **argv){
cidr = strchr((char *)argv[3], '/'); cidr = strchr((char *)argv[3], '/');
if(cidr) *cidr = 0; if(cidr) *cidr = 0;
if(!getip46(46, argv[3], (struct sockaddr *)&chains->addr)) { if(!getip46(46, argv[3], (struct sockaddr *)&chains->addr)) {
myfree(chains); free(chains);
return (5); return (5);
} }
#ifdef WITH_UN #ifdef WITH_UN
} }
#endif #endif
chains->exthost = (unsigned char *)mystrdup((char *)argv[3]); chains->exthost = (unsigned char *)strdup((char *)argv[3]);
if(!chains->exthost) { if(!chains->exthost) {
myfree(chains); free(chains);
return 21; return 21;
} }
if(cidr){ if(cidr){
@ -823,8 +836,8 @@ static int h_parent(int argc, unsigned char **argv){
chains->cidr = atoi(cidr + 1); chains->cidr = atoi(cidr + 1);
} }
*SAPORT(&chains->addr) = htons((uint16_t)atoi((char *)argv[4])); *SAPORT(&chains->addr) = htons((uint16_t)atoi((char *)argv[4]));
if(argc > 5) chains->extuser = (unsigned char *)mystrdup((char *)argv[5]); if(argc > 5) chains->extuser = (unsigned char *)strdup((char *)argv[5]);
if(argc > 6) chains->extpass = (unsigned char *)mystrdup((char *)argv[6]); if(argc > 6) chains->extpass = (unsigned char *)strdup((char *)argv[6]);
if(!acl->chains) { if(!acl->chains) {
acl->chains = chains; acl->chains = chains;
} }
@ -910,7 +923,7 @@ struct ace * make_ace (int argc, unsigned char ** argv){
struct hostname *hostnamel=NULL; struct hostname *hostnamel=NULL;
int res; int res;
acl = myalloc(sizeof(struct ace)); acl = malloc(sizeof(struct ace));
if(!acl) return acl; if(!acl) return acl;
memset(acl, 0, sizeof(struct ace)); memset(acl, 0, sizeof(struct ace));
if(argc > 0 && strcmp("*", (char *)argv[0])) { if(argc > 0 && strcmp("*", (char *)argv[0])) {
@ -918,10 +931,10 @@ struct ace * make_ace (int argc, unsigned char ** argv){
arg = (unsigned char *)strtok((char *)arg, ","); arg = (unsigned char *)strtok((char *)arg, ",");
if(arg) do { if(arg) do {
if(!acl->users) { if(!acl->users) {
acl->users = userl = myalloc(sizeof(struct userlist)); acl->users = userl = malloc(sizeof(struct userlist));
} }
else { else {
userl->next = myalloc(sizeof(struct userlist)); userl->next = malloc(sizeof(struct userlist));
userl = userl -> next; userl = userl -> next;
} }
if(!userl) { if(!userl) {
@ -929,7 +942,7 @@ struct ace * make_ace (int argc, unsigned char ** argv){
return(NULL); return(NULL);
} }
memset(userl, 0, sizeof(struct userlist)); memset(userl, 0, sizeof(struct userlist));
userl->user=(unsigned char*)mystrdup((char *)arg); userl->user=(unsigned char*)strdup((char *)arg);
if(!userl->user) return NULL; if(!userl->user) return NULL;
} while((arg = (unsigned char *)strtok((char *)NULL, ","))); } while((arg = (unsigned char *)strtok((char *)NULL, ",")));
} }
@ -937,10 +950,10 @@ struct ace * make_ace (int argc, unsigned char ** argv){
arg = (unsigned char *)strtok((char *)argv[1], ","); arg = (unsigned char *)strtok((char *)argv[1], ",");
if(arg) do { if(arg) do {
if(!acl->src) { if(!acl->src) {
acl->src = ipl = myalloc(sizeof(struct iplist)); acl->src = ipl = malloc(sizeof(struct iplist));
} }
else { else {
ipl->next = myalloc(sizeof(struct iplist)); ipl->next = malloc(sizeof(struct iplist));
ipl = ipl -> next; ipl = ipl -> next;
} }
if(!ipl) { if(!ipl) {
@ -965,10 +978,10 @@ struct ace * make_ace (int argc, unsigned char ** argv){
if(scanipl(arg, &tmpip)){ if(scanipl(arg, &tmpip)){
if(!arglen) continue; if(!arglen) continue;
if(!acl->dstnames) { if(!acl->dstnames) {
acl->dstnames = hostnamel = myalloc(sizeof(struct hostname)); acl->dstnames = hostnamel = malloc(sizeof(struct hostname));
} }
else { else {
hostnamel->next = myalloc(sizeof(struct hostname)); hostnamel->next = malloc(sizeof(struct hostname));
hostnamel = hostnamel -> next; hostnamel = hostnamel -> next;
} }
if(!hostnamel){ if(!hostnamel){
@ -988,7 +1001,7 @@ struct ace * make_ace (int argc, unsigned char ** argv){
arglen--; arglen--;
hostnamel->matchtype ^= MATCHBEGIN; hostnamel->matchtype ^= MATCHBEGIN;
} }
hostnamel->name = (unsigned char *) mystrdup( (char *)pattern); hostnamel->name = (unsigned char *) strdup( (char *)pattern);
if(!hostnamel->name) { if(!hostnamel->name) {
fprintf(stderr, "No memory for ACL entry, line %d\n", linenum); fprintf(stderr, "No memory for ACL entry, line %d\n", linenum);
return(NULL); return(NULL);
@ -997,10 +1010,10 @@ struct ace * make_ace (int argc, unsigned char ** argv){
else { else {
if(!acl->dst) { if(!acl->dst) {
acl->dst = ipl = myalloc(sizeof(struct iplist)); acl->dst = ipl = malloc(sizeof(struct iplist));
} }
else { else {
ipl->next = myalloc(sizeof(struct iplist)); ipl->next = malloc(sizeof(struct iplist));
ipl = ipl -> next; ipl = ipl -> next;
} }
if(!ipl) { if(!ipl) {
@ -1015,10 +1028,10 @@ struct ace * make_ace (int argc, unsigned char ** argv){
arg = (unsigned char *)strtok((char *)argv[3], ","); arg = (unsigned char *)strtok((char *)argv[3], ",");
if(arg) do { if(arg) do {
if(!acl->ports) { if(!acl->ports) {
acl->ports = portl = myalloc(sizeof(struct portlist)); acl->ports = portl = malloc(sizeof(struct portlist));
} }
else { else {
portl->next = myalloc(sizeof(struct portlist)); portl->next = malloc(sizeof(struct portlist));
portl = portl -> next; portl = portl -> next;
} }
if(!portl) { if(!portl) {
@ -1144,7 +1157,7 @@ struct ace * make_ace (int argc, unsigned char ** argv){
t2 = (t2 * 60) + (arg[12] - '0') * 10 + (arg[13] - '0'); t2 = (t2 * 60) + (arg[12] - '0') * 10 + (arg[13] - '0');
t2 = (t2 * 60) + (arg[15] - '0') * 10 + (arg[16] - '0'); t2 = (t2 * 60) + (arg[15] - '0') * 10 + (arg[16] - '0');
if(t2 < t1) break; if(t2 < t1) break;
sp = myalloc(sizeof(struct period)); sp = malloc(sizeof(struct period));
if(sp){ if(sp){
sp->fromtime = t1; sp->fromtime = t1;
sp->totime = t2; sp->totime = t2;
@ -1223,7 +1236,7 @@ static int h_ace(int argc, unsigned char **argv){
acl->action = res; acl->action = res;
switch(acl->action){ switch(acl->action){
case REDIRECT: case REDIRECT:
acl->chains = myalloc(sizeof(struct chain)); acl->chains = malloc(sizeof(struct chain));
if(!acl->chains) { if(!acl->chains) {
freeacl(acl); freeacl(acl);
return(21); return(21);
@ -1250,7 +1263,7 @@ static int h_ace(int argc, unsigned char **argv){
break; break;
case CONNLIM: case CONNLIM:
case NOCONNLIM: case NOCONNLIM:
ncl = myalloc(sizeof(struct connlim)); ncl = malloc(sizeof(struct connlim));
if(!ncl) { if(!ncl) {
freeacl(acl); freeacl(acl);
return(21); return(21);
@ -1277,7 +1290,7 @@ static int h_ace(int argc, unsigned char **argv){
case BANDLIM: case BANDLIM:
case NOBANDLIM: case NOBANDLIM:
nbl = myalloc(sizeof(struct bandlim)); nbl = malloc(sizeof(struct bandlim));
if(!nbl) { if(!nbl) {
freeacl(acl); freeacl(acl);
return(21); return(21);
@ -1287,7 +1300,7 @@ static int h_ace(int argc, unsigned char **argv){
if(acl->action == BANDLIM) { if(acl->action == BANDLIM) {
sscanf((char *)argv[1], "%u", &nbl->rate); sscanf((char *)argv[1], "%u", &nbl->rate);
if(nbl->rate < 300) { if(nbl->rate < 300) {
myfree(nbl); free(nbl);
freeacl(acl); freeacl(acl);
fprintf(stderr, "Wrong bandwidth specified, line %d\n", linenum); fprintf(stderr, "Wrong bandwidth specified, line %d\n", linenum);
return(4); return(4);
@ -1327,7 +1340,7 @@ static int h_ace(int argc, unsigned char **argv){
case COUNTALL: case COUNTALL:
case NOCOUNTALL: case NOCOUNTALL:
if(!conf.trafcountfunc) conf.trafcountfunc = trafcountfunc; if(!conf.trafcountfunc) conf.trafcountfunc = trafcountfunc;
tl = myalloc(sizeof(struct trafcount)); tl = malloc(sizeof(struct trafcount));
if(!tl) { if(!tl) {
freeacl(acl); freeacl(acl);
return(21); return(21);
@ -1341,14 +1354,14 @@ static int h_ace(int argc, unsigned char **argv){
tl->comment = ( char *)argv[1]; tl->comment = ( char *)argv[1];
while(isdigit(*tl->comment))tl->comment++; while(isdigit(*tl->comment))tl->comment++;
if(*tl->comment== '/')tl->comment++; if(*tl->comment== '/')tl->comment++;
tl->comment = mystrdup(tl->comment); tl->comment = strdup(tl->comment);
sscanf((char *)argv[1], "%u", &tl->number); sscanf((char *)argv[1], "%u", &tl->number);
sscanf((char *)argv[3], "%lu", &lim); sscanf((char *)argv[3], "%lu", &lim);
tl->type = getrotate(*argv[2]); tl->type = getrotate(*argv[2]);
tl->traflim64 = ((uint64_t)lim)*(1024*1024); tl->traflim64 = ((uint64_t)lim)*(1024*1024);
if(!tl->traflim64) { if(!tl->traflim64) {
myfree(tl); free(tl);
freeacl(acl); freeacl(acl);
fprintf(stderr, "Wrong traffic limit specified, line %d\n", linenum); fprintf(stderr, "Wrong traffic limit specified, line %d\n", linenum);
return(6); return(6);
@ -1585,7 +1598,7 @@ static int h_chroot(int argc, unsigned char **argv){
p--; p--;
*p = 0; *p = 0;
} }
chrootp = mystrdup((char *)argv[1]); chrootp = strdup((char *)argv[1]);
if(!chrootp) return 21; if(!chrootp) return 21;
} }
if (gid && setregid(gid,gid)) { if (gid && setregid(gid,gid)) {
@ -1738,7 +1751,7 @@ int parsestr (unsigned char *str, unsigned char **argm, int nitems, unsigned cha
} }
if((*bufsize - *inbuf) <STRINGBUF){ if((*bufsize - *inbuf) <STRINGBUF){
*bufsize += STRINGBUF; *bufsize += STRINGBUF;
if(!(buf = myrealloc(buf, *bufsize))){ if(!(buf = realloc(buf, *bufsize))){
fprintf(stderr, "Failed to allocate memory for %s\n", incbegin+1); fprintf(stderr, "Failed to allocate memory for %s\n", incbegin+1);
close(fd); close(fd);
return -1; return -1;
@ -1791,7 +1804,7 @@ int readconfig(FILE * fp){
struct commands * cm; struct commands * cm;
int res = 0; int res = 0;
if( !(buf = myalloc(bufsize)) || ! (argv = myalloc((NPARAMS + 1) * sizeof(unsigned char *))) ) { if( !(buf = malloc(bufsize)) || ! (argv = malloc((NPARAMS + 1) * sizeof(unsigned char *))) ) {
fprintf(stderr, "No memory for configuration"); fprintf(stderr, "No memory for configuration");
return(10); return(10);
} }
@ -1838,8 +1851,8 @@ int readconfig(FILE * fp){
fprintf(stderr, "Unknown command: '%s' line %d\n", argv[0], linenum); fprintf(stderr, "Unknown command: '%s' line %d\n", argv[0], linenum);
return(linenum); return(linenum);
} }
myfree(buf); free(buf);
myfree(argv); free(argv);
return 0; return 0;
} }
@ -1848,8 +1861,8 @@ int readconfig(FILE * fp){
void freepwl(struct passwords *pwl){ void freepwl(struct passwords *pwl){
for(; pwl; pwl = (struct passwords *)itfree(pwl, pwl->next)){ for(; pwl; pwl = (struct passwords *)itfree(pwl, pwl->next)){
if(pwl->user)myfree(pwl->user); if(pwl->user)free(pwl->user);
if(pwl->password)myfree(pwl->password); if(pwl->password)free(pwl->password);
} }
} }
@ -1892,11 +1905,7 @@ void freeconf(struct extparam *confp){
confp->connlimiter = NULL; confp->connlimiter = NULL;
_3proxy_mutex_unlock(&connlim_mutex); _3proxy_mutex_unlock(&connlim_mutex);
destroyhashtable(&pw_table); destroyhashtable(&pwl_table);
#ifdef WITH_SSL
destroyhashtable(&pwnt_table);
#endif
destroyhashtable(&pwcr_table);
confp->logfunc = lognone; confp->logfunc = lognone;
logformat = confp->logformat; logformat = confp->logformat;
@ -1935,7 +1944,7 @@ void freeconf(struct extparam *confp){
} }
if(tc)dumpcounters(tc,counterd); if(tc)dumpcounters(tc,counterd);
for(; tc; tc = (struct trafcount *) itfree(tc, tc->next)){ for(; tc; tc = (struct trafcount *) itfree(tc, tc->next)){
if(tc->comment)myfree(tc->comment); if(tc->comment)free(tc->comment);
freeacl(tc->ace); freeacl(tc->ace);
} }
@ -1949,14 +1958,14 @@ void freeconf(struct extparam *confp){
close(counterd); close(counterd);
} }
for(; fm; fm = (struct filemon *)itfree(fm, fm->next)){ for(; fm; fm = (struct filemon *)itfree(fm, fm->next)){
if(fm->path) myfree(fm->path); if(fm->path) free(fm->path);
} }
if(logformat) { if(logformat) {
myfree(logformat); free(logformat);
} }
if(archiver) { if(archiver) {
for(i = 0; i < archiverc; i++) myfree(archiver[i]); for(i = 0; i < archiverc; i++) free(archiver[i]);
myfree(archiver); free(archiver);
} }
havelog = 0; havelog = 0;
} }

View File

@ -33,7 +33,7 @@ void * dnsprchild(struct clientparam* param) {
#endif #endif
if(!(bbuf = myalloc(BUFSIZE+2))){ if(!(bbuf = malloc(BUFSIZE+2))){
param->srv->fds.events = POLLIN; param->srv->fds.events = POLLIN;
RETURN (21); RETURN (21);
} }
@ -75,7 +75,7 @@ void * dnsprchild(struct clientparam* param) {
} }
if(len > (i-4)) {RETURN(817);} if(len > (i-4)) {RETURN(817);}
host = mystrdup((char *)buf+13); host = strdup((char *)buf+13);
if(!host) {RETURN(21);} if(!host) {RETURN(21);}
for(s2 = buf + 12; (s1 = (unsigned char *)strchr((char *)s2 + 1, '.')); s2 = s1)*s2 = (unsigned char)((s1 - s2) - 1); for(s2 = buf + 12; (s1 = (unsigned char *)strchr((char *)s2 + 1, '.')); s2 = s1)*s2 = (unsigned char)((s1 - s2) - 1);
@ -200,8 +200,8 @@ CLEANRET:
} }
dolog(param, buf); dolog(param, buf);
} }
if(bbuf)myfree(bbuf); if(bbuf)free(bbuf);
if(host)myfree(host); if(host)free(host);
#ifndef _WIN32 #ifndef _WIN32
param->clisock = INVALID_SOCKET; param->clisock = INVALID_SOCKET;
#endif #endif

View File

@ -24,7 +24,7 @@ void * ftpprchild(struct clientparam* param) {
struct linger lg; struct linger lg;
struct pollfd fds; struct pollfd fds;
if(!(buf = myalloc(BUFSIZE))) RETURN(876); if(!(buf = malloc(BUFSIZE))) RETURN(876);
param->ctrlsock = param->clisock; param->ctrlsock = param->clisock;
param->operation = CONNECT; param->operation = CONNECT;
lg.l_onoff = 1; lg.l_onoff = 1;
@ -38,7 +38,7 @@ void * ftpprchild(struct clientparam* param) {
if(i<4) {RETURN(802);} if(i<4) {RETURN(802);}
buf[i] = 0; buf[i] = 0;
if ((se=(unsigned char *)strchr((char *)buf, '\r'))) *se = 0; if ((se=(unsigned char *)strchr((char *)buf, '\r'))) *se = 0;
if (req) myfree (req); if (req) free (req);
req = NULL; req = NULL;
if (!strncasecmp((char *)buf, "OPEN ", 5)){ if (!strncasecmp((char *)buf, "OPEN ", 5)){
@ -64,14 +64,14 @@ void * ftpprchild(struct clientparam* param) {
} }
else if (!strncasecmp((char *)buf, "PASS ", 5)){ else if (!strncasecmp((char *)buf, "PASS ", 5)){
param->extpassword = (unsigned char *)mystrdup((char *)buf+5); param->extpassword = (unsigned char *)strdup((char *)buf+5);
inbuf = BUFSIZE; inbuf = BUFSIZE;
res = ftplogin(param, (char *)buf, &inbuf); res = ftplogin(param, (char *)buf, &inbuf);
param->res = res; param->res = res;
if(inbuf && inbuf != BUFSIZE && socksend(param, param->ctrlsock, buf, inbuf, conf.timeouts[STRING_S])!=inbuf) {RETURN (807);} if(inbuf && inbuf != BUFSIZE && socksend(param, param->ctrlsock, buf, inbuf, conf.timeouts[STRING_S])!=inbuf) {RETURN (807);}
if(!res) status = 3; if(!res) status = 3;
sprintf((char *)buf, "%.128s@%.128s%c%hu", param->extusername, param->hostname, (ntohs(*SAPORT(&param->sinsr))==21)?0:':', ntohs(*SAPORT(&param->sinsr))); sprintf((char *)buf, "%.128s@%.128s%c%hu", param->extusername, param->hostname, (ntohs(*SAPORT(&param->sinsr))==21)?0:':', ntohs(*SAPORT(&param->sinsr)));
req = mystrdup((char *)buf); req = strdup((char *)buf);
#ifndef WITHMAIN #ifndef WITHMAIN
{ {
int action, reqbufsize, reqsize; int action, reqbufsize, reqsize;
@ -221,7 +221,7 @@ void * ftpprchild(struct clientparam* param) {
ss = INVALID_SOCKET; ss = INVALID_SOCKET;
} }
if(clidatasock == INVALID_SOCKET){RETURN(828);} if(clidatasock == INVALID_SOCKET){RETURN(828);}
req = mystrdup((char *)buf); req = strdup((char *)buf);
buf[4] = 0; buf[4] = 0;
status = 3; status = 3;
ss = ftpcommand(param, buf, arg? buf+5 : NULL); ss = ftpcommand(param, buf, arg? buf+5 : NULL);
@ -278,7 +278,7 @@ void * ftpprchild(struct clientparam* param) {
continue; continue;
} }
if(!strncasecmp((char *)buf, "QUIT", 4)) status = 5; if(!strncasecmp((char *)buf, "QUIT", 4)) status = 5;
if(!strncasecmp((char *)buf, "CWD ", 4)) req = mystrdup((char *)buf); if(!strncasecmp((char *)buf, "CWD ", 4)) req = strdup((char *)buf);
i = (int)strlen((char *)buf); i = (int)strlen((char *)buf);
buf[i++] = '\r'; buf[i++] = '\r';
buf[i++] = '\n'; buf[i++] = '\n';
@ -318,8 +318,8 @@ CLEANRET:
if(param->res != 0 || param->statscli64 || param->statssrv64 ){ if(param->res != 0 || param->statscli64 || param->statssrv64 ){
dolog(param, (unsigned char *)((req && (param->res > 802))? req:NULL)); dolog(param, (unsigned char *)((req && (param->res > 802))? req:NULL));
} }
if(req) myfree(req); if(req) free(req);
if(buf) myfree(buf); if(buf) free(buf);
freeparam(param); freeparam(param);
return (NULL); return (NULL);
} }

View File

@ -6,23 +6,20 @@ struct hashentry {
char value[4]; char value[4];
}; };
static uint32_t hashindex(unsigned tablesize, const uint8_t* hash){
return (*(unsigned *)hash) % tablesize;
}
void destroyhashtable(struct hashtable *ht){ void destroyhashtable(struct hashtable *ht){
_3proxy_mutex_lock(&ht->hash_mutex); _3proxy_mutex_lock(&ht->hash_mutex);
if(ht->ihashtable){ if(ht->ihashtable){
myfree(ht->ihashtable); free(ht->ihashtable);
ht->ihashtable = NULL; ht->ihashtable = NULL;
} }
if(ht->hashvalues){ if(ht->hashvalues){
myfree(ht->hashvalues); free(ht->hashvalues);
ht->hashvalues = NULL; ht->hashvalues = NULL;
} }
if(ht->hashhashvalues){ if(ht->hashhashvalues){
myfree(ht->hashhashvalues); free(ht->hashhashvalues);
ht->hashhashvalues = NULL; ht->hashhashvalues = NULL;
} }
ht->poolsize = 0; ht->poolsize = 0;
@ -32,6 +29,7 @@ void destroyhashtable(struct hashtable *ht){
_3proxy_mutex_destroy(&ht->hash_mutex); _3proxy_mutex_destroy(&ht->hash_mutex);
} }
#define hashindex(ht, tablesize, hash) (murmurhash3(hash, ht->hash_size, ht->entropy) % tablesize)
#define hvalue(ht,I) ((struct hashentry *)(ht->hashvalues + (I-1)*(sizeof(struct hashentry) + ht->recsize - 4))) #define hvalue(ht,I) ((struct hashentry *)(ht->hashvalues + (I-1)*(sizeof(struct hashentry) + ht->recsize - 4)))
#define hhash(ht,I) ((ht->hashhashvalues + (I-1)*(ht->hash_size))) #define hhash(ht,I) ((ht->hashhashvalues + (I-1)*(ht->hash_size)))
@ -55,15 +53,15 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u
if(ht->ihashtable){ if(ht->ihashtable){
_3proxy_mutex_lock(&ht->hash_mutex); _3proxy_mutex_lock(&ht->hash_mutex);
if(ht->ihashtable){ if(ht->ihashtable){
myfree(ht->ihashtable); free(ht->ihashtable);
ht->ihashtable = NULL; ht->ihashtable = NULL;
} }
if(ht->hashvalues){ if(ht->hashvalues){
myfree(ht->hashvalues); free(ht->hashvalues);
ht->hashvalues = NULL; ht->hashvalues = NULL;
} }
if(ht->hashhashvalues){ if(ht->hashhashvalues){
myfree(ht->hashhashvalues); free(ht->hashhashvalues);
ht->hashhashvalues = NULL; ht->hashhashvalues = NULL;
} }
ht->poolsize = 0; ht->poolsize = 0;
@ -73,13 +71,13 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u
_3proxy_mutex_init(&ht->hash_mutex); _3proxy_mutex_init(&ht->hash_mutex);
_3proxy_mutex_lock(&ht->hash_mutex); _3proxy_mutex_lock(&ht->hash_mutex);
} }
if(!(ht->ihashtable = myalloc(tablesize * sizeof(uint32_t))) if(!(ht->ihashtable = malloc(tablesize * sizeof(uint32_t)))
|| !(ht->hashvalues = myalloc(poolsize * (sizeof(struct hashentry) + ht->recsize - 4))) || !(ht->hashvalues = malloc(poolsize * (sizeof(struct hashentry) + ht->recsize - 4)))
|| !(ht->hashhashvalues = myalloc(poolsize * ht->hash_size)) || !(ht->hashhashvalues = malloc(poolsize * ht->hash_size))
){ ){
myfree(ht->ihashtable); free(ht->ihashtable);
ht->ihashtable = NULL; ht->ihashtable = NULL;
myfree(ht->hashvalues); free(ht->hashvalues);
ht->hashvalues = NULL; ht->hashvalues = NULL;
_3proxy_mutex_unlock(&ht->hash_mutex); _3proxy_mutex_unlock(&ht->hash_mutex);
return 3; return 3;
@ -87,6 +85,7 @@ int inithashtable(struct hashtable *ht, unsigned tablesize, unsigned poolsize, u
ht->poolsize = poolsize; ht->poolsize = poolsize;
ht->tablesize = tablesize; ht->tablesize = tablesize;
ht->growlimit = growlimit; ht->growlimit = growlimit;
ht->entropy = myrand(ht, sizeof(struct hashtable));
memset(ht->ihashtable, 0, ht->tablesize * sizeof(uint32_t)); memset(ht->ihashtable, 0, ht->tablesize * sizeof(uint32_t));
memset(ht->hashvalues, 0, ht->poolsize * (sizeof(struct hashentry) + ht->recsize - 4)); memset(ht->hashvalues, 0, ht->poolsize * (sizeof(struct hashentry) + ht->recsize - 4));
@ -128,10 +127,10 @@ static void hashgrow(struct hashtable *ht){
if(ht->ihashempty) return; if(ht->ihashempty) return;
if(ht->poolsize >= ht->growlimit) return; if(ht->poolsize >= ht->growlimit) return;
if(newsize > ht->growlimit) newsize = ht->growlimit; if(newsize > ht->growlimit) newsize = ht->growlimit;
newvalues = myrealloc(ht->hashvalues, newsize * (sizeof(struct hashentry) + ht->recsize - 4)); newvalues = realloc(ht->hashvalues, newsize * (sizeof(struct hashentry) + ht->recsize - 4));
if(!newvalues) return; if(!newvalues) return;
ht->hashvalues = newvalues; ht->hashvalues = newvalues;
newvalues = myrealloc(ht->hashhashvalues, newsize * ht->hash_size); newvalues = realloc(ht->hashhashvalues, newsize * ht->hash_size);
if(!newvalues) return; if(!newvalues) return;
ht->hashhashvalues = newvalues; ht->hashhashvalues = newvalues;
memset(ht->hashvalues + (ht->poolsize * (sizeof(struct hashentry) + ht->recsize - 4)), 0, (newsize - ht->poolsize) * (sizeof(struct hashentry) + ht->recsize - 4)); memset(ht->hashvalues + (ht->poolsize * (sizeof(struct hashentry) + ht->recsize - 4)), 0, (newsize - ht->poolsize) * (sizeof(struct hashentry) + ht->recsize - 4));
@ -143,7 +142,7 @@ static void hashgrow(struct hashtable *ht){
ht->poolsize = newsize; ht->poolsize = newsize;
if (ht->poolsize / ht->tablesize > 10) { if (ht->poolsize / ht->tablesize > 10) {
unsigned newtablesize = ht->poolsize / 3; unsigned newtablesize = ht->poolsize / 3;
uint32_t *newitable = myalloc(newtablesize * sizeof(uint32_t)); uint32_t *newitable = malloc(newtablesize * sizeof(uint32_t));
if (newitable) { if (newitable) {
unsigned j; unsigned j;
memset(newitable, 0, newtablesize * sizeof(uint32_t)); memset(newitable, 0, newtablesize * sizeof(uint32_t));
@ -151,13 +150,13 @@ static void hashgrow(struct hashtable *ht){
uint32_t he = ht->ihashtable[j]; uint32_t he = ht->ihashtable[j];
while (he) { while (he) {
uint32_t next = hvalue(ht, he)->inext; uint32_t next = hvalue(ht, he)->inext;
unsigned idx = hashindex(newtablesize, hhash(ht, he)); unsigned idx = hashindex(ht, newtablesize, hhash(ht, he));
hvalue(ht, he)->inext = newitable[idx]; hvalue(ht, he)->inext = newitable[idx];
newitable[idx] = he; newitable[idx] = he;
he = next; he = next;
} }
} }
myfree(ht->ihashtable); free(ht->ihashtable);
ht->ihashtable = newitable; ht->ihashtable = newitable;
ht->tablesize = newtablesize; ht->tablesize = newtablesize;
} }
@ -180,7 +179,7 @@ void hashadd(struct hashtable *ht, void* name, void* value, time_t expires){
ht->index2hash_add(ht, name, hash); ht->index2hash_add(ht, name, hash);
_3proxy_mutex_lock(&ht->hash_mutex); _3proxy_mutex_lock(&ht->hash_mutex);
index = hashindex(ht->tablesize, hash); index = hashindex(ht, ht->tablesize, hash);
for(hep = ht->ihashtable + index; (he = *hep)!=0; ){ for(hep = ht->ihashtable + index; (he = *hep)!=0; ){
if(hvalue(ht,he)->expires < conf.time || !memcmp(hash, hhash(ht,he), ht->hash_size)) { if(hvalue(ht,he)->expires < conf.time || !memcmp(hash, hhash(ht,he), ht->hash_size)) {
@ -228,7 +227,7 @@ int hashresolv(struct hashtable *ht, void* name, void* value, uint32_t *ttl){
} }
ht->index2hash_search(ht,name, hash); ht->index2hash_search(ht,name, hash);
_3proxy_mutex_lock(&ht->hash_mutex); _3proxy_mutex_lock(&ht->hash_mutex);
index = hashindex(ht->tablesize, hash); index = hashindex(ht, ht->tablesize, hash);
for(hep = ht->ihashtable + index; (he = *hep)!=0; ){ for(hep = ht->ihashtable + index; (he = *hep)!=0; ){
if(hvalue(ht, he)->expires < conf.time) { if(hvalue(ht, he)->expires < conf.time) {
(*hep) = hvalue(ht,he)->inext; (*hep) = hvalue(ht,he)->inext;
@ -259,7 +258,7 @@ void hashdelete(struct hashtable *ht, void *name){
} }
ht->index2hash_search(ht, name, hash); ht->index2hash_search(ht, name, hash);
_3proxy_mutex_lock(&ht->hash_mutex); _3proxy_mutex_lock(&ht->hash_mutex);
index = hashindex(ht->tablesize, hash); index = hashindex(ht, ht->tablesize, hash);
for(hep = ht->ihashtable + index; (he = *hep) != 0; ){ for(hep = ht->ihashtable + index; (he = *hep) != 0; ){
if((hvalue(ht, he)->expires && hvalue(ht, he)->expires < conf.time) || !memcmp(hash, hhash(ht, he), ht->hash_size)) { if((hvalue(ht, he)->expires && hvalue(ht, he)->expires < conf.time) || !memcmp(hash, hhash(ht, he), ht->hash_size)) {
(*hep) = hvalue(ht, he)->inext; (*hep) = hvalue(ht, he)->inext;

View File

@ -4,29 +4,64 @@
static void char_index2hash(const struct hashtable *ht, void *index, uint8_t *hash){ static void char_index2hash(const struct hashtable *ht, void *index, uint8_t *hash){
blake2b_state S; blake2b_state S;
int len;
blake2b_init(&S, ht->hash_size); len = strlen((const char*)index);
blake2b_update(&S, index, strlen((const char*)index) + 1); memset(hash, 0, ht->hash_size);
blake2b_final(&S, hash, ht->hash_size); if(len <= ht->hash_size) memcpy(hash, index, len);
else {
blake2b_init(&S, ht->hash_size);
blake2b_update(&S, index, strlen((const char*)index) + 1);
blake2b_final(&S, hash, ht->hash_size);
}
} }
static void param2hash_add(const struct hashtable *ht, void *index, uint8_t *hash){ static void param2hash_add(const struct hashtable *ht, void *index, uint8_t *hash){
blake2b_state S; blake2b_state S;
struct clientparam *param = (struct clientparam *)index; struct clientparam *param = (struct clientparam *)index;
unsigned type = param->srv->authcachetype; unsigned type = param->srv->authcachetype;
int len = 0, oplen = 0, acllen = 0, ulen = 0, plen = 0, hlen = 0, a1len = 0, a2len = 0, a3len = 0, p1len=0, p2len = 0;
blake2b_init(&S, ht->hash_size);
if((type & 2) && param->username)blake2b_update(&S, param->username, strlen((const char *)param->username) + 1); if((type & 2) && param->username) ulen = strlen((const char *)param->username) + 1;
if((type & 4) && param->password)blake2b_update(&S, param->password, strlen((const char *)param->password) + 1); if((type & 4) && param->password) plen = strlen((const char *)param->password) + 1;
if((type & 1) && !(type & 8))blake2b_update(&S, SAADDR(&param->sincr), SAADDRLEN(&param->sincr)); if((type & 1) && !(type & 8)) a1len = SAADDRLEN(&param->sincr);
if((type & 16))blake2b_update(&S, &param->srv->acl, sizeof(param->srv->acl)); if((type & 16)) acllen = sizeof(param->srv->acl);
if((type & 64))blake2b_update(&S, SAADDR(&param->req), SAADDRLEN(&param->req)); if((type & 64)) a2len = SAADDRLEN(&param->req);
if((type & 128))blake2b_update(&S, SAPORT(&param->req), 2); if((type & 128)) p1len = 2 ;
if((type & 256) && param->hostname)blake2b_update(&S, param->hostname, strlen((const char *)param->hostname) + 1); if((type & 256) && param->hostname) hlen = strlen((const char *)param->hostname) + 1;
if((type & 512))blake2b_update(&S, &param->operation, sizeof(param->operation)); if((type & 512)) oplen = sizeof(param->operation);
if((type & 1024))blake2b_update(&S, SAADDR(&param->srv->intsa), SAADDRLEN(&param->srv->intsa)); if((type & 1024)) a3len = SAADDRLEN(&param->srv->intsa);
if((type & 2048))blake2b_update(&S, SAPORT(&param->srv->intsa), 2); if((type & 2048)) p2len = 2;
blake2b_final(&S, hash, ht->hash_size);
memset(hash, 0, ht->hash_size);
if(ulen + plen + a1len + acllen + a2len + p1len + hlen + oplen + a3len + p2len <= ht->hash_size){
int offset = 0;
if((type & 2) && param->username){ memcpy(hash + offset, param->username, ulen); offset += ulen; }
if((type & 4) && param->password){ memcpy(hash + offset, param->password, plen); offset += plen; }
if((type & 1) && !(type & 8)){ memcpy(hash + offset, SAADDR(&param->sincr), a1len); offset += a1len; }
if((type & 16)){ memcpy(hash + offset, &param->srv->acl, acllen); offset += acllen; }
if((type & 64)){ memcpy(hash + offset, SAADDR(&param->req), a2len); offset += a2len; }
if((type & 128)){ memcpy(hash + offset, SAPORT(&param->req), p1len); offset += 2; }
if((type & 256) && param->hostname){ memcpy(hash + offset, param->hostname, hlen); offset += hlen; }
if((type & 512)){ memcpy(hash + offset, &param->operation, oplen); offset += oplen; }
if((type & 1024)){ memcpy(hash + offset, SAADDR(&param->srv->intsa), a3len); offset += a3len; }
if((type & 2048)){ memcpy(hash + offset, SAPORT(&param->srv->intsa), p2len); offset += 2; }
}
else {
blake2b_init(&S, ht->hash_size);
if((type & 2) && param->username)blake2b_update(&S, param->username, ulen);
if((type & 4) && param->password)blake2b_update(&S, param->password, plen);
if((type & 1) && !(type & 8))blake2b_update(&S, SAADDR(&param->sincr), a1len);
if((type & 16))blake2b_update(&S, &param->srv->acl, acllen);
if((type & 64))blake2b_update(&S, SAADDR(&param->req), a2len);
if((type & 128))blake2b_update(&S, SAPORT(&param->req), 2);
if((type & 256) && param->hostname)blake2b_update(&S, param->hostname, hlen);
if((type & 512))blake2b_update(&S, &param->operation, sizeof(param->operation));
if((type & 1024))blake2b_update(&S, SAADDR(&param->srv->intsa), a3len);
if((type & 2048))blake2b_update(&S, SAPORT(&param->srv->intsa), 2);
blake2b_final(&S, hash, ht->hash_size);
}
memcpy(param->hash, hash, ht->hash_size); memcpy(param->hash, hash, ht->hash_size);
} }
@ -36,15 +71,6 @@ void param2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
memcpy(hash, param->hash, ht->hash_size); memcpy(hash, param->hash, ht->hash_size);
} }
static void user2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
blake2b_state S;
blake2b_init(&S, ht->hash_size);
blake2b_update(&S, param->username, strlen((const char *)param->username) + 1);
blake2b_final(&S, hash, ht->hash_size);
}
static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash){ static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index; struct clientparam *param = (struct clientparam *)index;
blake2b_state S; blake2b_state S;
@ -56,54 +82,7 @@ static void udpparam2hash(const struct hashtable *ht, void *index, uint8_t *hash
blake2b_final(&S, hash, ht->hash_size); blake2b_final(&S, hash, ht->hash_size);
} }
static void pw2hash_add(const struct hashtable *ht, void *index, uint8_t *hash){ struct hashtable dns_table = {char_index2hash, char_index2hash, 4, 32};
char ** pw = (char **)index; struct hashtable dns6_table = {char_index2hash, char_index2hash, 16, 32};
blake2b_state S; struct hashtable auth_table = {param2hash_add, param2hash_search, sizeof(struct authcache), 64};
struct hashtable pwl_table = {char_index2hash, char_index2hash, 64, 64};
blake2b_init(&S, ht->hash_size);
if(pw[0])blake2b_update(&S, pw[0], strlen(pw[0]) + 1);
if(pw[1])blake2b_update(&S, pw[1], strlen(pw[1]) + 1);
blake2b_final(&S, hash, ht->hash_size);
}
static void pw2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
char *pw[2] = {(char *)param->username, (char *)param->password};
pw2hash_add(ht, pw, hash);
}
static void pwnt2hash_add(const struct hashtable *ht, void *index, uint8_t *hash){
char ** pw = (char **)index;
blake2b_state S;
blake2b_init(&S, ht->hash_size);
if(pw[0])blake2b_update(&S, pw[0], strlen(pw[0]) + 1);
if(pw[1])blake2b_update(&S, pw[1], strlen(pw[1]) + 1);
blake2b_final(&S, hash, ht->hash_size);
}
#ifdef WITH_SSL
static void pwnt2hash_search(const struct hashtable *ht, void *index, uint8_t *hash){
struct clientparam *param = (struct clientparam *)index;
unsigned char pass[40];
char *pw[2] = {(char *)param->username, (char *)pass};
ntpwdhash(pass, param->password, 1);
pwnt2hash_add(ht, pw, hash);
}
#endif
struct hashtable dns_table = {char_index2hash, char_index2hash, 4, 12};
struct hashtable dns6_table = {char_index2hash, char_index2hash, 16, 12};
struct hashtable auth_table = {param2hash_add, param2hash_search, sizeof(struct authcache), 12};
struct hashtable pw_table = {pw2hash_add, pw2hash_search, 0, 12};
#ifdef WITH_SSL
struct hashtable pwnt_table = {pwnt2hash_add, pwnt2hash_search, 0, 12};
#endif
struct hashtable pwcr_table = {char_index2hash, user2hash_search, 64, 12};

View File

@ -112,10 +112,10 @@ struct pluginlink pluginlink = {
decodeurl, decodeurl,
parsestr, parsestr,
make_ace, make_ace,
myalloc, malloc,
myfree, free,
myrealloc, realloc,
mystrdup, strdup,
trafcountfunc, trafcountfunc,
proxy_stringtable, proxy_stringtable,
&schedule, &schedule,

View File

@ -239,7 +239,7 @@ void * proxychild(struct clientparam* param) {
if(param->remsock != INVALID_SOCKET) haveconnection = 1; if(param->remsock != INVALID_SOCKET) haveconnection = 1;
if(!(buf = myalloc(BUFSIZE))) {RETURN(21);} if(!(buf = malloc(BUFSIZE))) {RETURN(21);}
bufsize = BUFSIZE; bufsize = BUFSIZE;
anonymous = param->srv->anonymous; anonymous = param->srv->anonymous;
for(;;){ for(;;){
@ -292,9 +292,9 @@ for(;;){
memset(&param->sinsr, 0, sizeof(param->sinsr)); memset(&param->sinsr, 0, sizeof(param->sinsr));
memset(&param->req, 0, sizeof(param->req)); memset(&param->req, 0, sizeof(param->req));
} }
myfree(req); free(req);
} }
req = (unsigned char *)mystrdup((char *)buf); req = (unsigned char *)strdup((char *)buf);
if(!req){RETURN(510);} if(!req){RETURN(510);}
if(i<10) { if(i<10) {
RETURN(511); RETURN(511);
@ -335,13 +335,13 @@ for(;;){
prefix = (int)(se - buf); prefix = (int)(se - buf);
su = (unsigned char*)strrchr((char *)sb, '@'); su = (unsigned char*)strrchr((char *)sb, '@');
if(su) { if(su) {
su = (unsigned char *)mystrdup((char *)sb); su = (unsigned char *)strdup((char *)sb);
decodeurl(su, 0); decodeurl(su, 0);
if(parseconnusername((char *)su, (struct clientparam *)param, 1, (uint16_t)((ftp)?21:80))) { if(parseconnusername((char *)su, (struct clientparam *)param, 1, (uint16_t)((ftp)?21:80))) {
myfree(su); free(su);
RETURN (100); RETURN (100);
} }
myfree(su); free(su);
} }
else if(parsehostname((char *)sb, (struct clientparam *)param, (uint16_t)((ftp)? 21:80))) RETURN(100); else if(parsehostname((char *)sb, (struct clientparam *)param, (uint16_t)((ftp)? 21:80))) RETURN(100);
if(!isconnect){ if(!isconnect){
@ -376,12 +376,12 @@ for(;;){
sb = (unsigned char *)strchr((char *)username, ':'); sb = (unsigned char *)strchr((char *)username, ':');
if(sb){ if(sb){
*sb = 0; *sb = 0;
if(param->password)myfree(param->password); if(param->password)free(param->password);
param->password = (unsigned char *)mystrdup((char *)sb+1); param->password = (unsigned char *)strdup((char *)sb+1);
param->pwtype = 0; param->pwtype = 0;
} }
if(param->username)myfree(param->username); if(param->username)free(param->username);
param->username = (unsigned char *)mystrdup((char *)username); param->username = (unsigned char *)strdup((char *)username);
continue; continue;
} }
} }
@ -420,12 +420,12 @@ for(;;){
if(!param->hostname){ if(!param->hostname){
if(parsehostname((char *)sb, param, 80)) RETURN(100); if(parsehostname((char *)sb, param, 80)) RETURN(100);
} }
newbuf = myalloc(strlen((char *)req) + strlen((char *)(buf+inbuf)) + 8); newbuf = malloc(strlen((char *)req) + strlen((char *)(buf+inbuf)) + 8);
if(newbuf){ if(newbuf){
sp = (unsigned char *)strchr((char *)req+1, '/'); sp = (unsigned char *)strchr((char *)req+1, '/');
memcpy(newbuf, req, (sp - req)); memcpy(newbuf, req, (sp - req));
sprintf((char*)newbuf + (sp - req), "http://%s%s",sb,sp); sprintf((char*)newbuf + (sp - req), "http://%s%s",sb,sp);
myfree(req); free(req);
req = newbuf; req = newbuf;
} }
if(se)*se = c; if(se)*se = c;
@ -445,11 +445,11 @@ for(;;){
sb = (unsigned char *)strchr((char *)username, ':'); sb = (unsigned char *)strchr((char *)username, ':');
if(sb){ if(sb){
*sb = 0; *sb = 0;
if(param->extpassword)myfree(param->extpassword); if(param->extpassword)free(param->extpassword);
param->extpassword = (unsigned char *)mystrdup((char *)sb+1); param->extpassword = (unsigned char *)strdup((char *)sb+1);
} }
if(param->extusername)myfree(param->extusername); if(param->extusername)free(param->extusername);
param->extusername = (unsigned char *)mystrdup((char *)username); param->extusername = (unsigned char *)strdup((char *)username);
continue; continue;
} }
} }
@ -469,7 +469,7 @@ for(;;){
if (bufsize > (LINESIZE * 16)){ if (bufsize > (LINESIZE * 16)){
RETURN (516); RETURN (516);
} }
if(!(newbuf = myrealloc(buf, bufsize + BUFSIZE))){RETURN (21);} if(!(newbuf = realloc(buf, bufsize + BUFSIZE))){RETURN (21);}
buf = newbuf; buf = newbuf;
bufsize += BUFSIZE; bufsize += BUFSIZE;
} }
@ -560,14 +560,14 @@ for(;;){
} }
} }
ckeepalive = 1; ckeepalive = 1;
if(ftpbase) myfree(ftpbase); if(ftpbase) free(ftpbase);
ftpbase = NULL; ftpbase = NULL;
if(!(sp = (unsigned char *)strchr((char *)ss, ' '))){RETURN(799);} if(!(sp = (unsigned char *)strchr((char *)ss, ' '))){RETURN(799);}
*sp = 0; *sp = 0;
decodeurl(ss, 0); decodeurl(ss, 0);
i = (int)strlen((char *)ss); i = (int)strlen((char *)ss);
if(!(ftpbase = myalloc(i+2))){RETURN(21);} if(!(ftpbase = malloc(i+2))){RETURN(21);}
memcpy(ftpbase, ss, i); memcpy(ftpbase, ss, i);
if(ftpbase[i-1] != '/') ftpbase[i++] = '/'; if(ftpbase[i-1] != '/') ftpbase[i++] = '/';
ftpbase[i] = 0; ftpbase[i] = 0;
@ -757,7 +757,7 @@ for(;;){
inbuf = 0; inbuf = 0;
} }
else { else {
if(!(newbuf = myrealloc(buf, bufsize + BUFSIZE))){RETURN (21);} if(!(newbuf = realloc(buf, bufsize + BUFSIZE))){RETURN (21);}
buf = newbuf; buf = newbuf;
bufsize += BUFSIZE; bufsize += BUFSIZE;
} }
@ -793,14 +793,14 @@ for(;;){
if(isconnect && param->redirtype != R_HTTP) { if(isconnect && param->redirtype != R_HTTP) {
if(param->redirectfunc) { if(param->redirectfunc) {
if(req)myfree(req); if(req)free(req);
if(buf)myfree(buf); if(buf)free(buf);
return (*param->redirectfunc)(param); return (*param->redirectfunc)(param);
} }
param->res = mapsocket(param, conf.timeouts[CONNECTION_L]); param->res = mapsocket(param, conf.timeouts[CONNECTION_L]);
if(param->redirectfunc) { if(param->redirectfunc) {
if(req)myfree(req); if(req)free(req);
if(buf)myfree(buf); if(buf)free(buf);
return (*param->redirectfunc)(param); return (*param->redirectfunc)(param);
} }
RETURN(param->res); RETURN(param->res);
@ -939,7 +939,7 @@ for(;;){
if (bufsize > 20000){ if (bufsize > 20000){
RETURN (516); RETURN (516);
} }
if(!(newbuf = myrealloc(buf, bufsize + BUFSIZE))){RETURN (21);} if(!(newbuf = realloc(buf, bufsize + BUFSIZE))){RETURN (21);}
buf = newbuf; buf = newbuf;
bufsize += BUFSIZE; bufsize += BUFSIZE;
} }
@ -1122,9 +1122,9 @@ CLEANRET:
} }
} }
logurl(param, (char *)buf, (char *)req, ftp); logurl(param, (char *)buf, (char *)req, ftp);
if(req)myfree(req); if(req)free(req);
if(buf)myfree(buf); if(buf)free(buf);
if(ftpbase)myfree(ftpbase); if(ftpbase)free(ftpbase);
freeparam(param); freeparam(param);
return (NULL); return (NULL);
} }

View File

@ -148,10 +148,6 @@ void daemonize(void);
#define DEFLOGFORMAT "G%y%m%d%H%M%S.%. %p %E %U %C:%c %R:%r %O %I %h %T" #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
#ifdef _TIME64_T_DEFINED #ifdef _TIME64_T_DEFINED
#ifdef _MAX__TIME64_T #ifdef _MAX__TIME64_T

View File

@ -204,17 +204,17 @@ void setopts(SOCKET s, int opts){
} }
static void freesrvstrings(struct srvparam *srv, unsigned char *cbc_string, unsigned char *cbl_string) { static void freesrvstrings(struct srvparam *srv, unsigned char *cbc_string, unsigned char *cbl_string) {
if(cbc_string) myfree(cbc_string); if(cbc_string) free(cbc_string);
if(cbl_string) myfree(cbl_string); if(cbl_string) free(cbl_string);
if(srv->logtarget) myfree(srv->logtarget); if(srv->logtarget) free(srv->logtarget);
if(srv->logformat) myfree(srv->logformat); if(srv->logformat) free(srv->logformat);
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF #if defined SO_BINDTODEVICE || defined IP_BOUND_IF
if(srv->ibindtodevice) myfree(srv->ibindtodevice); if(srv->ibindtodevice) free(srv->ibindtodevice);
if(srv->obindtodevice) myfree(srv->obindtodevice); if(srv->obindtodevice) free(srv->obindtodevice);
#endif #endif
#ifdef __linux__ #ifdef __linux__
if(srv->inetns) myfree(srv->inetns); if(srv->inetns) free(srv->inetns);
if(srv->onetns) myfree(srv->onetns); if(srv->onetns) free(srv->onetns);
#endif #endif
} }
@ -391,14 +391,14 @@ int MODULEMAINFUNC (int argc, char** argv){
break; break;
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF #if defined SO_BINDTODEVICE || defined IP_BOUND_IF
case 'D': case 'D':
if(argv[i][2] == 'i') srv.ibindtodevice = mystrdup(argv[i] + 3); if(argv[i][2] == 'i') srv.ibindtodevice = strdup(argv[i] + 3);
else srv.obindtodevice = mystrdup(argv[i] + 3); else srv.obindtodevice = strdup(argv[i] + 3);
break; break;
#endif #endif
case 'l': case 'l':
srv.logfunc = logstdout; srv.logfunc = logstdout;
if(srv.logtarget) myfree(srv.logtarget); if(srv.logtarget) free(srv.logtarget);
srv.logtarget = (unsigned char *)mystrdup(argv[i] + 2); srv.logtarget = (unsigned char *)strdup(argv[i] + 2);
if(argv[i][2]) { if(argv[i][2]) {
if(argv[i][2]=='@'){ if(argv[i][2]=='@'){
@ -450,8 +450,8 @@ int MODULEMAINFUNC (int argc, char** argv){
break; break;
#ifdef __linux__ #ifdef __linux__
case 'n': case 'n':
if(argv[i][2] == 'i') { if(srv.inetns) myfree(srv.inetns); srv.inetns = mystrdup(argv[i] + 3); } if(argv[i][2] == 'i') { if(srv.inetns) free(srv.inetns); srv.inetns = strdup(argv[i] + 3); }
else if(argv[i][2] == 'e') { if(srv.onetns) myfree(srv.onetns); srv.onetns = mystrdup(argv[i] + 3); } else if(argv[i][2] == 'e') { if(srv.onetns) free(srv.onetns); srv.onetns = strdup(argv[i] + 3); }
break; break;
#endif #endif
case 'p': case 'p':
@ -479,8 +479,8 @@ int MODULEMAINFUNC (int argc, char** argv){
#endif #endif
#endif #endif
case 'f': case 'f':
if(srv.logformat)myfree(srv.logformat); if(srv.logformat)free(srv.logformat);
srv.logformat = (unsigned char *)mystrdup(argv[i] + 2); srv.logformat = (unsigned char *)strdup(argv[i] + 2);
break; break;
case 't': case 't':
srv.silent = 1; srv.silent = 1;
@ -496,11 +496,11 @@ int MODULEMAINFUNC (int argc, char** argv){
if(isdigit(argv[i][2])) srv.requirecert = atoi(argv[i]+2); if(isdigit(argv[i][2])) srv.requirecert = atoi(argv[i]+2);
break; break;
case 'r': case 'r':
cbc_string = (unsigned char *)mystrdup(argv[i] + 2); cbc_string = (unsigned char *)strdup(argv[i] + 2);
iscbc = 1; iscbc = 1;
break; break;
case 'R': case 'R':
cbl_string = (unsigned char *)mystrdup(argv[i] + 2); cbl_string = (unsigned char *)strdup(argv[i] + 2);
iscbl = 1; iscbl = 1;
break; break;
case 'u': case 'u':
@ -621,7 +621,7 @@ int MODULEMAINFUNC (int argc, char** argv){
); );
return (1); return (1);
} }
srv.target = (unsigned char *)mystrdup(argv[i+1]); srv.target = (unsigned char *)strdup(argv[i+1]);
#endif #endif
#ifndef STDMAIN #ifndef STDMAIN
} }
@ -638,7 +638,7 @@ int MODULEMAINFUNC (int argc, char** argv){
srv.so._setsockopt(srv.so.state, 0, SOL_SOCKET, SO_OOBINLINE, (unsigned char *)&opt, sizeof(int)); srv.so._setsockopt(srv.so.state, 0, SOL_SOCKET, SO_OOBINLINE, (unsigned char *)&opt, sizeof(int));
} }
defparam.clisock = 0; defparam.clisock = 0;
if(! (newparam = myalloc (sizeof(defparam)))){ if(! (newparam = malloc (sizeof(defparam)))){
return 2; return 2;
}; };
*newparam = defparam; *newparam = defparam;
@ -1011,7 +1011,7 @@ int MODULEMAINFUNC (int argc, char** argv){
} }
} }
#endif #endif
if(! (newparam = myalloc (sizeof(defparam)))){ if(! (newparam = malloc (sizeof(defparam)))){
if(!isudp) srv.so._closesocket(srv.so.state, new_sock); if(!isudp) srv.so._closesocket(srv.so.state, new_sock);
#ifndef NOUDPMAIN #ifndef NOUDPMAIN
else { else {
@ -1024,7 +1024,7 @@ int MODULEMAINFUNC (int argc, char** argv){
continue; continue;
}; };
*newparam = defparam; *newparam = defparam;
if(defparam.hostname)newparam->hostname=(unsigned char *)mystrdup((char *)defparam.hostname); if(defparam.hostname)newparam->hostname=(unsigned char *)strdup((char *)defparam.hostname);
clearstat(newparam); clearstat(newparam);
if(!isudp) newparam->clisock = new_sock; if(!isudp) newparam->clisock = new_sock;
#ifndef STDMAIN #ifndef STDMAIN
@ -1104,9 +1104,9 @@ int MODULEMAINFUNC (int argc, char** argv){
#ifndef _WIN32 #ifndef _WIN32
pthread_attr_destroy(&pa); pthread_attr_destroy(&pa);
#endif #endif
if(defparam.hostname)myfree(defparam.hostname); if(defparam.hostname)free(defparam.hostname);
if(cbc_string)myfree(cbc_string); if(cbc_string)free(cbc_string);
if(cbl_string)myfree(cbl_string); if(cbl_string)free(cbl_string);
if(fp) fclose(fp); if(fp) fclose(fp);
return 0; return 0;
@ -1129,14 +1129,14 @@ void srvinit(struct srvparam * srv, struct clientparam *param){
srv->paused = conf.paused; srv->paused = conf.paused;
srv->logfunc = havelog?conf.logfunc:lognone; srv->logfunc = havelog?conf.logfunc:lognone;
srv->noforce = conf.noforce; srv->noforce = conf.noforce;
srv->logformat = conf.logformat? (unsigned char *)mystrdup((char *)conf.logformat) : NULL; srv->logformat = conf.logformat? (unsigned char *)strdup((char *)conf.logformat) : NULL;
srv->authfunc = conf.authfunc; srv->authfunc = conf.authfunc;
srv->maxchild = conf.maxchild; srv->maxchild = conf.maxchild;
srv->backlog = conf.backlog; srv->backlog = conf.backlog;
srv->stacksize = conf.stacksize; srv->stacksize = conf.stacksize;
srv->time_start = time(NULL); srv->time_start = time(NULL);
if(havelog && conf.logtarget){ if(havelog && conf.logtarget){
srv->logtarget = (unsigned char *)mystrdup((char *)conf.logtarget); srv->logtarget = (unsigned char *)strdup((char *)conf.logtarget);
} }
srv->srvsock = INVALID_SOCKET; srv->srvsock = INVALID_SOCKET;
srv->logdumpsrv = conf.logdumpsrv; srv->logdumpsrv = conf.logdumpsrv;
@ -1180,11 +1180,11 @@ void srvinit2(struct srvparam * srv, struct clientparam *param){
unsigned char* logformat = srv->logformat; unsigned char* logformat = srv->logformat;
*s = 0; *s = 0;
srv->nonprintable = (unsigned char *)mystrdup((char *)srv->logformat + 1); srv->nonprintable = (unsigned char *)strdup((char *)srv->logformat + 1);
srv->replace = s[1]; srv->replace = s[1];
srv->logformat = (unsigned char *)mystrdup(s + 2); srv->logformat = (unsigned char *)strdup(s + 2);
*s = '+'; *s = '+';
myfree(logformat); free(logformat);
} }
} }
memset(&param->sinsl, 0, sizeof(param->sinsl)); memset(&param->sinsl, 0, sizeof(param->sinsl));
@ -1221,24 +1221,24 @@ void srvfree(struct srvparam * srv){
(*srv->filter[srv->nfilters].filter_close)(srv->filter[srv->nfilters].data); (*srv->filter[srv->nfilters].filter_close)(srv->filter[srv->nfilters].data);
} }
} }
myfree(srv->filter); free(srv->filter);
} }
if(srv->acl)freeacl(srv->acl); if(srv->acl)freeacl(srv->acl);
if(srv->authfuncs)freeauth(srv->authfuncs); if(srv->authfuncs)freeauth(srv->authfuncs);
#endif #endif
_3proxy_mutex_destroy(&srv->counter_mutex); _3proxy_mutex_destroy(&srv->counter_mutex);
if(srv->target) myfree(srv->target); if(srv->target) free(srv->target);
if(srv->logtarget) myfree(srv->logtarget); if(srv->logtarget) free(srv->logtarget);
if(srv->logformat) myfree(srv->logformat); if(srv->logformat) free(srv->logformat);
if(srv->nonprintable) myfree(srv->nonprintable); if(srv->nonprintable) free(srv->nonprintable);
#if defined SO_BINDTODEVICE || defined IP_BOUND_IF #if defined SO_BINDTODEVICE || defined IP_BOUND_IF
if(srv->ibindtodevice) myfree(srv->ibindtodevice); if(srv->ibindtodevice) free(srv->ibindtodevice);
if(srv->obindtodevice) myfree(srv->obindtodevice); if(srv->obindtodevice) free(srv->obindtodevice);
#endif #endif
#ifdef __linux__ #ifdef __linux__
if(srv->inetns) myfree(srv->inetns); if(srv->inetns) free(srv->inetns);
if(srv->onetns) myfree(srv->onetns); if(srv->onetns) free(srv->onetns);
#endif #endif
if(srv->so.freefunc) srv->so.freefunc(srv->so.state); if(srv->so.freefunc) srv->so.freefunc(srv->so.state);
} }
@ -1263,8 +1263,8 @@ void freeparam(struct clientparam * param) {
(param->srv->childcount)--; (param->srv->childcount)--;
_3proxy_mutex_unlock(&param->srv->counter_mutex); _3proxy_mutex_unlock(&param->srv->counter_mutex);
} }
if(param->clibuf) myfree(param->clibuf); if(param->clibuf) free(param->clibuf);
if(param->srvbuf) myfree(param->srvbuf); if(param->srvbuf) free(param->srvbuf);
if(param->srv) { if(param->srv) {
if(param->ctrlsocksrv != INVALID_SOCKET && param->ctrlsocksrv != param->remsock) { if(param->ctrlsocksrv != INVALID_SOCKET && param->ctrlsocksrv != param->remsock) {
param->srv->so._shutdown(param->sostate, param->ctrlsocksrv, SHUT_RDWR); param->srv->so._shutdown(param->sostate, param->ctrlsocksrv, SHUT_RDWR);
@ -1283,30 +1283,30 @@ void freeparam(struct clientparam * param) {
param->srv->so._closesocket(param->sostate, param->clisock); param->srv->so._closesocket(param->sostate, param->clisock);
} }
} }
if(param->datfilterssrv) myfree(param->datfilterssrv); if(param->datfilterssrv) free(param->datfilterssrv);
#ifndef STDMAIN #ifndef STDMAIN
if(param->reqfilters) myfree(param->reqfilters); if(param->reqfilters) free(param->reqfilters);
if(param->connectfilters) myfree(param->connectfilters); if(param->connectfilters) free(param->connectfilters);
if(param->afterauthfilters) myfree(param->afterauthfilters); if(param->afterauthfilters) free(param->afterauthfilters);
if(param->hdrfilterscli) myfree(param->hdrfilterscli); if(param->hdrfilterscli) free(param->hdrfilterscli);
if(param->hdrfilterssrv) myfree(param->hdrfilterssrv); if(param->hdrfilterssrv) free(param->hdrfilterssrv);
if(param->predatfilters) myfree(param->predatfilters); if(param->predatfilters) free(param->predatfilters);
if(param->datfilterscli) myfree(param->datfilterscli); if(param->datfilterscli) free(param->datfilterscli);
if(param->filters){ if(param->filters){
if(param->nfilters)while(param->nfilters--){ if(param->nfilters)while(param->nfilters--){
if(param->filters[param->nfilters].filter->filter_clear) if(param->filters[param->nfilters].filter->filter_clear)
(*param->filters[param->nfilters].filter->filter_clear)(param->filters[param->nfilters].data); (*param->filters[param->nfilters].filter->filter_clear)(param->filters[param->nfilters].data);
} }
myfree(param->filters); free(param->filters);
} }
if(param->connlim) stopconnlims(param); if(param->connlim) stopconnlims(param);
#endif #endif
if(param->hostname) myfree(param->hostname); if(param->hostname) free(param->hostname);
if(param->username) myfree(param->username); if(param->username) free(param->username);
if(param->password) myfree(param->password); if(param->password) free(param->password);
if(param->extusername) myfree(param->extusername); if(param->extusername) free(param->extusername);
if(param->extpassword) myfree(param->extpassword); if(param->extpassword) free(param->extpassword);
myfree(param); free(param);
} }
FILTER_ACTION handleconnectflt(struct clientparam *cparam){ FILTER_ACTION handleconnectflt(struct clientparam *cparam){
@ -1327,7 +1327,7 @@ FILTER_ACTION handleconnectflt(struct clientparam *cparam){
static void * itcopy (void * from, size_t size){ static void * itcopy (void * from, size_t size){
void * ret; void * ret;
if(!from) return NULL; if(!from) return NULL;
ret = myalloc(size); ret = malloc(size);
if(ret) memcpy(ret, from, size); if(ret) memcpy(ret, from, size);
return ret; return ret;
} }
@ -1398,7 +1398,7 @@ struct ace * copyacl (struct ace *ac){
if(!ac->users) goto ERRORUSERS; if(!ac->users) goto ERRORUSERS;
for(ul = ac->users; ul; ul = ul->next){ for(ul = ac->users; ul; ul = ul->next){
if(ul->user) { if(ul->user) {
ul->user = (unsigned char*)mystrdup((char *)ul->user); ul->user = (unsigned char*)strdup((char *)ul->user);
if(!ul->user) { if(!ul->user) {
ul->next = NULL; ul->next = NULL;
goto ERRORUSERS; goto ERRORUSERS;
@ -1415,7 +1415,7 @@ struct ace * copyacl (struct ace *ac){
if(!ac->dstnames) goto ERRORDSTNAMES; if(!ac->dstnames) goto ERRORDSTNAMES;
for(hst = ac->dstnames; hst; hst = hst->next){ for(hst = ac->dstnames; hst; hst = hst->next){
if(hst->name) { if(hst->name) {
hst->name = (unsigned char*)mystrdup((char *)hst->name); hst->name = (unsigned char*)strdup((char *)hst->name);
if(!hst->name) { if(!hst->name) {
hst->next = NULL; hst->next = NULL;
goto ERRORDSTNAMES; goto ERRORDSTNAMES;
@ -1432,7 +1432,7 @@ struct ace * copyacl (struct ace *ac){
if(!ac->chains) goto ERRORCHAINS; if(!ac->chains) goto ERRORCHAINS;
for(ch = ac->chains; ch; ch = ch->next){ for(ch = ac->chains; ch; ch = ch->next){
if(ch->extuser){ if(ch->extuser){
ch->extuser = (unsigned char*)mystrdup((char *)ch->extuser); ch->extuser = (unsigned char*)strdup((char *)ch->extuser);
if(!ch->extuser){ if(!ch->extuser){
ch->extpass = NULL; ch->extpass = NULL;
ch->exthost = NULL; ch->exthost = NULL;
@ -1441,7 +1441,7 @@ struct ace * copyacl (struct ace *ac){
} }
} }
if(ch->extpass){ if(ch->extpass){
ch->extpass = (unsigned char*)mystrdup((char *)ch->extpass); ch->extpass = (unsigned char*)strdup((char *)ch->extpass);
if(!ch->extpass){ if(!ch->extpass){
ch->exthost = NULL; ch->exthost = NULL;
ch->next = NULL; ch->next = NULL;
@ -1449,7 +1449,7 @@ struct ace * copyacl (struct ace *ac){
} }
} }
if(ch->exthost){ if(ch->exthost){
ch->exthost = (unsigned char*)mystrdup((char *)ch->exthost); ch->exthost = (unsigned char*)strdup((char *)ch->exthost);
if(!ch->exthost){ if(!ch->exthost){
ch->next = NULL; ch->next = NULL;
goto ERRORCHAINS; goto ERRORCHAINS;
@ -1494,7 +1494,7 @@ void copyfilter (struct filter *filter, struct srvparam *srv){
if(!filter) return; if(!filter) return;
for(srv->filter = filter; srv->filter; srv->filter = srv->filter->next) nfilters++; for(srv->filter = filter; srv->filter; srv->filter = srv->filter->next) nfilters++;
srv->filter = myalloc(sizeof(struct filter) * nfilters); srv->filter = malloc(sizeof(struct filter) * nfilters);
if(!srv->filter) return; if(!srv->filter) return;
for(; filter; filter = filter->next){ for(; filter; filter = filter->next){
@ -1524,15 +1524,15 @@ FILTER_ACTION makefilters (struct srvparam *srv, struct clientparam *param){
if(!srv->nfilters) return PASS; if(!srv->nfilters) return PASS;
if(!(param->filters = myalloc(sizeof(struct filterp) * srv->nfilters)) || if(!(param->filters = malloc(sizeof(struct filterp) * srv->nfilters)) ||
(srv->nreqfilters && !(param->reqfilters = myalloc(sizeof(struct filterp *) * srv->nreqfilters))) || (srv->nreqfilters && !(param->reqfilters = malloc(sizeof(struct filterp *) * srv->nreqfilters))) ||
(srv->nconnectfilters && !(param->connectfilters = myalloc(sizeof(struct filterp *) * srv->nconnectfilters))) || (srv->nconnectfilters && !(param->connectfilters = malloc(sizeof(struct filterp *) * srv->nconnectfilters))) ||
(srv->nafterauthfilters && !(param->afterauthfilters = myalloc(sizeof(struct filterp *) * srv->nafterauthfilters))) || (srv->nafterauthfilters && !(param->afterauthfilters = malloc(sizeof(struct filterp *) * srv->nafterauthfilters))) ||
(srv->nhdrfilterssrv && !(param->hdrfilterssrv = myalloc(sizeof(struct filterp *) * srv->nhdrfilterssrv))) || (srv->nhdrfilterssrv && !(param->hdrfilterssrv = malloc(sizeof(struct filterp *) * srv->nhdrfilterssrv))) ||
(srv->nhdrfilterscli && !(param->hdrfilterscli = myalloc(sizeof(struct filterp *) * srv->nhdrfilterscli))) || (srv->nhdrfilterscli && !(param->hdrfilterscli = malloc(sizeof(struct filterp *) * srv->nhdrfilterscli))) ||
(srv->npredatfilters && !(param->predatfilters = myalloc(sizeof(struct filterp *) * srv->npredatfilters))) || (srv->npredatfilters && !(param->predatfilters = malloc(sizeof(struct filterp *) * srv->npredatfilters))) ||
(srv->ndatfilterssrv && !(param->datfilterssrv = myalloc(sizeof(struct filterp *) * srv->ndatfilterssrv))) || (srv->ndatfilterssrv && !(param->datfilterssrv = malloc(sizeof(struct filterp *) * srv->ndatfilterssrv))) ||
(srv->ndatfilterscli && !(param->datfilterscli = myalloc(sizeof(struct filterp *) * srv->ndatfilterscli))) (srv->ndatfilterscli && !(param->datfilterscli = malloc(sizeof(struct filterp *) * srv->ndatfilterscli)))
){ ){
param->res = 21; param->res = 21;
return REJECT; return REJECT;
@ -1558,7 +1558,7 @@ FILTER_ACTION makefilters (struct srvparam *srv, struct clientparam *param){
} }
void * itfree(void *data, void * retval){ void * itfree(void *data, void * retval){
myfree(data); free(data);
return retval; return retval;
} }
@ -1579,15 +1579,15 @@ void freeacl(struct ace *ac){
for(pl = ac->ports; pl; pl = (struct portlist *)itfree(pl, pl->next)); for(pl = ac->ports; pl; pl = (struct portlist *)itfree(pl, pl->next));
for(pel = ac->periods; pel; pel = (struct period *)itfree(pel, pel->next)); for(pel = ac->periods; pel; pel = (struct period *)itfree(pel, pel->next));
for(ul = ac->users; ul; ul = (struct userlist *)itfree(ul, ul->next)){ for(ul = ac->users; ul; ul = (struct userlist *)itfree(ul, ul->next)){
if(ul->user)myfree(ul->user); if(ul->user)free(ul->user);
} }
for(hst = ac->dstnames; hst; hst = (struct hostname *)itfree(hst, hst->next)){ for(hst = ac->dstnames; hst; hst = (struct hostname *)itfree(hst, hst->next)){
if(hst->name)myfree(hst->name); if(hst->name)free(hst->name);
} }
for(ch = ac->chains; ch; ch = (struct chain *) itfree(ch, ch->next)){ for(ch = ac->chains; ch; ch = (struct chain *) itfree(ch, ch->next)){
if(ch->extuser) myfree(ch->extuser); if(ch->extuser) free(ch->extuser);
if(ch->extpass) myfree(ch->extpass); if(ch->extpass) free(ch->extpass);
if(ch->exthost) myfree(ch->exthost); if(ch->exthost) free(ch->exthost);
} }
} }
} }

View File

@ -28,7 +28,7 @@ int clientnegotiate(struct chain * redir, struct clientparam * param, struct soc
pass = redir->extpass; pass = redir->extpass;
if (!param->srvbufsize){ if (!param->srvbufsize){
param->srvbufsize = SRVBUFSIZE; param->srvbufsize = SRVBUFSIZE;
param->srvbuf = myalloc(param->srvbufsize); param->srvbuf = malloc(param->srvbufsize);
if(!param->srvbuf) return 21; if(!param->srvbuf) return 21;
} }
buf = param->srvbuf; buf = param->srvbuf;
@ -322,12 +322,12 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
int i; int i;
if(cur->extuser){ if(cur->extuser){
if(param->extusername) if(param->extusername)
myfree(param->extusername); free(param->extusername);
param->extusername = (unsigned char *)mystrdup((char *)((*cur->extuser == '*' && param->username)? param->username : cur->extuser)); param->extusername = (unsigned char *)strdup((char *)((*cur->extuser == '*' && param->username)? param->username : cur->extuser));
if(cur->extpass){ if(cur->extpass){
if(param->extpassword) if(param->extpassword)
myfree(param->extpassword); free(param->extpassword);
param->extpassword = (unsigned char *)mystrdup((char *)((*cur->extuser == '*' && param->password)?param->password : cur->extpass)); param->extpassword = (unsigned char *)strdup((char *)((*cur->extuser == '*' && param->password)?param->password : cur->extpass));
} }
if(*cur->extuser == '*' && !param->username) return 4; if(*cur->extuser == '*' && !param->username) return 4;
} }
@ -389,12 +389,12 @@ int handleredirect(struct clientparam * param, struct ace * acentry){
if(cur->extuser){ if(cur->extuser){
if(*cur -> extuser == '*' && !param->username) return 4; if(*cur -> extuser == '*' && !param->username) return 4;
if(param->extusername) if(param->extusername)
myfree(param->extusername); free(param->extusername);
param->extusername = (unsigned char *)mystrdup((char *)((*cur->extuser == '*' && param->username)? param->username : cur->extuser)); param->extusername = (unsigned char *)strdup((char *)((*cur->extuser == '*' && param->username)? param->username : cur->extuser));
if(cur->extpass){ if(cur->extpass){
if(param->extpassword) if(param->extpassword)
myfree(param->extpassword); free(param->extpassword);
param->extpassword = (unsigned char *)mystrdup((char *)((*cur->extuser == '*' && param->password)?param->password : cur->extpass)); param->extpassword = (unsigned char *)strdup((char *)((*cur->extuser == '*' && param->password)?param->password : cur->extpass));
} }
} }
if(redir->secure) return ssl_parent(param); if(redir->secure) return ssl_parent(param);

View File

@ -171,8 +171,8 @@ uint32_t udpresolve(int af, unsigned char * name, unsigned char * value, uint32_
s2 = s1; s2 = s1;
} }
*s2 = 0; *s2 = 0;
if(param->username)myfree(param->username); if(param->username)free(param->username);
param->username = (unsigned char *)mystrdup ((char *)buf + k + 13); param->username = (unsigned char *)strdup ((char *)buf + k + 13);
return udpresolve(af,param->username, value, NULL, NULL, 2); return udpresolve(af,param->username, value, NULL, NULL, 2);
} }

View File

@ -19,26 +19,26 @@ int readreply (struct clientparam* param) {
unsigned char * buf; unsigned char * buf;
int res, i, bufsize = 640; int res, i, bufsize = 640;
if(!(buf = myalloc(bufsize))) return 0; if(!(buf = malloc(bufsize))) return 0;
do { do {
i = sockgetlinebuf(param, SERVER, buf, bufsize-1, '\n', conf.timeouts[STRING_L]); i = sockgetlinebuf(param, SERVER, buf, bufsize-1, '\n', conf.timeouts[STRING_L]);
if(i < 1) break; if(i < 1) break;
#ifndef WITHMAIN #ifndef WITHMAIN
res = handlehdrfilterssrv(param, &buf, &bufsize, 0, &i); res = handlehdrfilterssrv(param, &buf, &bufsize, 0, &i);
if(res != PASS) { if(res != PASS) {
myfree(buf); free(buf);
return -1; return -1;
} }
#endif #endif
socksend(param, param->clisock, buf, i, conf.timeouts[STRING_S]); socksend(param, param->clisock, buf, i, conf.timeouts[STRING_S]);
} while (i > 3 && buf[3] == '-'); } while (i > 3 && buf[3] == '-');
if(i < 3) { if(i < 3) {
myfree(buf); free(buf);
return 0; return 0;
} }
buf[i] = 0; buf[i] = 0;
res = atoi((char *)buf); res = atoi((char *)buf);
myfree(buf); free(buf);
return res; return res;
} }
@ -47,14 +47,14 @@ int readcommand (struct clientparam* param) {
int res, i, bufsize = 320; int res, i, bufsize = 320;
int ret = 1; int ret = 1;
if(!(buf = myalloc(bufsize))) return 0; if(!(buf = malloc(bufsize))) return 0;
i = sockgetlinebuf(param, CLIENT, buf, bufsize-1, '\n', conf.timeouts[STRING_L]); i = sockgetlinebuf(param, CLIENT, buf, bufsize-1, '\n', conf.timeouts[STRING_L]);
if(i < 4) return 0; if(i < 4) return 0;
#ifndef WITHMAIN #ifndef WITHMAIN
if(!strncasecmp((char *)buf, "MAIL", 4) || !strncasecmp((char *)buf, "RCPT", 4) || !strncasecmp((char *)buf, "STARTTLS", 8) || !strncasecmp((char *)buf, "TURN", 4)){ if(!strncasecmp((char *)buf, "MAIL", 4) || !strncasecmp((char *)buf, "RCPT", 4) || !strncasecmp((char *)buf, "STARTTLS", 8) || !strncasecmp((char *)buf, "TURN", 4)){
res = handlehdrfilterscli(param, &buf, &bufsize, 0, &i); res = handlehdrfilterscli(param, &buf, &bufsize, 0, &i);
if(res != PASS) { if(res != PASS) {
myfree(buf); free(buf);
if(res == HANDLED) return 2; if(res == HANDLED) return 2;
return -1; return -1;
} }
@ -64,7 +64,7 @@ int readcommand (struct clientparam* param) {
if(!strncasecmp((char *)buf, "STARTTLS", 8) || !strncasecmp((char *)buf, "TURN", 4)){ if(!strncasecmp((char *)buf, "STARTTLS", 8) || !strncasecmp((char *)buf, "TURN", 4)){
ret = 22; ret = 22;
} }
myfree(buf); free(buf);
return ret; return ret;
} }
@ -72,12 +72,12 @@ int readdata (struct clientparam* param) {
unsigned char * buf; unsigned char * buf;
int res, i, bufsize = 4096; int res, i, bufsize = 4096;
if(!(buf = myalloc(bufsize))) return 0; if(!(buf = malloc(bufsize))) return 0;
while ((i = sockgetlinebuf(param, CLIENT, buf, bufsize-1, '\n', conf.timeouts[STRING_L])) > 0 && !(i==3 && buf[0] == '.')){ while ((i = sockgetlinebuf(param, CLIENT, buf, bufsize-1, '\n', conf.timeouts[STRING_L])) > 0 && !(i==3 && buf[0] == '.')){
#ifndef WITHMAIN #ifndef WITHMAIN
res = handledatfltcli(param, &buf, &bufsize, 0, &i); res = handledatfltcli(param, &buf, &bufsize, 0, &i);
if(res != PASS) { if(res != PASS) {
myfree(buf); free(buf);
if(res == HANDLED) return 1; if(res == HANDLED) return 1;
return -1; return -1;
} }
@ -85,11 +85,11 @@ int readdata (struct clientparam* param) {
socksend(param, param->remsock, buf, i, conf.timeouts[STRING_S]); socksend(param, param->remsock, buf, i, conf.timeouts[STRING_S]);
} }
if(i < 1) { if(i < 1) {
myfree(buf); free(buf);
return 0; return 0;
} }
socksend(param, param->remsock, buf, i, conf.timeouts[STRING_S]); socksend(param, param->remsock, buf, i, conf.timeouts[STRING_S]);
myfree(buf); free(buf);
return 1; return 1;
} }
@ -118,7 +118,7 @@ void * smtppchild(struct clientparam* param) {
else { else {
login = -1; login = -1;
buf[i] = 0; buf[i] = 0;
command = mystrdup((char *)buf); command = strdup((char *)buf);
break; break;
} }
i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]); i = sockgetlinebuf(param, CLIENT, buf, sizeof(buf) - 10, '\n', conf.timeouts[STRING_S]);
@ -140,8 +140,8 @@ void * smtppchild(struct clientparam* param) {
i = de64(buf,username,255); i = de64(buf,username,255);
if(i < 0) {RETURN(666);} if(i < 0) {RETURN(666);}
username[i] = 0; username[i] = 0;
if(param->extpassword) myfree(param->extpassword); if(param->extpassword) free(param->extpassword);
param->extpassword = (unsigned char *)mystrdup((char *)username); param->extpassword = (unsigned char *)strdup((char *)username);
} }
else if(login == 2){ else if(login == 2){
if(i > 13) { if(i > 13) {
@ -160,8 +160,8 @@ void * smtppchild(struct clientparam* param) {
parseconnusername((char *)username+1, param, 0, 25); parseconnusername((char *)username+1, param, 0, 25);
res = (int)strlen((char *)username+1) + 2; res = (int)strlen((char *)username+1) + 2;
if(res < i){ if(res < i){
if(param->extpassword) myfree(param->extpassword); if(param->extpassword) free(param->extpassword);
param->extpassword = (unsigned char *)mystrdup((char *)username + res); param->extpassword = (unsigned char *)strdup((char *)username + res);
} }
} }
@ -298,7 +298,7 @@ CLEANRET:
if(param->clisock != INVALID_SOCKET) { if(param->clisock != INVALID_SOCKET) {
if ((param->res > 0 && param->res < 100) || (param->res > 661 && param->res <700)) socksend(param, param->clisock, (unsigned char *)"571 \r\n", 6,conf.timeouts[STRING_S]); if ((param->res > 0 && param->res < 100) || (param->res > 661 && param->res <700)) socksend(param, param->clisock, (unsigned char *)"571 \r\n", 6,conf.timeouts[STRING_S]);
} }
if(command) myfree(command); if(command) free(command);
freeparam(param); freeparam(param);
return (NULL); return (NULL);
} }

View File

@ -73,7 +73,7 @@ int sockgetcharcli(struct clientparam * param, int timeosec, int timeousec){
int len; int len;
if(!param->clibuf){ if(!param->clibuf){
if(!(param->clibuf = myalloc(SRVBUFSIZE))) return 0; if(!(param->clibuf = malloc(SRVBUFSIZE))) return 0;
param->clibufsize = SRVBUFSIZE; param->clibufsize = SRVBUFSIZE;
param->clioffset = param->cliinbuf = 0; param->clioffset = param->cliinbuf = 0;
} }
@ -137,7 +137,7 @@ int sockgetcharsrv(struct clientparam * param, int timeosec, int timeousec){
if(!param->srvbuf){ if(!param->srvbuf){
bufsize = SRVBUFSIZE; bufsize = SRVBUFSIZE;
if(param->ndatfilterssrv > 0 && bufsize < 32768) bufsize = 32768; if(param->ndatfilterssrv > 0 && bufsize < 32768) bufsize = 32768;
if(!(param->srvbuf = myalloc(bufsize))) return 0; if(!(param->srvbuf = malloc(bufsize))) return 0;
param->srvbufsize = bufsize; param->srvbufsize = bufsize;
param->srvoffset = param->srvinbuf = 0; param->srvoffset = param->srvinbuf = 0;

View File

@ -103,10 +103,10 @@ int sockmap(struct clientparam * param, int timeo, int usesplice){
if(!usesplice) if(!usesplice)
#endif #endif
{ {
if(fromserver && !param->srvbuf && (!(param->srvbuf=myalloc(SRVBUFSIZE)) || !(param->srvbufsize = SRVBUFSIZE))){ if(fromserver && !param->srvbuf && (!(param->srvbuf=malloc(SRVBUFSIZE)) || !(param->srvbufsize = SRVBUFSIZE))){
RETURN (21); RETURN (21);
} }
if(fromclient && !param->clibuf && (!(param->clibuf=myalloc(SRVBUFSIZE)) || !(param->clibufsize = SRVBUFSIZE))){ if(fromclient && !param->clibuf && (!(param->clibuf=malloc(SRVBUFSIZE)) || !(param->clibufsize = SRVBUFSIZE))){
RETURN (21); RETURN (21);
} }

View File

@ -49,7 +49,7 @@ void * sockschild(struct clientparam* param) {
param->service = S_SOCKS; param->service = S_SOCKS;
if(!(buf = myalloc(BUFSIZE))) {RETURN(21);} if(!(buf = malloc(BUFSIZE))) {RETURN(21);}
memset(buf, 0, BUFSIZE); memset(buf, 0, BUFSIZE);
if ((ver = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_L], 0)) != 5 && ver != 4) { if ((ver = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_L], 0)) != 5 && ver != 4) {
RETURN(401); RETURN(401);
@ -74,11 +74,11 @@ void * sockschild(struct clientparam* param) {
if ((i = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_S], 0)) == EOF) {RETURN(451);} if ((i = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_S], 0)) == EOF) {RETURN(451);}
if (i && (unsigned)(res = sockgetlinebuf(param, CLIENT, buf, i, 0, conf.timeouts[STRING_S])) != i){RETURN(441);}; if (i && (unsigned)(res = sockgetlinebuf(param, CLIENT, buf, i, 0, conf.timeouts[STRING_S])) != i){RETURN(441);};
buf[i] = 0; buf[i] = 0;
if(!param->username)param->username = (unsigned char *)mystrdup((char *)buf); if(!param->username)param->username = (unsigned char *)strdup((char *)buf);
if ((i = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_S], 0)) == EOF) {RETURN(445);} if ((i = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_S], 0)) == EOF) {RETURN(445);}
if (i && (unsigned)(res = sockgetlinebuf(param, CLIENT, buf, i, 0, conf.timeouts[STRING_S])) != i){RETURN(441);}; if (i && (unsigned)(res = sockgetlinebuf(param, CLIENT, buf, i, 0, conf.timeouts[STRING_S])) != i){RETURN(441);};
buf[i] = 0; buf[i] = 0;
if(!param->password)param->password = (unsigned char *)mystrdup((char *)buf); if(!param->password)param->password = (unsigned char *)strdup((char *)buf);
buf[0] = 1; buf[0] = 1;
buf[1] = 0; buf[1] = 0;
if(socksend(param, param->clisock, buf, 2, conf.timeouts[STRING_S])!=2){RETURN(481);} if(socksend(param, param->clisock, buf, 2, conf.timeouts[STRING_S])!=2){RETURN(481);}
@ -150,8 +150,8 @@ void * sockschild(struct clientparam* param) {
default: default:
RETURN(997); RETURN(997);
} }
if(param->hostname)myfree(param->hostname); if(param->hostname)free(param->hostname);
param->hostname = (unsigned char *)mystrdup((char *)buf); param->hostname = (unsigned char *)strdup((char *)buf);
if (ver == 5) { if (ver == 5) {
if ((res = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_S], 0)) == EOF) {RETURN(441);} if ((res = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_S], 0)) == EOF) {RETURN(441);}
buf[0] = (unsigned char) res; buf[0] = (unsigned char) res;
@ -163,13 +163,13 @@ void * sockschild(struct clientparam* param) {
else { else {
if(sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 1, 0, conf.timeouts[STRING_S]) < 0) {RETURN(441);} if(sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 1, 0, conf.timeouts[STRING_S]) < 0) {RETURN(441);}
buf[127] = 0; buf[127] = 0;
if(param->srv->needuser && *buf && !param->username)param->username = (unsigned char *)mystrdup((char *)buf); if(param->srv->needuser && *buf && !param->username)param->username = (unsigned char *)strdup((char *)buf);
if(!memcmp(SAADDR(&param->req), "\0\0\0", 3)){ if(!memcmp(SAADDR(&param->req), "\0\0\0", 3)){
param->service = S_SOCKS45; param->service = S_SOCKS45;
if(sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 1, 0, conf.timeouts[STRING_S]) < 0) {RETURN(441);} if(sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 1, 0, conf.timeouts[STRING_S]) < 0) {RETURN(441);}
buf[127] = 0; buf[127] = 0;
if(param->hostname)myfree(param->hostname); if(param->hostname)free(param->hostname);
param->hostname = (unsigned char *)mystrdup((char *)buf); param->hostname = (unsigned char *)strdup((char *)buf);
if(!getip46(param->srv->family, buf, (struct sockaddr *) &param->req)) RETURN(100); if(!getip46(param->srv->family, buf, (struct sockaddr *) &param->req)) RETURN(100);
param->sinsr = param->req; param->sinsr = param->req;
} }
@ -341,7 +341,7 @@ fflush(stderr);
case 1: case 1:
if(param->redirectfunc){ if(param->redirectfunc){
void *ret = (*param->redirectfunc)(param); void *ret = (*param->redirectfunc)(param);
if(buf)myfree(buf); if(buf)free(buf);
return ret; return ret;
} }
param->res = mapsocket(param, conf.timeouts[CONNECTION_L]); param->res = mapsocket(param, conf.timeouts[CONNECTION_L]);
@ -420,7 +420,7 @@ fflush(stderr);
printcommand(buf, command, param); printcommand(buf, command, param);
dolog(param, buf); dolog(param, buf);
myfree(buf); free(buf);
} }
freeparam(param); freeparam(param);
return (NULL); return (NULL);

View File

@ -36,8 +36,8 @@ int init_sql(char * s){
if(!s) return 0; if(!s) return 0;
if(!sqlstring || strcmp(sqlstring, s)){ if(!sqlstring || strcmp(sqlstring, s)){
string = sqlstring; string = sqlstring;
sqlstring=mystrdup(s); sqlstring=strdup(s);
if(string)myfree(string); if(string)free(string);
} }
if(hstmt || hdbc || henv) close_sql(); if(hstmt || hdbc || henv) close_sql();
@ -65,7 +65,7 @@ int init_sql(char * s){
} }
SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (void*)15, 0); SQLSetConnectAttr(hdbc, SQL_LOGIN_TIMEOUT, (void*)15, 0);
} }
string = mystrdup(sqlstring); string = strdup(sqlstring);
if(!string) return 0; if(!string) return 0;
datasource = strtok(string, ","); datasource = strtok(string, ",");
username = strtok(NULL, ","); username = strtok(NULL, ",");
@ -77,7 +77,7 @@ int init_sql(char * s){
(SQLCHAR*) username, (SQLSMALLINT)((username)?strlen(username):0), (SQLCHAR*) username, (SQLSMALLINT)((username)?strlen(username):0),
(SQLCHAR*) password, (SQLSMALLINT)((password)?strlen(password):0)); (SQLCHAR*) password, (SQLSMALLINT)((password)?strlen(password):0));
myfree(string); free(string);
if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO){ if (retcode != SQL_SUCCESS && retcode != SQL_SUCCESS_WITH_INFO){
SQLFreeHandle(SQL_HANDLE_DBC, hdbc); SQLFreeHandle(SQL_HANDLE_DBC, hdbc);
hdbc = NULL; hdbc = NULL;

View File

@ -505,6 +505,7 @@ struct hashtable {
time_t compacted; time_t compacted;
uint32_t ihashhashempty; uint32_t ihashhashempty;
uint32_t ihashempty; uint32_t ihashempty;
uint32_t entropy;
}; };
struct srvparam { struct srvparam {
@ -780,11 +781,7 @@ struct child {
extern struct hashtable dns_table; extern struct hashtable dns_table;
extern struct hashtable dns6_table; extern struct hashtable dns6_table;
extern struct hashtable auth_table; extern struct hashtable auth_table;
extern struct hashtable pw_table; extern struct hashtable pwl_table;
#ifdef WITH_SSL
extern struct hashtable pwnt_table;
#endif
extern struct hashtable pwcr_table;
extern struct hashtable udp_table; extern struct hashtable udp_table;
struct authcache { struct authcache {

View File

@ -21,7 +21,7 @@ void * tcppmchild(struct clientparam* param) {
if(!strncmp((char *)param->srv->target, "unix:", 5)){ if(!strncmp((char *)param->srv->target, "unix:", 5)){
make_un(param->srv->target + 5, (struct sockaddr_un *)&param->sinsr); make_un(param->srv->target + 5, (struct sockaddr_un *)&param->sinsr);
make_un(param->srv->target + 5, (struct sockaddr_un *)&param->req); make_un(param->srv->target + 5, (struct sockaddr_un *)&param->req);
param->hostname = (unsigned char *)mystrdup((char *)param->srv->target); param->hostname = (unsigned char *)strdup((char *)param->srv->target);
} else } else
#endif #endif
if( if(

View File

@ -111,7 +111,7 @@ int parsehello(int type, unsigned char *hello, unsigned len, char *sni, int * sn
int tlstobufcli(struct clientparam *param){ int tlstobufcli(struct clientparam *param){
unsigned long len, newlen; unsigned long len, newlen;
if(!param->clibuf){ if(!param->clibuf){
if(!(param->clibuf = myalloc(SRVBUFSIZE))) return -1; if(!(param->clibuf = malloc(SRVBUFSIZE))) return -1;
param->clibufsize = SRVBUFSIZE; param->clibufsize = SRVBUFSIZE;
param->clioffset = param->cliinbuf = 0; param->clioffset = param->cliinbuf = 0;
} }
@ -149,7 +149,7 @@ int tlstobufsrv(struct clientparam *param){
param->cliinbuf = param->clioffset = 0; param->cliinbuf = param->clioffset = 0;
} }
if(!param->srvbuf){ if(!param->srvbuf){
if(!(param->srvbuf = myalloc(SRVBUFSIZE))) return -1; if(!(param->srvbuf = malloc(SRVBUFSIZE))) return -1;
param->srvbufsize = SRVBUFSIZE; param->srvbufsize = SRVBUFSIZE;
param->srvoffset = param->srvinbuf = 0; param->srvoffset = param->srvinbuf = 0;
} }
@ -186,11 +186,11 @@ void * tlsprchild(struct clientparam* param) {
res = parsehello(1, param->clibuf, (unsigned)res, sni, &snipos, &lv, proto); res = parsehello(1, param->clibuf, (unsigned)res, sni, &snipos, &lv, proto);
if(res > 0){ if(res > 0){
if(param->hostname){ if(param->hostname){
myfree(param->hostname); free(param->hostname);
param->hostname = NULL; param->hostname = NULL;
} }
else if (parsehostname(sni, param, param->srv->targetport? ntohs(param->srv->targetport):443)) RETURN (100); else if (parsehostname(sni, param, param->srv->targetport? ntohs(param->srv->targetport):443)) RETURN (100);
if (!param->hostname)param->hostname = (unsigned char *)mystrdup(sni); if (!param->hostname)param->hostname = (unsigned char *)strdup(sni);
if(param->srv->singlepacket && snipos && res > 1){ if(param->srv->singlepacket && snipos && res > 1){
int len; int len;

View File

@ -58,7 +58,7 @@ void * udppmchild(struct clientparam* param) {
if(authres) { RETURN(authres); } if(authres) { RETURN(authres); }
if(!param->srv->singlepacket)hashadd(&udp_table, param, &param, MAX_COUNTER_TIME); if(!param->srv->singlepacket)hashadd(&udp_table, param, &param, MAX_COUNTER_TIME);
if(!param->srvbuf){ if(!param->srvbuf){
if(!(param->srvbuf = myalloc(UDPBUFSIZE)))RETURN(11); if(!(param->srvbuf = malloc(UDPBUFSIZE)))RETURN(11);
param->srvbufsize = UDPBUFSIZE; param->srvbufsize = UDPBUFSIZE;
} }
if(param->udp_nhops){ if(param->udp_nhops){

View File

@ -58,7 +58,7 @@ int udpsockmap(struct clientparam *param, int timeo)
int clisock_idx = -1, ctrlsock_idx = -1, ctrlsocksrv_idx = -1; int clisock_idx = -1, ctrlsock_idx = -1, ctrlsocksrv_idx = -1;
int firstpacket = 1; int firstpacket = 1;
if (param->srvbufsize < UDPBUFSIZE) { if (param->srvbufsize < UDPBUFSIZE) {
unsigned char *newbuf = myrealloc(param->srvbuf, UDPBUFSIZE); unsigned char *newbuf = realloc(param->srvbuf, UDPBUFSIZE);
if (!newbuf) return 21; if (!newbuf) return 21;
param->srvbuf = newbuf; param->srvbuf = newbuf;
param->srvbufsize = UDPBUFSIZE; param->srvbufsize = UDPBUFSIZE;

View File

@ -382,7 +382,7 @@ void * adminchild(struct clientparam* param) {
pp.inbuf = 0; pp.inbuf = 0;
pp.cp = param; pp.cp = param;
buf = myalloc(LINESIZE); buf = malloc(LINESIZE);
if(!buf) {RETURN(555);} if(!buf) {RETURN(555);}
i = sockgetlinebuf(param, CLIENT, (unsigned char *)buf, LINESIZE - 1, '\n', conf.timeouts[STRING_S]); i = sockgetlinebuf(param, CLIENT, (unsigned char *)buf, LINESIZE - 1, '\n', conf.timeouts[STRING_S]);
if(i<5 || ((buf[0]!='G' || buf[1]!='E' || buf[2]!='T' || buf[3]!=' ' || buf[4]!='/') && if(i<5 || ((buf[0]!='G' || buf[1]!='E' || buf[2]!='T' || buf[3]!=' ' || buf[4]!='/') &&
@ -396,7 +396,7 @@ void * adminchild(struct clientparam* param) {
RETURN(702); RETURN(702);
} }
*sb = 0; *sb = 0;
req = mystrdup(buf + ((*buf == 'P')? 6 : 5)); req = strdup(buf + ((*buf == 'P')? 6 : 5));
while((i = sockgetlinebuf(param, CLIENT, (unsigned char *)buf, LINESIZE - 1, '\n', conf.timeouts[STRING_S])) > 2){ while((i = sockgetlinebuf(param, CLIENT, (unsigned char *)buf, LINESIZE - 1, '\n', conf.timeouts[STRING_S])) > 2){
buf[i] = 0; buf[i] = 0;
if(i > 19 && (!strncasecmp(buf, "authorization", 13))){ if(i > 19 && (!strncasecmp(buf, "authorization", 13))){
@ -415,11 +415,11 @@ void * adminchild(struct clientparam* param) {
sb = strchr((char *)username, ':'); sb = strchr((char *)username, ':');
if(sb){ if(sb){
*sb = 0; *sb = 0;
if(param->password)myfree(param->password); if(param->password)free(param->password);
param->password = (unsigned char *)mystrdup(sb+1); param->password = (unsigned char *)strdup(sb+1);
} }
if(param->username) myfree(param->username); if(param->username) free(param->username);
param->username = (unsigned char *)mystrdup(username); param->username = (unsigned char *)strdup(username);
continue; continue;
} }
else if(i > 15 && (!strncasecmp(buf, "content-length:", 15))){ else if(i > 15 && (!strncasecmp(buf, "content-length:", 15))){
@ -611,9 +611,9 @@ CLEANRET:
printstr(&pp, NULL); printstr(&pp, NULL);
if(buf) myfree(buf); if(buf) free(buf);
dolog(param, (unsigned char *)req); dolog(param, (unsigned char *)req);
if(req)myfree(req); if(req)free(req);
freeparam(param); freeparam(param);
return (NULL); return (NULL);
} }