further preparations for 3.4.0alpha3
Revert "lib/ivykis: Point the submodule to github"

This reverts commit 5a0f89cc47e890e7975b3d1dfb35a4d02b668486.
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>
configure: fixed bashism in systemdsystemunitdir support

Signed-off-by: Tamas Pal <folti@balabit.hu>
Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
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>
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.
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>
LogProtoBufferedServer: fixed a SockAddr caching problem that shouldn't be user-visible

The log_proto_buffered_server_fetch() function improperly NULLed the
cached GSockAddr instance every time it attempted to read. However that
forthcoming read may return EAGAIN, which causes the sockaddr to remain
NULL.

In case an EOF is read the next time, log_proto_fetch() will return NULL as
the originating sockaddr for the partial message still in the buffer.

This bug shouldn't bite anyone as the cached sockaddr is only used for
udp() sources, but which in turn don't have partial messages nor EOFs.

Signed-off-by: Balazs Scheidler <bazsi@balabit.hu>
LogProtoFramedServer: change dynamic buffer allocation

Until now the buffer of LogProtoFramedServer class implementing
RFC5424 style framing was sized in accordance to the maximum frame length
processed by the class. More exactly it was sized as "max_frame_len + 10".

This could mean that if most of the messages are about the same size, that
the buffer is limited to hold one single message. This is certainly not
the best for performance, so be a bit more liberal when allocating this
buffer size, it is scaled to hold 16 messages, but at the same time limited
to 6*log_msg_size().

This is 48k buffer space for the default log_msg_size() value of 8k and
matches exactly with the buffer size used by LogProtoTextServer.

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>