You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

147 lines
4.1 KiB

  1. From 2cfcadf5e6d5c444765aa460915ae27109a8dbce Mon Sep 17 00:00:00 2001
  2. From: Darshit Shah <darnir@gmail.com>
  3. Date: Mon, 16 Nov 2015 23:16:25 +0000
  4. Subject: Fix compile error when IPv6 is disabled
  5. * src/ftp-basic.c: The code for the new FTPS functionality was unintentionally
  6. inside a #ifdef IPV6 block. Move the code around so that it is defined even when
  7. IPV6 isn't used
  8. ---
  9. diff --git a/src/ftp-basic.c b/src/ftp-basic.c
  10. index bcb7847..378374c 100644
  11. --- a/src/ftp-basic.c
  12. +++ b/src/ftp-basic.c
  13. @@ -429,6 +429,65 @@ ip_address_to_eprt_repr (const ip_address *addr, int port, char *buf,
  14. buf[buflen - 1] = '\0';
  15. }
  16. +/* Bind a port and send the appropriate PORT command to the FTP
  17. + server. Use acceptport after RETR, to get the socket of data
  18. + connection. */
  19. +uerr_t
  20. +ftp_eprt (int csock, int *local_sock)
  21. +{
  22. + uerr_t err;
  23. + char *request, *respline;
  24. + ip_address addr;
  25. + int nwritten;
  26. + int port;
  27. + /* Must contain the argument of EPRT (of the form |af|addr|port|).
  28. + * 4 chars for the | separators, INET6_ADDRSTRLEN chars for addr
  29. + * 1 char for af (1-2) and 5 chars for port (0-65535) */
  30. + char bytes[4 + INET6_ADDRSTRLEN + 1 + 5 + 1];
  31. +
  32. + /* Get the address of this side of the connection. */
  33. + if (!socket_ip_address (csock, &addr, ENDPOINT_LOCAL))
  34. + return FTPSYSERR;
  35. +
  36. + /* Setting port to 0 lets the system choose a free port. */
  37. + port = 0;
  38. +
  39. + /* Bind the port. */
  40. + *local_sock = bind_local (&addr, &port);
  41. + if (*local_sock < 0)
  42. + return FTPSYSERR;
  43. +
  44. + /* Construct the argument of EPRT (of the form |af|addr|port|). */
  45. + ip_address_to_eprt_repr (&addr, port, bytes, sizeof (bytes));
  46. +
  47. + /* Send PORT request. */
  48. + request = ftp_request ("EPRT", bytes);
  49. + nwritten = fd_write (csock, request, strlen (request), -1);
  50. + if (nwritten < 0)
  51. + {
  52. + xfree (request);
  53. + fd_close (*local_sock);
  54. + return WRITEFAILED;
  55. + }
  56. + xfree (request);
  57. + /* Get appropriate response. */
  58. + err = ftp_response (csock, &respline);
  59. + if (err != FTPOK)
  60. + {
  61. + fd_close (*local_sock);
  62. + return err;
  63. + }
  64. + if (*respline != '2')
  65. + {
  66. + xfree (respline);
  67. + fd_close (*local_sock);
  68. + return FTPPORTERR;
  69. + }
  70. + xfree (respline);
  71. + return FTPOK;
  72. +}
  73. +#endif
  74. +
  75. #ifdef HAVE_SSL
  76. /*
  77. * The following three functions defined into this #ifdef block
  78. @@ -542,65 +601,6 @@ bail:
  79. }
  80. #endif /* HAVE_SSL */
  81. -/* Bind a port and send the appropriate PORT command to the FTP
  82. - server. Use acceptport after RETR, to get the socket of data
  83. - connection. */
  84. -uerr_t
  85. -ftp_eprt (int csock, int *local_sock)
  86. -{
  87. - uerr_t err;
  88. - char *request, *respline;
  89. - ip_address addr;
  90. - int nwritten;
  91. - int port;
  92. - /* Must contain the argument of EPRT (of the form |af|addr|port|).
  93. - * 4 chars for the | separators, INET6_ADDRSTRLEN chars for addr
  94. - * 1 char for af (1-2) and 5 chars for port (0-65535) */
  95. - char bytes[4 + INET6_ADDRSTRLEN + 1 + 5 + 1];
  96. -
  97. - /* Get the address of this side of the connection. */
  98. - if (!socket_ip_address (csock, &addr, ENDPOINT_LOCAL))
  99. - return FTPSYSERR;
  100. -
  101. - /* Setting port to 0 lets the system choose a free port. */
  102. - port = 0;
  103. -
  104. - /* Bind the port. */
  105. - *local_sock = bind_local (&addr, &port);
  106. - if (*local_sock < 0)
  107. - return FTPSYSERR;
  108. -
  109. - /* Construct the argument of EPRT (of the form |af|addr|port|). */
  110. - ip_address_to_eprt_repr (&addr, port, bytes, sizeof (bytes));
  111. -
  112. - /* Send PORT request. */
  113. - request = ftp_request ("EPRT", bytes);
  114. - nwritten = fd_write (csock, request, strlen (request), -1);
  115. - if (nwritten < 0)
  116. - {
  117. - xfree (request);
  118. - fd_close (*local_sock);
  119. - return WRITEFAILED;
  120. - }
  121. - xfree (request);
  122. - /* Get appropriate response. */
  123. - err = ftp_response (csock, &respline);
  124. - if (err != FTPOK)
  125. - {
  126. - fd_close (*local_sock);
  127. - return err;
  128. - }
  129. - if (*respline != '2')
  130. - {
  131. - xfree (respline);
  132. - fd_close (*local_sock);
  133. - return FTPPORTERR;
  134. - }
  135. - xfree (respline);
  136. - return FTPOK;
  137. -}
  138. -#endif
  139. -
  140. /* Similar to ftp_port, but uses `PASV' to initiate the passive FTP
  141. transfer. Reads the response from server and parses it. Reads the
  142. host and port addresses and returns them. */
  143. --
  144. cgit v0.9.0.2