Allow --version to work in debug mode

In debug mode, we use msg_debug(), but the eventlog context does not
get initialized at the time --version is handled. Thus, syslog-ng -d
-V will segfault, which isn't exactly useful.

This patch moves the eventlog context initialization earlier, and
thereby fixes the issue.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Do not link anything but libsyslog-ng against ivykis

There is no need to link anything but libsyslog-ng against ivykis: the
rest will have the symbols available via libsyslog-ng, and linking
again can trigger constructors, which is not something we want.

For this reason, this patch stops libsyslog-ng-crypto from being
linked to ivykis directly.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
autogen.sh: Create configure.gnu ourselves in submodules

To make it easier to use upstream git repos as submodules, which do
not have configure.gnu, create those from within autogen.sh.

This way, it becomes much easier to switch to an upstream repo, and
still continue reaping the benefits the configure.gnu brings us (such
as forcing a static linkage).

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
lib/: Use upstream ivykis

This patch converts syslog-ng to use upstream ivykis,
unmodified. Apart from the boring struct and type renaming stuff,
there is one major change: iv_fd_pollable() is gone, we have
iv_fd_register_try().

As such, the logic in log_reader_start_watches() and
log_writer_start_watches() was updated to use the upstream API
instead.

The control socket code was also updated to use iv_fd_register_try(),
because we want synchronous registration in that case, and
iv_fd_register_try() provides that for us.

Furthermore, we now use iv_set_fatal_msg_handler() to print ivykis
errors to stderr, instead of syslog (this is functionally equivalent
to what the balabit-patched ivykis did).

The included ivykis is also updated to 0.30 (+ two small patches), and
the minimum ivykis requirement when compiling with a system ivykis has
been increased to 0.30 aswell, and the linking magic updated to use
the combined libivykis, and not search for ivykis-modules anymore.

And since the git submodule now points to upstream, and the
configure.gnu for ivykis is generated by our own autogen.sh, we need
to get that into the dist tarball. This is accomplished by including
it in lib/Makefile.am's EXTRA_DIST.

Many thanks to Lennert Buytenhek <buytenh@wantstofly.org> and Balazs
Scheidler <bazsi@balabit.hu> for their invaluable help.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
lib/ivykis: Update to a new upstream commit

Updated the lib/ivykis submodule to point to an upstream commit that
has a deadlock triggered by syslog-ng fixed.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
configure.in: Check for utmp.h too

Check the existence of utmp.h too at configure time, because code
relies on this check already. This makes it so that the getutent()
compatibility function gets used on FreeBSD 8, and makes afuser
loadable again.

Reported-by: Peter Czanik <czanik@balabit.hu>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Fix the eventlog context initialisation

A regression introduced a few patches earlier, that meant to bring
eventlog context initialisation earlier broke the test suite.

To fix both problems, app_startup() will call msg_init() once again,
and msg_init() was made idempotent: once called, it will be a no-op if
called another time. This allows us to initialize the context early so
syslog-ng --version will continue working in debug mode, yet, still
allow tests to call app_startup() only, without another explicit call
to msg_init().

Reported-by: Jose Oliveira <jpo@di.uminho.pt>
Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Update to, and require ivykis 0.30.1

Now that ivykis 0.30.1 is out, update configure.in to require that
version, and the git submodule to include it.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Preparations for 3.3.5.90

NEWS & Version updated for the 3.3.5.90 (3.3.6 Release Candidate)
release.
afsql: Create proper indexes for Oracle DBs.

When creating an index for an Oracle DB, the field name was enclosed
in apostrophes, which made Oracle very unhappy: it did not associate
the index with the intended field.

With other databases, the field name is not quoted in the CREATE INDEX
statement, and for Oracle, it shouldn't be, either.

This patch corrects the mistake, and removes the apostrophes in the
Oracle case too.

Signed-off-by: Gergely Nagy <algernon@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
log_proto_buffered_server_apply_state: fixed a complete source-file-resend in case encoding is used

The size of the raw data can grow up to max_buffer_size and at reload time
raw_buffer_size was validated against init_buffer_size, which is clearly
wrong as the buffer can grow at runtime.

Signed-off-by: Juhasz Viktor <jviktor@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
logproto: refactor fixed encoding lookup into a separate function

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogProto: fixed a bug in fixed-size-encoding detection

Due to a typo, fixed-size encodings were not properly recognized, causing
syslog-ng to use the slow-path in case encoding() was used on a source.

This change fixes that issue, and at the same time publishes the function
log_proto_get_char_size_for_fixed_encoding() so that its unit test can call
it directly.

Cc: <syslog-ng-stable@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogProtoTextServer: fixed a possible memory leak in case encoding() was used

In case encoding was used on a source, its related data structures were
not properly freed as the destructor function wasn't properly registered.

Cc: <syslog-ng-stable@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogProtoFramedServer: fixed an incorrect error message

This patch changes the generic I/O error message to reflect that it
actually can apply to the framed data as well as the header.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogProtoDGramServer: encoding is to be applied to individual frames

Instead of trying to make up missing characters in one frame from the next,
treat them individually, especially as they might come from a different
source.

The same change is applied to LogProtoRecordServer used to read binary
files.

Cc: <syslog-ng-stable@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
Merge remote-tracking branch '3.3/master'

Conflicts:
	.gitmodules
	NEWS
	VERSION
	configure.in
	lib/Makefile.am
	lib/ivykis
syslog-ng/main: refactor interactive command line setup into a separate function

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
afsocket: handle max_connections validation properly on SIGHUP

In case a SIGHUP was processed, the num_connections variable got reset to
zero, which made it possible to accept connections excess the
max-connections() option. This patch fixes that by properly setting
the number of connections after reload.

Reported-By: Sandor Geller <wildy@muhelybt.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
syslog-format: increase the limit for SDATA value length to 64k

Reported-By: Sergey <cloun-rulez@yandex.ru>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>