]> git.tuebingen.mpg.de Git - paraslash.git/log
paraslash.git
6 years agoaft.c: Trivial whitespace fix.
Andre Noll [Wed, 18 Apr 2018 18:33:32 +0000 (20:33 +0200)]
aft.c: Trivial whitespace fix.

6 years agoserver: Add --http-listen-address and --dccp-listen-address.
Andre Noll [Sat, 17 Mar 2018 01:11:01 +0000 (02:11 +0100)]
server: Add --http-listen-address and --dccp-listen-address.

Currently the http and the dccp sender accept connections on all IP
addresses. This commit makes it possible to configure the senders to
listen only on the specified subset of addresses.

To make this work, the sender_status structure has to be extended to
store an array of file descriptors rather than just a single one.
Several places need to iterate over all listening sockets of the
sender. The new FOR_EACH_LISTEN_FD macro helps to avoid duplicating
the corresponding loop.

The status part of the sender command now prints the listening
addresses instead of just on/off. This is why we also maintain the
ascii representation of the listening addresses in the sender_status
structure and introduce the format_url() helper to format host/port
pairs.

6 years agoMove MAX_HOSTLEN from server.h to net.h.
Andre Noll [Wed, 7 Mar 2018 18:45:09 +0000 (19:45 +0100)]
Move MAX_HOSTLEN from server.h to net.h.

This generic networking-related constant does not belong to
server.h. However, since server.h uses the constant, we have to make
sure that net.h is included before server.h.

6 years agoserver: Implement --listen-address for control service.
Andre Noll [Wed, 7 Mar 2018 11:32:15 +0000 (12:32 +0100)]
server: Implement --listen-address for control service.

For hosts with multiple IP addresses one might want to configure the
listening sockets so that connections can only arrive on a subset of
the host's addresses. This patch implements this feature.

Unlike para_listen_simple() the new para_listen() receives an optional
argument to let the caller specify the listening address in addition
to the port number. para_listen_simple() is now a simple wrapper
that passes a NULL pointer as the new argument which indicates that
the socket should listen on all local addresses, just like prior to
this change.

The set of listening addresses for the control service of para_server
can be specified via the new --listen-address option. This option
can be given multiple times, once for each listening address.

Due to this change the server needs to maintain more than a single
file descriptor to dispatch incoming connections. Hence the integer
->listen_fd of struct server_command_task has to be replaced by an
array of file descriptors and the {pre,post}_select methods of the
command task have iterate over all descriptors in the array.

The meaning of the --port option has changed due to the new option:
since the argument to --listen-address can also contain a port number,
the argument to --port is only used for addresses with no port number,
or if --listen-address is not given at all.

Although the http and dccp senders also open a listening socket, this
commit affects only the control service of para_server (listening on
TCP 2990 by default). Senders will be covered in the next commit.

6 years agonet: Combine para_listen() and para_listen_simple().
Andre Noll [Wed, 7 Mar 2018 11:00:58 +0000 (12:00 +0100)]
net: Combine para_listen() and para_listen_simple().

The only caller of para_listen() is para_listen_simple(), since
flowops are only used for active sockets.

6 years agonet: Improve error diagnostics of makesock_addrinfo().
Andre Noll [Thu, 22 Mar 2018 01:09:43 +0000 (02:09 +0100)]
net: Improve error diagnostics of makesock_addrinfo().

Since the function iterates over all addresses in the passed
addressinfo structure, errors can be non-fatal and may even be
expected. Therefore the function does not log any errors from
socket(2), setsockopt(2), connect(2) or bind(2), but only returns
a generic -E_MAKESOCK error code if none of the addressinfo members
worked. Unfortunately, this means it's impossible to tell from the
log message which of these system calls has failed.

This patch changes the function to also log the errors from the above
system calls, but only with loglevel notice. This way the non-fatal
errors are not shown by default (since the default loglevel is
"warning"), but one can easily activate them by specifying a lower
loglevel.

6 years agosend_common: Improve error diagnostics of generic_com_on().
Andre Noll [Sat, 17 Mar 2018 01:10:55 +0000 (02:10 +0100)]
send_common: Improve error diagnostics of generic_com_on().

Currently the function returns an error code but does not log a message
on errors. The callers, http_send_init() and dccp_send_init(), print
the strerror text with no indication that it is was generic_com_on()
which caused the error.

This commit moves the log messages from the callers to generic_com_on()
and changes the return type of generic_com_on() to void because both
callers now ignore the return value. The new log messages include a
text which tells the user what went wrong.

6 years agosend_common: Combine generic_com_on() and open_sender().
Andre Noll [Sat, 17 Mar 2018 00:57:43 +0000 (01:57 +0100)]
send_common: Combine generic_com_on() and open_sender().

The latter function is only called by the former, and both are short.

6 years agofd: Let readv_nonblock() recover from EINTR.
Andre Noll [Mon, 26 Mar 2018 22:39:48 +0000 (00:39 +0200)]
fd: Let readv_nonblock() recover from EINTR.

No need to fail the operation if the read was interrupted by a signal.

The patch also fixes some minor issues in the documentation:
a typo ("The" was incorrectly capitalized) and a missing \ref
for xwrite().  We use the opportunity to get rid of the \a and \p
font annotations. This improves the readability of the source code,
which is more imporatant than nice looking web pages. However, we
only touch those parts of the documentation which are modified anyway.

