config parsing: Consider services with 'name' potential templates

Weird commit subject, but whatever. With this patch, we no longer
bomb out when encountering services that lack both 'host_name' and
'hostgroup_name' variable so long as they have a 'name' variable
and can thus be used as templates.

This brings config parsing in line with how Nagios does it, which
is a good thing for a project supposed to be a drop-in replacement.

Signed-off-by: Andreas Ericsson <ae@op5.se>
commands.c: Remove a debugging printf() statement

Signed-off-by: Andreas Ericsson <ae@op5.se>
Handle retention data gracefully when config changes

Previously, object settings changed by submitting external commands
were impossible to change via config, as the modified_attributes
variable would always trigger, and always be read in to see which
variables we should retain.

This has led to much confusion from people who have, for example,
disabled active checks through external commands, then changed
the settings for those active checks through configuration only to
notice that no active checks are run.

With this patch, we stash the configured object the first time we
change it and only print the changed variables to the retention
file, alongside the then-configured value. This means that we now
normally write less data in the retention data file, but when there
are things we actually need to remember we'll also have the config
for that setting at the time when the external command was submitted
to change the value. When we then read retention data back in, we can
compare the configured value with the last configured value and see
if the config has changed during the time Naemon was shut down. If it
has, we will use the new configuration value rather than the retained
settings. If it hasn't, we'll use the retained data.

So far, this patch only covers boolean variables for hosts and
services. Since we've disabled changing check- and eventhandler
commands, that covers most of it though (and only timeperiod settings
remain to be handled).

Contacts should be fixed in the same way, and will be soon.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Handle retention data gracefully for contacts

Same as with hosts and services, we only handle binary options for
this first patch.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Make find_bang_command() globally available

It makes sense to reuse it in other places, so let's do just that.

Signed-off-by: Andreas Ericsson <ae@op5.se>
Use find_bang_command() instead of duplicating functionality

This is primarily a janitorial rework in order to start getting rid
of the insane excess of strdup() and strtok() calls we issue when
reading retention data and, to some extent, configuration.

Signed-off-by: Andreas Ericsson <ae@op5.se>
retention data: Fix bit-twiddling of modified_attributes flags

The way to remove a particular flag from a bitfield is to use
bitwise AND with the inverse of the bit to remove. Subtracting
the value of the bit will only work if the bit is guaranteed to
be set, and will cause bitfield corruption if it's not.

Signed-off-by: Andreas Ericsson <ae@op5.se>
retention data: Prevent coredumps and memory leaks

Previously when reading modified timeperiods from objects, we would
free() the name of the timeperiod from the object and strdup() in a
new one. However, since quite some time now, we don't even copy the
name to the object anymore, but just assign it from the name used
for the timeperiod itself.

This patch brings the retention data code in line with the config
parsing routines, preventing coredumps (although only on debug
messages or when the same timeperiod has been changed for multiple
objects through external commands without a program restart in
between) and memory leaks (on soft restarts when a timeperiod has
changed for a single object).

Signed-off-by: Andreas Ericsson <ae@op5.se>