On Windows if the compiler and C RTL is >= 1400 then the rand_s()
function is available. rand_s() unlike rand() makes use of the
RtlGenRandom() API to produce a random number between 0 and UINT_MAX.
If rand_s() is not available or fails, fallback to rand().
One of the benefits of rand_s() is that no initialization is required
so it will provide random output even if rk_random_init() is not called.
Change-Id: I2768155de744bd49604fc8237728bb205d637f2a
Tests that start daemons have to "wait" for them to start.
This commit makes Heimdal daemons prep to detach (when requested) by
forking early, then having the child signal readiness to the parent when
the child really is ready. The parent exits only which the child is
ready. This means that tests will no longer need to wait for daemons.
However, tests will still need a pidfile or such so they can stop the
daemons.
Note that the --detach options should not be used on OS X from launchd,
only from tests.
Modify the NTMakefile rules for tests so that a failed test does
not prevent subsequent tests from being executed.
Change-Id: I9595ad4a1527feae7c402241bf06ab21a0b76d4a
Add an implementation of memset_s to roken.
Some optimising compilers may remove the memset() instruction when it
is used immediately before a free, which defeats its purpose if the
intention is to zero memory before returning it to the heap or stack.
C11 added memset_s, provide a fallback in roken so that memset_s can
be used on all platforms.
Add a version of usleep() which is capable of sleeping in one
millisecond increments instead of microseconds.
Change-Id: I173f7e6f91a947cdb66f7cc6df5520e1c03f10b7
openpty() is not available on all Linux distributions. Trust autoconf's
determination for HAVE_OPENPTY instead of unconditionally using
openpty() on all Linux.
LoadLibrary() is unable to load DLLs which are being loaded from
a global side by side assembly directory. Instead, use
LoadLibraryEx() with LOAD_WITH_ALTERED_SEARCH_PATH
This permits a DLL to be loaded from the WinSxs tree when a fully
qualified path is provided.
Change-Id: I0e5da1a8610c6b571f73c0e7b0beabeecbbb3b77
Normally one would dlopen() a shared object's basename, not its absolute
path. However, lib/krb5/plugin.c, in an effort to be zero-conf-ish,
wants to readdir() to find plugins to load, and in the process it ends
up defeating the RTLD's search-the-caller's-rpath.
This commit partially addresses this by allowing the use of $ORIGIN in
plugin_dir values and using them for the default (except on OS X).
This allows multiple Heimdal versions installed on the same host, but
with different plugin ABIs, to co-exist. A step forward for doing make
check on hosts where Heimdal is installed.
For now we hardcode $ORIGIN/../lib/plugin/krb5 (linux, Solaris, *BSD),
or $ORIGIN (Windows; for assemblies objects need to be in the same
directory) and we eval $ORIGIN by using dladdr() (Linux, Solaris) or
GetModuleHandleEx() (Win32, via a dladdr() wrapper in libroken) to find
the path to libkrb5 whose dirname to use as $ORIGIN. For Windows,
because we need the plugins to be in the same directory as libkrb5, we
require a prefix on plugin DLLs ("plugin_krb5_") to distinguish them
from other objects.
We should add a special token to mean "look in $ORIGIN, sure, but
dlopen() the plugin basenames only (so the RTLD can search the rpath)".
rk_mkdir() should not be redefined to mkdir() nor should mkdir()
be redefined to rk_mkdir() when compiling lib/roken/mkdir.c
Change-Id: I329fd2eb5794548635d33218a65df8958746a6f9
Although rk_mkdir can be provided on all platforms there is no
reason to require that it be used by unconditionally mapping
mkdir -> rk_mkdir
Change-Id: Ic149500037abf446434332bf6ba67dfb3906cd72
The Windows version of mkdir() does not share the same signature
as the POSIX version. Add rk_mkdir() with an POSIX compliant signature
to libroken. The current implementation ignores the 'mode' parameter
on Windows but a future implementation could provide the required
functionality with native Win32 APIs.
Change-Id: I084d42e0f27932e9b8131d310dbf34849f5fe4b6
POSIX mkdir (unlike the Windows version) takes a 'mode_t' parameter.
Provide definitions for the mode_t constants.
Change-Id: Ie57e746aa3e579e28f93064ab430f1128508cc84
Windows has neither O_NONBLOCK nor FIOBIO and sockets aren't file
descriptors in any case. Avoid warning that 'flags' is unused in
socket_set_nonblocking().
Change-Id: I431cfae3a88577e75b5230f645639b5a17832f5c
Everywhere that roken is used supports limits.h. The behavior of
roken should not depend on whether or not the including application
includes limits.h before or after roken.h. Include limits.h in
roken.h and be done with it.
Change-Id: Id0be5487c791592dfe722ce880b8400bb16d05b1
If a program does not include limits.h (or includes it after roken.h),
it can end up with PATH_MAX defined to be MAX_PATH, but MAX_PATH
undefined. This causes consumers of PATH_MAX to become unhappy.
Work around this case by only using MAX_PATH if it is available, and
a constant otherwise.
Windows applications become very unhappy when memory is allocated
in one module (exe or dll) and deallocated in another. This is
because each of the C run time library instances uses its own
heap. Mixing allocating in one heap and deallocating in another
will lead to memory leaks and heap corruption. For modules that
build against roken avoid this problem by sharing roken's allocator
with the module that uses it.
Change-Id: I31e35c600a78350b168a281811160696dc327544
This reverts commit cb6f7ea40e.
stdint.h can be included everywhere now that the Windows
platform generates and installs a stdint.h when Visual
Studio does not provide one.
Change-Id: Ia3cab28d7f5806203cd45227765debda54ac7472