6 years agomixer: Improve sleep subcommand.
Andre Noll [Fri, 5 Jan 2018 15:11:36 +0000 (16:11 +0100)]
mixer: Improve sleep subcommand.

This avoids a pointless exec of "para_client stop" in case no fade-out
mood is given, and another pointless "para_client play" exec which
was executed when already playing.

Other than that behaviour should be identical.

6 years agohttp_recv: Improve error diagnostics.
Andre Noll [Wed, 21 Mar 2018 12:56:04 +0000 (13:56 +0100)]
http_recv: Improve error diagnostics.

If the http receiver is started when the stream is stopped or paused,
para_recv exits silently with no error message. Let's tell the user
what is going on.

6 years agoafh_recv: Improve error diagnostics.
Andre Noll [Tue, 9 Jan 2018 23:19:13 +0000 (00:19 +0100)]
afh_recv: Improve error diagnostics.

There are many reasons for afh_recv_open() to fail. For example, the
afh receiver could be unable to open its input file, or the given
begin chunk was larger than the end chunk. At the moment the error
reporting is a bit scarce since only the string of the error code is
printed. This commit makes afh_recv_open() print also the reason for
the error and the name of the file that caused the error.

6 years agoafs: Document ->lpr of struct afs_callback_arg.
Andre Noll [Mon, 26 Mar 2018 23:23:07 +0000 (01:23 +0200)]
afs: Document ->lpr of struct afs_callback_arg.

This should have been documented when the ->lpr member was introduced
two years ago in commit ba0a963f (server: Convert com_add() to lopsub).

6 years agobase64.h: Add Copyright and Doxygen header.
Andre Noll [Tue, 20 Mar 2018 02:58:09 +0000 (03:58 +0100)]
base64.h: Add Copyright and Doxygen header.

6 years agodoxygen: Exclude config.h.
Andre Noll [Tue, 20 Mar 2018 03:00:14 +0000 (04:00 +0100)]
doxygen: Exclude config.h.

This file is generated by autoconf and contains no doxygen
comments. Therefore it should not be part of the web documentation.

6 years agorecv: Mention default for --receiver.
Andre Noll [Wed, 21 Mar 2018 12:40:23 +0000 (13:40 +0100)]
recv: Mention default for --receiver.

It's not obvious that http is the default receiver, so let's mention this.

6 years agorecv: Add description of para_recv.
Andre Noll [Mon, 12 Mar 2018 17:32:52 +0000 (18:32 +0100)]
recv: Add description of para_recv.

para_recv is the only executable whose man page has no short
description at the beginning.

6 years agoclient: Remove unused ->config_file member.
Andre Noll [Wed, 14 Mar 2018 19:39:28 +0000 (20:39 +0100)]
client: Remove unused ->config_file member.

Currently we store a copy of the config file path in the client task
structure for no reason at all. Remove it.

6 years agoclient: Remove duplicate error message.
Andre Noll [Wed, 14 Mar 2018 19:33:58 +0000 (20:33 +0100)]
client: Remove duplicate error message.

client_parse_config() returns an error code, so the caller is responsible
for printing a suitable error message.

6 years agoclient: Fix loglevel setting.
Andre Noll [Sat, 17 Mar 2018 22:29:12 +0000 (23:29 +0100)]
client: Fix loglevel setting.

If --loglevel is given in the config file but not at the command line,
the value from the config file should be used. However, currently we
use the default value in this case. Moreover, client_parse_config()
sets the loglevel *after* it already printed some log messages.

This commit changes client_parse_config() to initialize the loglevel
pointer right after the command line and config file options have
been merged.

6 years agocommand.c: Document return value of handle_connect().
Andre Noll [Mon, 26 Mar 2018 23:09:35 +0000 (01:09 +0200)]
command.c: Document return value of handle_connect().

Kind of pointless, but gets rid of the following Doxygen warning:

/home/maan/scm/paraslash/server.h:112: warning: return type of member handle_connect is not documented

6 years agoFix help text of the dccp receiver.
Andre Noll [Mon, 12 Mar 2018 19:18:07 +0000 (20:18 +0100)]
Fix help text of the dccp receiver.

CCIDs are no longer reported in the server info output for more than
three years, see commit 435ad905 (Add sender subcommand "status").

6 years agosend_common: Remove outdated comment.
Andre Noll [Thu, 8 Mar 2018 20:39:24 +0000 (21:39 +0100)]
send_common: Remove outdated comment.

Commit 8dab386f (Rework para_accept()) from eight years ago changed
the function to receive also a pointer to the read fd set and pass
this pointer to para_accept() which performs the check for readability
of the socket file descriptor. Since then the comment which says that
the caller must check the fd set is stale.

6 years agouser_list: Make list head static.
Andre Noll [Sun, 18 Feb 2018 14:48:42 +0000 (15:48 +0100)]
user_list: Make list head static.

It is only used in user_list.c.

6 years agoafs: Allow database switching on sighup.
Andre Noll [Wed, 3 Jan 2018 01:49:22 +0000 (02:49 +0100)]
afs: Allow database switching on sighup.

Currently the database dir is set at startup and stays unmodified even
after the sighup handler has reloaded a configuration which specifies
a different database path.

This patch makes it possible to switch to a different database after
SIGHUP was received. To make this work, we only have invalidate the
database_dir pointer after the database has been closed.

6 years agoafs: Free current mood or playlist on exit.
Andre Noll [Wed, 3 Jan 2018 00:07:45 +0000 (01:07 +0100)]
afs: Free current mood or playlist on exit.

