Imported Upstream version 2.5.1
[ossec-hids.git] / src / win32 / setup-syscheck.c
1 /* @(#) $Id$ */
2
3 /* Copyright (C) 2009 Trend Micro Inc.
4  * All rights reserved.
5  *
6  * This program is a free software; you can redistribute it
7  * and/or modify it under the terms of the GNU General Public
8  * License (version 2) as published by the FSF - Free Software
9  * Foundation
10  */
11        
12
13 #include "setup-shared.h"
14 #include "os_xml/os_xml.h"
15 #include "os_xml/os_xml_writer.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     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                    NULL, "no", status, 0) != 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 */