1
0

some bugs

This commit is contained in:
Daniel Tartavel 2020-05-27 22:37:45 +02:00
parent 0bb0c7885e
commit 001a819a59

18
main.c
View File

@ -68,6 +68,7 @@ int printlog(char str[], int level, int errnum)
if ( level <= loglevel ) if ( level <= loglevel )
{ {
time( &now );
if (errnum != 0) if (errnum != 0)
{ {
sprintf( tmp, "%s: %s %s\n", frtime(now), str, strerror(errnum)); sprintf( tmp, "%s: %s %s\n", frtime(now), str, strerror(errnum));
@ -309,8 +310,8 @@ void getutmp( struct connexion * conn, time_t * time )
char str[6]; char str[6];
char strlog[128]; char strlog[128];
conn->host_ip[0]='\0'; //conn->host_ip[0]='\0';
conn->host_ipv6[0]='\0'; //conn->host_ipv6[0]='\0';
setutent(); setutent();
while ( (utmp = getutent()) != NULL ) while ( (utmp = getutent()) != NULL )
{ {
@ -320,7 +321,7 @@ void getutmp( struct connexion * conn, time_t * time )
printlog(conn->user, DEBUG, 0); printlog(conn->user, DEBUG, 0);
sprintf(conn->hostname, "%s", utmp->ut_host); //got ip of origin sprintf(conn->hostname, "%s", utmp->ut_host); //got ip of origin
printlog(conn->hostname, DEBUG, 0); printlog(conn->hostname, DEBUG, 0);
if((utmp->ut_addr_v6[1] || utmp->ut_addr_v6[2] || utmp->ut_addr_v6[3]) == 0) if(utmp->ut_addr_v6[1] == 0)
{ {
ipv4 = utmp->ut_addr_v6[0] & 0x00000000000000ff; ipv4 = utmp->ut_addr_v6[0] & 0x00000000000000ff;
sprintf( str, "%d.", ipv4); sprintf( str, "%d.", ipv4);
@ -586,7 +587,7 @@ int main()
r = isinarray(pid, childrens, n_pid); r = isinarray(pid, childrens, n_pid);
if( r == 0 ) if( r == 0 )
{ {
conn.user[0]='\0'; //conn.user[0]='\0';
conn.pid=pid; conn.pid=pid;
rinfo = getprocinfo( &conn ); rinfo = getprocinfo( &conn );
if( rinfo == 0 ) if( rinfo == 0 )
@ -655,15 +656,18 @@ int main()
{ {
time( &now ); time( &now );
sprintf( date, "%s", frtime(now) ); sprintf( date, "%s", frtime(now) );
sprintf(strlog, "%s: Session %d de %s terminée\n", date, connexions[i].pid, connexions[i].user ); sprintf(strlog, "Session %d de %s terminée\n", connexions[i].pid, connexions[i].user );
printlog(strlog, INFO, 0);
sprintf(strlog, "%s: %s - pid %d - Connexion de %s terminée", connexions[i].date, cfg.hostname, connexions[i].pid, connexions[i].user);
printlog(strlog, INFO, 0); printlog(strlog, INFO, 0);
//sprintf(strlog, "%s: %s - pid %d - Connexion de %s terminée", connexions[i].date, cfg.hostname, connexions[i].pid, connexions[i].user);
//printlog(strlog, INFO, 0);
for( j=i; j<n_pid; j++ ) for( j=i; j<n_pid; j++ )
{ {
childrens[j] = childrens[j+1]; childrens[j] = childrens[j+1];
connexions[j] = connexions[j+1];
flag[j] = flag[j+1]; flag[j] = flag[j+1];
} }
childrens[n_pid] = 0;
flag[n_pid] = 0;
i--; i--;
n_pid--; n_pid--;
}else }else