Andre Noll [Thu, 4 Oct 2007 14:11:59 +0000 (16:11 +0200)]
afs.c: Introduce client list for afs (fixes dosable bug).
With the old code, a malicious local user could easily cause a DOS
by connecting to the local afs socket but never sending any data
through that socket. This caused afs to block on the read() from the
new client fd.
This patch fixes this flaw by introducing a doubly liked list of
connected clients. Each entry in this list contains an open file
descriptor and the time the client connected.
In command_pre_select() we add each fd in the list to the set of
fds to be checked for readability. In command_post_select() we loop
through that list and check each fd again. Whenever the fd for a
client is readable we read from that fd and execute an afs command
if the client sent the valid magic cookie.
However, if the fd is not ready, we close the connection if more than
AFS_CLIENT_TIMEOUT seconds (default: 3) have passed since the client
connected. This hopefully avoids another possible DOS: A malicious
user could try to flood us with connections until the limit of open
fds is reached.
Andre Noll [Tue, 2 Oct 2007 13:56:10 +0000 (15:56 +0200)]
Make it compile on FreeBSD.
This was easier than expected. Only two items needed fixing:
- signal.h has to be included for several files that use signals.
- The __used and __packed macros are already defined on FreeBSD which
leads to an error at compile time. Fortunately paraslash doesn't use
these macros at all, so we can simply remove them.
Andre Noll [Tue, 2 Oct 2007 12:04:46 +0000 (14:04 +0200)]
fsck.c: Fix several bugs in dump mode.
- Don't abort if a directory can't be created because it already exists.
- Use correct variable for the disk storage name column.
- If more than one table is to be dumped, use a directory for each table.
- Remove __a_unused for main()'s argc which _is_ being used.
Andre Noll [Sat, 29 Sep 2007 12:00:14 +0000 (14:00 +0200)]
attribute.c: Clear attribute bits already at remove time.
If an attribute gets removed, the old code deferred clearing the
corresponding attribute bit in the afsi of all audio files until
that bit got reclaimed by add_att. This is problematic because of
the new no_attribute_set mood method.
Andre Noll [Sat, 29 Sep 2007 11:39:34 +0000 (13:39 +0200)]
mood.c: Add no_attributes_set mood method.
Also fix a bug in mm_played_rarely_parser(): If no arg was
specified in the mood definition, a NULL pointer is passed to that
function, so it must not blindly dereference that pointer.
Andre Noll [Sat, 29 Sep 2007 11:13:50 +0000 (13:13 +0200)]
Speed up mood loading.
The old code passed a pointer to the row of the audio file table to the
mood scoring functions. The scoring functions had to obtain the afsi,
afhi, path from that row pointer. Thus, at mood load time, the afsi,
afhi, path was extracted N times for each audio file if there are N
mood lines that used this info.
This patch changes the mood scoring functions so that they take
three pointers to afsi, afhi, path instead of the row pointer.
add_item_score(), the single caller of the mood scoring functions,
provides these pointers, i.e. they get extracted from the row pointer
only once per audio file.
This is still not optimal as most scoring functions use only one of
the three pointers. But let's not over-engineer the thing.
Andre Noll [Thu, 27 Sep 2007 15:47:46 +0000 (17:47 +0200)]
Implement pattern matching for com_touch().
Also, add -p and -v options and fix converting the last played
time which is a 64 bit intger, so strtol() will fail do it on 32
bit machines after 2039 ;)
To fix this, introduce para_atoi64() which calls strtoll() which
is 64 bit even on 32 bit machines and define para_atoi32() which
calls para_atoi64() and checks the boundaries.
Andre Noll [Thu, 27 Sep 2007 10:25:05 +0000 (12:25 +0200)]
Gerneralize for_each_matching_blob().
It's not only useful for blobs. For instance the rm and the touch
commands might also want to use something similar. So move it to
afs.c and call it for_each_matching_row().
Andre Noll [Wed, 26 Sep 2007 14:37:00 +0000 (16:37 +0200)]
Fix table init.
The previous patch introduced two instances of a bug which weren't noticed by
the compiler because attribute_table and score_table were declared as void *
pointers. Change that to struct osl_table *, and add the missing '&' operator.
Andre Noll [Wed, 26 Sep 2007 09:29:07 +0000 (11:29 +0200)]
addblob: Overwrite existing blobs.
Previously, an attempt to add a blob with a name of an already
existing blob failed (siltenly). Just replace the existing blob
with the new contents instead.
Andre Noll [Tue, 25 Sep 2007 12:16:14 +0000 (14:16 +0200)]
make get_playlist_data() generic.
Other blob types might use an analogous function as well, so introduce
blob_get_name_and_def_by_row() in blob.c, and use some preprocessor
magic to define such a function for each blob type.
Change all users of get_playlist_data() to use the new
pl_blob_get_name_and_def_by_row() and remove get_playlist_data().
Andre Noll [Tue, 25 Sep 2007 09:39:23 +0000 (11:39 +0200)]
More mood cleanups.
- Avoid use of global current_mood pointer where possible.
- Change name of non-static functions that use the current mood pointer:
mood_open() -> change_current_mood()
mood_close() -> close_current_mood()
mood_reload() -> reload_current_mood()
Andre Noll [Sun, 23 Sep 2007 20:38:54 +0000 (22:38 +0200)]
afs.c: Avoid noisy log message.
para_server regularly sends SIGUSR1 to all of its children. afs
just ignores that signal, so only print a log message if a signal
different from SIGUSR1 was caught.
Andre Noll [Sat, 22 Sep 2007 12:45:21 +0000 (14:45 +0200)]
Fix some bugs in blob handling.
- make fd2buf() decrypt the received data.
- stdin_command() has to read from the socket fd rather than from stdin.
Moreover, it must send the AWAITING_DATA_MSG to the client.
- com_catblob() really needs to use send_bin_buffer() rather than send_buffer().
- com_addblob() has to pass the socket fd to stdin_command().
Andre Noll [Sat, 15 Sep 2007 17:42:29 +0000 (19:42 +0200)]
replace para_connect() by PARA_CONNECT.
PARA_CONNECT is a macro which works for all three socket address types
used in paraslash (sockaddr_in, sockaddr, sockaddr_un) and which does
not need a length parameter.
Change all instances of connect() and para_connect() to use PARA_CONNECT().