Another harmless memory leak in the afs process which only occurs
on exit.

6 years agoafs: Free status items on exit.
Andre Noll [Wed, 3 Jan 2018 00:01:42 +0000 (01:01 +0100)]
afs: Free status items on exit.

The server process frees the memory allocated for the status items
on exit but the afs process does not. To avoid the leak we have to
make free_status_items() public.

6 years agoafs: Shutdown signals on exit.
Andre Noll [Mon, 1 Jan 2018 03:35:53 +0000 (04:35 +0100)]
afs: Shutdown signals on exit.

This frees the signal task structure, avoiding a (harmless) memory
leak on exit.

6 years agoserver: Free parse result also in afs.
Andre Noll [Mon, 1 Jan 2018 03:28:29 +0000 (04:28 +0100)]
server: Free parse result also in afs.

Both the server and the afs process need to access the lopsub parse
result which is allocated and initialized prior to the fork(2) that
creates the afs process. Hence both processes should free this memory
on exit.

The new public free_lpr() frees the memory allocated by both parse result
structures.

6 years agoafs: Deplete user list at startup.
Andre Noll [Mon, 1 Jan 2018 03:13:17 +0000 (04:13 +0100)]
afs: Deplete user list at startup.

The afs process does not need the user list, so we may free the list
in server.c before calling init_afs().

6 years agoserver: Free audio file header on exit.
Andre Noll [Tue, 2 Jan 2018 23:05:06 +0000 (00:05 +0100)]
server: Free audio file header on exit.

This fixes a harmless memory leak which occurs when para_server terminates
while a header stream is active.

6 years agosender: Deplete ACLs on exit.
Andre Noll [Thu, 16 Nov 2017 02:35:01 +0000 (03:35 +0100)]
sender: Deplete ACLs on exit.

This teaches the dccp and the http sender to empty their access control
lists during shutdown, avoiding some (harmless) memory leaks at exit.

6 years agoRemove some unused includes from {dccp,http}_send.c.
Andre Noll [Thu, 16 Nov 2017 01:41:31 +0000 (02:41 +0100)]
Remove some unused includes from {dccp,http}_send.c.

The access control and close on fork lists are handled in send_common.c,
so the two senders do not need to know anything about them.

The dccp sender does not perform chunk queuing, so it does not need to
include chunk_queue.h.

6 years agoserver: Make argument of user_list_init() constant.
Andre Noll [Sun, 31 Dec 2017 22:37:16 +0000 (23:37 +0100)]
server: Make argument of user_list_init() constant.

The function does not modify the memory pointed to by user_list_file.

6 years agoserver: Deplete user list on exit.
Andre Noll [Sun, 22 Oct 2017 12:46:16 +0000 (14:46 +0200)]
server: Deplete user list on exit.

This eliminates a bunch of valgrind memory leak warnings when
run with --leak-check=full --show-leak-kinds=all.

6 years agoserver: Combine user_list_init() and populate().
Andre Noll [Sun, 13 Aug 2017 20:07:57 +0000 (22:07 +0200)]
server: Combine user_list_init() and populate().

The latter is only called by the former, and both are short enough.

6 years agoserver: Move para_fgets() to user_list.c.
Andre Noll [Sun, 13 Aug 2017 00:36:14 +0000 (02:36 +0200)]
server: Move para_fgets() to user_list.c.

It's only used there, so we can make it static and dedoxify its
documentation.

6 years agoserver: Initialize user list at compile time.
Andre Noll [Sat, 12 Aug 2017 23:05:22 +0000 (01:05 +0200)]
server: Initialize user list at compile time.

This allows the removal of the "initialized" variable, and it
simplifies user_list_init().

6 years agoserver: Rename functions related to user lists.
Andre Noll [Sat, 12 Aug 2017 23:10:01 +0000 (01:10 +0200)]
server: Rename functions related to user lists.

The common user_list prefix of the two public functions declared in
user_list.h indicates that these functions are defined in user_list.c.

6 years agoserver: Constify return value of lookup_user().
Andre Noll [Sat, 12 Aug 2017 23:02:17 +0000 (01:02 +0200)]
server: Constify return value of lookup_user().

Command handlers only need to read this structure.

6 years agoserver: Let stat command handler perform cleanup on signals.
Andre Noll [Sat, 12 Aug 2017 21:27:55 +0000 (23:27 +0200)]
server: Let stat command handler perform cleanup on signals.

The stat command is special because it is the only command which may
run for a very long time, and because it catches SIGUSR1 which is sent
by the server to notify the command handler process when the status
items have changed and the command handler should update the client.

The stat command handler catches neither SIGINT nor SIGTERM, though,
so these signals terminate the process. This happens when para_server
is started without --daemon and CTRL+C is pressed (causing SIGINT
to be sent to the all processes in the foreground process group)
or when the server is about to exit, because in this case the main
process sends SIGTERM to all child processes.

If the command handler process terminates because it received SIGINT
or SIGTERM, valgrind reports various memory leaks. Although the leaks
are harmless, they clutter the valgrind output and make real memory
leaks hard to spot.

This commit changes com_stat() to ignore SIGINT and catch SIGTERM in
addition to SIGUSR1. We don't need to care about SIGINT in com_stat()
because in the above scenario, the main process sends SIGTERM to all
command handlers after it received SIGINT. With the patch applied, if
com_stat() received SIGTERM, it returns and the normal cleanup on exit
is performed.

