1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
|
From 167a679db79a93c27b7bb367bef9e0d9abdc47d0 Mon Sep 17 00:00:00 2001
From: Andy Postnikov <apostnikov@gmail.com>
Date: Mon, 13 Jul 2020 20:13:34 +0300
Subject: [PATCH 1/4] Fix compatibility with 8.0 - call_user_function_ex
---
ssh2.c | 8 ++++----
1 file changed, 4 insertions(+), 4 deletions(-)
diff --git a/ssh2.c b/ssh2.c
index 5a1deef..ee60f7b 100644
--- a/ssh2.c
+++ b/ssh2.c
@@ -100,7 +100,7 @@ LIBSSH2_DEBUG_FUNC(php_ssh2_debug_cb)
ZVAL_STRINGL(&args[1], language, language_len);
ZVAL_LONG(&args[2], always_display);
- if (FAILURE == call_user_function_ex(NULL, NULL, data->disconnect_cb, NULL, 3, args, 0, NULL)) {
+ if (FAILURE == call_user_function(NULL, NULL, data->disconnect_cb, NULL, 3, args)) {
php_error_docref(NULL, E_WARNING, "Failure calling disconnect callback");
}
}
@@ -125,7 +125,7 @@ LIBSSH2_IGNORE_FUNC(php_ssh2_ignore_cb)
ZVAL_STRINGL(&args[0], message, message_len);
- if (FAILURE == call_user_function_ex(NULL, NULL, data->ignore_cb, &zretval, 1, args, 0, NULL)) {
+ if (FAILURE == call_user_function(NULL, NULL, data->ignore_cb, &zretval, 1, args)) {
php_error_docref(NULL, E_WARNING, "Failure calling ignore callback");
}
if (Z_TYPE_P(&zretval) != IS_UNDEF) {
@@ -155,7 +155,7 @@ LIBSSH2_MACERROR_FUNC(php_ssh2_macerror_cb)
ZVAL_STRINGL(&args[0], packet, packet_len);
- if (FAILURE == call_user_function_ex(NULL, NULL, data->macerror_cb, &zretval, 1, args, 0, NULL)) {
+ if (FAILURE == call_user_function(NULL, NULL, data->macerror_cb, &zretval, 1, args)) {
php_error_docref(NULL, E_WARNING, "Failure calling macerror callback");
} else {
retval = zval_is_true(&zretval) ? 0 : -1;
@@ -188,7 +188,7 @@ LIBSSH2_DISCONNECT_FUNC(php_ssh2_disconnect_cb)
ZVAL_STRINGL(&args[1], message, message_len);
ZVAL_STRINGL(&args[2], language, language_len);
- if (FAILURE == call_user_function_ex(NULL, NULL, data->disconnect_cb, NULL, 3, args, 0, NULL)) {
+ if (FAILURE == call_user_function(NULL, NULL, data->disconnect_cb, NULL, 3, args)) {
php_error_docref(NULL, E_WARNING, "Failure calling disconnect callback");
}
}
From 9e6074a4eae3b4ebbe883ba1b93c9eccb9c78d02 Mon Sep 17 00:00:00 2001
From: Andy Postnikov <apostnikov@gmail.com>
Date: Mon, 13 Jul 2020 23:32:53 +0300
Subject: [PATCH 3/4] Fix function definition arguments
- ssh2_poll() updated outdated ZEND_ARG_PASS_INFO usage and argument names
- added argument definition for ssh2_forward_listen() and ssh2_forward_accept()
---
ssh2.c | 28 +++++++++++++++++++++-------
1 file changed, 21 insertions(+), 7 deletions(-)
diff --git a/ssh2.c b/ssh2.c
index ee60f7b..4605f1a 100644
--- a/ssh2.c
+++ b/ssh2.c
@@ -45,10 +45,6 @@ int le_ssh2_listener;
int le_ssh2_sftp;
int le_ssh2_pkey_subsys;
-ZEND_BEGIN_ARG_INFO(php_ssh2_first_arg_force_ref, 0)
- ZEND_ARG_PASS_INFO(1)
-ZEND_END_ARG_INFO()
-
/* *************
* Callbacks *
************* */
@@ -1416,6 +1412,19 @@ ZEND_BEGIN_ARG_INFO_EX(arginfo_ssh2_auth_hostbased_file, 0, 0, 5)
ZEND_ARG_INFO(0, local_username)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ssh2_forward_listen, 0, 0, 2)
+ ZEND_ARG_INFO(0, session)
+ ZEND_ARG_INFO(0, port)
+ ZEND_ARG_INFO(0, host)
+ ZEND_ARG_INFO(0, max_connections)
+ZEND_END_ARG_INFO()
+
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ssh2_forward_accept, 0, 0, 1)
+ ZEND_ARG_INFO(0, listener)
+ ZEND_ARG_INFO(1, host)
+ ZEND_ARG_INFO(0, port)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO_EX(arginfo_ssh2_shell, 0, 0, 1)
ZEND_ARG_INFO(0, session)
ZEND_ARG_INFO(0, termtype)
@@ -1459,6 +1468,11 @@ ZEND_BEGIN_ARG_INFO(arginfo_ssh2_fetch_stream, 2)
ZEND_ARG_INFO(0, streamid)
ZEND_END_ARG_INFO()
+ZEND_BEGIN_ARG_INFO_EX(arginfo_ssh2_poll, 0, 0, 1)
+ ZEND_ARG_INFO(1, polldes)
+ ZEND_ARG_INFO(0, timeout)
+ZEND_END_ARG_INFO()
+
ZEND_BEGIN_ARG_INFO(arginfo_ssh2_sftp, 1)
ZEND_ARG_INFO(0, session)
ZEND_END_ARG_INFO()
@@ -1559,8 +1573,8 @@ zend_function_entry ssh2_functions[] = {
PHP_FE(ssh2_auth_pubkey_file, arginfo_ssh2_auth_pubkey_file)
PHP_FE(ssh2_auth_hostbased_file, arginfo_ssh2_auth_hostbased_file)
- PHP_FE(ssh2_forward_listen, NULL)
- PHP_FE(ssh2_forward_accept, NULL)
+ PHP_FE(ssh2_forward_listen, arginfo_ssh2_forward_listen)
+ PHP_FE(ssh2_forward_accept, arginfo_ssh2_forward_accept)
/* Stream Stuff */
PHP_FE(ssh2_shell, arginfo_ssh2_shell)
@@ -1569,7 +1583,7 @@ zend_function_entry ssh2_functions[] = {
PHP_FE(ssh2_scp_recv, arginfo_ssh2_scp_recv)
PHP_FE(ssh2_scp_send, arginfo_ssh2_scp_send)
PHP_FE(ssh2_fetch_stream, arginfo_ssh2_fetch_stream)
- PHP_FE(ssh2_poll, php_ssh2_first_arg_force_ref)
+ PHP_FE(ssh2_poll, arginfo_ssh2_poll)
/* SFTP Stuff */
PHP_FE(ssh2_sftp, arginfo_ssh2_sftp)
From c9647c5d296e8693d0b5672f1c22945ea024ebdc Mon Sep 17 00:00:00 2001
From: Remi Collet <remi@remirepo.net>
Date: Thu, 10 Sep 2020 15:53:52 +0200
Subject: [PATCH 4/4] fix for PHP 7.4 (stream API) and 8.0
---
ssh2.c | 4 +---
ssh2_fopen_wrappers.c | 26 +++++++++++++++++++-------
ssh2_sftp.c | 20 ++++++++++++++++++++
3 files changed, 40 insertions(+), 10 deletions(-)
diff --git a/ssh2.c b/ssh2.c
index 4605f1a..31ee8f7 100644
--- a/ssh2.c
+++ b/ssh2.c
@@ -436,9 +436,7 @@ PHP_FUNCTION(ssh2_disconnect)
RETURN_FALSE;
}
- if (zend_list_close(Z_RES_P(zsession)) != SUCCESS) {
- RETURN_FALSE;
- }
+ zend_list_close(Z_RES_P(zsession));
RETURN_TRUE;
}
diff --git a/ssh2_fopen_wrappers.c b/ssh2_fopen_wrappers.c
index ef82134..d79a051 100644
--- a/ssh2_fopen_wrappers.c
+++ b/ssh2_fopen_wrappers.c
@@ -40,10 +40,14 @@ void *php_ssh2_zval_from_resource_handle(int handle) {
* channel_stream_ops *
********************** */
+#if PHP_VERSION_ID < 70400
static size_t php_ssh2_channel_stream_write(php_stream *stream, const char *buf, size_t count)
+#else
+static ssize_t php_ssh2_channel_stream_write(php_stream *stream, const char *buf, size_t count)
+#endif
{
php_ssh2_channel_data *abstract = (php_ssh2_channel_data*)stream->abstract;
- size_t writestate;
+ ssize_t writestate;
LIBSSH2_SESSION *session;
libssh2_channel_set_blocking(abstract->channel, abstract->is_blocking);
@@ -64,24 +68,31 @@ static size_t php_ssh2_channel_stream_write(php_stream *stream, const char *buf,
libssh2_session_set_timeout(session, 0);
}
#endif
+
if (writestate == LIBSSH2_ERROR_EAGAIN) {
+#if PHP_VERSION_ID < 70400
writestate = 0;
- }
-
- if (writestate < 0) {
+#endif
+ } else if (writestate < 0) {
char *error_msg = NULL;
if (libssh2_session_last_error(session, &error_msg, NULL, 0) == writestate) {
php_error_docref(NULL, E_WARNING, "Failure '%s' (%ld)", error_msg, writestate);
}
stream->eof = 1;
+#if PHP_VERSION_ID < 70400
writestate = 0;
+#endif
}
return writestate;
}
+#if PHP_VERSION_ID < 70400
static size_t php_ssh2_channel_stream_read(php_stream *stream, char *buf, size_t count)
+#else
+static ssize_t php_ssh2_channel_stream_read(php_stream *stream, char *buf, size_t count)
+#endif
{
php_ssh2_channel_data *abstract = (php_ssh2_channel_data*)stream->abstract;
ssize_t readstate;
@@ -104,11 +115,12 @@ static size_t php_ssh2_channel_stream_read(php_stream *stream, char *buf, size_t
libssh2_session_set_timeout(session, 0);
}
#endif
+
if (readstate == LIBSSH2_ERROR_EAGAIN) {
+#if PHP_VERSION_ID < 70400
readstate = 0;
- }
-
- if (readstate < 0) {
+#endif
+ } else if (readstate < 0) {
char *error_msg = NULL;
if (libssh2_session_last_error(session, &error_msg, NULL, 0) == readstate) {
php_error_docref(NULL, E_WARNING, "Failure '%s' (%ld)", error_msg, readstate);
diff --git a/ssh2_sftp.c b/ssh2_sftp.c
index ae8f6f8..0f62d35 100644
--- a/ssh2_sftp.c
+++ b/ssh2_sftp.c
@@ -103,20 +103,32 @@ typedef struct _php_ssh2_sftp_handle_data {
/* {{{ php_ssh2_sftp_stream_write
*/
+#if PHP_VERSION_ID < 70400
static size_t php_ssh2_sftp_stream_write(php_stream *stream, const char *buf, size_t count)
+#else
+static ssize_t php_ssh2_sftp_stream_write(php_stream *stream, const char *buf, size_t count)
+#endif
{
php_ssh2_sftp_handle_data *data = (php_ssh2_sftp_handle_data*)stream->abstract;
ssize_t bytes_written;
bytes_written = libssh2_sftp_write(data->handle, buf, count);
+#if PHP_VERSION_ID < 70400
return (size_t)(bytes_written<0 ? 0 : bytes_written);
+#else
+ return bytes_written;
+#endif
}
/* }}} */
/* {{{ php_ssh2_sftp_stream_read
*/
+#if PHP_VERSION_ID < 70400
static size_t php_ssh2_sftp_stream_read(php_stream *stream, char *buf, size_t count)
+#else
+static ssize_t php_ssh2_sftp_stream_read(php_stream *stream, char *buf, size_t count)
+#endif
{
php_ssh2_sftp_handle_data *data = (php_ssh2_sftp_handle_data*)stream->abstract;
ssize_t bytes_read;
@@ -125,7 +137,11 @@ static size_t php_ssh2_sftp_stream_read(php_stream *stream, char *buf, size_t co
stream->eof = (bytes_read <= 0 && bytes_read != LIBSSH2_ERROR_EAGAIN);
+#if PHP_VERSION_ID < 70400
return (size_t)(bytes_read<0 ? 0 : bytes_read);
+#else
+ return bytes_read;
+#endif
}
/* }}} */
@@ -264,7 +280,11 @@ static php_stream *php_ssh2_sftp_stream_opener(php_stream_wrapper *wrapper, cons
/* {{{ php_ssh2_sftp_dirstream_read
*/
+#if PHP_VERSION_ID < 70400
static size_t php_ssh2_sftp_dirstream_read(php_stream *stream, char *buf, size_t count)
+#else
+static ssize_t php_ssh2_sftp_dirstream_read(php_stream *stream, char *buf, size_t count)
+#endif
{
php_ssh2_sftp_handle_data *data = (php_ssh2_sftp_handle_data*)stream->abstract;
php_stream_dirent *ent = (php_stream_dirent*)buf;
|