diff options
author | Martin Willi <martin@revosec.ch> | 2014-06-04 16:26:58 +0200 |
---|---|---|
committer | Martin Willi <martin@revosec.ch> | 2014-06-04 16:26:58 +0200 |
commit | 8c55f8ef42816a695895990cf89697a30c235355 (patch) | |
tree | c4aa8a3f0f08166b37369bb93132d0ece470af42 /src/libstrongswan/utils/capabilities.c | |
parent | b4c51061c3c649e948324d1f3ad37ef6e48f8b96 (diff) | |
parent | d930d184177ef352c4b5def4e5848463819435ec (diff) | |
download | strongswan-8c55f8ef42816a695895990cf89697a30c235355.tar.bz2 strongswan-8c55f8ef42816a695895990cf89697a30c235355.tar.xz |
Merge branch 'win'
Ports the strongSwan core libraries and some plugins to the Windows platform
using a MinGW based toolchain. Beside generic platform abstraction and
the windows.[ch] compatibility layer, this merge introduces a Windows native
threading backend and a charon-svc Windows IKE service.
Travis adds a MinGW cross-compile build to Windows, and further enables -Werror
to let builds fail for all compiler warnings with gcc and Clang.
Diffstat (limited to 'src/libstrongswan/utils/capabilities.c')
-rw-r--r-- | src/libstrongswan/utils/capabilities.c | 40 |
1 files changed, 37 insertions, 3 deletions
diff --git a/src/libstrongswan/utils/capabilities.c b/src/libstrongswan/utils/capabilities.c index c5e90b6c3..923b7d4db 100644 --- a/src/libstrongswan/utils/capabilities.c +++ b/src/libstrongswan/utils/capabilities.c @@ -17,24 +17,27 @@ #include "capabilities.h" +#include <utils/debug.h> + #include <errno.h> #include <string.h> #include <sys/types.h> +#include <unistd.h> + +#ifndef WIN32 #include <pwd.h> #include <grp.h> -#include <unistd.h> #ifdef HAVE_PRCTL # include <sys/prctl.h> #endif /* HAVE_PRCTL */ -#include <utils/debug.h> - #if !defined(HAVE_GETPWNAM_R) || \ !defined(HAVE_GETGRNAM_R) || \ !defined(HAVE_GETPWUID_R) # include <threading/mutex.h> # define EMULATE_R_FUNCS #endif +#endif /* !WIN32 */ typedef struct private_capabilities_t private_capabilities_t; @@ -76,6 +79,8 @@ struct private_capabilities_t { #endif }; +#ifndef WIN32 + /** * Returns TRUE if the current process/user is member of the given group */ @@ -181,6 +186,19 @@ static bool has_capability(private_capabilities_t *this, u_int cap, #endif /* CAPABILITIES_NATIVE */ } +#else /* WIN32 */ + +/** + * Verify that the current process has the given capability, dummy variant + */ +static bool has_capability(private_capabilities_t *this, u_int cap, + bool *ignore) +{ + return TRUE; +} + +#endif /* WIN32 */ + /** * Keep the given capability if it is held by the current process. Returns * FALSE, if this is not the case. @@ -232,13 +250,21 @@ METHOD(capabilities_t, check, bool, METHOD(capabilities_t, get_uid, uid_t, private_capabilities_t *this) { +#ifdef WIN32 + return this->uid; +#else return this->uid ?: geteuid(); +#endif } METHOD(capabilities_t, get_gid, gid_t, private_capabilities_t *this) { +#ifdef WIN32 + return this->gid; +#else return this->gid ?: getegid(); +#endif } METHOD(capabilities_t, set_uid, void, @@ -256,6 +282,7 @@ METHOD(capabilities_t, set_gid, void, METHOD(capabilities_t, resolve_uid, bool, private_capabilities_t *this, char *username) { +#ifndef WIN32 struct passwd *pwp; int err; @@ -284,12 +311,14 @@ METHOD(capabilities_t, resolve_uid, bool, } DBG1(DBG_LIB, "resolving user '%s' failed: %s", username, err ? strerror(err) : "user not found"); +#endif /* !WIN32 */ return FALSE; } METHOD(capabilities_t, resolve_gid, bool, private_capabilities_t *this, char *groupname) { +#ifndef WIN32 struct group *grp; int err; @@ -318,9 +347,11 @@ METHOD(capabilities_t, resolve_gid, bool, } DBG1(DBG_LIB, "resolving user '%s' failed: %s", groupname, err ? strerror(err) : "group not found"); +#endif /* !WIN32 */ return FALSE; } +#ifndef WIN32 /** * Initialize supplementary groups for unprivileged user */ @@ -348,10 +379,12 @@ static bool init_supplementary_groups(private_capabilities_t *this) #endif /* HAVE_GETPWUID_R */ return res == 0; } +#endif /* WIN32 */ METHOD(capabilities_t, drop, bool, private_capabilities_t *this) { +#ifndef WIN32 #ifdef HAVE_PRCTL prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0); #endif @@ -404,6 +437,7 @@ METHOD(capabilities_t, drop, bool, DBG1(DBG_LIB, "dropped capabilities, running as uid %u, gid %u", geteuid(), getegid()); #endif /* CAPABILITIES */ +#endif /*!WIN32 */ return TRUE; } |