We have to employ pselect(2) to avoid race conditions.

6 years agoserver: Have afs process close the current mood on exit().
Andre Noll [Sat, 12 Aug 2017 20:02:48 +0000 (22:02 +0200)]
server: Have afs process close the current mood on exit().

This eliminates a few (harmless but annoying) warnings about memory
leaks from the valgrind output.

6 years agoserver: Deplete close on fork list on exit.
Andre Noll [Sat, 12 Aug 2017 19:32:28 +0000 (21:32 +0200)]
server: Deplete close on fork list on exit.

We empty the list in the command handler process by calling
close_listed_fds(), but the server process leaks the memory
allocated for the entries of the close on fork list.

This commit introduces deplete_close_on_fork_list() to empty the
list without closing any file descriptors. It is called from main()
to avoid the leak.

With the patch applied, valgrind --show-reachable=no no longer
complains about possibly lost blocks for the server process.

6 years agodaemon: Introduce log mutex.
Andre Noll [Mon, 7 Aug 2017 22:02:03 +0000 (00:02 +0200)]
daemon: Introduce log mutex.

Currently the server processes append messages to the log file without
coordination. This usually does not cause problems, but sometimes
the log messages of the main server process and the afs process get
interleaved due to the lack of serialization.

This patch serializes access to the common log file by employing a
new lock: the log_mutex. Like the mmd_mutex, it is realized as an
one-element System V semaphore set.

Logging is performed by the daemon subsystem implemented in daemon.c.
This subsystem is also used by para_audiod which is single-threaded
and thus does not need to care about serialization of log messages.
To keep daemon.c working for both para_server and para_audiod,
struct daemon gains two optional methods, ->pre_log_hook and
->post_log_hook. If the function pointers are not NULL, the methods
are called before and after a message is logged. For para_server
the methods call back to the server code to take and release the
lock. para_audiod does not need to be modified because if the new
function pointers are left at their default value NULL, so no hooks
are called.

6 years agoserver: Exit cleanly on SIGINT/SIGTERM.
Andre Noll [Mon, 7 Aug 2017 19:41:00 +0000 (21:41 +0200)]
server: Exit cleanly on SIGINT/SIGTERM.

Currently signal_post_select() kills all child processes and then
calls exit(3) if SIGNINT or SIGTERM was received. This leaves all file
descriptors open and memory blocks allocated, which makes debugging
memory leaks difficult because the valgrind output is hard to read.

This patch changes the server to cleanly shutdown the scheduler and
deallocate resources (close file descriptors, free memory, destroy
locks and shared memory areas) before exit(3) is called.

6 years agoserver: Cleanly shut down senders on exit.
Andre Noll [Mon, 7 Aug 2017 19:11:26 +0000 (21:11 +0200)]
server: Cleanly shut down senders on exit.

This introduces ->shutdown for struct sender. Each of the three senders
implements the new method to close file descriptors and to deallocate
the resources occupied by the sender. The method is only called on
exit via the new vss_shutdown() from both server and command handler
context after schedule() returns.

We need to introduce another helper, process_is_command_handler(), to
distinguish between the two callers.

6 years agoserver: Shutdown the scheduler before handling commands.
Andre Noll [Mon, 7 Aug 2017 01:44:07 +0000 (03:44 +0200)]
server: Shutdown the scheduler before handling commands.

Currently the command handlers are called from the ->post_select
method of the command task after the main server process has forked.
When the command handler is done, it exits with the scheduler still
active. This is not a problem per se, and it has been like this
for more than a decade, but it does make it harder to debug memory
leaks because we leak some resources. Valgrind complains about this,
cluttering the output with pointless warnings.

This commit cleans up the memory handling of the child process on
exit. The command task of the child process notifies all tasks in its
->post_select method and then returns the new pseudo error code
-E_CHILD_CONTEXT. This causes the scheduler to return to main().

The main() function checks via the new ->child_fd of struct
server_command_task whether it is running in child context after
schedule() has returned and calls the command handler in this case.

6 years agoserver: Make array of senders constant.
Andre Noll [Mon, 7 Aug 2017 15:44:15 +0000 (17:44 +0200)]
server: Make array of senders constant.

Currently we define an array of static non-constant sender structures
in vss.c with only ->init being initialized at compile time.
At startup the ->init method of each sender must fill out the other
function pointers of the structure. This approach is kind of pointless,
as these pointers are known at compile time and never change.

This patch changes the three senders to define a non-static constant
sender structure instead. The vss maintains an array of pointers to
these structures.

Since the new sender structures are non-static, they need to be
doxified. We use the opportunity to provide an overview of each sender.

The patch also introduces FOR_EACH_SENDER(), a macro which is used
several times to replace the open-coded loops we had before.

6 years agoserver: Define server command task structure in main().
Andre Noll [Sun, 6 Aug 2017 21:39:02 +0000 (23:39 +0200)]
server: Define server command task structure in main().

This way it does not need to be static, and we can look at the
contents after schedule() returns.

Preparatory patch for shutting down cleanly on exit.

6 years agobuild: Compile with -Wdiscarded-qualifiers.
Andre Noll [Wed, 3 Jan 2018 17:50:15 +0000 (18:50 +0100)]
build: Compile with -Wdiscarded-qualifiers.

This option is unsupported (but warnings are invariably enabled) for
old gcc versions including 4.2.2. It is supported but not enabled by
default for vanilla gcc-5.5.0, but is enabled for the gcc versions
which ship with Ubuntu-14.04 (4.8.4) and Ubuntu-16.04 (5.4.0).

