2 # Shell script update functions for the OSSEC HIDS
3 # Author: Daniel B. Cid <daniel.cid@gmail.com>
4 # Last modification: May 24, 2006
16 ls -la ${OSSEC_INIT} > /dev/null 2>&1
19 if [ "X$DIRECTORY" = "X" ]; then
20 echo "# ($FUNCNAME) ERROR: The variable DIRECTORY wasn't set" 1>&2
24 ls -la $DIRECTORY > /dev/null 2>&1
42 if [ "X$DIRECTORY" = "X" ]; then
43 echo "# ($FUNCNAME) ERROR: The variable DIRECTORY wasn't set." 1>&2
48 # Checking if the directory is valid.
49 _dir_pattern_update="^/[-a-zA-Z0-9/\.-]{3,128}$"
50 echo $DIRECTORY | grep -E "$_dir_pattern_update" > /dev/null 2>&1
52 echo "# ($FUNCNAME) ERROR: directory name ($DIRECTORY) doesn't match the pattern $_dir_pattern_update" 1>&2
67 cat $DIRECTORY/etc/ossec.conf | grep "<client>" > /dev/null 2>&1
73 cat $DIRECTORY/etc/ossec.conf | grep "<remote>" > /dev/null 2>&1
102 $DIRECTORY/bin/ossec-control start
113 $DIRECTORY/bin/ossec-control stop
115 # We also need to remove all syscheck queue file (format changed)
116 if [ "X$VERSION" = "X0.9-3" ]; then
117 rm -f $DIRECTORY/queue/syscheck/* > /dev/null 2>&1
118 rm -f $DIRECTORY/queue/agent-info/* > /dev/null 2>&1
120 rm -f $DIRECTORY/queue/syscheck/.* > /dev/null 2>&1
130 OSSEC_CONF_FILE="$DIRECTORY/etc/ossec.conf"
132 # Backing up the old config
133 cp -pr ${OSSEC_CONF_FILE} "${OSSEC_CONF_FILE}.$$.bak"
135 # Getting rid of old rules entries
136 grep -Ev "</*rules>|<include>|<list>|<decoder>|<decoder_dir|<rule_dir>|rules global entry" ${OSSEC_CONF_FILE} > "${OSSEC_CONF_FILE}.$$.tmp"
138 # Customer decoder, decoder_dir, rule_dir are carried over during upgrade
139 grep -E '<decoder>|<decoder_dir|<rule_dir>' ${OSSEC_CONF_FILE} | grep -v '<!--' >> "${OSSEC_CONF_FILE}.$$.tmp2"
141 # Check for custom files that may have been added in <rules> element
142 for i in `grep -E '<include>|<list>' ${OSSEC_CONF_FILE} | grep -v '<!--'`
144 grep "$i" ${RULES_TEMPLATE}>/dev/null || echo " $i" >> "${OSSEC_CONF_FILE}.$$.tmp2"
147 # Putting everything back together
148 cat "${OSSEC_CONF_FILE}.$$.tmp" > ${OSSEC_CONF_FILE}
149 rm "${OSSEC_CONF_FILE}.$$.tmp"
150 echo "" >> ${OSSEC_CONF_FILE}
151 echo "<ossec_config> <!-- rules global entry -->" >> ${OSSEC_CONF_FILE}
152 grep -v '</rules>' ${RULES_TEMPLATE} >> ${OSSEC_CONF_FILE}
153 cat "${OSSEC_CONF_FILE}.$$.tmp2" >> ${OSSEC_CONF_FILE}
154 echo "</rules>" >> ${OSSEC_CONF_FILE}
155 echo "</ossec_config> <!-- rules global entry -->" >> ${OSSEC_CONF_FILE}
156 rm "${OSSEC_CONF_FILE}.$$.tmp2"