X-Git-Url: http://ftp.carnet.hr/carnet-debian/scm?a=blobdiff_plain;ds=sidebyside;f=src%2Fwin32%2Fadd-localfile.c;h=8168af5913eed3d1273619d8b156d0664b8be11d;hb=3f728675941dc69d4e544d3a880a56240a6e394a;hp=8cf11e43edd957b7e862f187c40a2641d24d6054;hpb=927951d1c1ad45ba9e7325f07d996154a91c911b;p=ossec-hids.git diff --git a/src/win32/add-localfile.c b/src/win32/add-localfile.c old mode 100755 new mode 100644 index 8cf11e4..8168af5 --- a/src/win32/add-localfile.c +++ b/src/win32/add-localfile.c @@ -1,6 +1,3 @@ -/* @(#) $Id: ./src/win32/add-localfile.c, 2011/09/08 dcid Exp $ - */ - /* Copyright (C) 2009 Trend Micro Inc. * All rights reserved. * @@ -10,12 +7,12 @@ * Foundation */ - #include #include #include #include #include + #include "os_regex/os_regex.h" #define OSSECCONF "ossec.conf" @@ -23,49 +20,48 @@ int total; + int fileexist(char *file) { FILE *fp; - /* Opening file */ + /* Open file */ fp = fopen(file, "r"); - if(!fp) - return(0); + if (!fp) { + return (0); + } fclose(fp); - return(1); + return (1); } int dogrep(char *file, char *str) { - char line[OS_MAXSTR +1]; + char line[OS_MAXSTR + 1]; FILE *fp; - /* Opening file */ + /* Open file */ fp = fopen(file, "r"); - if(!fp) - return(0); + if (!fp) { + return (0); + } - /* Clearing memory */ - memset(line, '\0', OS_MAXSTR +1); + /* Clear memory */ + memset(line, '\0', OS_MAXSTR + 1); - /* Reading file and looking for str */ - while(fgets(line, OS_MAXSTR, fp) != NULL) - { - if(OS_Match(str, line)) - { + /* Read file and look for str */ + while (fgets(line, OS_MAXSTR, fp) != NULL) { + if (OS_Match(str, line)) { fclose(fp); - return(1); + return (1); } } fclose(fp); - return(0); + return (0); } - - -/* Check is syscheck is present in the config */ +/* Check if syscheck is present in the config */ int config_file(char *name, char *file, int quiet) { char ffile[256]; @@ -73,100 +69,80 @@ int config_file(char *name, char *file, int quiet) ffile[255] = '\0'; - - /* Checking if the file has a variable format */ - if(strchr(file, '%') != NULL) - { + /* Check if the file has a variable format */ + if (strchr(file, '%') != NULL) { time_t tm; struct tm *p; tm = time(NULL); p = localtime(&tm); - if(strftime(ffile, 255, file, p) == 0) - { - return(-1); + if (strftime(ffile, 255, file, p) == 0) { + return (-1); } - } - else - { + } else { strncpy(ffile, file, 255); } - - /* Looking for ffile */ - if(!fileexist(ffile)) - { - if(quiet == 0) - { + /* Look for ffile */ + if (!fileexist(ffile)) { + if (quiet == 0) { printf("%s: Log file not existent: '%s'.\n", name, file); } - return(-1); + return (-1); } - if(dogrep(OSSECCONF, file)) - { + if (dogrep(OSSECCONF, file)) { printf("%s: Log file already configured: '%s'.\n", - name, file); - return(0); + name, file); + return (0); } - - /* Add iis config config */ + /* Add IIS config */ fp = fopen(OSSECCONF, "a"); - if(!fp) - { + if (!fp) { printf("%s: Unable to edit configuration file.\n", name); - return(0); + return (0); } - printf("%s: Adding log file to be monitored: '%s'.\n", name,file); + printf("%s: Adding log file to be monitored: '%s'.\n", name, file); fprintf(fp, "\r\n" - "\r\n" - "\r\n" - "\r\n" - " \r\n" - " %s\r\n" - " syslog\r\n" - " \r\n" - "\r\n\r\n", file); - + "\r\n" + "\r\n" + "\r\n" + " \r\n" + " %s\r\n" + " syslog\r\n" + " \r\n" + "\r\n\r\n", file); printf("%s: Action completed.\n", name); fclose(fp); - return(0); - + return (0); } -/* Setup windows after install */ +/* Setup Windows after install */ int main(int argc, char **argv) { int quiet = 0; - if(argc < 2) - { + if (argc < 2) { printf("%s: Invalid syntax.\n", argv[0]); printf("Try: '%s '\n\n", argv[0]); } - /* Looking for the quiet option */ - if((argc == 3) && (strcmp(argv[2],"--quiet") == 0)) - { + /* Look for the quiet option */ + if ((argc == 3) && (strcmp(argv[2], "--quiet") == 0)) { quiet = 1; } - - /* Checking if ossec was installed already */ - if(!fileexist(OSSECCONF)) - { + /* Check if OSSEC-HIDS was installed already */ + if (!fileexist(OSSECCONF)) { printf("%s: Unable to find ossec config: '%s'.\n", argv[0], OSSECCONF); - } - - else - { + } else { config_file(argv[0], argv[1], quiet); } - return(0); + return (0); }