This patch enables the warning everywhere. We have to employ the
cc-option macro to determine whether the option is supported.

6 years agoacl: Fix/improve acl_del_entry log message.
Andre Noll [Wed, 3 Jan 2018 13:12:00 +0000 (14:12 +0100)]
acl: Fix/improve acl_del_entry log message.

The given address/netmask can match any number of entries. Currently
we log one message per removed address but all messages contain the
address/netmask to match rather than the removed one that was stored
in the acl.

This patch changes acl_del_entry() to log both, with different
severities.

6 years agoacl: Avoid undefined behaviour due to 32-bit shift.
Andre Noll [Thu, 16 Nov 2017 02:24:47 +0000 (03:24 +0100)]
acl: Avoid undefined behaviour due to 32-bit shift.

On x86 a shift by 32-bits is a nop, but this is not backed by any
standard. Moreover, not shifting at all results in an effective netmask
of 32, which is unexpected for for v4_addr_match(), as the function
is supposed to answer the question "do the first zero bits of these
two addresses match?". This should always be true, regardless of the
two addresses.

Fix this, and change the return type of the function while at it.

6 years agoafs: Fix typo in error message.
Andre Noll [Wed, 3 Jan 2018 00:48:09 +0000 (01:48 +0100)]
afs: Fix typo in error message.

It was the ->open() method that failed when this message is logged.

6 years agoafs: Fix memory leak in make_status_items().
Andre Noll [Tue, 2 Jan 2018 23:55:03 +0000 (00:55 +0100)]
afs: Fix memory leak in make_status_items().

The leak occurs when the second call to print_list_item() fails. In
this case we leak the memory pointed to by the lpr pointer. This patch
also streamlines the code a bit by introducing the free_status_items()
helper.

6 years agofd.c: Simplify para_mmap().
Andre Noll [Sun, 14 Jan 2018 17:57:22 +0000 (18:57 +0100)]
fd.c: Simplify para_mmap().

Both callers pass in a zero offset, so we can get rid of this
parameter.

6 years agogcrypt: Allocate a secmem pool at startup.
Andre Noll [Wed, 3 Jan 2018 03:33:02 +0000 (04:33 +0100)]
gcrypt: Allocate a secmem pool at startup.

The client side loads private keys. This patch makes sure the memory
which contains such key material is never swapped out.

6 years agocrypt: Introduce crypt_shutdown().
Andre Noll [Fri, 29 Dec 2017 15:22:37 +0000 (16:22 +0100)]
crypt: Introduce crypt_shutdown().

This plugs a few harmless memory leaks in the openssl crypto
backend. The leaks occur on exit and are only reported by valgrind
if it is run with --leak-check=full --show-leak-kinds=all.

The gcrypt backend has similar problems, but there is no way to
provide a similar patch for libgrypt. The newly added comment in
gcrypt.c explains why.

6 years agocrypt: Rename init_random_seed_or_die() -> crypt_init().
Andre Noll [Thu, 28 Dec 2017 20:57:23 +0000 (21:57 +0100)]
crypt: Rename init_random_seed_or_die() -> crypt_init().

At least the gcrypt implementation does more than just seed the
PRNG. The new name is shorter and more descriptive.

6 years agogcrypt: Use ROUND_DOWN() macro.
Andre Noll [Thu, 28 Dec 2017 20:48:10 +0000 (21:48 +0100)]
gcrypt: Use ROUND_DOWN() macro.

6 years agocrypt: Rename RSA functions.
Andre Noll [Thu, 28 Dec 2017 14:52:31 +0000 (15:52 +0100)]
crypt: Rename RSA functions.

This renames the functions and constants of the public crypto API
which deal with RSA to have the common "apc" (asymmetric pubkey
cryptosystem) prefix.  This hides RSA as an implementation detail
and makes it clear that the functions/constants are related to apc.

Pure renaming, no semantic change. The only other changes are a new
comment to crypt.h and a \ref statement in the doxygen comment of
apc_free_pubkey().

6 years agocrypt: Deduplicate get_public_key().
Andre Noll [Thu, 28 Dec 2017 00:41:14 +0000 (01:41 +0100)]
crypt: Deduplicate get_public_key().

The openssl and grypt implementations of this function share quite
some code. This patch factors out the common code into the new
decode_ssh_key() helper of crypt_common.c. Both implementations are
changed to call the new helper.

As a side effect of this change, all callers of is_ssh_rsa_key()
and check_ssh_key_header() now reside in crypt_common.c, so we can
make these two functions static and remove their declarations from
crypt_backend.h.

6 years agocrypt.h: Remove two unused constants.
Andre Noll [Wed, 27 Dec 2017 20:59:33 +0000 (21:59 +0100)]
crypt.h: Remove two unused constants.

These should have been removed already last year in commit d9f54f43
(crypto: Remove support for ASN public keys), since that commit made
the constants obsolete.

6 years agoRename crypt.c -> openssl.c.
Andre Noll [Wed, 27 Dec 2017 20:47:40 +0000 (21:47 +0100)]
Rename crypt.c -> openssl.c.

The old name made sense back when we had only one crypto backend. These
days paraslash can be compiled against either openssl or gcrypt,
so the new name makes it clear that the file is only compiled in if
the openssl library was selected as the crypto backend.

6 years agoserver: Avoid use of uninitialized memory.
Andre Noll [Mon, 29 Jan 2018 22:21:11 +0000 (23:21 +0100)]
server: Avoid use of uninitialized memory.

