nvtable: fix an NV registry corruption in the unit tests

nv_registry_add_alias() used the passed in pointer to the alias verbatim,
without copying it.  However the unit test program generated alias names
dynamically, e.g.  editing the memory area that was used to store the hash
table key.

Since this wasn't intuitive at all, this patch changes the code so that the
key in the NV registry is now always duplicated before insertion.

Signed-off-by: Igor Ippolitov <iippolitov@gmail.com>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
cfg: Add a cfg_load_config() function

This new function can be used to load configuration from memory, instead
of a file, which is a boon for writing tests.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
str-format: Moved format_hex_string to str-format and added delimitered version.

Added unit tests for simple and delimitered variant.
Replaced data_to_hex_string with format_hex_string_with_delimiter.

Signed-off-by: Viktor Tusa <tusa@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
persist-state: Add foreach function on persist-state entries.

Signed-off-by: Viktor Tusa <tusa@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
persist-state: Add dump and edit mode to persist_state_start.

Using edit or dump mode on an invalid file results in an error,
when starting persist-state instead of silently creating a new one.
In dump mode, the not used entries (in_use = 0) are read as well
at load time instead of being purged.

Signed-off-by: Viktor Tusa <tusa@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
persist-state: Add PersistableStatePresenter.

PersistableStatePresenter is an interface, which turns *State objects into
PresentedPersistableState.

Every *State object which has it's own PersistableStatePresenter
implementation can represent/load itself into/from a
PresentedPersistableState.

PresentedPersistableState is an abstract interface, which provides
functions to represent basic types in its implementation.
Currently it has only one implementation, JsonPresentedPersistableState.

Signed-off-by: Viktor Tusa <tusa@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
persist-state: remove tailing semicolons from the end of functions

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
pathutils: Added filesystem path-related utility functions.

Signed-off-by: Viktor Tusa <tusa@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
Merge branch 'persist-tool-integrate'
LogPipe: add GlobalConfig parameter to constructors

This patch promotes the GlobalConfig *cfg parameter from log_pipe_init()
to the constructor, so it is already present tha log_pipe_init() time.

This causes a lot of tickle-down effects as all LogPipe derivates must
be changed to add this argument.

This is in preparation for two things:
  * further remove the usage of the global "configuration" variable
  * allow LogPipe methods that get called earlier than _init()
  * the configuration instance is always available, in every
    LogPipe instance, not just those where log_pipe_init() was called
    with a non-NULL pointer.

It is still possible to reassign a LogPipe instance to a different
GlobalConfig by calling the log_pipe_set_config() method, but now that is
the exception and not the norm.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
afsocket: avoid stale cfg pointer in AFSocketSourceConnection->reader

AFSocketSourceConnection instances are propagated upon reload from the old
to the new configuration, thus its LogPipe->cfg pointers has to
be updated both in AFSocketSourceConnection and its LogReader instance.

LogReader instances do not use their cfg pointers, so it used to be NULL,
prior to introducing the GlobalConfig *cfg argument to the LogPipe
constructor. I wanted to change this and make cfg always present, which
means that it has to be maintained, that's what this patch does.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
affile: avoid stale cfg pointer in AFFileDestWriter->writer

AFFileDestWriter instances are propagated upon reload from the old
to the new configuration, thus its LogPipe->cfg pointers has to
be updated both in AFFileDestWriter and its LogWriter instance.

LogWriter instances do not use their cfg pointers, so it used to be NULL,
prior to introducing the GlobalConfig *cfg argument to the LogPipe
constructor. I wanted to change this and make cfg always present, which
means that it has to be maintained, that's what this patch does.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogPipe: reduce the use of the "configuration" global

Now as LogPipe gets a GlobalConfig instance in its constructor we can avoid
using the global variable directly.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
str-format: Fixed format_hex_string_with_delimiter.

g_snprintf adds a terminating NULL character, which was not considered.
We need more space for this extra character, so the result length
check should also be tweaked.

Signed-off-by: Viktor Tusa <tusa@balabit.hu>
Merge pull request #78 from talien/f/format-hex-string-fix

str-format: Fixed format_hex_string_with_delimiter.
Merge pull request #81 from balabit/3.6/f/add-globalconfig-to-logpipe-constructor

3.6/f/add globalconfig to logpipe constructor
escape glob to avoid weird behaviour when cwd contains .pdb files
Merge pull request #82 from ccin2p3/f/patterndb

escape glob to avoid weird behaviour when cwd contains .pdb files