summaryrefslogtreecommitdiff
path: root/ext/ftp/ftp.c
diff options
context:
space:
mode:
Diffstat (limited to 'ext/ftp/ftp.c')
-rw-r--r--ext/ftp/ftp.c71
1 files changed, 34 insertions, 37 deletions
diff --git a/ext/ftp/ftp.c b/ext/ftp/ftp.c
index 4c8a94f81..0d6704f9d 100644
--- a/ext/ftp/ftp.c
+++ b/ext/ftp/ftp.c
@@ -39,7 +39,7 @@
#ifdef PHP_WIN32
#include <winsock2.h>
#elif defined(NETWARE)
-#ifdef USE_WINSOCK /* Modified to use Winsock (NOVSOCK2.H), atleast for now */
+#ifdef USE_WINSOCK /* Modified to use Winsock (NOVSOCK2.H), at least for now */
#include <novsock2.h>
#else
#include <sys/socket.h>
@@ -182,6 +182,7 @@ ftp_close(ftpbuf_t *ftp)
#if HAVE_OPENSSL_EXT
if (ftp->ssl_active) {
SSL_shutdown(ftp->ssl_handle);
+ SSL_free(ftp->ssl_handle);
}
#endif
closesocket(ftp->fd);
@@ -297,6 +298,7 @@ ftp_login(ftpbuf_t *ftp, const char *user, const char *pass TSRMLS_DC)
if (SSL_connect(ftp->ssl_handle) <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "SSL/TLS handshake failed");
SSL_shutdown(ftp->ssl_handle);
+ SSL_free(ftp->ssl_handle);
return 0;
}
@@ -610,7 +612,7 @@ ftp_chmod(ftpbuf_t *ftp, const int mode, const char *filename, const int filenam
/* {{{ ftp_alloc
*/
int
-ftp_alloc(ftpbuf_t *ftp, const int size, char **response)
+ftp_alloc(ftpbuf_t *ftp, const long size, char **response)
{
char buffer[64];
@@ -618,8 +620,8 @@ ftp_alloc(ftpbuf_t *ftp, const int size, char **response)
return 0;
}
- snprintf(buffer, sizeof(buffer) - 1, "%d", size);
-
+ snprintf(buffer, sizeof(buffer) - 1, "%ld", size);
+
if (!ftp_putcmd(ftp, "ALLO", buffer)) {
return 0;
}
@@ -785,7 +787,7 @@ ftp_pasv(ftpbuf_t *ftp, int pasv)
/* {{{ ftp_get
*/
int
-ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, int resumepos TSRMLS_DC)
+ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, long resumepos TSRMLS_DC)
{
databuf_t *data = NULL;
int lastch;
@@ -806,11 +808,7 @@ ftp_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type,
ftp->data = data;
if (resumepos > 0) {
- if (resumepos > 2147483647) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "PHP cannot handle files greater than 2147483647 bytes.");
- goto bail;
- }
- snprintf(arg, sizeof(arg), "%u", resumepos);
+ snprintf(arg, sizeof(arg), "%ld", resumepos);
if (!ftp_putcmd(ftp, "REST", arg)) {
goto bail;
}
@@ -883,10 +881,10 @@ bail:
/* {{{ ftp_put
*/
int
-ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, int startpos TSRMLS_DC)
+ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, long startpos TSRMLS_DC)
{
databuf_t *data = NULL;
- int size;
+ long size;
char *ptr;
int ch;
char arg[11];
@@ -903,11 +901,7 @@ ftp_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, i
ftp->data = data;
if (startpos > 0) {
- if (startpos > 2147483647) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "PHP cannot handle files with a size greater than 2147483647 bytes.");
- goto bail;
- }
- snprintf(arg, sizeof(arg), "%u", startpos);
+ snprintf(arg, sizeof(arg), "%ld", startpos);
if (!ftp_putcmd(ftp, "REST", arg)) {
goto bail;
}
@@ -964,7 +958,7 @@ bail:
/* {{{ ftp_size
*/
-int
+long
ftp_size(ftpbuf_t *ftp, const char *path)
{
if (ftp == NULL) {
@@ -979,7 +973,7 @@ ftp_size(ftpbuf_t *ftp, const char *path)
if (!ftp_getresp(ftp) || ftp->resp != 213) {
return -1;
}
- return atoi(ftp->inbuf);
+ return atol(ftp->inbuf);
}
/* }}} */
@@ -1141,7 +1135,7 @@ ftp_putcmd(ftpbuf_t *ftp, const char *cmd, const char *args)
int
ftp_readline(ftpbuf_t *ftp)
{
- int size, rcvd;
+ long size, rcvd;
char *data, *eol;
/* shift the extra to the front */
@@ -1234,7 +1228,8 @@ ftp_getresp(ftpbuf_t *ftp)
int
my_send(ftpbuf_t *ftp, php_socket_t s, void *buf, size_t len)
{
- int n, size, sent;
+ long size, sent;
+ int n;
size = len;
while (size) {
@@ -1548,6 +1543,7 @@ data_accepted:
if (SSL_connect(data->ssl_handle) <= 0) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "data_accept: SSL/TLS handshake failed");
SSL_shutdown(data->ssl_handle);
+ SSL_free(data->ssl_handle);
return 0;
}
@@ -1565,13 +1561,21 @@ data_accepted:
databuf_t*
data_close(ftpbuf_t *ftp, databuf_t *data)
{
+#if HAVE_OPENSSL_EXT
+ SSL_CTX *ctx;
+#endif
if (data == NULL) {
return NULL;
}
if (data->listener != -1) {
#if HAVE_OPENSSL_EXT
if (data->ssl_active) {
+
+ ctx = SSL_get_SSL_CTX(data->ssl_handle);
+ SSL_CTX_free(ctx);
+
SSL_shutdown(data->ssl_handle);
+ SSL_free(data->ssl_handle);
data->ssl_active = 0;
}
#endif
@@ -1580,7 +1584,11 @@ data_close(ftpbuf_t *ftp, databuf_t *data)
if (data->fd != -1) {
#if HAVE_OPENSSL_EXT
if (data->ssl_active) {
+ ctx = SSL_get_SSL_CTX(data->ssl_handle);
+ SSL_CTX_free(ctx);
+
SSL_shutdown(data->ssl_handle);
+ SSL_free(data->ssl_handle);
data->ssl_active = 0;
}
#endif
@@ -1704,7 +1712,7 @@ bail:
/* {{{ ftp_nb_get
*/
int
-ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, int resumepos TSRMLS_DC)
+ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t type, long resumepos TSRMLS_DC)
{
databuf_t *data = NULL;
char arg[11];
@@ -1722,14 +1730,7 @@ ftp_nb_get(ftpbuf_t *ftp, php_stream *outstream, const char *path, ftptype_t typ
}
if (resumepos>0) {
- /* We are working on an architecture that supports 64-bit integers
- * since php is 32 bit by design, we bail out with warning
- */
- if (resumepos > 2147483647) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "PHP cannot handle files greater than 2147483648 bytes.");
- goto bail;
- }
- snprintf(arg, sizeof(arg), "%u", resumepos);
+ snprintf(arg, sizeof(arg), "%ld", resumepos);
if (!ftp_putcmd(ftp, "REST", arg)) {
goto bail;
}
@@ -1828,7 +1829,7 @@ bail:
/* {{{ ftp_nb_put
*/
int
-ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, int startpos TSRMLS_DC)
+ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type, long startpos TSRMLS_DC)
{
databuf_t *data = NULL;
char arg[11];
@@ -1843,11 +1844,7 @@ ftp_nb_put(ftpbuf_t *ftp, const char *path, php_stream *instream, ftptype_t type
goto bail;
}
if (startpos > 0) {
- if (startpos > 2147483647) {
- php_error_docref(NULL TSRMLS_CC, E_WARNING, "PHP cannot handle files with a size greater than 2147483647 bytes.");
- goto bail;
- }
- snprintf(arg, sizeof(arg), "%u", startpos);
+ snprintf(arg, sizeof(arg), "%ld", startpos);
if (!ftp_putcmd(ftp, "REST", arg)) {
goto bail;
}
@@ -1884,7 +1881,7 @@ bail:
int
ftp_nb_continue_write(ftpbuf_t *ftp TSRMLS_DC)
{
- int size;
+ long size;
char *ptr;
int ch;