change_current_mood() receives an errmsg pointer which the callers
expect to be initialized with an error string if (and only if) the
function returns negative.

However, most error paths miss to initialize the pointer which results
in undefined behaviour in the caller which attempts to free(3)
uninitialized memory. The gcc AddressSanitizer and valgrind both
catch this:

gcc:

==14788==ERROR: AddressSanitizer: attempting free on address which was not malloc()-ed: 0x081af250 in thread T0

valgrind:

==4410== Invalid free() / delete / delete[] / realloc()

The bug was introduced half a year ago when version 2 moods were
introduced in commit 3d3a2f50.

6 years agodaemon: Fix log reload for relative paths.
Andre Noll [Sun, 31 Dec 2017 20:56:35 +0000 (21:56 +0100)]
daemon: Fix log reload for relative paths.

If the argument to --logfile is a relative path, it is interpreted
as relative to the current working directory. In daemon mode, the
current working directory is changed to / during startup. Hence,
when para_server re-opens the log file after it received SIGHUP, the
logfile path will now be interpreted as relative to the the root of
the file system.

Fix this by remembering the original current working directory.
Opening "." as recommended in getcwd(3) is not an option here since the
whole point of changing the cwd to / is to prevent the daemon from
keeping the cwd busy.

6 years agoImprove daemon_open_log_or_die().
Andre Noll [Sun, 31 Dec 2017 19:32:52 +0000 (20:32 +0100)]
Improve daemon_open_log_or_die().

If the log file can not be re-opened, the error message is lost
because the log file has already been closed when PARA_EMERG_LOG() is
called. We can do better by deferring the call to daemon_close_log()
until the new log file has been opened.

With the patch applied, the reason why the (new) log file could not
be opened is logged to the old file.

6 years agoserver: Close logfile later on SIGHUP.
Andre Noll [Sun, 31 Dec 2017 19:27:57 +0000 (20:27 +0100)]
server: Close logfile later on SIGHUP.

The call to daemon_open_log_or_die() will close the log file just
before it is reopened. This is better because that way any errors
which occur in between won't get lost.

6 years agoserver: Simplify afs socket cookie code.
Andre Noll [Sun, 31 Dec 2017 15:27:25 +0000 (16:27 +0100)]
server: Simplify afs socket cookie code.

Currently, the afs_socket_cookie value is passed to afs_init() and
is stored in the commmand task structure of the afs process. This
is unnecessary since the variable defined in server.c is non-static,
and declared as extern in afs.c. We may thus refer to this variable
from afs.c.

The variable was also documented twice. Get rid of one comment.

6 years agomixer: Remove default moods for sleep.
Andre Noll [Tue, 30 Jan 2018 18:56:16 +0000 (19:56 +0100)]
mixer: Remove default moods for sleep.

The documented behavior of the sleep subcommand is to not fade out
if no fade out mood was given. The current code, however, tries to
switch to the default m/fade. This fails if this mood does not exist,
causing the sleep subcommand to terminate. By removing the default
value we get the documented behaviour.

The --fo-mood and --sleep-mood suffer from the same issue and can be
fixed in the same way.

6 years agobuild: Error out early if flex or bison are not found.
Andre Noll [Thu, 11 Jan 2018 08:05:13 +0000 (09:05 +0100)]
build: Error out early if flex or bison are not found.

The configure script tests for these executables, but we happily
proceed even if they are not found. For the m4 executable we got
the check right, however. Introduce a general helper that calls
AC_PATH_PROG() to locate an executable and aborts if it is not found.

6 years agoFix bad grammar "allows <infinitive>".
Andre Noll [Tue, 7 Nov 2017 22:29:03 +0000 (23:29 +0100)]
Fix bad grammar "allows <infinitive>".

In standard English, the verb "allows" can never take an infinitive as
its direct object. This patch corrects these mistakes.

6 years agoaft: Avoid implicit fallthrough in switch statement.
Andre Noll [Sat, 27 Jan 2018 11:08:04 +0000 (12:08 +0100)]
aft: Avoid implicit fallthrough in switch statement.

The missing return statement causes gcc-7 to complain:

aft.c:2579:3: warning: this statement may fall through [-Wimplicit-fallthrough=]

And indeed, this fall through was not intended when the code in
question was introduced some months ago in commit a7a8d30e (Update
status items on blob events).

The issue is benign though, because also after falling through we
return 0.

6 years agoogg_afh_common.c: Add missing whitespace to log message.
Andre Noll [Wed, 3 Jan 2018 04:11:23 +0000 (05:11 +0100)]
ogg_afh_common.c: Add missing whitespace to log message.

There was no space character between the number and the word "seconds".

6 years agomp.c: Fix typo in comment.
Andre Noll [Sun, 7 Jan 2018 00:20:49 +0000 (01:20 +0100)]
mp.c: Fix typo in comment.

6 years agocommand.c: Fix typo in comment.
Andre Noll [Thu, 28 Dec 2017 21:37:20 +0000 (22:37 +0100)]
command.c: Fix typo in comment.

6 years agoUpdate copyright year to 2018.
Andre Noll [Thu, 11 Jan 2018 08:04:17 +0000 (09:04 +0100)]
Update copyright year to 2018.

Fortunately, there is only a single place to update.

6 years agoplay: Print help text if no audio files are given.
Andre Noll [Fri, 29 Dec 2017 14:08:15 +0000 (15:08 +0100)]
play: Print help text if no audio files are given.

