14a131ac |
/*
* OpenVPN -- An application to securely tunnel IP networks
* over a single TCP/UDP port, with support for SSL/TLS-based
* session authentication and key exchange,
* packet encryption, packet authentication, and
* packet compression.
* |
49979459 |
* Copyright (C) 2002-2018 OpenVPN Inc <sales@openvpn.net> |
14a131ac |
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
* |
caa54ac3 |
* You should have received a copy of the GNU General Public License along
* with this program; if not, write to the Free Software Foundation, Inc.,
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
14a131ac |
*/
#ifndef PLATFORM_H
#define PLATFORM_H
#ifdef HAVE_SYS_TYPES_H
#include <sys/types.h>
#endif
#ifdef HAVE_SYS_STAT_H
#include <sys/stat.h>
#endif
#ifdef HAVE_UNISTD_H
#include <unistd.h>
#endif
#ifdef HAVE_PWD_H
#include <pwd.h>
#endif
#ifdef HAVE_GRP_H
#include <grp.h>
#endif
#ifdef HAVE_STDIO_H
#include <stdio.h>
#endif
#include "basic.h" |
b7bea782 |
#include "buffer.h" |
14a131ac |
/* Get/Set UID of process */
struct platform_state_user {
#if defined(HAVE_GETPWNAM) && defined(HAVE_SETUID) |
81d882d5 |
const char *username;
struct passwd *pw; |
14a131ac |
#else |
81d882d5 |
int dummy; |
14a131ac |
#endif
};
/* Get/Set GID of process */
struct platform_state_group {
#if defined(HAVE_GETGRNAM) && defined(HAVE_SETGID) |
81d882d5 |
const char *groupname;
struct group *gr; |
14a131ac |
#else |
81d882d5 |
int dummy; |
14a131ac |
#endif
};
|
81d882d5 |
bool platform_user_get(const char *username, struct platform_state_user *state); |
14a131ac |
|
81d882d5 |
void platform_user_set(const struct platform_state_user *state);
bool platform_group_get(const char *groupname, struct platform_state_group *state);
void platform_group_set(const struct platform_state_group *state); |
14a131ac |
/*
* Extract UID or GID
*/
static inline int |
81d882d5 |
platform_state_user_uid(const struct platform_state_user *s) |
14a131ac |
{
#if defined(HAVE_GETPWNAM) && defined(HAVE_SETUID) |
81d882d5 |
if (s->pw)
{
return s->pw->pw_uid;
} |
14a131ac |
#endif |
81d882d5 |
return -1; |
14a131ac |
}
static inline int |
81d882d5 |
platform_state_group_gid(const struct platform_state_group *s) |
14a131ac |
{
#if defined(HAVE_GETGRNAM) && defined(HAVE_SETGID) |
81d882d5 |
if (s->gr)
{
return s->gr->gr_gid;
} |
14a131ac |
#endif |
81d882d5 |
return -1; |
14a131ac |
}
|
81d882d5 |
void platform_chroot(const char *path); |
14a131ac |
|
81d882d5 |
void platform_nice(int niceval); |
14a131ac |
|
81d882d5 |
unsigned int platform_getpid(void); |
14a131ac |
|
81d882d5 |
void platform_mlockall(bool print_msg); /* Disable paging */ |
14a131ac |
|
81d882d5 |
int platform_chdir(const char *dir); |
14a131ac |
|
05634736 |
/* interpret the status code returned by execve() */ |
81d882d5 |
bool platform_system_ok(int stat); |
14a131ac |
|
81d882d5 |
int platform_access(const char *path, int mode); |
14a131ac |
|
81d882d5 |
void platform_sleep_milliseconds(unsigned int n); |
14a131ac |
|
81d882d5 |
void platform_sleep_until_signal(void); |
14a131ac |
/* delete a file, return true if succeeded */ |
81d882d5 |
bool platform_unlink(const char *filename); |
14a131ac |
|
81d882d5 |
int platform_putenv(char *string); |
14a131ac |
|
81d882d5 |
FILE *platform_fopen(const char *path, const char *mode);
int platform_open(const char *path, int flags, int mode); |
14a131ac |
|
445b192a |
#ifdef _WIN32 |
14a131ac |
typedef struct _stat platform_stat_t;
#else
typedef struct stat platform_stat_t;
#endif |
81d882d5 |
int platform_stat(const char *path, platform_stat_t *buf); |
14a131ac |
|
b7bea782 |
/**
* Create a temporary file in directory, returns the filename of the created
* file.
*/
const char *platform_create_temp_file(const char *directory, const char *prefix,
struct gc_arena *gc);
/** Put a directory and filename together. */
const char *platform_gen_path(const char *directory, const char *filename,
struct gc_arena *gc);
/** Return true if pathname is absolute. */
bool platform_absolute_pathname(const char *pathname);
/** Return true if filename can be opened for read. */
bool platform_test_file(const char *filename);
|
81d882d5 |
#endif /* ifndef PLATFORM_H */ |