34#include "blocxx/BLOCXX_config.h"
42#ifdef BLOCXX_HAVE_DIRENT_H
50#ifdef BLOCXX_HAVE_PWD_H
53#ifdef BLOCXX_HAVE_SYS_PARAM_H
58#ifdef BLOCXX_HAVE_UNISTD_H
75#if defined(BLOCXX_NO_SETRESGID_PROTO) && defined(BLOCXX_HAVE_SETRESGID)
76extern "C" {
int setresgid(gid_t rgid, gid_t egid, gid_t sgid); }
79#if defined(BLOCXX_NO_SETRESUID_PROTO) && defined(BLOCXX_HAVE_SETRESUID)
80extern "C" {
int setresuid(uid_t ruid, uid_t euid, uid_t suid); }
83using namespace blocxx;
85#define THRBLOCXX_IF(tst, ExceptionClass, msg) \
90 BLOCXX_THROW(ExceptionClass, (msg)); \
94#define THRBLOCXX_ERRNO_IF(tst, ExceptionClass, msg) \
99 BLOCXX_THROW_ERRNO_MSG(ExceptionClass, (msg)); \
103#define ABORT_IF(tst, msg) THRBLOCXX_IF((tst), Secure::ProcessAbortException, (msg))
105#define ABORT_ERRNO_IF(tst, msg) \
106 THRBLOCXX_ERRNO_IF((tst), Secure::ProcessAbortException, (msg))
110#if !defined(BLOCXX_HAVE_SETEUID) && defined(BLOCXX_HAVE_SETREUID)
111int seteuid(uid_t euid)
113 return (setreuid(-1, euid));
118#if !defined(BLOCXX_HAVE_SETEGID) && defined(BLOCXX_HAVE_SETRESGID)
119int setegid(uid_t egid)
121 return(setresgid(-1, egid, -1));
140#pragma message(Reminder "TODO: implement it for Win!")
183#if defined(BLOCXX_HAVE_SETRESGID) && !defined(BLOCXX_BROKEN_SETRESGID)
185#elif defined(BLOCXX_HAVE_SETREGID) && !defined(BLOCXX_BROKEN_SETREGID)
195#if defined(BLOCXX_HAVE_SETRESUID) && !defined(BLOCXX_BROKEN_SETRESUID)
197#elif defined(BLOCXX_HAVE_SETREUID) && !defined(BLOCXX_BROKEN_SETREUID)
200#if !defined(BLOCXX_SETEUID_BREAKS_SETUID)
221 "drop_privileges [4]"
237 "drop_privileges [6]"
255 for (s =
line.c_str(); (
c = *s) && !std::isspace(
c); ++s)
282 while (std::isspace(*s))
288 return sb.releaseString();
297 std::ifstream
is(
"/etc/environment");
301 if (s.startsWith(
"ODMDIR="))
311 NonRecursiveMutexLock lock(
envMutex);
340 struct MinimalEnvironmentConstructor
345 retval->push_back(
"IFS= \t\n");
368#pragma message(Reminder "TODO: implement it for Win!")
BLOCXX_IMPORT char ** environ
#define BLOCXX_DEFINE_EXCEPTION(NAME)
Define a new exception class named <NAME>Exception that derives from Exception.
#define BLOCXX_LAZY_GLOBAL_INIT(...)
Statically initialize a LazyGlobal instance.
#define ABORT_IF(tst, msg)
#define ABORT_ERRNO_IF(tst, msg)
Note that descriptions of what exceptions may be thrown assumes that object is used correctly,...
This String class is an abstract data type that represents as NULL terminated string of characters.
static String getLine(std::istream &istr)
Reads from in input stream until a newline is encountered.
String & trim()
Strip all leading and trailing space characters (as defined by the C function isspace()) from this St...
StringArray minimalEnvironment()
@ E_SOURCE_EXTENDED_GROUPS
void dropPrivilegesPermanently(::uid_t newuid, ::gid_t newgid, EChildGroupAction extendedGroupAction)
void runAs(char const *username, EChildGroupAction extendedGroupAction)
Look up user ID and group ID for username in password file, chdir to "/", then drop privileges and ru...
Array< String > StringArray
bool operator==(const Array< T > &x, const Array< T > &y)