This is more helpful than the lopsub error message. Since
handle_help_flags() already checked the arg count, the call to
lls_check_arg_count() can be removed.

6 years agoplay: Always check arg count and init keymap.
Andre Noll [Sun, 14 Jan 2018 21:12:32 +0000 (22:12 +0100)]
play: Always check arg count and init keymap.

Currently we miss to do so if the config file does not exist or
is empty. This triggers the following assertion if, in addition,
no non-option arguments given:

        para_play: string.c:62: para_malloc: Assertion `size' failed.

This is because we try to allocate a zero sized buffer in main() due
to lls_num_inputs() returning 0. Fix this by changing the target of
the goto in handle_help_flags().

This bug was introduced during the conversion to lopsub.

6 years agodoc: Move filter examples to man page.
Andre Noll [Mon, 6 Nov 2017 17:02:57 +0000 (18:02 +0100)]
doc: Move filter examples to man page.

para_filter(1) is a better place for examples than the user manual
because the man pages explain one command command while purpose of
the manual is to describe the connection and the interaction of the
various commands.

6 years agodoc: Move sender examples to manual page.
Andre Noll [Sun, 5 Nov 2017 16:36:15 +0000 (17:36 +0100)]
doc: Move sender examples to manual page.

The general paraslash user manual contains a couple of examples for
the sender subcommand of para_server. However, the para_server(1)
manual page is a better place for this, so this patch moves the
examples there. They have also been slightly reworded, and the help
text of the sender command has been clarified.

6 years agoMerge branch 'maint'
Andre Noll [Sun, 31 Dec 2017 14:04:16 +0000 (15:04 +0100)]
Merge branch 'maint'

A conflict in init_random_seed_or_die() of gcrypt.c. The fix added
in the maint branch conflicted against the master branch which also
modified the function to bump the required libgcrypt version.

* maint:
  resample filter: Don't discard const.
  gcrypt: Seed PRNG in init_random_seed_or_die().
  bash_completion: Get rid of weird retry logic.

6 years agoresample filter: Don't discard const.
Andre Noll [Fri, 29 Dec 2017 13:50:28 +0000 (14:50 +0100)]
resample filter: Don't discard const.

Newer versions of libsamplerate made the data_in pointer const. This
causes the following warning:

In file included from resample_filter.c:6:0:
/usr/local/include/samplerate.h:177:6: note: expected 'float *' but argument is of type 'const float *'
 void src_short_to_float_array (const short *in, float *out, int len) ;
      ^
resample_filter.c:173:7: warning: passing argument 1 of 'free' discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers]
In file included from para.h:11:0,
 from resample_filter.c:10:
/usr/include/stdlib.h:460:13: note: expected 'void *' but argument is of type 'const float *'
 extern void free (void *__ptr) __THROW;

The problem is that we first convert the input from int16 to float
and use the data_in pointer as the target for the conversion.

Fix this by introducing a temporary non-const variable for the
converted input.

6 years agocrypt.c: Plug memory leak in get_public_key().
Andre Noll [Thu, 16 Nov 2017 01:18:50 +0000 (02:18 +0100)]
crypt.c: Plug memory leak in get_public_key().

If server.users refers to an existing file which is not a ssh public
key, we leak 4 bytes of memory:

==27302== 4 bytes in 1 blocks are definitely lost in loss record 1 of 8
==27302==    at 0x402C201: malloc (vg_replace_malloc.c:299)
==27302==    by 0x8052FF3: para_malloc (string.c:63)
==27302==    by 0x8066532: get_public_key (crypt.c:151)
==27302==    by 0x80569D1: user_list_init (user_list.c:90)
==27302==    by 0x804D74D: parse_config_or_die (server.c:279)
==27302==    by 0x804C719: server_init (server.c:554)
==27302==    by 0x804C719: main (server.c:655)

Furtunately, this issue is trivial to fix.

6 years agogcrypt: Seed PRNG in init_random_seed_or_die().
Andre Noll [Thu, 28 Dec 2017 15:48:48 +0000 (16:48 +0100)]
gcrypt: Seed PRNG in init_random_seed_or_die().

The function is supposed to call srandom(3) to set the seed for a new
sequence of pseudo-random integers to be returned by random(3). The
openssl crypto backend does this, but the gcrypt one does not.

This is not a fatal flaw as we don't use random(3) for any
cryptographic purpose. Let's fix it anyway.

6 years agocrypt.c: Fix two typos in comment.
Andre Noll [Wed, 27 Dec 2017 20:37:23 +0000 (21:37 +0100)]
crypt.c: Fix two typos in comment.

s/adds/add and s/random/urandom. Also add the man section to random().

6 years agobash_completion: Get rid of weird retry logic.
Andre Noll [Sun, 5 Nov 2017 18:38:44 +0000 (19:38 +0100)]
bash_completion: Get rid of weird retry logic.

It's totally unclear what this is supposed to do, as the commit which
introduced it six years ago does not say anything about the space
character being the only "proper" value.

Removing the check fixes an issue that only happens on the first
completion attempt: if a unique completion is possible, the completer
prints this completion as if there were multiple completions possible
instead of completing the command line.

6 years agogui: Catch SIGWINCH.
Andre Noll [Sat, 23 Sep 2017 17:48:40 +0000 (19:48 +0200)]
gui: Catch SIGWINCH.

Commit 9775f534 from more than three years ago removed the signal
handler for SIGWINCH on the grounds that it is unnecessary and
simplifies the gui menu code that was in preparation back then.

However, the gui menu feature was never merged and handling SIGWINCH in
the input task does have a disadvantage: since KEY_RESIZE is generated
by the curses library, select(2) (which watches STDIN_FILENO) does
not notice that wgetch(3) would not block or return ERR any more
after SIGWINCH was received. Hence the window will only be refreshed
after select(2) returns for another reason. This can delay the window
update for up to one second.

This patch gets rid of the delay by reintroducing the signal handler
for SIGWINCH, effectively reverting the above mentioned commit.

6 years agoserver: Disable com_tasks().
Andre Noll [Tue, 8 Aug 2017 11:08:27 +0000 (13:08 +0200)]
server: Disable com_tasks().

This server subcommand will break once we terminate the scheduler
before calling the command handler. The command was only a debugging
aid anyway, and the output was not very interesting to begin with. In
particular, it did not include the tasks of the afs process, and
always showed the same three tasks (command, vss and status).

We keep the subcommand for backward compatibility, but this commit
changes it to be a no-op. Scheduled for removal in v0.7.0.

6 years agoserver: Move afs_pid out of mmd struct.
Andre Noll [Mon, 7 Aug 2017 18:33:55 +0000 (20:33 +0200)]
server: Move afs_pid out of mmd struct.

The afs_pid variable is read-only after it has been initialized. Hence
it does not qualify for being part of the shared memory area which
contains the mmd struct. Make it a global variable instead.

6 years agoserver: Don't pass peername to handle_connect().
Andre Noll [Sun, 6 Aug 2017 21:45:38 +0000 (23:45 +0200)]
server: Don't pass peername to handle_connect().

The only reason we pass it is that handle_connect() can print a
log message containing the peer name. However, we already log this
information right after the connection was accepted.

6 years agoserver: Rename "vss task" -> vss.
Andre Noll [Mon, 7 Aug 2017 22:32:33 +0000 (00:32 +0200)]
server: Rename "vss task" -> vss.

The other tasks of the server process are called "server command"
and "signal", so let's be consistent and drop the redundant "task".

6 years agobash_completion: Fix typo.
Andre Noll [Sun, 24 Sep 2017 19:25:04 +0000 (21:25 +0200)]
bash_completion: Fix typo.

The underscore was dropped by mistake recently in commit d31995b3
(Shorten copyright notice).

6 years agoparaslash 0.6.1 v0.6.1
Andre Noll [Sat, 23 Sep 2017 15:09:19 +0000 (17:09 +0200)]
paraslash 0.6.1

6 years agoMerge branch 'maint'
Andre Noll [Sat, 23 Sep 2017 14:36:08 +0000 (16:36 +0200)]
Merge branch 'maint'

* maint:
  paraslash 0.5.8

NEWS.md conflicted slightly, but this was easy resolve.

6 years agoparaslash 0.5.8 v0.5.8
Andre Noll [Sat, 23 Sep 2017 14:31:26 +0000 (16:31 +0200)]
paraslash 0.5.8

6 years agovss: Reduce indentation level in vss_send().
Andre Noll [Sun, 6 Aug 2017 14:26:14 +0000 (16:26 +0200)]
vss: Reduce indentation level in vss_send().

If the current chunk is not due yet, we return from the function.
Reversing the logic of the test allows to reduce indentation by
one level. No semantic change.

6 years agovss: Propagate return value of afh_get_chunk().
Andre Noll [Sun, 6 Aug 2017 12:21:15 +0000 (14:21 +0200)]
vss: Propagate return value of afh_get_chunk().

With dynamic chunks, afh_get_chunk() may fail. Currently
vss_get_chunk() prints an error message in this case and returns
the null pointer. However, some callers of vss_get_chunk() happily
dereference the returned pointer without checking for NULL.

This patch modifies vss_get_chunk() to return int and teaches all
callers to check the return value. For the udp and dccp transport,
we disable the fec client temporarily in the error case while for
the http transport we log the error (but otherwise ignore it), and
try to continue with the next chunk.

This flaw was noticed by the clang static analyzer.

6 years agoaudioc: Use file_exists().
Andre Noll [Mon, 14 Aug 2017 00:13:00 +0000 (02:13 +0200)]
audioc: Use file_exists().

There is no need to open-code this function.

6 years agofd.c: Change return value of file_exists() to bool.
Andre Noll [Mon, 14 Aug 2017 00:10:44 +0000 (02:10 +0200)]
fd.c: Change return value of file_exists() to bool.

file_exists() is in fact a misnomer, since it simply calls stat(2),
which may fail for many reasons besides ENOENT. But that's another
issue for another patch..

6 years agoShorten copyright notice.
Andre Noll [Sun, 10 Sep 2017 12:15:50 +0000 (14:15 +0200)]
Shorten copyright notice.

The GPLv2 line does not add any additional information, so drop
it. This leaves a single line of legalese text for most files, which
is about the amount of screen real estate it deserves.

This patch was created with the following script (plus some manual
fixups):

awk '{
if (NR <= 5) {
gs = gensub(/.*Copyright.* ([0-9]+).*Andre Noll.*/, "\\1", "g")
if (gs != $0)
year = gs
next
}
if (NR == 6 && year != "")
printf("/* Copyright (C) %s Andre Noll <maan@tuebingen.mpg.de>, see file COPYING. */\n", year)
print
}'