capabilities: Add build support for Windows
We might extend it in the future using some Windows rights management.
This commit is contained in:
@@ -17,24 +17,27 @@
|
|||||||
|
|
||||||
#include "capabilities.h"
|
#include "capabilities.h"
|
||||||
|
|
||||||
|
#include <utils/debug.h>
|
||||||
|
|
||||||
#include <errno.h>
|
#include <errno.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
#include <pwd.h>
|
#include <pwd.h>
|
||||||
#include <grp.h>
|
#include <grp.h>
|
||||||
#include <unistd.h>
|
|
||||||
#ifdef HAVE_PRCTL
|
#ifdef HAVE_PRCTL
|
||||||
# include <sys/prctl.h>
|
# include <sys/prctl.h>
|
||||||
#endif /* HAVE_PRCTL */
|
#endif /* HAVE_PRCTL */
|
||||||
|
|
||||||
#include <utils/debug.h>
|
|
||||||
|
|
||||||
#if !defined(HAVE_GETPWNAM_R) || \
|
#if !defined(HAVE_GETPWNAM_R) || \
|
||||||
!defined(HAVE_GETGRNAM_R) || \
|
!defined(HAVE_GETGRNAM_R) || \
|
||||||
!defined(HAVE_GETPWUID_R)
|
!defined(HAVE_GETPWUID_R)
|
||||||
# include <threading/mutex.h>
|
# include <threading/mutex.h>
|
||||||
# define EMULATE_R_FUNCS
|
# define EMULATE_R_FUNCS
|
||||||
#endif
|
#endif
|
||||||
|
#endif /* !WIN32 */
|
||||||
|
|
||||||
typedef struct private_capabilities_t private_capabilities_t;
|
typedef struct private_capabilities_t private_capabilities_t;
|
||||||
|
|
||||||
@@ -76,6 +79,8 @@ struct private_capabilities_t {
|
|||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns TRUE if the current process/user is member of the given group
|
* 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 */
|
#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
|
* Keep the given capability if it is held by the current process. Returns
|
||||||
* FALSE, if this is not the case.
|
* FALSE, if this is not the case.
|
||||||
@@ -232,13 +250,21 @@ METHOD(capabilities_t, check, bool,
|
|||||||
METHOD(capabilities_t, get_uid, uid_t,
|
METHOD(capabilities_t, get_uid, uid_t,
|
||||||
private_capabilities_t *this)
|
private_capabilities_t *this)
|
||||||
{
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
return this->uid;
|
||||||
|
#else
|
||||||
return this->uid ?: geteuid();
|
return this->uid ?: geteuid();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(capabilities_t, get_gid, gid_t,
|
METHOD(capabilities_t, get_gid, gid_t,
|
||||||
private_capabilities_t *this)
|
private_capabilities_t *this)
|
||||||
{
|
{
|
||||||
|
#ifdef WIN32
|
||||||
|
return this->gid;
|
||||||
|
#else
|
||||||
return this->gid ?: getegid();
|
return this->gid ?: getegid();
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(capabilities_t, set_uid, void,
|
METHOD(capabilities_t, set_uid, void,
|
||||||
@@ -256,6 +282,7 @@ METHOD(capabilities_t, set_gid, void,
|
|||||||
METHOD(capabilities_t, resolve_uid, bool,
|
METHOD(capabilities_t, resolve_uid, bool,
|
||||||
private_capabilities_t *this, char *username)
|
private_capabilities_t *this, char *username)
|
||||||
{
|
{
|
||||||
|
#ifndef WIN32
|
||||||
struct passwd *pwp;
|
struct passwd *pwp;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@@ -284,12 +311,14 @@ METHOD(capabilities_t, resolve_uid, bool,
|
|||||||
}
|
}
|
||||||
DBG1(DBG_LIB, "resolving user '%s' failed: %s", username,
|
DBG1(DBG_LIB, "resolving user '%s' failed: %s", username,
|
||||||
err ? strerror(err) : "user not found");
|
err ? strerror(err) : "user not found");
|
||||||
|
#endif /* !WIN32 */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
METHOD(capabilities_t, resolve_gid, bool,
|
METHOD(capabilities_t, resolve_gid, bool,
|
||||||
private_capabilities_t *this, char *groupname)
|
private_capabilities_t *this, char *groupname)
|
||||||
{
|
{
|
||||||
|
#ifndef WIN32
|
||||||
struct group *grp;
|
struct group *grp;
|
||||||
int err;
|
int err;
|
||||||
|
|
||||||
@@ -318,9 +347,11 @@ METHOD(capabilities_t, resolve_gid, bool,
|
|||||||
}
|
}
|
||||||
DBG1(DBG_LIB, "resolving user '%s' failed: %s", groupname,
|
DBG1(DBG_LIB, "resolving user '%s' failed: %s", groupname,
|
||||||
err ? strerror(err) : "group not found");
|
err ? strerror(err) : "group not found");
|
||||||
|
#endif /* !WIN32 */
|
||||||
return FALSE;
|
return FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef WIN32
|
||||||
/**
|
/**
|
||||||
* Initialize supplementary groups for unprivileged user
|
* Initialize supplementary groups for unprivileged user
|
||||||
*/
|
*/
|
||||||
@@ -348,10 +379,12 @@ static bool init_supplementary_groups(private_capabilities_t *this)
|
|||||||
#endif /* HAVE_GETPWUID_R */
|
#endif /* HAVE_GETPWUID_R */
|
||||||
return res == 0;
|
return res == 0;
|
||||||
}
|
}
|
||||||
|
#endif /* WIN32 */
|
||||||
|
|
||||||
METHOD(capabilities_t, drop, bool,
|
METHOD(capabilities_t, drop, bool,
|
||||||
private_capabilities_t *this)
|
private_capabilities_t *this)
|
||||||
{
|
{
|
||||||
|
#ifndef WIN32
|
||||||
#ifdef HAVE_PRCTL
|
#ifdef HAVE_PRCTL
|
||||||
prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
|
prctl(PR_SET_KEEPCAPS, 1, 0, 0, 0);
|
||||||
#endif
|
#endif
|
||||||
@@ -404,6 +437,7 @@ METHOD(capabilities_t, drop, bool,
|
|||||||
DBG1(DBG_LIB, "dropped capabilities, running as uid %u, gid %u",
|
DBG1(DBG_LIB, "dropped capabilities, running as uid %u, gid %u",
|
||||||
geteuid(), getegid());
|
geteuid(), getegid());
|
||||||
#endif /* CAPABILITIES */
|
#endif /* CAPABILITIES */
|
||||||
|
#endif /*!WIN32 */
|
||||||
return TRUE;
|
return TRUE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user