Commit Graph

678 Commits

Author SHA1 Message Date
Martin Willi 1e02eddb72 status: Move status_t type and functions to separate files 2015-04-16 14:50:05 +02:00
Martin Willi 001a22e2c1 path: Move path related utility functions to separate files 2015-04-16 14:50:04 +02:00
Martin Willi 7585a85f1a tty: Move tty related functions to separate files 2015-04-16 14:50:04 +02:00
Martin Willi 7802ab88a1 memory: Move memory manipulation related functions to separate files 2015-04-16 14:50:02 +02:00
Martin Willi bbfe7a80b1 string: Move string related utility functions to separate files 2015-04-16 14:49:19 +02:00
Martin Willi 03cf888277 byteorder: Move byte order related functions to separate header file 2015-04-16 14:49:19 +02:00
Martin Willi 95726f7617 types: Use generic type definitions to separate header file 2015-04-16 14:49:19 +02:00
Martin Willi 717313c542 atomics: Move atomics/recounting support to separate files 2015-04-16 14:49:19 +02:00
Martin Willi de1c492a0f enum-names: Fail gracefully when passing a NULL value as enum names 2015-04-15 14:38:43 +02:00
Martin Willi d72817491d leak-detective: Whitelist gcrypt_plugin_create()
gcry_check_version() does not free statically allocated resources. However,
we can't whitelist it in some versions, as it is not a resolvable symbol name.
Instead, whitelist our own plugin constructor function.
2015-04-15 14:38:42 +02:00
Martin Willi 0c83225883 utils: Provide aligning variants of INIT/INIT_EXTRA macros 2015-04-15 13:44:40 +02:00
Martin Willi f206bb7444 utils: Add malloc/free wrappers returning aligned data
While we could use posix_memalign(3), that is not fully portable. Further, it
might be difficult on some platforms to properly catch it in leak-detective,
which results in invalid free()s when releasing such memory.

We instead use a simple wrapper, which allocates larger data, and saves the
padding size in the allocated header. This requires that memory is released
using a dedicated function.

