When a signal is caught we want to exit from the boost::asio loop.
However, we can't do this by pusing another handler onto the io_service,
since this will involve a malloc call, and this can cause a deadlock (if
the signal handler is invoked from within a malloc call).
Therefore we instead need to use the signal_set functionality of
boost::asio, which guarantees that signal handling is done without
issue.
close() is not part of the standard C API, so is not covered by any of the
C++ versions of the C standard headers. Later compilers seem to require
this be included explicitly.
* common/system.cpp, common/system.h: Add security_init(), a
function to initialise any security or crypto related libraries
used. This is required by recent version of libgcrypt when
using hash functions.
* server/server.cpp, tests/systemtest.cpp, tools/cypasswd.cpp:
Call security_init() in all programs that use security related
functions.
* common/system.h: Add a new exit status code indicating that no
ports were available in the dynamic range.
* server/server.cpp, common/system.cpp: When there are no ports
available, write an appropriate message, and a hint describing
how to allocate more.
* common/system.h: Add prototypes for required C library functions
we implement on systems where they are missing.
* common/system.cpp: Adapt the system specific code for systems
which are missing libc functions are system calls, including
uname, getuid, nice, fork, kill and some of the signals.
* common/system.cpp, common/system.h: Add a function to increment nice
value for the server. Change security check to return unsigned, as
the magic number is in fact unsigned.
* server/server.cpp: Call system function to increment nice, thus
reducing priority once setup is complete.
* common/system.h, common/system.cpp: Add security check function
which for now just ensures cyphesis is not run as root.
* server/server.cpp: Use security check function when starting
the server.
* common/system.cpp, common/system.h: Add new functions for handling
encrypted password hashes with a salt, based on gcrypt rather
than openssl. Include legacy support for hashes without a salt.
* common/const.cpp: Add a salt to the default admin password.
* tests/systemtest.cpp: Modify the password tests to use the new
functions.
* server/Connection.cpp, server/Connection.h,
server/TrustedConnection.cpp, server/TrustedConnection.h:
Update the login code to use the new password functions.
* common/system.h, common/system.cpp: Add code to md5 hash
strings, like passwords.
* server/Connection.cpp: Use md5 hash code for storing and
verifying passwords.
* common/system.h, common/system.cpp, server/server.cpp: Moved all
the system dependant signal handling and background handling
code into system module, and implemented propper handling of
going into the background, including reporting error status
back to the waiting parent using exit status and user signals.