]>
git.ipfire.org Git - thirdparty/openvpn.git/blob - src/openvpn/platform.h
d8dad74bbd7ed35e3998c532f8403c17e2c85d90
2 * OpenVPN -- An application to securely tunnel IP networks
3 * over a single TCP/UDP port, with support for SSL/TLS-based
4 * session authentication and key exchange,
5 * packet encryption, packet authentication, and
8 * Copyright (C) 2002-2023 OpenVPN Inc <sales@openvpn.net>
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License version 2
12 * as published by the Free Software Foundation.
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
19 * You should have received a copy of the GNU General Public License along
20 * with this program; if not, write to the Free Software Foundation, Inc.,
21 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
27 #ifdef HAVE_SYS_TYPES_H
28 #include <sys/types.h>
31 #ifdef HAVE_SYS_STAT_H
52 #include <sys/resource.h>
58 /* forward declared to avoid large amounts of extra includes */
61 /* Get/Set UID of process */
63 struct platform_state_user
{
64 #if defined(HAVE_GETPWNAM) && defined(HAVE_SETUID)
72 /* Get/Set GID of process */
74 struct platform_state_group
{
75 #if defined(HAVE_GETGRNAM) && defined(HAVE_SETGID)
76 const char *groupname
;
83 bool platform_user_get(const char *username
, struct platform_state_user
*state
);
85 bool platform_group_get(const char *groupname
, struct platform_state_group
*state
);
87 void platform_user_group_set(const struct platform_state_user
*user_state
,
88 const struct platform_state_group
*group_state
,
97 platform_state_user_uid(const struct platform_state_user
*s
)
99 #if defined(HAVE_GETPWNAM) && defined(HAVE_SETUID)
106 platform_state_group_gid(const struct platform_state_group
*s
)
108 #if defined(HAVE_GETGRNAM) && defined(HAVE_SETGID)
114 void platform_chroot(const char *path
);
116 void platform_nice(int niceval
);
118 unsigned int platform_getpid(void);
120 void platform_mlockall(bool print_msg
); /* Disable paging */
122 int platform_chdir(const char *dir
);
124 /** interpret the status code returned by execve() */
125 bool platform_system_ok(int stat
);
127 /** Return an exit code if valid and between 0 and 255, -1 otherwise */
128 int platform_ret_code(int stat
);
130 int platform_access(const char *path
, int mode
);
132 void platform_sleep_milliseconds(unsigned int n
);
134 void platform_sleep_until_signal(void);
136 /* delete a file, return true if succeeded */
137 bool platform_unlink(const char *filename
);
139 int platform_putenv(char *string
);
141 FILE *platform_fopen(const char *path
, const char *mode
);
143 int platform_open(const char *path
, int flags
, int mode
);
146 typedef struct _stat platform_stat_t
;
148 typedef struct stat platform_stat_t
;
150 int platform_stat(const char *path
, platform_stat_t
*buf
);
153 * Create a temporary file in directory, returns the filename of the created
156 const char *platform_create_temp_file(const char *directory
, const char *prefix
,
157 struct gc_arena
*gc
);
159 /** Put a directory and filename together. */
160 const char *platform_gen_path(const char *directory
, const char *filename
,
161 struct gc_arena
*gc
);
163 /** Return true if pathname is absolute. */
164 bool platform_absolute_pathname(const char *pathname
);
166 /** Return true if filename can be opened for read. */
167 bool platform_test_file(const char *filename
);
169 #endif /* ifndef PLATFORM_H */