acquire hostname from env
This commit is contained in:
parent
e48701bde9
commit
1b27bccac5
30
main.c
30
main.c
@ -182,7 +182,6 @@ int getprocinfo( struct connexion * conn )
|
||||
time( &timet );
|
||||
}
|
||||
sprintf( conn->date, "%s", frtime(timet) );
|
||||
conn->date[strlen(conn->date)-1] = 0;
|
||||
|
||||
//get the pid of the last processus
|
||||
while ( flag == 0)
|
||||
@ -250,7 +249,7 @@ int main()
|
||||
// char cmd[24];
|
||||
// char cmdline[1000];
|
||||
// char user[24]="";
|
||||
// char hostname[128];
|
||||
char hostname[128];
|
||||
char ip[42]="";
|
||||
// char host_ip[42]="";
|
||||
// char host_ipv6[42]="";
|
||||
@ -259,9 +258,18 @@ int main()
|
||||
time_t now ;
|
||||
char * locale;
|
||||
char * language;
|
||||
char * buff;
|
||||
struct connexion conn;
|
||||
struct connexion connexions[n_ssh];
|
||||
//char * ptr;
|
||||
buff = getenv("HOSTNAME");
|
||||
if ( buff != NULL)
|
||||
{
|
||||
strcpy(hostname, buff);
|
||||
}else
|
||||
{
|
||||
strcpy(hostname, HOSTNAME);
|
||||
}
|
||||
|
||||
language = getenv("LANGUAGE");
|
||||
strtok (language, ":");
|
||||
@ -283,7 +291,7 @@ int main()
|
||||
exit(r);
|
||||
}else if( id<0 )
|
||||
{
|
||||
printf("erreur de création du fork: %s", str);
|
||||
printf("erreur de création du fork: %s\n", str);
|
||||
}
|
||||
|
||||
while (1)
|
||||
@ -296,7 +304,7 @@ int main()
|
||||
}
|
||||
if ( fscanf(fh, "%i", &pid) == 0)
|
||||
{
|
||||
printf("erreur fscanf: /run/sshd.pid" );
|
||||
printf("erreur fscanf: /run/sshd.pid\n" );
|
||||
return 10;
|
||||
}
|
||||
fclose(fh);
|
||||
@ -331,10 +339,10 @@ int main()
|
||||
|
||||
if (conn.user[0] == '\0')
|
||||
{
|
||||
sprintf( str, "%s \"%s: tunnel ouvert le %s depuis %s avec la commande: %s %s\"", commande, HOSTNAME, conn.date, ip, conn.cmd, conn.cmdline );
|
||||
sprintf( str, "%s \"%s: tunnel ouvert le %s depuis %s avec la commande: %s %s\"", commande, hostname, conn.date, ip, conn.cmd, conn.cmdline );
|
||||
}else
|
||||
{
|
||||
sprintf( str, "%s \"%s: %s s'est connecté le %s depuis %s avec la commande: %s %s\"", commande, HOSTNAME, conn.user, conn.date, ip, conn.cmd, conn.cmdline );
|
||||
sprintf( str, "%s \"%s: %s s'est connecté le %s depuis %s avec la commande: %s %s\"", commande, hostname, conn.user, conn.date, ip, conn.cmd, conn.cmdline );
|
||||
}
|
||||
if ( start != 1 )
|
||||
{
|
||||
@ -346,11 +354,11 @@ int main()
|
||||
perror(logfile);
|
||||
return 7;
|
||||
}
|
||||
fprintf(fh1, "%s: Connexion de %s depuis %s commande: %s %s", conn.date, conn.user, ip, conn.cmd, conn.cmdline);
|
||||
fprintf(fh1, "%s: Connexion de %s depuis %s commande: %s %s\n", conn.date, conn.user, ip, conn.cmd, conn.cmdline);
|
||||
fclose(fh1);
|
||||
}else if (id<0)
|
||||
{
|
||||
printf("erreur de création du fork: %s", str);
|
||||
printf("erreur de création du fork: %s\n", str);
|
||||
}else
|
||||
{
|
||||
printf("%s\n", str);
|
||||
@ -380,6 +388,12 @@ int main()
|
||||
time( &now );
|
||||
sprintf( date, "%s", frtime(now));
|
||||
printf("Session %d de %s terminée le %s\n", connexions[i].pid, connexions[i].user, date);
|
||||
if ( (fh1 = fopen(logfile, "a")) == NULL)
|
||||
{
|
||||
perror(logfile);
|
||||
return 7;
|
||||
}
|
||||
fprintf(fh1, "%s: Connexion de %s terminée le %", hostname, connexions[i].date);
|
||||
for( j=i; j<x; j++ )
|
||||
{
|
||||
childrens[j] = childrens[j+1];
|
||||
|
Reference in New Issue
Block a user