]> git.ipfire.org Git - thirdparty/openvpn.git/commitdiff
Remaining IO abstractions
authorGuido Vranken <guidovranken@gmail.com>
Mon, 26 Jun 2017 20:09:49 +0000 (22:09 +0200)
committerGuido Vranken <guidovranken@gmail.com>
Mon, 26 Jun 2017 20:09:49 +0000 (22:09 +0200)
src/openvpn/console_builtin.c
src/openvpn/crypto_openssl.c
src/openvpn/event.c
src/openvpn/init.c
src/openvpn/manage.c
src/openvpn/mtu.c
src/openvpn/packet_id.c
src/openvpn/ps.c
src/openvpn/ssl_openssl.c
src/openvpn/ssl_verify.c
src/openvpn/tun.c

index 7b95da9dd94127e41e7fde817963db5873d59090..d3bfc665560cc719ff5d5f37ff528e1ca1b9cdf9 100644 (file)
@@ -154,7 +154,7 @@ static FILE *
 open_tty(const bool write)
 {
     FILE *ret;
-    ret = fopen("/dev/tty", write ? "w" : "r");
+    ret = platform_fopen("/dev/tty", write ? "w" : "r");
     if (!ret)
     {
         ret = write ? stderr : stdin;
@@ -173,7 +173,7 @@ close_tty(FILE *fp)
 {
     if (fp != stderr && fp != stdin)
     {
-        fclose(fp);
+        platform_fclose(fp);
     }
 }
 
@@ -230,7 +230,7 @@ get_console_input(const char *prompt, const bool echo, char *input, const int ca
         close_tty(fp);
 
         fp = open_tty(false);
-        if (fgets(input, capacity, fp) != NULL)
+        if (platform_fgets(input, capacity, fp) != NULL)
         {
             chomp(input);
             ret = true;
index 9cf3355b77ca5e8561c9d2068a037770ad188fa3..5baae6fc662026a69b14eaeda7e7c0e3c93db7f9 100644 (file)
@@ -163,10 +163,10 @@ void
 crypto_uninit_lib(void)
 {
 #ifdef CRYPTO_MDEBUG
-    FILE *fp = fopen("sdlog", "w");
+    FILE *fp = platform_fopen("sdlog", "w");
     ASSERT(fp);
     CRYPTO_mem_leaks_fp(fp);
-    fclose(fp);
+    platform_fclose(fp);
 #endif
 
 #if HAVE_OPENSSL_ENGINE
index d12307049bc594bf5b38159e1b83a8d509b9c77b..9dc079373d4c284431bf63f2ee92efb52f4ff4a8 100644 (file)
@@ -1046,7 +1046,7 @@ se_wait_fast(struct event_set *es, const struct timeval *tv, struct event_set_re
          (int)tv_tmp.tv_sec,
          (int)tv_tmp.tv_usec);
 
-    stat = select(ses->maxfd + 1, &ses->readfds, &ses->writefds, NULL, &tv_tmp);
+    stat = platform_select(ses->maxfd + 1, &ses->readfds, &ses->writefds, NULL, &tv_tmp);
 
     if (stat > 0)
     {
@@ -1068,7 +1068,7 @@ se_wait_scalable(struct event_set *es, const struct timeval *tv, struct event_se
     dmsg(D_EVENT_WAIT, "SE_WAIT_SCALEABLE maxfd=%d tv=%d/%d",
          ses->maxfd, (int)tv_tmp.tv_sec, (int)tv_tmp.tv_usec);
 
-    stat = select(ses->maxfd + 1, &read, &write, NULL, &tv_tmp);
+    stat = platform_select(ses->maxfd + 1, &read, &write, NULL, &tv_tmp);
 
     if (stat > 0)
     {
index a54307ad33b36129b33ab010a130e8f255b8c81a..b7fc22d6194c196fb38bc888411ab63eeae00b73 100644 (file)
@@ -324,7 +324,7 @@ clear_remote_addrlist(struct link_socket_addr *lsa, bool free)
 {
     if (lsa->remote_list && free)
     {
-        freeaddrinfo(lsa->remote_list);
+        platform_freeaddrinfo(lsa->remote_list);
     }
     lsa->remote_list = NULL;
     lsa->current_remote = NULL;
@@ -1447,7 +1447,7 @@ initialization_sequence_completed(struct context *c, const unsigned int flags)
         CLEAR(local);
         actual = &get_link_socket_info(c)->lsa->actual;
         remote = actual->dest;
-        getsockname(c->c2.link_socket->sd, &local.addr.sa, &sa_len);
+        platform_getsockname(c->c2.link_socket->sd, &local.addr.sa, &sa_len);
 #if ENABLE_IP_PKTINFO
         if (!addr_defined(&local))
         {
@@ -3366,7 +3366,7 @@ do_close_link_socket(struct context *c)
     {
         if (c->c1.link_socket_addr.bind_local && !c->options.resolve_in_advance)
         {
-            freeaddrinfo(c->c1.link_socket_addr.bind_local);
+            platform_freeaddrinfo(c->c1.link_socket_addr.bind_local);
         }
 
         c->c1.link_socket_addr.bind_local = NULL;
index c2e8dc72d12124774d3a03b2dbf8366ae855ffa8..0b7436b6c796e30a55de3c580580d73b6d3c96e3 100644 (file)
@@ -1617,7 +1617,7 @@ man_record_peer_info(struct management *man)
             int status;
 
             CLEAR(addr);
-            status = getsockname(man->connection.sd_cli, (struct sockaddr *)&addr, &addrlen);
+            status = platform_getsockname(man->connection.sd_cli, (struct sockaddr *)&addr, &addrlen);
             if (!status && addrlen == sizeof(addr))
             {
                 const in_addr_t a = ntohl(addr.sin_addr.s_addr);
@@ -1626,7 +1626,7 @@ man_record_peer_info(struct management *man)
                 if (fp)
                 {
                     fprintf(fp, "%s\n%d\n", print_in_addr_t(a, 0, &gc), p);
-                    if (!fclose(fp))
+                    if (!platform_fclose(fp))
                     {
                         success = true;
                     }
@@ -2050,7 +2050,7 @@ man_send_with_fd(int fd, void *ptr, size_t nbytes, int flags, int sendfd)
     msg.msg_iov = iov;
     msg.msg_iovlen = 1;
 
-    return (sendmsg(fd, &msg, flags));
+    return (platform_sendmsg(fd, &msg, flags));
 }
 
 static ssize_t
@@ -2077,7 +2077,7 @@ man_recv_with_fd(int fd, void *ptr, size_t nbytes, int flags, int *recvfd)
     msghdr.msg_iov = iov;
     msghdr.msg_iovlen = 1;
 
-    if ( (n = recvmsg(fd, &msghdr, flags)) <= 0)
+    if ( (n = platform_recvmsg(fd, &msghdr, flags)) <= 0)
     {
         return (n);
     }
@@ -2173,7 +2173,7 @@ man_read(struct management *man)
         man->connection.lastfdreceived = fd;
     }
 #else  /* ifdef TARGET_ANDROID */
-    len = recv(man->connection.sd_cli, buf, sizeof(buf), MSG_NOSIGNAL);
+    len = platform_recv(man->connection.sd_cli, buf, sizeof(buf), MSG_NOSIGNAL);
 #endif
 
     if (len == 0)
@@ -2270,7 +2270,7 @@ man_write(struct management *man)
         }
         else
 #endif
-        sent = send(man->connection.sd_cli, BPTR(buf), len, MSG_NOSIGNAL);
+        sent = platform_send(man->connection.sd_cli, BPTR(buf), len, MSG_NOSIGNAL);
         if (sent >= 0)
         {
             buffer_list_advance(man->connection.out, sent);
@@ -2478,7 +2478,7 @@ man_settings_close(struct man_settings *ms)
 {
     if (ms->local)
     {
-        freeaddrinfo(ms->local);
+        platform_freeaddrinfo(ms->local);
     }
     free(ms->write_peer_info_file);
     CLEAR(*ms);
index 44bef681ea38da3e8dece1fe4dab7148f827c40d..fa500ece9dd9d8b01c8f81f24bfde0c2e7404e00 100644 (file)
@@ -174,7 +174,7 @@ set_mtu_discover_type(int sd, int mtu_type, sa_family_t proto_af)
         {
 #if defined(HAVE_SETSOCKOPT) && defined(IP_MTU_DISCOVER)
             case AF_INET:
-                if (setsockopt
+                if (platform_setsockopt
                         (sd, IPPROTO_IP, IP_MTU_DISCOVER, &mtu_type, sizeof(mtu_type)))
                 {
                     msg(M_ERR, "Error setting IP_MTU_DISCOVER type=%d on TCP/UDP socket",
@@ -185,7 +185,7 @@ set_mtu_discover_type(int sd, int mtu_type, sa_family_t proto_af)
 #endif
 #if defined(HAVE_SETSOCKOPT) && defined(IPV6_MTU_DISCOVER)
             case AF_INET6:
-                if (setsockopt
+                if (platform_setsockopt
                         (sd, IPPROTO_IPV6, IPV6_MTU_DISCOVER, &mtu_type, sizeof(mtu_type)))
                 {
                     msg(M_ERR, "Error setting IPV6_MTU_DISCOVER type=%d on TCP6/UDP6 socket",
@@ -262,7 +262,7 @@ format_extended_socket_error(int fd, int *mtu, struct gc_arena *gc)
         msg.msg_control = cbuf;
         msg.msg_controllen = 256; /* size of cbuf */
 
-        res = recvmsg(fd, &msg, MSG_ERRQUEUE);
+        res = platform_recvmsg(fd, &msg, MSG_ERRQUEUE);
         if (res < 0)
         {
             goto exit;
@@ -336,7 +336,7 @@ void
 set_sock_extended_error_passing(int sd)
 {
     int on = 1;
-    if (setsockopt(sd, SOL_IP, IP_RECVERR, (void *) &on, sizeof(on)))
+    if (platform_setsockopt(sd, SOL_IP, IP_RECVERR, (void *) &on, sizeof(on)))
     {
         msg(M_WARN | M_ERRNO,
             "Note: enable extended error passing on TCP/UDP socket failed (IP_RECVERR)");
index 30ae8fbcbdd954a69a454c99f46e0867fee103c6..fab9c62dcaa112df7b732a6ac2dbee15bcaeff6b 100644 (file)
@@ -659,7 +659,7 @@ packet_id_interactive_test()
     while (true)
     {
         char buf[80];
-        if (!fgets(buf, sizeof(buf), stdin))
+        if (!platform_fgets(buf, sizeof(buf), stdin))
         {
             break;
         }
index c2b05cd951870f73e0caca106b8493961825fb41..1e062d873a746a632390386f86c33c9601c2af26 100644 (file)
@@ -240,7 +240,7 @@ port_share_sendmsg(const socket_descriptor_t sd,
             memcpy(CMSG_DATA(h), &sd_null[0], sizeof(sd_null[0]));
         }
 
-        status = sendmsg(sd, &mesg, MSG_NOSIGNAL);
+        status = platform_sendmsg(sd, &mesg, MSG_NOSIGNAL);
         if (status == -1)
         {
             msg(M_WARN|M_ERRNO, "PORT SHARE: sendmsg failed -- unable to communicate with background process (%d,%d,%d,%d)",
@@ -349,7 +349,7 @@ journal_add(const char *journal_dir, struct proxy_connection *pc, struct proxy_c
     slen = sizeof(from.addr.sa);
     dlen = sizeof(to.addr.sa);
     if (!getpeername(pc->sd, (struct sockaddr *) &from.addr.sa, &slen)
-        && !getsockname(cp->sd, (struct sockaddr *) &to.addr.sa, &dlen))
+        && !platform_getsockname(cp->sd, (struct sockaddr *) &to.addr.sa, &dlen))
     {
         const char *f = print_openvpn_sockaddr(&from, &gc);
         const char *t = print_openvpn_sockaddr(&to, &gc);
@@ -427,7 +427,7 @@ proxy_entry_new(struct proxy_connection **list,
     struct proxy_connection *cp;
 
     /* connect to port share server */
-    if ((sd_server = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
+    if ((sd_server = platform_socket(PF_INET, SOCK_STREAM, IPPROTO_TCP)) < 0)
     {
         msg(M_WARN|M_ERRNO, "PORT SHARE PROXY: cannot create socket");
         return false;
@@ -530,7 +530,7 @@ control_message_from_parent(const socket_descriptor_t sd_control,
     static const socket_descriptor_t socket_undefined = SOCKET_UNDEFINED;
     memcpy(CMSG_DATA(h), &socket_undefined, sizeof(socket_undefined));
 
-    status = recvmsg(sd_control, &mesg, MSG_NOSIGNAL);
+    status = platform_recvmsg(sd_control, &mesg, MSG_NOSIGNAL);
     if (status != -1)
     {
         if (h == NULL
@@ -580,7 +580,7 @@ static int
 proxy_connection_io_recv(struct proxy_connection *pc)
 {
     /* recv data from socket */
-    const int status = recv(pc->sd, BPTR(&pc->buf), BCAP(&pc->buf), MSG_NOSIGNAL);
+    const int status = platform_recv(pc->sd, BPTR(&pc->buf), BCAP(&pc->buf), MSG_NOSIGNAL);
     if (status < 0)
     {
         return (errno == EAGAIN) ? IOSTAT_EAGAIN_ON_READ : IOSTAT_READ_ERROR;
@@ -601,7 +601,7 @@ static int
 proxy_connection_io_send(struct proxy_connection *pc, int *bytes_sent)
 {
     const socket_descriptor_t sd = pc->counterpart->sd;
-    const int status = send(sd, BPTR(&pc->buf), BLEN(&pc->buf), MSG_NOSIGNAL);
+    const int status = platform_send(sd, BPTR(&pc->buf), BLEN(&pc->buf), MSG_NOSIGNAL);
 
     if (status < 0)
     {
@@ -841,7 +841,7 @@ port_share_open(const char *host,
                                  host, port,  0, NULL, AF_INET, &ai);
     ASSERT(status==0);
     hostaddr = *((struct sockaddr_in *) ai->ai_addr);
-    freeaddrinfo(ai);
+    platform_freeaddrinfo(ai);
 
     /*
      * Make a socket for foreground and background processes
index 11f4a567ba7bf44b0313596284a56cca954c3071..6cc5cb32df533f03cb5fdce3bdd0a9f3e5031050 100644 (file)
@@ -600,7 +600,7 @@ tls_ctx_load_pkcs12(struct tls_root_ctx *ctx, const char *pkcs12_file,
             crypto_msg(M_FATAL, "Error opening file %s", pkcs12_file);
         }
         p12 = d2i_PKCS12_fp(fp, NULL);
-        fclose(fp);
+        platform_fclose(fp);
         if (!p12)
         {
             crypto_msg(M_FATAL, "Error reading PKCS#12 file %s", pkcs12_file);
@@ -1331,7 +1331,7 @@ close_biofp()
 {
     if (biofp)
     {
-        ASSERT(!fclose(biofp));
+        ASSERT(!platform_fclose(biofp));
         biofp = NULL;
     }
 }
@@ -1350,7 +1350,7 @@ open_biofp()
     {
         char fn[256];
         openvpn_snprintf(fn, sizeof(fn), "bio/%d-%d.log", pid, biofp_toggle);
-        biofp = fopen(fn, "w");
+        biofp = platform_fopen(fn, "w");
         ASSERT(biofp);
         biofp_last_open = time(NULL);
         biofp_toggle ^= 1;
index 9cd36d7a2d7e7dadbe118b8e4f86e4daeb100c9d..84ebe8c17c96e70be711706e8d55fa9388f09580 100644 (file)
@@ -556,7 +556,7 @@ verify_cert_export_cert(openvpn_x509_cert_t *peercert, const char *tmp_dir, stru
     peercert_filename = create_temp_file(tmp_dir, "pcf", gc);
 
     /* write peer-cert in tmp-file */
-    peercert_file = fopen(peercert_filename, "w+");
+    peercert_file = platform_fopen(peercert_filename, "w+");
     if (!peercert_file)
     {
         msg(M_ERR, "Failed to open temporary file : %s", peercert_filename);
@@ -568,7 +568,7 @@ verify_cert_export_cert(openvpn_x509_cert_t *peercert, const char *tmp_dir, stru
         msg(M_ERR, "Error writing PEM file containing certificate");
     }
 
-    fclose(peercert_file);
+    platform_fclose(peercert_file);
     return peercert_filename;
 }
 
@@ -904,10 +904,10 @@ key_state_test_auth_control_file(struct key_state *ks)
         unsigned int ret = ks->auth_control_status;
         if (ret == ACF_UNDEFINED)
         {
-            FILE *fp = fopen(ks->auth_control_file, "r");
+            FILE *fp = platform_fopen(ks->auth_control_file, "r");
             if (fp)
             {
-                const int c = fgetc(fp);
+                const int c = platform_fgetc(fp);
                 if (c == '1')
                 {
                     ret = ACF_SUCCEEDED;
@@ -916,7 +916,7 @@ key_state_test_auth_control_file(struct key_state *ks)
                 {
                     ret = ACF_FAILED;
                 }
-                fclose(fp);
+                platform_fclose(fp);
                 ks->auth_control_status = ret;
             }
         }
index 75a156c13d5cf60afce962da4ca161919bf98525..710f8f288923d07859d3c6574f84f2bf42645edc 100644 (file)
@@ -2011,7 +2011,7 @@ open_tun(const char *dev, const char *dev_type, const char *dev_node, struct tun
             struct ifreq netifr;
             int ctl_fd;
 
-            if ((ctl_fd = socket(AF_INET, SOCK_DGRAM, 0)) >= 0)
+            if ((ctl_fd = platform_socket(AF_INET, SOCK_DGRAM, 0)) >= 0)
             {
                 CLEAR(netifr);
                 strncpynt(netifr.ifr_name, ifr.ifr_name, IFNAMSIZ);
@@ -3018,7 +3018,7 @@ utun_open_helper(struct ctl_info ctlInfo, int utunnum)
     struct sockaddr_ctl sc;
     int fd;
 
-    fd = socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL);
+    fd = platform_socket(PF_SYSTEM, SOCK_DGRAM, SYSPROTO_CONTROL);
 
     if (fd < 0)
     {
@@ -3118,7 +3118,7 @@ open_darwin_utun(const char *dev, const char *dev_type, const char *dev_node, st
     }
 
     /* Retrieve the assigned interface name. */
-    if (getsockopt(fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, utunname, &utunname_len))
+    if (platform_getsockopt(fd, SYSPROTO_CONTROL, UTUN_OPT_IFNAME, utunname, &utunname_len))
     {
         msg(M_ERR | M_ERRNO, "Error retrieving utun interface name");
     }