Sunday, April 26, 2015

Building JSONs using the POCO C++ library

POCO refers to a very handy set of libraries for C++. They are cleanly written, STL-like, easy to use and most importantly, free (Boost License). I've had a small encounter with these libraries, mainly the JSON module and I'll detail, in this article, on how to build a JSON and then how to parse a JSON object manually using POCO::JSON.



Monday, April 13, 2015

How to drop root permissions in C

Sometimes it is necessary to run an application with root permissions in order to do some elevated work like binding to ports lower than 1024 or writing to files in /var/log, etc.  After the elevated work is finished, it is good practice to drop the root privileges and continue with the execution path as a non-privileged user. The motivation is based on security reasons: if ever an attacker takes control over your application, it should not give him control over the whole system.



Saturday, April 11, 2015

Getting the stack trace programmatically in C

In some situations where applications run for a long period of time on remote systems, if the application crashes, there is little information about the crash: no core dump or valuable log available. In such cases it is useful to get and log the stack trace at the moment of the crash, thus having some more information in order to solve the problem.
Getting some information about the stack trace is possible using C, as we will see below.