Skip to content

Commit

Permalink
build: move wrappers into platform module
Browse files Browse the repository at this point in the history
+ Some fixups within the platform.c functions.
- need to check environment set on Windows.

Signed-off-by: Alon Bar-Lev <alon.barlev@gmail.com>
Acked-by: Gert Doering <gert@greenie.muc.de>
Signed-off-by: David Sommerseth <davids@redhat.com>
  • Loading branch information
alonbl authored and David Sommerseth committed Mar 23, 2012
1 parent 72c7b12 commit 14a131a
Show file tree
Hide file tree
Showing 23 changed files with 584 additions and 468 deletions.
1 change: 1 addition & 0 deletions src/openvpn/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ openvpn_SOURCES = \
mbuf.c mbuf.h \
memdbg.h \
misc.c misc.h \
platform.c platform.h \
console.c console.h \
mroute.c mroute.h \
mss.c mss.h \
Expand Down
2 changes: 1 addition & 1 deletion src/openvpn/buffer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1080,7 +1080,7 @@ buffer_list_advance (struct buffer_list *ol, int n)
struct buffer_list *
buffer_list_file (const char *fn, int max_line_len)
{
FILE *fp = openvpn_fopen (fn, "r");
FILE *fp = platform_fopen (fn, "r");
struct buffer_list *bl = NULL;

if (fp)
Expand Down
6 changes: 3 additions & 3 deletions src/openvpn/crypto.c
Original file line number Diff line number Diff line change
Expand Up @@ -868,7 +868,7 @@ read_key_file (struct key2 *key2, const char *file, const unsigned int flags)
#endif
{
in = alloc_buf_gc (2048, &gc);
fd = openvpn_open (file, O_RDONLY, 0);
fd = platform_open (file, O_RDONLY, 0);
if (fd == -1)
msg (M_ERR, "Cannot open file key file '%s'", file);
size = read (fd, in.data, in.capacity);
Expand Down Expand Up @@ -1029,7 +1029,7 @@ read_passphrase_hash (const char *passphrase_file,
const int min_passphrase_size = 8;
uint8_t buf[64];
int total_size = 0;
int fd = openvpn_open (passphrase_file, O_RDONLY, 0);
int fd = platform_open (passphrase_file, O_RDONLY, 0);

if (fd == -1)
msg (M_ERR, "Cannot open passphrase file: '%s'", passphrase_file);
Expand Down Expand Up @@ -1079,7 +1079,7 @@ write_key_file (const int nkeys, const char *filename)
const int bytes_per_line = 16;

/* open key file */
fd = openvpn_open (filename, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);
fd = platform_open (filename, O_CREAT | O_TRUNC | O_WRONLY, S_IRUSR | S_IWUSR);

if (fd == -1)
msg (M_ERR, "Cannot open shared secret file '%s' for write", filename);
Expand Down
2 changes: 1 addition & 1 deletion src/openvpn/error.c
Original file line number Diff line number Diff line change
Expand Up @@ -640,7 +640,7 @@ x_check_status (int status,
my_errno);

if (x_cs_err_delay_ms)
sleep_milliseconds (x_cs_err_delay_ms);
platform_sleep_milliseconds (x_cs_err_delay_ms);
}
gc_free (&gc);
}
Expand Down
18 changes: 9 additions & 9 deletions src/openvpn/init.c
Original file line number Diff line number Diff line change
Expand Up @@ -935,7 +935,7 @@ do_genkey (const struct options * options)
"shared secret output file (--secret)");

if (options->mlock) /* should we disable paging? */
do_mlockall (true);
platform_mlockall (true);

nbits_written = write_key_file (2, options->shared_secret_file);

Expand Down Expand Up @@ -1022,16 +1022,16 @@ do_uid_gid_chroot (struct context *c, bool no_delay)
if (c->options.chroot_dir)
{
if (no_delay)
do_chroot (c->options.chroot_dir);
platform_chroot (c->options.chroot_dir);
else
msg (M_INFO, "NOTE: chroot %s", why_not);
}

