6c230b4f6a696c89552d7d3481cfecd8c02adf5d
[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
17 #define OSSEC_CONFIG_TMP  ".tmp.ossec.conf"
18
19
20 /* Enable Syscheck.*/
21 int main(int argc, char **argv)
22 {
23     char *status;
24     const char *(xml_syscheck_status[])={"ossec_config","syscheck","disabled", NULL};
25
26     if(argc < 3)
27     {
28         printf("%s: Invalid syntax.\n", argv[0]);
29         printf("Try: '%s <dir> [enable|disable]'\n\n", argv[0]);
30         return(0);
31     }
32
33     /* Checking for directory. */
34     if(chdir(argv[1]) != 0)
35     {
36         printf("%s: Invalid directory: '%s'.\n", argv[0], argv[1]);
37         return(0);
38     }
39
40
41     /* Checking if ossec was installed already */
42     if(!fileexist(OSSECCONF))
43     {
44         printf("%s: OSSEC not installed yet. Exiting.\n", argv[0]);
45         return(0);
46     }
47
48
49     /* Checking status. */
50     if(strcmp(argv[2], "enable") == 0)
51     {
52         status = "no";
53     }
54     else
55     {
56         status = "yes";
57     }
58
59
60     /* Writing to the XML. */
61     if(OS_WriteXML(OSSECCONF, OSSEC_CONFIG_TMP, xml_syscheck_status,
62                    "no", status) != 0)
63     {
64         printf("%s: Error writing to the Config file. Exiting.\n", argv[0]);
65         return(0);
66     }
67
68     /* Renaming config files */
69     unlink(OSSECLAST);
70     rename(OSSECCONF, OSSECLAST);
71     rename(OSSEC_CONFIG_TMP, OSSECCONF);
72
73     return(0);
74 }
75
76
77 /* EOF */