Minor logging improvement / code cleanup
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

This commit is contained in:
Vladimir Dubrovin 2026-05-12 21:21:59 +03:00
parent 1de06c5059
commit 381ef993a7
4 changed files with 51 additions and 24 deletions

View File

@ -72,6 +72,8 @@
#define PW_ACCT_INPUT_PACKETS 47
#define PW_ACCT_OUTPUT_PACKETS 48
#define PW_ACCT_TERMINATE_CAUSE 49
#define PW_ACCT_INPUT_GIGAWORDS 52
#define PW_ACCT_OUTPUT_GIGAWORDS 53
#define PW_EVENT_TIMESTAMP 55
@ -375,7 +377,7 @@ int radsend(struct clientparam * param, int auth, int stop){
/* NAS-Port */
*ptr++ = PW_NAS_PORT_ID;
*ptr++ = 6;
(*(uint32_t *)ptr)=htonl((uint32_t)ntohs((*SAPORT(&param->srv->intsa))));
(*(uint32_t *)ptr)=htonl(param->srv?(uint32_t)ntohs((*SAPORT(&param->srv->intsa))):0);
ptr+=4;
total_length+=6;
@ -479,12 +481,28 @@ int radsend(struct clientparam * param, int auth, int stop){
(*(uint32_t *)ptr)=htonl((uint32_t)param->statssrv64);
ptr+=4;
total_length+=6;
/* Acct-Input-Gigawords */
if(param->statssrv64 > 0xFFFFFFFFULL){
*ptr++ = PW_ACCT_INPUT_GIGAWORDS;
*ptr++ = 6;
(*(uint32_t *)ptr)=htonl((uint32_t)(param->statssrv64 >> 32));
ptr+=4;
total_length+=6;
}
/* Acct-Output-Octets */
*ptr++ = PW_ACCT_OUTPUT_OCTETS;
*ptr++ = 6;
(*(uint32_t *)ptr)=htonl((uint32_t)param->statscli64);
ptr+=4;
total_length+=6;
/* Acct-Output-Gigawords */
if(param->statscli64 > 0xFFFFFFFFULL){
*ptr++ = PW_ACCT_OUTPUT_GIGAWORDS;
*ptr++ = 6;
(*(uint32_t *)ptr)=htonl((uint32_t)(param->statscli64 >> 32));
ptr+=4;
total_length+=6;
}
/* Acct-Input-Packets */
*ptr++ = PW_ACCT_INPUT_PACKETS;
*ptr++ = 6;

View File

@ -115,10 +115,7 @@ unsigned char * dologname (unsigned char *buf, unsigned char *name, const unsign
return buf;
}
if(strchr((char *)name, '%')){
struct clientparam fakecli;
memset(&fakecli, 0, sizeof(fakecli));
dobuf2(&fakecli, buf, NULL, NULL, ts, (char *)name);
dobuf2(NULL, buf, NULL, NULL, ts, (char *)name);
}
else switch(lt){
case NONE:

View File

@ -20,16 +20,8 @@ struct srvparam logsrv;
void dolog(struct clientparam * param, const unsigned char *s){
static int init = 0;
if(param)param->srv->logfunc(param, s);
else {
if(!init){
srvinit(&logsrv, &logparam);
init = 1;
}
logstdout(&logparam, s);
}
if(param && param->srv)param->srv->logfunc(param, s);
else logstdout(NULL, s);
}
@ -70,6 +62,9 @@ int dobuf2(struct clientparam * param, unsigned char * buf, const unsigned char
long timezone;
unsigned delay;
if(!logparam.srv) srvinit(&logsrv, &logparam);
if(!param) param = &logparam;
#ifdef _WIN32
@ -317,15 +312,21 @@ int dobuf(struct clientparam * param, unsigned char * buf, const unsigned char *
int i;
char * format;
time_t t;
int has_srv;
time(&t);
if(!param) return 0;
has_srv = param && param->srv;
if(has_srv){
if(param->trafcountfunc)(*param->trafcountfunc)(param);
format = param->srv->logformat?(char *)param->srv->logformat : DEFLOGFORMAT;
}
else {
format = DEFLOGFORMAT;
}
tm = (*format == 'G' || *format == 'g')?
gmtime(&t) : localtime(&t);
i = dobuf2(param, buf, s, doublec, tm, format + 1);
clearstat(param);
if(has_srv) clearstat(param);
return i;
}
@ -339,8 +340,8 @@ void logstdout(struct clientparam * param, const unsigned char *s) {
unsigned char tmpbuf[8192];
dobuf(param, tmpbuf, s, NULL);
log = param->srv->stdlog?param->srv->stdlog:conf.stdlog?conf.stdlog:stdout;
if(!param->nolog)if(fprintf(log, "%s\n", tmpbuf) < 0) {
log = (param && param->srv && param->srv->stdlog)?param->srv->stdlog:conf.stdlog?conf.stdlog:stdout;
if(!param || !param->nolog)if(fprintf(log, "%s\n", tmpbuf) < 0) {
perror("printf()");
};
if(log != conf.stdlog)fflush(log);

View File

@ -77,11 +77,17 @@ void * sockschild(struct clientparam* param) {
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);};
buf[i] = 0;
if(!param->username)param->username = (unsigned char *)strdup((char *)buf);
if(!param->username) {
param->username = (unsigned char *)strdup((char *)buf);
if(!param->username){RETURN(21);}
}
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);};
buf[i] = 0;
if(!param->password)param->password = (unsigned char *)strdup((char *)buf);
if(!param->password) {
param->password = (unsigned char *)strdup((char *)buf);
if(!param->password){RETURN(21);}
}
buf[0] = 1;
buf[1] = 0;
if(socksend(param, param->clisock, buf, 2, conf.timeouts[STRING_S])!=2){RETURN(481);}
@ -155,6 +161,7 @@ void * sockschild(struct clientparam* param) {
}
if(param->hostname)free(param->hostname);
param->hostname = (unsigned char *)strdup((char *)buf);
if(!param->hostname){RETURN(21);}
if (ver == 5) {
if ((res = sockgetcharcli(param, conf.timeouts[SINGLEBYTE_S], 0)) == EOF) {RETURN(441);}
buf[0] = (unsigned char) res;
@ -166,13 +173,17 @@ void * sockschild(struct clientparam* param) {
else {
if(sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 1, 0, conf.timeouts[STRING_S]) < 0) {RETURN(441);}
buf[127] = 0;
if(param->srv->needuser && *buf && !param->username)param->username = (unsigned char *)strdup((char *)buf);
if(param->srv->needuser && *buf && !param->username) {
param->username = (unsigned char *)strdup((char *)buf);
if(!param->username){RETURN(21);}
}
if(!memcmp(SAADDR(&param->req), "\0\0\0", 3)){
param->service = S_SOCKS45;
if(sockgetlinebuf(param, CLIENT, buf, BUFSIZE - 1, 0, conf.timeouts[STRING_S]) < 0) {RETURN(441);}
buf[127] = 0;
if(param->hostname)free(param->hostname);
param->hostname = (unsigned char *)strdup((char *)buf);
if(!param->hostname){RETURN(21);}
if(!getip46(param->srv->family, buf, (struct sockaddr *) &param->req)) RETURN(100);
param->sinsr = param->req;
}