/* set user and/or group that we want to setuid/setgid to */
if (no_delay)
{
set_group (&c0->group_state);
set_user (&c0->user_state);
platform_group_set (&c0->platform_state_group);
platform_user_set (&c0->platform_state_user);
c0->uid_gid_set = true;
}
else if (c0->uid_gid_specified)
Expand Down Expand Up @@ -2780,8 +2780,8 @@ do_init_first_time (struct context *c)

/* get user and/or group that we want to setuid/setgid to */
c0->uid_gid_specified =
get_group (c->options.groupname, &c0->group_state) |
get_user (c->options.username, &c0->user_state);
platform_group_get (c->options.groupname, &c0->platform_state_group) |
platform_user_get (c->options.username, &c0->platform_state_user);

/* get --writepid file descriptor */
get_pid_file (c->options.writepid, &c0->pid_state);
Expand All @@ -2791,13 +2791,13 @@ do_init_first_time (struct context *c)

/* should we disable paging? */
if (c->options.mlock && c->did_we_daemonize)
do_mlockall (true); /* call again in case we daemonized */
platform_mlockall (true); /* call again in case we daemonized */

/* save process ID in a file */
write_pid (&c0->pid_state);

/* should we change scheduling priority? */
set_nice (c->options.nice);
platform_nice (c->options.nice);
}
}

Expand Down Expand Up @@ -3342,7 +3342,7 @@ init_instance (struct context *c, const struct env_set *env, const unsigned int

/* should we disable paging? */
if (c->first_time && options->mlock)
do_mlockall (true);
platform_mlockall (true);

#if P2MP
/* get passwords if undefined */
Expand Down
16 changes: 8 additions & 8 deletions src/openvpn/manage.c
Original file line number Diff line number Diff line change
Expand Up @@ -1146,7 +1146,7 @@ man_dispatch_command (struct management *man, struct status_output *so, const ch
}
else if (streq (p[0], "pid"))
{
msg (M_CLIENT, "SUCCESS: pid=%d", openvpn_getpid ());
msg (M_CLIENT, "SUCCESS: pid=%d", platform_getpid ());
}
#ifdef MANAGEMENT_DEF_AUTH
else if (streq (p[0], "nclients"))
Expand Down Expand Up @@ -1429,7 +1429,7 @@ man_record_peer_info (struct management *man)
{
const in_addr_t a = ntohl (addr.sin_addr.s_addr);
const int p = ntohs (addr.sin_port);
FILE *fp = openvpn_fopen (man->settings.write_peer_info_file, "w");
FILE *fp = platform_fopen (man->settings.write_peer_info_file, "w");
if (fp)
{
fprintf (fp, "%s\n%d\n", print_in_addr_t (a, 0, &gc), p);
Expand Down Expand Up @@ -2013,17 +2013,17 @@ man_settings_init (struct man_settings *ms,
*/
if (client_user)
{
struct user_state s;
get_user (client_user, &s);
ms->client_uid = user_state_uid (&s);
struct platform_state_user s;
platform_user_get (client_user, &s);
ms->client_uid = platform_state_user_uid (&s);
msg (D_MANAGEMENT, "MANAGEMENT: client_uid=%d", ms->client_uid);
ASSERT (ms->client_uid >= 0);
}
if (client_group)
{
struct group_state s;
get_group (client_group, &s);
ms->client_gid = group_state_gid (&s);
struct platform_state_group s;
platform_group_get (client_group, &s);
ms->client_gid = platform_state_group_gid (&s);
msg (D_MANAGEMENT, "MANAGEMENT: client_gid=%d", ms->client_gid);
ASSERT (ms->client_gid >= 0);
}
Expand Down
Loading

0 comments on commit 14a131a

Please sign in to comment.