*/
if (!isatty(0) && !isatty(2) )
{
- int fd = open( "/dev/tty", O_RDWR );
+ int fd = platform_open2( "/dev/tty", O_RDWR );
if (fd < 0)
{
msg(M_FATAL, "neither stdin nor stderr are a tty device and you have neither a "
"you need to use --askpass to make passphrase-protected keys work, and you "
"can not use --auth-nocache.", prompt );
}
- close(fd);
+ platform_close(fd);
}
if (echo)
chomp(input);
ret = true;
}
- close(std_out);
+ platform_close(std_out);
argv_reset(&argv);
{
msg(M_FATAL, "Key file ('%s') can be a maximum of %d bytes", file, (int)in.capacity);
}
- close(fd);
+ platform_close(fd);
}
cp = (unsigned char *)in.data;
/* write key file, now formatted in out, to file */
buf_write_string_file(&out, filename, fd);
- if (close(fd))
+ if (platform_close(fd))
{
msg(M_ERR, "Close error on shared secret file %s", filename);
}
#include "integer.h"
#include "ps.h"
#include "mstats.h"
+#include "platform.h"
#if SYSLOG_CAPABILITY
#elif defined(HAVE_DUP2)
if (!std_redir)
{
- int out = open(file,
+ int out = platform_open(file,
O_CREAT | O_WRONLY | (append ? O_APPEND : O_TRUNC),
S_IRUSR | S_IWUSR);
if (out > 2)
{
- close(out);
+ platform_close(out);
}
std_redir = true;
#include "integer.h"
#include "event.h"
#include "fdmisc.h"
+#include "platform.h"
#include "memdbg.h"
ep_free(struct event_set *es)
{
struct ep_set *eps = (struct ep_set *) es;
- close(eps->epfd);
+ platform_close(eps->epfd);
free(eps->events);
free(eps);
}
#include "route.h"
#include "console.h"
#include "win32.h"
+#include "platform.h"
#include "memdbg.h"
{
#if defined(HAVE_DUP) && defined(HAVE_DUP2)
int fd;
- if ((fd = open("/dev/null", O_RDWR, 0)) != -1)
+ if ((fd = platform_open("/dev/null", O_RDWR, 0)) != -1)
{
dup2(fd, 0);
if (!stdin_only)
}
if (fd > 2)
{
- close(fd);
+ platform_close(fd);
}
}
#endif
pid = fork();
if (pid == (pid_t)0) /* child side */
{
- close(pipe_stdout[0]); /* Close read end */
+ platform_close(pipe_stdout[0]); /* Close read end */
dup2(pipe_stdout[1],1);
execve(cmd, argv, envp);
exit(127);
{
int status = 0;
- close(pipe_stdout[1]); /* Close write end */
+ platform_close(pipe_stdout[1]); /* Close write end */
waitpid(pid, &status, 0);
ret = pipe_stdout[0];
}
else /* fork failed */
{
- close(pipe_stdout[0]);
- close(pipe_stdout[1]);
+ platform_close(pipe_stdout[0]);
+ platform_close(pipe_stdout[1]);
msg(M_ERR, "openvpn_popen: unable to fork %s", cmd);
}
}
fd = platform_open(retfname, O_CREAT | O_EXCL | O_WRONLY, S_IRUSR | S_IWUSR);
if (fd != -1)
{
- close(fd);
+ platform_close(fd);
return retfname;
}
else if (fd == -1 && errno != EEXIST)
}
/* create file that will be memory mapped */
- fd = open(fn, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
+ fd = platform_open(fn, O_CREAT | O_TRUNC | O_RDWR, S_IRUSR | S_IWUSR);
if (fd < 0)
{
msg(M_ERR, "mstats_open: cannot open: %s", fn);
if (stat != sizeof(ms))
{
msg(M_ERR, "mstats_open: write error: %s", fn);
- close(fd);
+ platform_close(fd);
return;
}
if (data == MAP_FAILED)
{
msg(M_ERR, "mstats_open: write error: %s", fn);
- close(fd);
+ platform_close(fd);
return;
}
/* close the fd (mmap now controls the file) */
- if (close(fd))
+ if (platform_close(fd))
{
msg(M_ERR, "mstats_open: close error: %s", fn);
}
#include "syshead.h"
+#include "platform.h"
#if P2MP_SERVER
#include "multi.h"
#include "forward-inline.h"
-
#include "memdbg.h"
#ifdef HAVE_SYS_INOTIFY_H
}
#ifdef ENABLE_ASYNC_PUSH
- close(top->c2.inotify_fd);
+ platform_close(top->c2.inotify_fd);
#endif
/* shut down management interface */
#include "multi.h"
#include <inttypes.h>
#include "forward-inline.h"
+#include "platform.h"
#include "memdbg.h"
}
#ifdef ENABLE_ASYNC_PUSH
- close(top->c2.inotify_fd);
+ platform_close(top->c2.inotify_fd);
#endif
/* shut down management interface */
{
if (packet_id_persist_enabled(p))
{
- if (close(p->fd))
+ if (platform_close(p->fd))
{
msg(D_PID_PERSIST | M_ERRNO, "Close error on --replay-persist file %s", p->filename);
}
#endif
}
+int
+platform_open2(const char *path, int flags)
+{
+ FUZZING_BLOCK;
+ return open(path, flags);
+}
+
int
platform_stat(const char *path, platform_stat_t *buf)
{
return platform_send(fd, buf, len, 0);
}
+int platform_close(int fd)
+{
+ return 0;
+}
+
ssize_t platform_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout)
{
return 1;
FILE *platform_fopen(const char *path, const char *mode);
int platform_open(const char *path, int flags, int mode);
+int platform_open2(const char *path, int flags);
#ifdef _WIN32
typedef struct _stat platform_stat_t;
ssize_t platform_send(int sockfd, const void* buf, size_t len, int flags);
ssize_t platform_read(int fd, void* buf, size_t len);
ssize_t platform_write(int fd, const void* buf, size_t len);
+int platform_close(int fd);
ssize_t platform_select(int nfds, fd_set *readfds, fd_set *writefds, fd_set *exceptfds, struct timeval *timeout);
char* platform_fgets(char *s, int size, FILE *stream);
int platform_fgetc(FILE *stream);
{
msg(M_WARN, "PORT SHARE: writing to journal file (%s) failed", jfn);
}
- close(fd);
+ platform_close(fd);
cp->jfn = jfn;
}
else
done:
if (sd >= 0)
{
- close(sd);
+ platform_close(sd);
}
gc_free(&gc);
}
done:
if (nls >= 0)
{
- close(nls);
+ platform_close(nls);
}
}
{
l = platform_read(sockfd, (char *)&m_rtmsg, sizeof(m_rtmsg));
} while (l > 0 && (rtm.rtm_seq != seq || rtm.rtm_pid != pid));
- close(sockfd);
+ platform_close(sockfd);
sockfd = -1;
/* extract return data from routing socket */
msg(M_WARN, "GDG: ioctl #1 failed");
goto done;
}
- close(sockfd);
+ platform_close(sockfd);
sockfd = -1;
rgi->gateway.netmask = ntohl(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr.s_addr);
msg(M_WARN, "GDG: ioctl #2 failed");
goto done;
}
- close(sockfd);
+ platform_close(sockfd);
sockfd = -1;
for (cp = buffer; cp <= buffer + ifc.ifc_len - sizeof(struct ifreq); )
done:
if (sockfd >= 0)
{
- close(sockfd);
+ platform_close(sockfd);
}
gc_free(&gc);
}
}
while (l > 0 && (rtm.rtm_seq != seq || rtm.rtm_pid != pid));
- close(sockfd);
+ platform_close(sockfd);
sockfd = -1;
/* extract return data from routing socket */
done:
if (sockfd >= 0)
{
- close(sockfd);
+ platform_close(sockfd);
}
}
#include "proxy.h"
#include "socks.h"
#include "misc.h"
+#include "platform.h"
/*
* OpenVPN's default port number as assigned by IANA.
#else /* ifdef _WIN32 */
-#define openvpn_close_socket(s) close(s)
+#define openvpn_close_socket(s) platform_close(s)
#endif
#include "base64.h"
#include "ssl_verify.h"
#include "ssl_verify_backend.h"
+#include "platform.h"
#ifdef ENABLE_CRYPTO_OPENSSL
#include "ssl_verify_openssl.h"
if (fd != -1)
{
- close(fd);
+ platform_close(fd);
}
gc_free(&gc);
return ret;
}
if (so->fd >= 0)
{
- if (close(so->fd) < 0)
+ if (platform_close(so->fd) < 0)
{
ret = false;
}
if (dynamic && strcmp( dev, "tap" ) == 0)
{
struct ifreq ifr;
- if ((tt->fd = open( "/dev/tap", O_RDWR)) < 0)
+ if ((tt->fd = platform_open( "/dev/tap", O_RDWR)) < 0)
{
msg(M_FATAL, "Cannot allocate NetBSD TAP dev dynamically");
}
"/dev/%s%d", dev, i);
openvpn_snprintf(dynamic_name, sizeof(dynamic_name),
"%s%d", dev, i);
- if ((tt->fd = open(tunname, O_RDWR)) > 0)
+ if ((tt->fd = platform_open(tunname, O_RDWR)) > 0)
{
dynamic_opened = true;
break;
tt->persistent_if = true;
}
- if ((tt->fd = open(tunname, O_RDWR)) < 0)
+ if ((tt->fd = platform_open(tunname, O_RDWR)) < 0)
{
msg(M_ERR, "Cannot open TUN/TAP dev %s", tunname);
}
{
if (tt->fd >= 0)
{
- close(tt->fd);
+ platform_close(tt->fd);
}
if (tt->actual_name)
{
/* Android 4.4 workaround */
if (oldtunfd >=0 && android_method == ANDROID_OPEN_AFTER_CLOSE)
{
- close(oldtunfd);
+ platform_close(oldtunfd);
openvpn_sleep(2);
}
if (oldtunfd>=0 && android_method == ANDROID_OPEN_BEFORE_CLOSE)
{
- close(oldtunfd);
+ platform_close(oldtunfd);
}
/* Set the actual name to a dummy name */
/*
* Open the interface
*/
- if ((tt->fd = open(node, O_RDWR)) < 0)
+ if ((tt->fd = platform_open2(node, O_RDWR)) < 0)
{
msg(M_ERR, "ERROR: Cannot open TUN/TAP dev %s", node);
}
{
msg(M_WARN | M_ERRNO, "Note: Cannot set tx queue length on %s", ifr.ifr_name);
}
- close(ctl_fd);
+ platform_close(ctl_fd);
}
else
{
dev);
}
- if ((tt->ip_fd = open(ip_node, O_RDWR, 0)) < 0)
+ if ((tt->ip_fd = platform_open(ip_node, O_RDWR, 0)) < 0)
{
msg(M_ERR, "Can't open %s", ip_node);
}
- if ((tt->fd = open(dev_node, O_RDWR, 0)) < 0)
+ if ((tt->fd = platform_open(dev_node, O_RDWR, 0)) < 0)
{
msg(M_ERR, "Can't open %s", dev_node);
}
}
}
- if ((if_fd = open(dev_node, O_RDWR, 0)) < 0)
+ if ((if_fd = platform_open(dev_node, O_RDWR, 0)) < 0)
{
msg(M_ERR, "Can't open %s (2)", dev_node);
}
}
/* Open arp_fd */
- if ((arp_fd = open(arp_node, O_RDWR, 0)) < 0)
+ if ((arp_fd = platform_open(arp_node, O_RDWR, 0)) < 0)
{
msg(M_ERR, "Can't open %s\n", arp_node);
}
{
msg(M_ERR, "Can't link %s device to ARP", dev_tuntap_type);
}
- close(arp_fd);
+ platform_close(arp_fd);
}
CLEAR(ifr);
msg(M_WARN | M_ERRNO, "Can't unlink interface(ip)");
}
- close(tt->ip_fd);
+ platform_close(tt->ip_fd);
tt->ip_fd = -1;
}
if (tt->fd >= 0)
{
- close(tt->fd);
+ platform_close(tt->fd);
tt->fd = -1;
}
}
if (ioctl(fd, CTLIOCGINFO, &ctlInfo) == -1)
{
- close(fd);
+ platform_close(fd);
msg(M_INFO, "Opening utun (%s): %s", "ioctl(CTLIOCGINFO)",
strerror(errno));
return -2;
{
msg(M_INFO, "Opening utun (%s): %s", "connect(AF_SYS_CONTROL)",
strerror(errno));
- close(fd);
+ platform_close(fd);
return -1;
}
tt->persistent_if = TRUE;
}
- if ((tt->fd = open(tunname, O_RDWR)) < 0)
+ if ((tt->fd = platform_open(tunname, O_RDWR)) < 0)
{
msg(M_ERR, "Cannot open TAP device '%s'", tunname);
}