To reduce the risk of invalid free() when working on corrupted data, we fill up
all the padding with the padding length, and verify it during free_align().
2015-04-15 13:44:40 +02:00
Martin Willi 1ef6c0ef06 utils: Provide an INIT_EXTRA() macro, that allocates extra data to INIT() 2015-04-15 11:35:26 +02:00
Martin Willi 3ba3be97d6 utils: Define MAX_(U)INT_TYPE to the maximum size integer type available 2015-04-14 12:03:57 +02:00
Martin Willi 051064ac60 utils: Typedef int128_t and u_int128_t types if supported 2015-04-14 12:03:46 +02:00
Martin Willi 9d6e952201 utils: Add a constant time chunk_equals() variant for cryptographic purposes 2015-04-14 12:02:48 +02:00
Martin Willi b833963270 utils: Add a constant time memeq() variant for cryptographic purposes 2015-04-14 11:51:54 +02:00
Martin Willi 793851856b cpu-feature: Support Via Padlock security features 2015-04-13 15:31:58 +02:00
Martin Willi f155880eda cpu-feature: Add a common class to query available CPU features
Currently supported is x86/x64 via cpuid() for some common features.
2015-04-13 15:31:58 +02:00
Martin Willi b546a98e0a utils: Fix enum_flags_to_string parameter name to match Doxygen description 2015-03-19 12:14:30 +01:00
Thomas Egerer 4dc72f5e57 enum: Extend printf hook to print flags
Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2015-03-03 13:41:49 +01:00
Martin Willi 04337fed02 apple: Redefine some additional clashing Mach types
While they usually are not included in a normal strongSwan build, the XPC
header indirectly defines these Mach types. To build charon-xpc, which uses
both XPC and strongSwan includes, we have to redefine these types.
2014-12-16 17:22:28 +01:00
Martin Willi 6e4620adfb apple: Use precancelable poll() to wrap accept/recvmsg calls
To make accept/recvmsg cancelable, we wrap them with poll. As poll itself
does not honor pending cancellations when entering the function, we use our
variant that checks for pending cancellation requests before entering poll().
2014-12-12 12:08:34 +01:00
Martin Willi 02fd29acc1 windows: Properly set errno for read/write functions using Winsock 2014-11-28 12:45:58 +01:00
Martin Willi 89f19ef876 windows: Move the compatibility header to the compat subfolder 2014-11-21 12:02:08 +01:00
Martin Willi aec3d5fb7f apple: Wrap accept() and recvfrom() with poll(2) instead of select 2014-11-21 12:02:08 +01:00
Martin Willi f65779dd0f apple: Introduce a central compatibility header with all __APPLE__ quirks 2014-11-21 12:02:08 +01:00
Martin Willi a301a9c939 windows: Provide a write(2) wrapper that uses send(2) on sockets 2014-11-21 12:02:08 +01:00
Martin Willi 09624c6cec windows: Provide a read(2) wrapper that uses recv(2) on sockets 2014-11-21 12:02:08 +01:00
Martin Willi fc829ec9fb windows: Provide a poll(2) wrapper calling WSAPoll() 2014-11-21 11:16:48 +01:00
Martin Willi 6528338753 identification: Support custom types in string constructor prefixes 2014-10-30 11:07:08 +01:00
Martin Willi c0da835a9f identification: Support prefixes in string constructors for an explicit type 2014-10-30 11:05:44 +01:00
Tobias Brunner eb218ff80b chunk: Fix internet checksum calculation on big-endian systems
ntohs() might be defined as noop (#define ntohs(x) (x)) so we have
to manually shorten the negated value (gets promoted to an int).

Fixes #747.
2014-10-23 11:13:28 +02:00
Tobias Brunner c71e6820ab backtrace: Fix symbol lookup in dynamic symtab via libbfd 2014-10-14 17:26:48 +02:00
Martin Willi 5b2d89b3c3 process: Include missing <signal.h> for raise(3)
Fixes OS X build.
2014-10-14 16:33:10 +02:00
Martin Willi 7dd06d274d process: Add a wrapper to invoke a command under the system default shell 2014-10-06 18:24:39 +02:00
Martin Willi 02e4dedce5 process: Port child process spawning to the Windows platform 2014-10-06 18:24:39 +02:00
Martin Willi 1fea589c1f process: Provide an abstraction to spawn child processes with redirected I/O 2014-10-06 18:24:39 +02:00
Martin Willi 6eaec1e349 leak-detective: Whitelist libssl SSL_COMP_get_compression_methods()
This function is called by libcurl initialization with SSL, and uses
a static allocation of compression algorithms not freed.
2014-09-24 11:35:59 +02:00
Tobias Brunner c6e8b5dc2c chunk: Fix Doxygen comments for chunk_internet_checksum[_inc] 2014-09-11 17:56:12 +02:00
Martin Willi 11bf11c1f5 utils: Check if the parameter passed to countof() is actually an array type
This should avoid errors such as the one fixed with 118b2879.
2014-08-25 09:48:53 +02:00
Martin Willi bb6be26197 utils: Add some initial build time assertion macros
These are useful to assert constants during build time. We evaluate the
expression to 0 when valid, so we can safely use the evaluated value.
2014-08-25 09:48:53 +02:00
Tobias Brunner b557f4a7cd chunk: Add function to calculate Internet Checksums according to RFC 1071 2014-07-22 11:10:35 +02:00
Martin Willi 920d466f05 utils: Undefine mem{cpy,move,set} if set before defining them
Some platforms, such as OS X, use macros for these functions. Undefine them
to avoid compiler warnings.
2014-07-07 16:14:26 +02:00
Tobias Brunner 831045ef45 optionsfrom: Properly handle errors when determining file size 2014-07-02 12:38:45 +02:00
Tobias Brunner e44223dbcc windows: Fix off-by-one error in strerror_s_extended() 2014-07-02 12:38:45 +02:00
Tobias Brunner 0026600bfe windows: accept() socket handle could theoretically be 0 2014-07-02 12:38:45 +02:00
Tobias Brunner babe9e4f45 windows: Close correct socket when opening second socket fails in socketpair() 2014-07-02 12:38:44 +02:00
Tobias Brunner 0a26f39a71 windows: Make sure the string returned from ReadConsole() is null terminated 2014-07-02 12:38:44 +02:00
Tobias Brunner 0e48f67562 backtrace: Remove name checks after SymFromAddr() calls
The Name member is an array whose address is always defined.
2014-07-02 12:11:59 +02:00
Tobias Brunner 1be2b84124 parser-helper: Ensure file_next() does not remove the sentinel item 2014-07-01 17:58:36 +02:00
Tobias Brunner e79dbda390 utils: Helper macros to define overloaded macros based on number of arguments 2014-06-30 13:29:26 +02:00
Tobias Brunner aad072d517 enum: Replace þ with p in Doxygen comments 2014-06-30 13:16:17 +02:00
Tobias Brunner ed01c1afff Fixed some typos 2014-06-30 13:16:16 +02:00
Martin Willi 07b57e203b windows: Include <sys/stat.h> explicitly before overloading memset()/memcpy()
fstat() in newer MinGWs is defined as non-static inline. With our new static
inline memset()/memcpy() overloads, this raises a warning. To avoid it,
explicitly include <sys/stat.h> once before defining these overloads.
2014-06-25 16:09:42 +02:00
Tobias Brunner 6d4654b9f9 utils: Add wrappers for memcpy(3), memmove(3) and memset(3)
These wrappers guarantee that calls to these functions are noops if the
number of bytes is 0, as calling them with NULL pointers is undefined
according to the C standard, even if the number of bytes is 0 (most
implementations probably ignore the pointers anyway in this case, but
lets make sure).
2014-06-24 15:11:27 +02:00
Tobias Brunner aba55fdffe identification: Only use either , or / to separate RDNs
If a DN starts with a slash (or whitespace and a slash) slashes will
be used, otherwise commas.
2014-06-18 09:24:03 +02:00
Martin Willi dff39a4c5b windows: Declare strerror_s()
Older MinGW versions seem to miss this function declaration. Fixes build on
Travis using Ubuntu 12.04.
2014-06-17 15:23:33 +02:00
Martin Willi 1bcf850738 windows: Extend strerror_r/s by extended POSIX errno strings 2014-06-17 15:23:33 +02:00
Martin Willi c2119cded4 windows: Implement strerror_r using strerror_s 2014-06-17 15:23:33 +02:00
Martin Willi 8b5d41a274 windows: Wrap most Winsock2 Posix functions to set errno
While Winsock provides many Posix compatibility functions, they do not set
errno, but use WSAGetLastError() for error reporting. The wrapped functions
derive an errno from WSAGetLastError() on failure.
2014-06-17 15:23:32 +02:00
Martin Willi 8c2c63e09d backtrace: Use GetModuleInformation/GetModuleFileNameEx directly on Win32
The K32 variants are actually needed on 64-bit only.
2014-06-06 16:28:28 +02:00
Martin Willi cab59c73fc windows: Use WINAPI call convention for Windows API callbacks
For x86_64 it does not actually matter, but for i686 builds the call convention
is different with WINAPI.
2014-06-06 16:28:28 +02:00
Martin Willi 7659f67af3 windows: Provide POSIX supplement errno values missing in MinGW
MinGW headers do not define these values, but Windows system headers do.
Windows defines them for POSIX compatibility, we do the same locally.
2014-06-04 15:53:12 +02:00
Martin Willi 2162e50004 windows: Provide shutdown(2) operation aliases mapping to those on Windows 2014-06-04 15:53:12 +02:00
Martin Willi 0c34c1b3af unit-tests: Support testable functions on Windows, avoid weak GCC symbols
Instead of using weak symbols, we use dlsym() on Windows to find an arbitrary
symbol in libtest to detect its linkage. Instead of creating the associated
hashtable in the test runner, we maintain it in libstrongswan, making it
significantly simpler.
2014-06-04 15:53:12 +02:00
Martin Willi 460adb5d09 unit-tests: Seed chunk_hash() only once, but before creating any hashtables
Due to the removal of pthread_once, we manually create the seed for
chunk_hash(). With the new testable functions interface, this won't work for
the hashtable initiated using __attribute__((constructor)). Enforce seeding
before creating that hashtable.
2014-06-04 15:53:11 +02:00
Martin Willi 66c0801dc7 utils: Add a wait_sigint() function to wait for SIGINT or equivalent 2014-06-04 15:53:11 +02:00
Martin Willi 1309cb7b1a chunk: On Windows, use binary mode in chunk_write() 2014-06-04 15:53:10 +02:00
Martin Willi bc9fd3735d parser-helper: Detect absolute pathnames and concatenate paths on Windows 2014-06-04 15:53:09 +02:00
Martin Willi 67b3bcd13d utils: Provide a path_absolute() function to check path for non-relativeness
The usually used trivial '/' check won't work on Windows platforms.
2014-06-04 15:53:09 +02:00
Martin Willi 2496eaffde utils: Return plain drive letter as base/pathname for drive letters on Windows 2014-06-04 15:53:08 +02:00
Martin Willi 8182631bc3 utils: Support Windows path separators in path_basename/dirname 2014-06-04 15:53:08 +02:00
Martin Willi a43f1e5631 utils: Define a platform directory separator character used in paths 2014-06-04 15:53:08 +02:00
Martin Willi 41bb8ba5d2 windows: Provide a getpass() implementation 2014-06-04 15:53:08 +02:00
Martin Willi c5447bc2f5 chunk: On Windows, chunk_map() opens files in binary mode 2014-06-04 15:53:08 +02:00
Martin Willi 8120b3c339 windows: Don't redeclare inet_ntop/pton if already defined 2014-06-04 15:53:05 +02:00
Martin Willi 1f3bf4175d windows: Check for existence of error codes before defining them 2014-06-04 15:53:05 +02:00
Martin Willi 3d50dd47ef windows: Overload sleep() cancellable when it is defined in <unistd.h> 2014-06-04 15:53:04 +02:00
Martin Willi efcf249aeb windows: Provide a close(2) that can close both file handles and sockets 2014-06-04 15:53:04 +02:00
Martin Willi 740404d481 chunk: Fallback to recv() on Windows chunk_from_fd() when operating on socket 2014-06-04 15:53:04 +02:00
Martin Willi 9ff1716029 windows: Don't use function macros to overload send/recv() and friends
While the macro versions would not catch non-function invocations, we actually
have to use catch all to support the sender_t.send() function.
2014-06-04 15:53:03 +02:00
Martin Willi f3c809e615 windows: Provide a strndup(3) replacement 2014-06-04 15:53:02 +02:00
Martin Willi 110e42361e unit-tests: Uninline dlopen() and friends, make more dynamic, fix dlerror()
As the error string contains a newline, we have to remove that before
returning the string.
2014-06-04 15:53:02 +02:00
Martin Willi a48570a046 windows: Provide a cancellable usleep(), but with ms resolution only 2014-06-04 15:53:01 +02:00
Martin Willi 986a577097 windows: Add a sleep function acting as cancellation point 2014-06-04 15:53:01 +02:00
Martin Willi 266ee0a190 windows: Provide a sched_yield() implementation 2014-06-04 15:53:01 +02:00
Martin Willi 4de7401a98 windows: Provide a time_monotonic() based on GetTickCount64() 2014-06-04 15:53:01 +02:00
Martin Willi c46cee6f6d chunk: Don't depend on pthread directly 2014-06-04 15:53:00 +02:00
Martin Willi f1c9653e04 utils: Don't directly depend on pthread 2014-06-04 15:53:00 +02:00
Martin Willi eb94f58595 strerror: Don't directly depend on pthread 2014-06-04 15:53:00 +02:00
Martin Willi a506b922f3 windows: Provide a strdup variant safe when passing zero-length strings 2014-06-04 15:53:00 +02:00
Martin Willi aa5b49c037 stream: Separate TCP/Unix stream helpers from stream/service implementations
This allows us to disable Unix sockets cleanly on Windows. Replaces some
read/write calls with recv/send counterparts, as Winsock does not like
read/writes.
2014-06-04 15:53:00 +02:00
Martin Willi df0769299a windows: Map WSAGetLastError() to errno failures in wrapped send/recv/from/to 2014-06-04 15:52:59 +02:00
Martin Willi 20021277f2 windows: Add send/recv and sendto/recvfrom wrappers supporting MSG_DONTWAIT 2014-06-04 15:52:59 +02:00
Martin Willi 82fcb80276 windows: Implement socketpair() using TCP sockets 2014-06-04 15:52:59 +02:00
Martin Willi 87a79e6a03 windows: Add utils_init/deinit functions to initialize Winsock2 2014-06-04 15:52:59 +02:00
Martin Willi fb81820796 windows: Provide a setenv() wrapper 2014-06-04 15:52:59 +02:00
Martin Willi a2216a2868 windows: Fix up PRI* printf formatters when building against own backend 2014-06-04 15:52:58 +02:00
Martin Willi 95a8d53dbe windows: Use localtime/gmtime to implement _r variants
The _s variants and friends do not seem to work on Windows 7 and always fail.
2014-06-04 15:52:58 +02:00
Martin Willi 8f129319ff utils: Printf() defined time output should gmtime/localtime_r() fail 2014-06-04 15:52:58 +02:00
Martin Willi 087e02e47e backtrace: Inline esc() helper, making it available to all build variants 2014-06-04 15:52:58 +02:00
Martin Willi 2127831cda backtrace: Support backtraces on Windows without DbgHelp
While DbgHelp provides a convenient API to create backtraces, any executable
linking against DbgHelp gets a more than a significant slow down. Further, it
can only lookup global symbols, as it expects PDB files we can't produce with a
MinGW build.

With some core Kernel32.dll functionality, we can capture stack traces much
faster. Together with the optional libbfd, we can print very fine backtraces.

When --enable-bfd-backtraces is used on Windows, a libbfd.dll is required for
the build. Such a DLL can be created from the binutils sources using:

  # build binutils with mingw...

  # extract archive members from binutils libraries
  x86_64-w64-mingw32-ar x $BINUTILS/bfd/.libs/libbfd.a
  x86_64-w64-mingw32-ar x $BINUTILS/intl/libintl.a
  x86_64-w64-mingw32-ar x $BINUTILS/libiberty/libiberty.a

  # create self-contained libbfd.a, with index
  x86_64-w64-mingw32-ar qs libbfd.a *.o

  # create DLL from static library
  x86_64-w64-mingw32-dlltool -e libbfd.o -l libbfd.lib libbfd.a
  x86_64-w64-mingw32-gcc -shared libbfd.a libbfd.o -o libbfd.dll
2014-06-04 15:52:58 +02:00
Martin Willi a7e943a640 backtrace: Add DbgHelp based Windows support for creating/printing backtraces 2014-06-04 15:52:57 +02:00
Martin Willi 1f2b8c8c80 printf-hook-builtin: Support Windows console colors using TTY escape codes 2014-06-04 15:52:57 +02:00
Martin Willi e7f3ceb7c8 capabilities: Add build support for Windows
We might extend it in the future using some Windows rights management.
2014-06-04 15:52:57 +02:00
Martin Willi d3c30b356c windows: Use _getmaxstdio as replacement for syscall(_SC_OPEN_MAX) 2014-06-03 12:24:35 +02:00
Martin Willi a3f7dfc1ca windows: replace mkdir() with Windows _mkdir() variant 2014-06-03 12:24:35 +02:00
Martin Willi 2e6c203bad windows: Provide wrappers for dlopen() function family 2014-06-03 12:24:34 +02:00
Martin Willi 922ee2c529 windows: Add a common Windows header for platform specific wrappers
Include some more basic system headers in utils.h, so we can use that common
header on the different platforms.
2014-06-03 12:24:34 +02:00
Martin Willi 064fe9c963 enum: Return boolean result for enum_from_name() lookup
Handling the result for enum_from_name() is difficult, as checking for
negative return values requires a cast if the enum type is unsigned. The new
signature clearly differentiates lookup result from lookup value.

Further, this actually allows to convert real -1 enum values, which could not
be distinguished from "not-found" and the -1 return value.

This also fixes several clang warnings where enums are unsigned.
2014-05-16 15:42:07 +02:00
Martin Willi 9ee8b3b41f enum: Don't directly include enum.h
To allow enum.h to depend on utils.h definitions, avoid its direct inclusion.
Instead include utils.h, which includes enum.h as well.
2014-05-16 15:42:07 +02:00
Tobias Brunner 4102fc9c09 parser-helper: Define debug macros depending on DEBUG_LEVEL 2014-05-15 11:28:10 +02:00
Tobias Brunner 66248396c6 parser-helper: Make parser_helper_file_t private 2014-05-15 11:28:10 +02:00
Tobias Brunner c976cc7d33 parser-helper: Make parser_helper_log a function 2014-05-15 11:28:10 +02:00
Tobias Brunner f65ac98c64 settings: Reduce log verbosity if files can't be opened
Basically reintroducing 2a38b4556e.
2014-05-15 11:28:09 +02:00
Tobias Brunner 3cb8016f0e parser-helper: Add utility class for flex/bison based parsers 2014-05-15 11:28:06 +02:00
Tobias Brunner b9b1114ab1 settings: Move to a separate folder 2014-05-15 11:28:05 +02:00
Martin Willi 9e93251397 utils: Provide a CALLBACK macro, similar to METHOD, but for void* callbacks
Using the same mechanism as the METHOD macro, the CALLBACK macro defines
a hybrid function signature. It strictly uses a weak void* for the first
function parameter, in contrast to the dynamic METHOD object "this" type.
2014-05-07 14:13:34 +02:00
Tobias Brunner a0c2370ea5 utils: Enable __atomic* built-ins based on the GCC version
This solves a problem with GNAT when compiling charon-tkm as __atomic*
built-ins are only provided in GCC 4.7 and newer.

Currently GNAT 4.6 and GCC 4.7.2 is shipped with Debian wheezy (stable),
as used in the testing environment.  So while the configure script correctly
detected the __atomic* built-ins, and defined HAVE_GCC_ATOMIC_OPERATIONS,
this define turned out to be incorrect when charon-tkm was later built
with GNAT.
2014-05-04 19:16:46 +02:00
Tobias Brunner 0f603d425d utils: Use GCC's __atomic built-ins if available
These are available since GCC 4.7 and will eventually replace the __sync
operations.  They support the memory model defined by C++11. For instance,
by using __ATOMIC_RELAXED for some operations on the reference counters we
can avoid memory barriers, which are required by __sync operations (whose
memory model essentially is __ATOMIC_SEQ_CST).
2014-04-24 17:54:14 +02:00
Tobias Brunner efedd0d21e utils: Add ref_cur() to retrieve the current value of a reference counter
On many architectures it is safe to read the value directly (those
using cache coherency protocols, and with atomic loads for 32-bit
values) but it is not if that's not the case or if we ever decide to
make refcount_t 64-bit (load not atomic on x86).

So make sure the operation is actually atomic and that users do not
have to care about the size of refcount_t.
2014-04-24 17:53:42 +02:00
Tobias Brunner adc1157487 leak-detective: LEAK_DETECTIVE_DISABLE completely disables LD
If lib->leak_detective is non-null some code parts (e.g. the plugin
loader) assume LD is actually used.
2014-04-03 09:44:26 +02:00
Tobias Brunner 036dab0a10 unit-tests: Always load address of testable functions
The addresses can actually change as plugins are loaded/unloaded for
each test case.

Fixes #551.
2014-03-31 17:00:22 +02:00
Tobias Brunner 2a38b4556e settings: Reduce log verbosity if strongswan.conf does not exist
In some situations we expect strongswan.conf to not exist, for instance,
when running the unit tests before installation.
2014-03-31 16:40:04 +02:00
Tobias Brunner b751f6f25a unit-tests: Implement registered functions without __builtin_apply()
This makes the tests work with clang, which does not implement said
builtin.
2014-03-20 15:37:44 +01:00
Tobias Brunner 2c687b3cb3 unit-tests: Prefix imported testable functions with TEST_
This avoids any clashes with existing functions in the monolithic build.
2014-03-20 15:29:27 +01:00
Tobias Brunner f51169eb09 unit-tests: Change how hashtable for testable functions is created
Because GCC does not adhere to the priorities defined for constructors
when building with --enable-monolithic (not sure if it was just luck
that it worked in non-monolithic mode - anyway, it's not very portable)
function registration would fail because the hashtable would not be
created yet.
2014-03-20 15:29:27 +01:00
Tobias Brunner d517a9893e settings: Log all errors on level 1
Closes #539.
2014-03-04 13:30:09 +01:00
Thomas Egerer 7acdebf6c0 settings: Avoid conf file parsing beyond allocated buffer
A valgrind analysis of libstrongswan revealed an invalid read of 1 in
the function starts_with(). A more thorough analysis proved this to be
true and showed that with a specially crafted config file (e.g. a single
'#'-character not followed by a newline), the parser might even
interpret the random memory contents following the allocated buffer as
part of the configuration file.
The way the parser is designed, it must be able to skip an inserted
'\0' and continue parsing. Since it is not able to skip two '\0'
characters, the 'fix' of allocating two more bytes than the size of the
parsed file and setting them to '\0' seems to be a safe bet.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2014-03-03 17:27:58 +01:00
Tobias Brunner 2ed241aeb3 utils: Add memrchr(3) replacement for platforms that don't support it
For instance, on Mac OS X memrchr(3) is not provided by the C library.
2014-02-26 11:05:07 +01:00
Tobias Brunner 18019a3b89 settings: Use thread-safe dirname(3) 2014-02-24 12:04:11 +01:00
Tobias Brunner 766141bc77 utils: Add thread-safe variants of dirname(3) and basename(3) 2014-02-24 12:04:11 +01:00
Tobias Brunner ba10cd3c7f utils: Move thread-safe strerror replacement to a separate file
For some utils _GNU_SOURCE might be needed but that conflicts with the
signature of strerror_r(3).
2014-02-24 12:04:10 +01:00
Tobias Brunner caf1770905 settings: Use dirname(3) correctly
dirname(3) may return a pointer to a statically allocated buffer.
So freeing the returned value can result to undefined behavior. This was
noticed on FreeBSD where it caused very strange crashes.

It is also not thread-safe, which will be addressed later.
2014-02-24 12:03:49 +01:00
Tobias Brunner 4ab38d98a7 Fixed some typos 2014-02-18 10:36:25 +01:00
Tobias Brunner 6477e64a8d printf-hook-glibc: printf.h on FreeBSD 10 does not include stdargs.h 2014-02-13 10:46:52 +01:00
Tobias Brunner 9925eeabd2 settings: Add support to enumerate sections and key/value pairs with fallbacks 2014-02-12 14:34:33 +01:00
Tobias Brunner f4da1989cd settings: Implement subsections and key/value pairs with sorted arrays
Is a bit more memory efficient (also due to lazy instantiation) and
lookups for sections with lots of subsections/keys (e.g. charon.plugins) are
faster.
2014-02-12 14:34:33 +01:00
Tobias Brunner 8dc6e71632 lib: All settings use configured namespace 2014-02-12 14:34:32 +01:00
Tobias Brunner 1713d88278 settings: Add method that allows to define fallback sections for other sections
The fallbacks are currently only used for single value lookups.
Enumerators are not affected by them.
2014-02-12 14:34:32 +01:00
Tobias Brunner ef72d4cc3f settings: Make print_key() not rely on null-terminated beginning of key buffer
The key to print (e.g. until the next .) still has to be
null-terminated.
2014-02-12 14:34:32 +01:00
Tobias Brunner 25ee33ba65 settings: Allow empty strings in section key 2014-02-12 14:34:32 +01:00
Tobias Brunner 5e75f50b70 identification: Fix printing of empty RDNs on FreeBSD
On FreeBSD (null) is printed for NULL even if the precision is 0.
2014-02-12 13:45:42 +01:00
Thomas Egerer b351acfed6 leak_detective: Assign return value of realloc to buf
If realloc return a pointer value different from the value to be
reallocated, a double free can occur in this context.

Signed-off-by: Thomas Egerer <thomas.egerer@secunet.com>
2014-02-10 17:23:54 +01:00
Martin Willi 69be6a9e05 integrity-checker: Use chunk_map() instead of non-portable mmap() 2014-01-23 15:55:32 +01:00
Martin Willi b9ee059ca9 chunk: Externalize error reporting in chunk_write()
This avoids passing that arbitrary label just for error messages, and gives
greater flexibility in handling errors.
2014-01-23 15:55:32 +01:00
Martin Willi 37374a292a chunk: Provide a fallback chunk_map() if mmap is not available 2014-01-23 15:55:32 +01:00
Martin Willi 1c4a3459f7 chunk: Use dynamically allocated buffer in chunk_from_fd()
When acting on files, we can use fstat() to estimate the buffer size. On
non-file FDs, we dynamically increase an allocated buffer.

Additionally we slightly change the function signature to properly handle
zero-length files and add appropriate unit tests.
2014-01-23 15:55:32 +01:00
Martin Willi 595b6d9a82 chunk: Add functions to map file contents to a chunk 2014-01-23 15:55:32 +01:00