diff --git a/main.c b/main.c index 91ed5af..599beb5 100644 --- a/main.c +++ b/main.c @@ -63,6 +63,7 @@ int explode( char * str, char * separator, size_t m, size_t n, char exploded[m][ int readconfig( struct config * cfg ) { FILE * fh = NULL; + FILE * fh1 = NULL; char path[2][30] = {"/etc/sshdetect.conf", ""}; int x; int retval=0; @@ -77,18 +78,19 @@ int readconfig( struct config * cfg ) { sprintf( path[1], "%s%s", homepath, "/.config/sshdetect.conf" ); } - sprintf( logfilepath, "%s%s", homepath, "/.locale/share/sshdetect.log"); + sprintf( logfilepath, "%s%s", homepath, "/.local/share/sshdetect.log"); for(x=0;x<2;x++) { if ((fh = fopen( path[x], "r")) == NULL) { if (debug >= 1) perror(path[x]); - if(x==1) retval = -1; + retval = -1; }else { strcpy( cfg->configfile, path[x]); if (debug >= 1) printf("Found config file: %s\n", path[x]); x = 3; + retval = 0; } } if (fh != NULL) @@ -98,20 +100,22 @@ int readconfig( struct config * cfg ) explode(str, "= \n", 2, 1024, exploded); if ( strcmp( exploded[0], "commande") == 0 ) { - if ( fopen(exploded[1],"r") != NULL) + if ( (fh1 = fopen(exploded[1],"r")) != NULL) { strcpy( cfg->commande, exploded[1] ); if (debug >= 1) printf("Found command: %s\n", cfg->commande); + fclose(fh1); }else { if (debug >= 1) perror(exploded[1]); } }else if( strcmp( exploded[0], "logfile") == 0) { - if ( fopen(exploded[1], "a") != NULL ) + if ( (fh1 = fopen(exploded[1], "a")) != NULL ) { strcpy( cfg->logfile, exploded[1] ); if (debug >= 1) printf("Found logfile: %s\n", cfg->logfile); + fclose(fh1); } }else if( strcmp( exploded[0], "hostname") == 0 ) { @@ -122,12 +126,14 @@ int readconfig( struct config * cfg ) } if ( cfg->logfile[0] == 0 ) { - if ( fopen("/var/log/sshdetect.log", "a") != NULL ) + if ( (fh1 = fopen("/var/log/sshdetect.log", "a")) != NULL ) { strcpy( cfg->logfile, "/var/log/sshdetect.log" ); - }else if ( fopen(logfilepath, "a") != NULL ) + fclose(fh1); + }else if ( (fh1 = fopen(logfilepath, "a")) != NULL ) { strcpy( cfg->logfile, logfilepath ); + fclose(fh1); }else { if (debug >= 1) perror(logfilepath);