Imported Upstream version 2.7
[ossec-hids.git] / src / win32 / setup-syscheck.c
1 /* @(#) $Id: ./src/win32/setup-syscheck.c, 2011/09/08 dcid Exp $
2  */
3
4 /* Copyright (C) 2009 Trend Micro Inc.
5  * All rights reserved.
6  *
7  * This program is a free software; you can redistribute it
8  * and/or modify it under the terms of the GNU General Public
9  * License (version 2) as published by the FSF - Free Software
10  * Foundation
11  */
12
13
14 #include "setup-shared.h"
15 #include "os_xml/os_xml.h"
16 #include "os_xml/os_xml_writer.h"
17
18 #define OSSEC_CONFIG_TMP  ".tmp.ossec.conf"
19
20
21 /* Enable Syscheck.*/
22 int main(int argc, char **argv)
23 {
24     char *status;
25     char *(xml_syscheck_status[])={"ossec_config","syscheck","disabled", NULL};
26
27     if(argc < 3)
28     {
29         printf("%s: Invalid syntax.\n", argv[0]);
30         printf("Try: '%s <dir> [enable|disable]'\n\n", argv[0]);
31         return(0);
32     }
33
34     /* Checking for directory. */
35     if(chdir(argv[1]) != 0)
36     {
37         printf("%s: Invalid directory: '%s'.\n", argv[0], argv[1]);
38         return(0);
39     }
40
41
42     /* Checking if ossec was installed already */
43     if(!fileexist(OSSECCONF))
44     {
45         printf("%s: OSSEC not installed yet. Exiting.\n", argv[0]);
46         return(0);
47     }
48
49
50     /* Checking status. */
51     if(strcmp(argv[2], "enable") == 0)
52     {
53         status = "no";
54     }
55     else
56     {
57         status = "yes";
58     }
59
60
61     /* Writing to the XML. */
62     if(OS_WriteXML(OSSECCONF, OSSEC_CONFIG_TMP, xml_syscheck_status,
63                    NULL, "no", status, 0) != 0)
64     {
65         printf("%s: Error writing to the Config file. Exiting.\n", argv[0]);
66         return(0);
67     }
68
69     /* Renaming config files */
70     unlink(OSSECLAST);
71     rename(OSSECCONF, OSSECLAST);
72     rename(OSSEC_CONFIG_TMP, OSSECCONF);
73
74     return(0);
75 }
76
77
78 /* EOF */