SSL_shutdown(ftp->ssl_handle);
SSL_free(ftp->ssl_handle);
}
-#endif
+#endif
closesocket(ftp->fd);
- }
+ }
ftp_gc(ftp);
efree(ftp);
return NULL;
if (!ftp_getresp(ftp)) {
return 0;
}
-
+
if (ftp->resp != 234) {
if (!ftp_putcmd(ftp, "AUTH", "SSL")) {
return 0;
if (!ftp_getresp(ftp)) {
return 0;
}
-
+
if (ftp->resp != 334) {
return 0;
} else {
ftp->use_ssl_for_data = 1;
}
}
-
+
ctx = SSL_CTX_new(SSLv23_client_method());
if (ctx == NULL) {
php_error_docref(NULL TSRMLS_CC, E_WARNING, "failed to create the SSL context");
if (!ftp_getresp(ftp)) {
return 0;
}
-
- ftp->use_ssl_for_data = (ftp->resp >= 200 && ftp->resp <=299);
+
+ ftp->use_ssl_for_data = (ftp->resp >= 200 && ftp->resp <=299);
}
}
#endif
{
if (ftp == NULL) {
return 0;
- }
+ }
ftp_gc(ftp);
if (!ftp_putcmd(ftp, "SYST", NULL)) {
return NULL;
}
- if (!ftp_getresp(ftp) || ftp->resp != 215) {
+ if (!ftp_getresp(ftp) || ftp->resp != 215) {
return NULL;
}
syst = ftp->inbuf;
if (!ftp_putcmd(ftp, "PWD", NULL)) {
return NULL;
}
- if (!ftp_getresp(ftp) || ftp->resp != 257) {
+ if (!ftp_getresp(ftp) || ftp->resp != 257) {
return NULL;
}
/* copy out the pwd from response */
- if ((pwd = strchr(ftp->inbuf, '"')) == NULL) {
+ if ((pwd = strchr(ftp->inbuf, '"')) == NULL) {
return NULL;
}
- if ((end = strrchr(++pwd, '"')) == NULL) {
+ if ((end = strrchr(++pwd, '"')) == NULL) {
return NULL;
}
ftp->pwd = estrndup(pwd, end - pwd);
if (!ftp_getresp(ftp) || ftp->resp != 200) {
return 0;
}
-
+
return 1;
}
/* }}} */
}
snprintf(buffer, sizeof(buffer) - 1, "%ld", size);
-
+
if (!ftp_putcmd(ftp, "ALLO", buffer)) {
return 0;
}
return 0;
}
- return 1;
+ return 1;
}
/* }}} */
if (ftp == NULL) {
return 0;
}
- if (type == ftp->type) {
+ if (type == ftp->type) {
return 1;
}
if (type == FTPTYPE_ASCII) {
if (!ftp_putcmd(ftp, "PASV", NULL)) {
return 0;
}
- if (!ftp_getresp(ftp) || ftp->resp != 227) {
+ if (!ftp_getresp(ftp) || ftp->resp != 227) {
return 0;
}
/* parse out the IP and port */
if ((data = ftp_getdata(ftp TSRMLS_CC)) == NULL) {
goto bail;
}
-
+
ftp->data = data;
if (resumepos > 0) {
if ((data = ftp_getdata(ftp TSRMLS_CC)) == NULL) {
goto bail;
}
- ftp->data = data;
+ ftp->data = data;
if (startpos > 0) {
snprintf(arg, sizeof(arg), "%ld", startpos);
if (strpbrk(cmd, "\r\n")) {
return 0;
- }
+ }
/* build the output buffer */
if (args && args[0]) {
/* "cmd args\r\n\0" */
#if HAVE_OPENSSL_EXT
if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) {
sent = SSL_write(ftp->ssl_handle, buf, size);
- } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) {
+ } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) {
sent = SSL_write(ftp->data->ssl_handle, buf, size);
} else {
#endif
#if HAVE_OPENSSL_EXT
if (ftp->use_ssl && ftp->fd == s && ftp->ssl_active) {
nr_bytes = SSL_read(ftp->ssl_handle, buf, len);
- } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) {
+ } else if (ftp->use_ssl && ftp->fd != s && ftp->use_ssl_for_data && ftp->data->ssl_active) {
nr_bytes = SSL_read(ftp->data->ssl_handle, buf, len);
} else {
#endif
nr_bytes = recv(s, buf, len, 0);
#if HAVE_OPENSSL_EXT
}
-#endif
+#endif
return (nr_bytes);
}
/* }}} */
data_accepted:
#if HAVE_OPENSSL_EXT
-
+
/* now enable ssl if we need to */
if (ftp->use_ssl && ftp->use_ssl_for_data) {
ctx = SSL_CTX_new(SSLv23_client_method());
SSL_CTX_free(ctx);
return 0;
}
-
-
+
+
SSL_set_fd(data->ssl_handle, data->fd);
if (ftp->old_ssl) {
SSL_copy_session_id(data->ssl_handle, ftp->ssl_handle);
}
-
+
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;
}
-
+
data->ssl_active = 1;
- }
+ }
#endif
{
#if HAVE_OPENSSL_EXT
SSL_CTX *ctx;
-#endif
+#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_free(data->ssl_handle);
data->ssl_active = 0;
}
-#endif
+#endif
closesocket(data->listener);
- }
+ }
if (data->fd != -1) {
#if HAVE_OPENSSL_EXT
if (data->ssl_active) {
SSL_free(data->ssl_handle);
data->ssl_active = 0;
}
-#endif
+#endif
closesocket(data->fd);
- }
+ }
if (ftp) {
ftp->data = NULL;
}
databuf_t *data = NULL;
char *ptr;
int ch, lastch;
- int size, rcvd;
- int lines;
+ size_t size, rcvd;
+ size_t lines;
char **ret = NULL;
char **entry;
char *text;
if ((data = ftp_getdata(ftp TSRMLS_CC)) == NULL) {
goto bail;
}
- ftp->data = data;
+ ftp->data = data;
if (!ftp_putcmd(ftp, cmd, path)) {
goto bail;
lines = 0;
lastch = 0;
while ((rcvd = my_recv(ftp, data->fd, data->buf, FTP_BUFSIZE))) {
- if (rcvd == -1) {
+ if (rcvd == -1 || rcvd > ((size_t)(-1))-size) {
goto bail;
}
if (!ftp_getresp(ftp) || (ftp->resp != 150 && ftp->resp != 125)) {
goto bail;
}
- if ((data = data_accept(data, ftp TSRMLS_CC)) == NULL) {
+ if ((data = data_accept(data, ftp TSRMLS_CC)) == NULL) {
goto bail;
}
ftp->data = data;
goto bail;
}
ftp->data = data_close(ftp, ftp->data);
-
+
if (!ftp_getresp(ftp) || (ftp->resp != 226 && ftp->resp != 250)) {
goto bail;
}