1
|
1 /*****************************************************************************/
|
|
2 /* sshv2.c - functions that will use the sshv2 protocol */
|
122
|
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
|
1
|
4 /* */
|
|
5 /* This program is free software; you can redistribute it and/or modify */
|
|
6 /* it under the terms of the GNU General Public License as published by */
|
|
7 /* the Free Software Foundation; either version 2 of the License, or */
|
|
8 /* (at your option) any later version. */
|
|
9 /* */
|
|
10 /* This program is distributed in the hope that it will be useful, */
|
|
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
|
|
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
|
|
13 /* GNU General Public License for more details. */
|
|
14 /* */
|
|
15 /* You should have received a copy of the GNU General Public License */
|
|
16 /* along with this program; if not, write to the Free Software */
|
|
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
|
|
18 /*****************************************************************************/
|
|
19
|
|
20 #include "gftp.h"
|
33
|
21 static const char cvsid[] = "$Id$";
|
1
|
22
|
|
23 #define SSH_MAX_HANDLE_SIZE 256
|
|
24 #define SSH_MAX_STRING_SIZE 34000
|
|
25
|
122
|
26 static gftp_config_vars config_vars[] =
|
|
27 {
|
227
|
28 {"", N_("SSH"), gftp_option_type_notebook, NULL, NULL,
|
|
29 GFTP_CVARS_FLAGS_SHOW_BOOKMARK, NULL, GFTP_PORT_GTK, NULL},
|
122
|
30
|
|
31 {"ssh_prog_name", N_("SSH Prog Name:"),
|
|
32 gftp_option_type_text, "ssh", NULL, 0,
|
|
33 N_("The path to the SSH executable"), GFTP_PORT_ALL, NULL},
|
|
34 {"ssh_extra_params", N_("SSH Extra Params:"),
|
124
|
35 gftp_option_type_text, NULL, NULL, 0,
|
122
|
36 N_("Extra parameters to pass to the SSH program"), GFTP_PORT_ALL, NULL},
|
|
37 {"ssh2_sftp_path", N_("SSH2 sftp-server path:"),
|
227
|
38 gftp_option_type_text, NULL, NULL, GFTP_CVARS_FLAGS_SHOW_BOOKMARK,
|
122
|
39 N_("Default remote SSH2 sftp-server path"), GFTP_PORT_ALL, NULL},
|
|
40
|
|
41 {"ssh_need_userpass", N_("Need SSH User/Pass"),
|
227
|
42 gftp_option_type_checkbox, GINT_TO_POINTER(1), NULL,
|
|
43 GFTP_CVARS_FLAGS_SHOW_BOOKMARK,
|
122
|
44 N_("Require a username/password for SSH connections"), GFTP_PORT_ALL, NULL},
|
|
45 {"sshv2_use_sftp_subsys", N_("Use SSH2 SFTP subsys"),
|
227
|
46 gftp_option_type_checkbox, GINT_TO_POINTER(0), NULL,
|
|
47 GFTP_CVARS_FLAGS_SHOW_BOOKMARK,
|
122
|
48 N_("Call ssh with the -s sftp flag. This is helpful because you won't have to know the remote path to the remote sftp-server"),
|
|
49 GFTP_PORT_GTK, NULL},
|
227
|
50
|
122
|
51 {NULL, NULL, 0, NULL, NULL, 0, NULL, 0, NULL}
|
|
52 };
|
|
53
|
|
54
|
1
|
55 typedef struct sshv2_attribs_tag
|
|
56 {
|
|
57 gint32 flags;
|
|
58 gint64 size;
|
|
59 gint32 uid;
|
|
60 gint32 gid;
|
|
61 gint32 perm;
|
|
62 gint32 atime;
|
|
63 gint32 mtime;
|
|
64 } sshv2_attribs;
|
|
65
|
|
66 typedef struct sshv2_message_tag
|
|
67 {
|
|
68 gint32 length;
|
|
69 char command;
|
|
70 char *buffer,
|
|
71 *pos,
|
|
72 *end;
|
|
73 } sshv2_message;
|
|
74
|
|
75 typedef struct sshv2_params_tag
|
|
76 {
|
296
|
77 char handle[SSH_MAX_HANDLE_SIZE + 4], /* We'll encode the ID in here too */
|
|
78 *read_buffer;
|
|
79
|
|
80 gint32 handle_len,
|
|
81 id,
|
|
82 count;
|
1
|
83 sshv2_message message;
|
|
84
|
296
|
85 unsigned int initialized : 1,
|
|
86 dont_log_status : 1; /* For uploading files */
|
|
87
|
1
|
88 #ifdef G_HAVE_GINT64
|
|
89 gint64 offset;
|
|
90 #else
|
|
91 gint32 offset;
|
|
92 #endif
|
|
93 } sshv2_params;
|
|
94
|
|
95
|
|
96 #define SSH_MY_VERSION 3
|
|
97
|
|
98 #define SSH_FXP_INIT 1
|
|
99 #define SSH_FXP_VERSION 2
|
|
100 #define SSH_FXP_OPEN 3
|
|
101 #define SSH_FXP_CLOSE 4
|
|
102 #define SSH_FXP_READ 5
|
|
103 #define SSH_FXP_WRITE 6
|
|
104 #define SSH_FXP_LSTAT 7
|
|
105 #define SSH_FXP_FSTAT 8
|
|
106 #define SSH_FXP_SETSTAT 9
|
|
107 #define SSH_FXP_FSETSTAT 10
|
|
108 #define SSH_FXP_OPENDIR 11
|
|
109 #define SSH_FXP_READDIR 12
|
|
110 #define SSH_FXP_REMOVE 13
|
|
111 #define SSH_FXP_MKDIR 14
|
|
112 #define SSH_FXP_RMDIR 15
|
|
113 #define SSH_FXP_REALPATH 16
|
|
114 #define SSH_FXP_STAT 17
|
|
115 #define SSH_FXP_RENAME 18
|
|
116 #define SSH_FXP_STATUS 101
|
|
117 #define SSH_FXP_HANDLE 102
|
|
118 #define SSH_FXP_DATA 103
|
|
119 #define SSH_FXP_NAME 104
|
|
120 #define SSH_FXP_ATTRS 105
|
|
121 #define SSH_FXP_EXTENDED 200
|
|
122 #define SSH_FXP_EXTENDED_REPLY 201
|
|
123
|
|
124 #define SSH_FILEXFER_ATTR_SIZE 0x00000001
|
|
125 #define SSH_FILEXFER_ATTR_UIDGID 0x00000002
|
|
126 #define SSH_FILEXFER_ATTR_PERMISSIONS 0x00000004
|
|
127 #define SSH_FILEXFER_ATTR_ACMODTIME 0x00000008
|
|
128 #define SSH_FILEXFER_ATTR_EXTENDED 0x80000000
|
|
129
|
|
130 #define SSH_FXF_READ 0x00000001
|
|
131 #define SSH_FXF_WRITE 0x00000002
|
|
132 #define SSH_FXF_APPEND 0x00000004
|
|
133 #define SSH_FXF_CREAT 0x00000008
|
|
134 #define SSH_FXF_TRUNC 0x00000010
|
|
135 #define SSH_FXF_EXCL 0x00000020
|
|
136
|
|
137 #define SSH_FX_OK 0
|
|
138 #define SSH_FX_EOF 1
|
|
139 #define SSH_FX_NO_SUCH_FILE 2
|
|
140 #define SSH_FX_PERMISSION_DENIED 3
|
|
141 #define SSH_FX_FAILURE 4
|
|
142 #define SSH_FX_BAD_MESSAGE 5
|
|
143 #define SSH_FX_NO_CONNECTION 6
|
|
144 #define SSH_FX_CONNECTION_LOST 7
|
|
145 #define SSH_FX_OP_UNSUPPORTED 8
|
|
146
|
122
|
147 #define SSH_LOGIN_BUFSIZE 200
|
|
148 #define SSH_ERROR_BADPASS -1
|
|
149 #define SSH_ERROR_QUESTION -2
|
|
150 #define SSH_WARNING -3
|
|
151
|
124
|
152 static void
|
|
153 sshv2_add_exec_args (char **logstr, size_t *logstr_len, char ***args,
|
|
154 size_t *args_len, size_t *args_cur, char *first, ...)
|
|
155 {
|
|
156 char tempstr[2048], *curpos, *endpos, save_char;
|
|
157 va_list argp;
|
|
158 int at_end;
|
|
159
|
|
160 va_start (argp, first);
|
|
161 g_vsnprintf (tempstr, sizeof (tempstr), first, argp);
|
|
162 va_end (argp);
|
|
163
|
|
164 *logstr_len += strlen (tempstr);
|
|
165 *logstr = g_realloc (*logstr, *logstr_len + 1);
|
|
166 strcat (*logstr, tempstr);
|
|
167
|
|
168 curpos = tempstr;
|
|
169 while (*curpos == ' ')
|
|
170 curpos++;
|
|
171
|
|
172 save_char = ' ';
|
|
173 at_end = 0;
|
|
174 while (!at_end)
|
|
175 {
|
|
176 if (*curpos == '"')
|
|
177 {
|
|
178 curpos++;
|
|
179 endpos = strchr (curpos + 1, '"');
|
|
180 }
|
|
181 else
|
|
182 endpos = strchr (curpos, ' ');
|
|
183
|
|
184 if (endpos == NULL)
|
|
185 at_end = 1;
|
|
186 else
|
|
187 {
|
|
188 save_char = *endpos;
|
|
189 *endpos = '\0';
|
|
190 }
|
|
191
|
|
192 if (*args_cur == *args_len + 1)
|
|
193 {
|
|
194 *args_cur += 10;
|
|
195 *args = g_realloc (*args, sizeof (char *) * *args_cur);
|
|
196 }
|
|
197
|
|
198 (*args)[(*args_len)++] = g_strdup (curpos);
|
|
199 (*args)[*args_len] = NULL;
|
|
200
|
|
201 if (!at_end)
|
|
202 {
|
|
203 *endpos = save_char;
|
|
204 curpos = endpos + 1;
|
|
205 while (*curpos == ' ')
|
|
206 curpos++;
|
|
207 }
|
|
208 }
|
|
209 }
|
|
210
|
122
|
211
|
|
212 static char **
|
|
213 sshv2_gen_exec_args (gftp_request * request, char *execname,
|
124
|
214 int use_sftp_subsys)
|
122
|
215 {
|
124
|
216 size_t logstr_len, args_len, args_cur;
|
|
217 char **args, *tempstr, *logstr;
|
122
|
218
|
124
|
219 gftp_lookup_request_option (request, "ssh_prog_name", &tempstr);
|
|
220 if (tempstr == NULL || *tempstr == '\0')
|
|
221 tempstr = "ssh";
|
122
|
222
|
124
|
223 args_len = 1;
|
|
224 args_cur = 15;
|
|
225 args = g_malloc (sizeof (char *) * args_cur);
|
|
226 args[0] = g_strdup (tempstr);
|
122
|
227
|
124
|
228 logstr = g_strdup (args[0]);
|
|
229 logstr_len = strlen (logstr);
|
122
|
230
|
124
|
231 gftp_lookup_request_option (request, "ssh_extra_params", &tempstr);
|
|
232 if (tempstr != NULL && *tempstr != '\0')
|
|
233 sshv2_add_exec_args (&logstr, &logstr_len, &args, &args_len, &args_cur,
|
|
234 "%s", tempstr);
|
122
|
235
|
124
|
236 sshv2_add_exec_args (&logstr, &logstr_len, &args, &args_len, &args_cur,
|
|
237 " -e none");
|
122
|
238
|
|
239 if (request->username && *request->username != '\0')
|
124
|
240 sshv2_add_exec_args (&logstr, &logstr_len, &args, &args_len, &args_cur,
|
|
241 " -l %s", request->username);
|
122
|
242
|
124
|
243 sshv2_add_exec_args (&logstr, &logstr_len, &args, &args_len, &args_cur,
|
|
244 " -p %d", request->port);
|
122
|
245
|
|
246 if (use_sftp_subsys)
|
124
|
247 sshv2_add_exec_args (&logstr, &logstr_len, &args, &args_len, &args_cur,
|
|
248 " %s -s sftp", request->hostname);
|
122
|
249 else
|
124
|
250 sshv2_add_exec_args (&logstr, &logstr_len, &args, &args_len, &args_cur,
|
458
|
251 " %s %s", request->hostname, execname);
|
122
|
252
|
186
|
253 request->logging_function (gftp_logging_misc, request,
|
124
|
254 _("Running program %s\n"), logstr);
|
|
255 g_free (logstr);
|
122
|
256 return (args);
|
|
257 }
|
|
258
|
|
259
|
458
|
260 static int
|
|
261 sshv2_start_login_sequence (gftp_request * request, int fdm, int ptymfd)
|
122
|
262 {
|
460
|
263 char *tempstr, *pwstr, *tmppos, *yesstr = "yes\n", *question_pos;
|
458
|
264 size_t rem, len, diff, lastdiff;
|
|
265 int wrotepw, ok, maxfd, ret;
|
|
266 fd_set rset, eset;
|
122
|
267 ssize_t rd;
|
|
268
|
460
|
269 question_pos = NULL;
|
122
|
270 rem = len = SSH_LOGIN_BUFSIZE;
|
|
271 tempstr = g_malloc0 (len + 1);
|
458
|
272 diff = lastdiff = 0;
|
122
|
273 wrotepw = 0;
|
|
274 ok = 1;
|
|
275
|
458
|
276 if (gftp_fd_set_sockblocking (request, fdm, 1) == -1)
|
|
277 return (GFTP_ERETRYABLE);
|
|
278
|
|
279 if (gftp_fd_set_sockblocking (request, ptymfd, 1) == -1)
|
|
280 return (GFTP_ERETRYABLE);
|
122
|
281
|
458
|
282 if (request->password == NULL)
|
|
283 pwstr = g_strdup ("\n");
|
|
284 else
|
|
285 pwstr = g_strconcat (request->password, "\n", NULL);
|
|
286
|
|
287 FD_ZERO (&rset);
|
|
288 FD_ZERO (&eset);
|
|
289 maxfd = fdm > ptymfd ? fdm : ptymfd;
|
122
|
290
|
|
291 errno = 0;
|
|
292 while (1)
|
|
293 {
|
458
|
294 FD_SET (fdm, &rset);
|
|
295 FD_SET (ptymfd, &rset);
|
|
296
|
|
297 FD_SET (fdm, &eset);
|
|
298 FD_SET (ptymfd, &eset);
|
|
299
|
|
300 ret = select (maxfd + 1, &rset, NULL, &eset, NULL);
|
|
301 if (ret < 0 && errno == EINTR)
|
|
302 continue;
|
|
303
|
|
304 if (ret < 0)
|
122
|
305 {
|
458
|
306 request->logging_function (gftp_logging_error, request,
|
|
307 _("Connection to %s timed out\n"),
|
|
308 request->hostname);
|
|
309 gftp_disconnect (request);
|
|
310 return (GFTP_ERETRYABLE);
|
|
311 }
|
|
312
|
|
313 if (FD_ISSET (fdm, &eset) || FD_ISSET (ptymfd, &eset))
|
|
314 {
|
|
315 request->logging_function (gftp_logging_error, request,
|
|
316 _("Error: Could not read from socket: %s\n"),
|
|
317 g_strerror (errno));
|
|
318 gftp_disconnect (request);
|
|
319 return (GFTP_ERETRYABLE);
|
|
320 }
|
|
321
|
|
322 if (FD_ISSET (fdm, &rset))
|
|
323 {
|
|
324 ok = 1;
|
122
|
325 break;
|
|
326 }
|
458
|
327 else if (!FD_ISSET (ptymfd, &rset))
|
|
328 continue;
|
|
329
|
|
330 rd = gftp_fd_read (request, tempstr + diff, rem - 1, ptymfd);
|
|
331 if (rd < 0)
|
|
332 return (rd);
|
|
333 else if (rd == 0)
|
|
334 continue;
|
|
335
|
122
|
336 rem -= rd;
|
|
337 diff += rd;
|
|
338 tempstr[diff] = '\0';
|
|
339
|
232
|
340 if ( (strcmp (tempstr, "Password:") == 0) ||
|
|
341 (diff >= 10 && strcmp (tempstr + diff - 9, "assword: ") == 0))
|
122
|
342 {
|
|
343 if (wrotepw)
|
|
344 {
|
|
345 ok = SSH_ERROR_BADPASS;
|
|
346 break;
|
|
347 }
|
|
348
|
|
349 if (strstr (tempstr, "WARNING") != NULL ||
|
|
350 strstr (tempstr, _("WARNING")) != NULL)
|
|
351 {
|
|
352 ok = SSH_WARNING;
|
|
353 break;
|
|
354 }
|
|
355
|
|
356 wrotepw = 1;
|
458
|
357 if (gftp_fd_write (request, pwstr, strlen (pwstr), ptymfd) < 0)
|
122
|
358 {
|
|
359 ok = 0;
|
|
360 break;
|
|
361 }
|
|
362 }
|
|
363 else if (diff > 2 && strcmp (tempstr + diff - 2, ": ") == 0 &&
|
458
|
364 ((tmppos = strstr (tempstr, "Enter passphrase for RSA key")) != NULL ||
|
|
365 ((tmppos = strstr (tempstr, "Enter passphrase for key '")) != NULL)))
|
122
|
366 {
|
|
367 if (wrotepw)
|
|
368 {
|
|
369 ok = SSH_ERROR_BADPASS;
|
|
370 break;
|
|
371 }
|
|
372
|
|
373 if (strstr (tempstr, "WARNING") != NULL ||
|
|
374 strstr (tempstr, _("WARNING")) != NULL)
|
|
375 {
|
|
376 ok = SSH_WARNING;
|
|
377 break;
|
|
378 }
|
|
379
|
|
380 wrotepw = 1;
|
458
|
381 if (gftp_fd_write (request, pwstr, strlen (pwstr), ptymfd) < 0)
|
122
|
382 {
|
|
383 ok = 0;
|
|
384 break;
|
|
385 }
|
|
386 }
|
|
387 else if (diff > 10 && strcmp (tempstr + diff - 10, "(yes/no)? ") == 0)
|
|
388 {
|
460
|
389 question_pos = tempstr + diff;
|
|
390 if (!gftpui_protocol_ask_yes_no (request, request->hostname, tempstr))
|
|
391 {
|
|
392 ok = SSH_ERROR_QUESTION;
|
|
393 break;
|
|
394 }
|
|
395 else
|
|
396 {
|
|
397 if (gftp_fd_write (request, yesstr, strlen (yesstr), ptymfd) < 0)
|
|
398 {
|
|
399 ok = 0;
|
|
400 break;
|
|
401 }
|
|
402 }
|
122
|
403 }
|
|
404 else if (rem <= 1)
|
|
405 {
|
|
406 len += SSH_LOGIN_BUFSIZE;
|
|
407 rem += SSH_LOGIN_BUFSIZE;
|
|
408 lastdiff = diff;
|
|
409 tempstr = g_realloc (tempstr, len);
|
|
410 continue;
|
|
411 }
|
|
412 }
|
|
413
|
|
414 g_free (pwstr);
|
|
415
|
460
|
416 if (question_pos != NULL)
|
|
417 {
|
|
418 if (*question_pos != '\0')
|
|
419 request->logging_function (gftp_logging_recv, request, "%s\n",
|
|
420 question_pos);
|
|
421 }
|
|
422 else if (*tempstr != '\0')
|
|
423 request->logging_function (gftp_logging_recv, request, "%s\n", tempstr);
|
122
|
424
|
458
|
425 g_free (tempstr);
|
|
426
|
122
|
427 if (ok <= 0)
|
|
428 {
|
|
429 if (ok == SSH_ERROR_BADPASS)
|
186
|
430 request->logging_function (gftp_logging_error, request,
|
122
|
431 _("Error: An incorrect password was entered\n"));
|
|
432 else if (ok == SSH_WARNING)
|
186
|
433 request->logging_function (gftp_logging_error, request,
|
122
|
434 _("Please correct the above warning to connect to this host.\n"));
|
|
435
|
460
|
436 gftp_disconnect (request);
|
458
|
437 return (GFTP_EFATAL);
|
122
|
438 }
|
|
439
|
458
|
440 return (0);
|
122
|
441 }
|
|
442
|
|
443
|
|
444 #ifdef G_HAVE_GINT64
|
|
445
|
|
446 static gint64
|
|
447 hton64 (gint64 val)
|
|
448 {
|
|
449 if (G_BYTE_ORDER != G_BIG_ENDIAN)
|
|
450 return (GINT64_TO_BE (val));
|
|
451 else
|
|
452 return (val);
|
|
453 }
|
|
454
|
|
455 #endif
|
|
456
|
1
|
457
|
48
|
458 static void
|
|
459 sshv2_log_command (gftp_request * request, gftp_logging_level level,
|
|
460 char type, char *message, size_t length)
|
1
|
461 {
|
48
|
462 gint32 id, num, attr, stattype;
|
|
463 char *descr, *pos, oldchar;
|
1
|
464 sshv2_params * params;
|
|
465
|
48
|
466 params = request->protocol_data;
|
|
467 memcpy (&id, message, 4);
|
|
468 id = ntohl (id);
|
|
469 switch (type)
|
|
470 {
|
|
471 case SSH_FXP_INIT:
|
186
|
472 request->logging_function (level, request,
|
48
|
473 _("%d: Protocol Initialization\n"), id);
|
|
474 break;
|
|
475 case SSH_FXP_VERSION:
|
|
476 memcpy (&num, message, 4);
|
|
477 num = ntohl (num);
|
186
|
478 request->logging_function (level, request,
|
48
|
479 _("%d: Protocol version %d\n"), id, num);
|
|
480 break;
|
|
481 case SSH_FXP_OPEN:
|
|
482 memcpy (&num, message + 4, 4);
|
|
483 num = ntohl (num);
|
|
484 pos = message + 12 + num - 1;
|
|
485 oldchar = *pos;
|
|
486 *pos = '\0';
|
186
|
487 request->logging_function (level, request,
|
48
|
488 _("%d: Open %s\n"), id, message + 8);
|
|
489 *pos = oldchar;
|
|
490 break;
|
|
491 case SSH_FXP_CLOSE:
|
186
|
492 request->logging_function (level, request,
|
48
|
493 _("%d: Close\n"), id);
|
|
494 case SSH_FXP_READ:
|
|
495 case SSH_FXP_WRITE:
|
|
496 break;
|
|
497 case SSH_FXP_OPENDIR:
|
186
|
498 request->logging_function (level, request,
|
48
|
499 _("%d: Open Directory %s\n"), id,
|
|
500 message + 8);
|
|
501 break;
|
|
502 case SSH_FXP_READDIR:
|
186
|
503 request->logging_function (level, request,
|
48
|
504 _("%d: Read Directory\n"), id);
|
|
505 break;
|
|
506 case SSH_FXP_REMOVE:
|
186
|
507 request->logging_function (level, request,
|
48
|
508 _("%d: Remove file %s\n"), id,
|
|
509 message + 8);
|
|
510 break;
|
|
511 case SSH_FXP_MKDIR:
|
186
|
512 request->logging_function (level, request,
|
48
|
513 _("%d: Make directory %s\n"), id,
|
|
514 message + 8);
|
|
515 break;
|
|
516 case SSH_FXP_RMDIR:
|
186
|
517 request->logging_function (level, request,
|
48
|
518 _("%d: Remove directory %s\n"), id,
|
|
519 message + 8);
|
|
520 break;
|
|
521 case SSH_FXP_REALPATH:
|
186
|
522 request->logging_function (level, request,
|
48
|
523 _("%d: Realpath %s\n"), id,
|
|
524 message + 8);
|
|
525 break;
|
|
526 case SSH_FXP_ATTRS:
|
186
|
527 request->logging_function (level, request,
|
48
|
528 _("%d: File attributes\n"), id);
|
|
529 break;
|
|
530 case SSH_FXP_STAT:
|
186
|
531 request->logging_function (level, request,
|
48
|
532 _("%d: Stat %s\n"), id,
|
|
533 message + 8);
|
|
534 break;
|
|
535 case SSH_FXP_SETSTAT:
|
|
536 memcpy (&num, message + 4, 4);
|
|
537 num = ntohl (num);
|
|
538 pos = message + 12 + num - 1;
|
|
539 oldchar = *pos;
|
|
540 *pos = '\0';
|
|
541 memcpy (&stattype, message + 8 + num, 4);
|
|
542 stattype = ntohl (stattype);
|
|
543 memcpy (&attr, message + 12 + num, 4);
|
|
544 attr = ntohl (attr);
|
|
545 switch (stattype)
|
|
546 {
|
|
547 case SSH_FILEXFER_ATTR_PERMISSIONS:
|
186
|
548 request->logging_function (level, request,
|
48
|
549 _("%d: Chmod %s %o\n"), id,
|
|
550 message + 8, attr);
|
|
551 break;
|
|
552 case SSH_FILEXFER_ATTR_ACMODTIME:
|
186
|
553 request->logging_function (level, request,
|
48
|
554 _("%d: Utime %s %d\n"), id,
|
|
555 message + 8, attr);
|
|
556 }
|
|
557 *pos = oldchar;
|
|
558 break;
|
|
559 case SSH_FXP_STATUS:
|
|
560 if (params->dont_log_status)
|
|
561 break;
|
|
562 memcpy (&num, message + 4, 4);
|
|
563 num = ntohl (num);
|
|
564 switch (num)
|
|
565 {
|
|
566 case SSH_FX_OK:
|
|
567 descr = _("OK");
|
|
568 break;
|
|
569 case SSH_FX_EOF:
|
|
570 descr = _("EOF");
|
|
571 break;
|
|
572 case SSH_FX_NO_SUCH_FILE:
|
|
573 descr = _("No such file or directory");
|
|
574 break;
|
|
575 case SSH_FX_PERMISSION_DENIED:
|
|
576 descr = _("Permission denied");
|
|
577 break;
|
|
578 case SSH_FX_FAILURE:
|
|
579 descr = _("Failure");
|
|
580 break;
|
|
581 case SSH_FX_BAD_MESSAGE:
|
|
582 descr = _("Bad message");
|
|
583 break;
|
|
584 case SSH_FX_NO_CONNECTION:
|
|
585 descr = _("No connection");
|
|
586 break;
|
|
587 case SSH_FX_CONNECTION_LOST:
|
|
588 descr = _("Connection lost");
|
|
589 break;
|
|
590 case SSH_FX_OP_UNSUPPORTED:
|
|
591 descr = _("Operation unsupported");
|
|
592 break;
|
|
593 default:
|
|
594 descr = _("Unknown message returned from server");
|
|
595 break;
|
|
596 }
|
186
|
597 request->logging_function (level, request,
|
48
|
598 "%d: %s\n", id, descr);
|
|
599 break;
|
|
600 case SSH_FXP_HANDLE:
|
186
|
601 request->logging_function (level, request,
|
48
|
602 "%d: File handle\n", id);
|
|
603 break;
|
|
604 case SSH_FXP_DATA:
|
|
605 break;
|
|
606 case SSH_FXP_NAME:
|
|
607 memcpy (&num, message + 4, 4);
|
|
608 num = ntohl (num);
|
186
|
609 request->logging_function (level, request,
|
48
|
610 "%d: Filenames (%d entries)\n", id,
|
|
611 num);
|
|
612 break;
|
|
613 default:
|
186
|
614 request->logging_function (level, request,
|
48
|
615 "Command: %x\n", type);
|
|
616 }
|
|
617 }
|
1
|
618
|
48
|
619
|
|
620 static int
|
|
621 sshv2_send_command (gftp_request * request, char type, char *command,
|
321
|
622 size_t len)
|
48
|
623 {
|
|
624 char buf[34000];
|
|
625 gint32 clen;
|
84
|
626 int ret;
|
48
|
627
|
|
628 if (len > 33995)
|
|
629 {
|
186
|
630 request->logging_function (gftp_logging_error, request,
|
48
|
631 _("Error: Message size %d too big\n"), len);
|
|
632 gftp_disconnect (request);
|
84
|
633 return (GFTP_EFATAL);
|
48
|
634 }
|
|
635
|
|
636 clen = htonl (len + 1);
|
|
637 memcpy (buf, &clen, 4);
|
|
638 buf[4] = type;
|
|
639 memcpy (&buf[5], command, len);
|
|
640 buf[len + 5] = '\0';
|
|
641
|
|
642 #ifdef DEBUG
|
458
|
643 printf ("\rSending to FD %d: ", request->datafd);
|
61
|
644 for (clen=0; clen<len + 5; clen++)
|
|
645 printf ("%x ", buf[clen] & 0xff);
|
48
|
646 printf ("\n");
|
|
647 #endif
|
|
648
|
|
649 sshv2_log_command (request, gftp_logging_send, type, buf + 5, len);
|
|
650
|
169
|
651 if ((ret = gftp_fd_write (request, buf, len + 5, request->datafd)) < 0)
|
84
|
652 return (ret);
|
48
|
653
|
84
|
654 return (0);
|
48
|
655 }
|
|
656
|
|
657
|
|
658 static int
|
|
659 sshv2_read_response (gftp_request * request, sshv2_message * message,
|
58
|
660 int fd)
|
48
|
661 {
|
219
|
662 char buf[6], error_buffer[255], *pos;
|
|
663 sshv2_params * params;
|
61
|
664 ssize_t numread, rem;
|
219
|
665
|
|
666 params = request->protocol_data;
|
48
|
667
|
58
|
668 if (fd <= 0)
|
169
|
669 fd = request->datafd;
|
1
|
670
|
61
|
671 pos = buf;
|
|
672 rem = 5;
|
|
673 while (rem > 0)
|
|
674 {
|
168
|
675 if ((numread = gftp_fd_read (request, pos, rem, fd)) < 0)
|
84
|
676 return ((int) numread);
|
61
|
677 rem -= numread;
|
|
678 pos += numread;
|
|
679 }
|
219
|
680 buf[5] = '\0';
|
48
|
681
|
|
682 memcpy (&message->length, buf, 4);
|
|
683 message->length = ntohl (message->length);
|
|
684 if (message->length > 34000)
|
|
685 {
|
219
|
686 if (params->initialized)
|
|
687 {
|
|
688 request->logging_function (gftp_logging_error, request,
|
48
|
689 _("Error: Message size %d too big from server\n"),
|
|
690 message->length);
|
219
|
691 }
|
|
692 else
|
|
693 {
|
|
694 request->logging_function (gftp_logging_error, request,
|
|
695 _("There was an error initializing a SSH connection with the remote server. The error message from the remote server follows:\n"), buf);
|
|
696
|
|
697 request->logging_function (gftp_logging_error, request, "%s", buf);
|
|
698
|
243
|
699 if (gftp_fd_set_sockblocking (request, fd, 0) == -1)
|
|
700 return (GFTP_EFATAL);
|
|
701
|
|
702 if ((numread = gftp_fd_read (NULL, error_buffer,
|
219
|
703 sizeof (error_buffer) - 1,
|
|
704 fd)) > 0)
|
|
705 {
|
|
706 error_buffer[numread] = '\0';
|
|
707 request->logging_function (gftp_logging_error, request,
|
|
708 "%s", error_buffer);
|
|
709 }
|
|
710 }
|
|
711
|
48
|
712 memset (message, 0, sizeof (*message));
|
|
713 gftp_disconnect (request);
|
84
|
714 return (GFTP_EFATAL);
|
48
|
715 }
|
58
|
716
|
48
|
717 message->command = buf[4];
|
61
|
718 message->buffer = g_malloc (message->length + 1);
|
48
|
719
|
|
720 message->pos = message->buffer;
|
|
721 message->end = message->buffer + message->length - 1;
|
|
722
|
61
|
723 pos = message->buffer;
|
|
724 rem = message->length - 1;
|
|
725 while (rem > 0)
|
|
726 {
|
168
|
727 if ((numread = gftp_fd_read (request, pos, rem, fd)) < 0)
|
84
|
728 return ((int) numread);
|
61
|
729 rem -= numread;
|
|
730 pos += numread;
|
|
731 }
|
48
|
732
|
61
|
733 message->buffer[message->length] = '\0';
|
48
|
734
|
|
735 sshv2_log_command (request, gftp_logging_recv, message->command,
|
|
736 message->buffer, message->length);
|
|
737
|
|
738 return (message->command);
|
1
|
739 }
|
|
740
|
|
741
|
|
742 static void
|
|
743 sshv2_destroy (gftp_request * request)
|
|
744 {
|
|
745 g_return_if_fail (request != NULL);
|
|
746 g_return_if_fail (request->protonum == GFTP_SSHV2_NUM);
|
|
747
|
|
748 g_free (request->protocol_data);
|
|
749 request->protocol_data = NULL;
|
|
750 }
|
|
751
|
|
752
|
48
|
753 static void
|
|
754 sshv2_message_free (sshv2_message * message)
|
|
755 {
|
|
756 if (message->buffer)
|
|
757 g_free (message->buffer);
|
|
758 memset (message, 0, sizeof (*message));
|
|
759 }
|
|
760
|
|
761
|
|
762 static gint32
|
|
763 sshv2_buffer_get_int32 (gftp_request * request, sshv2_message * message,
|
|
764 int expected_response)
|
|
765 {
|
|
766 gint32 ret;
|
|
767
|
|
768 if (message->end - message->pos < 4)
|
|
769 {
|
186
|
770 request->logging_function (gftp_logging_error, request,
|
48
|
771 _("Received wrong response from server, disconnecting\n"));
|
|
772 sshv2_message_free (message);
|
|
773 gftp_disconnect (request);
|
84
|
774 return (GFTP_EFATAL);
|
48
|
775 }
|
|
776
|
|
777 memcpy (&ret, message->pos, 4);
|
|
778 ret = ntohl (ret);
|
|
779 message->pos += 4;
|
|
780
|
|
781 if (expected_response > 0 && ret != expected_response)
|
|
782 {
|
186
|
783 request->logging_function (gftp_logging_error, request,
|
48
|
784 _("Received wrong response from server, disconnecting\n"));
|
|
785 sshv2_message_free (message);
|
|
786 gftp_disconnect (request);
|
84
|
787 return (GFTP_EFATAL);
|
48
|
788 }
|
|
789
|
|
790 return (ret);
|
|
791 }
|
|
792
|
|
793
|
|
794 static char *
|
|
795 sshv2_buffer_get_string (gftp_request * request, sshv2_message * message)
|
|
796 {
|
|
797 char *string;
|
|
798 gint32 len;
|
|
799
|
|
800 if ((len = sshv2_buffer_get_int32 (request, message, -1)) < 0)
|
|
801 return (NULL);
|
|
802
|
|
803 if (len > SSH_MAX_STRING_SIZE || (message->end - message->pos < len))
|
|
804 {
|
186
|
805 request->logging_function (gftp_logging_error, request,
|
48
|
806 _("Received wrong response from server, disconnecting\n"));
|
|
807 sshv2_message_free (message);
|
|
808 gftp_disconnect (request);
|
|
809 return (NULL);
|
|
810 }
|
|
811
|
|
812 string = g_malloc (len + 1);
|
|
813 memcpy (string, message->pos, len);
|
|
814 string[len] = '\0';
|
|
815 message->pos += len;
|
|
816 return (string);
|
|
817 }
|
|
818
|
|
819
|
|
820 static int
|
|
821 sshv2_getcwd (gftp_request * request)
|
|
822 {
|
|
823 sshv2_message message;
|
|
824 sshv2_params * params;
|
|
825 char *tempstr, *dir;
|
|
826 gint32 num;
|
|
827 size_t len;
|
64
|
828 int ret;
|
48
|
829
|
84
|
830 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
831 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
48
|
832
|
|
833 if (request->directory == NULL || *request->directory == '\0')
|
|
834 dir = ".";
|
|
835 else
|
|
836 dir = request->directory;
|
|
837
|
|
838 params = request->protocol_data;
|
|
839 len = strlen (dir);
|
|
840 tempstr = g_malloc (len + 9);
|
|
841 strcpy (tempstr + 8, dir);
|
|
842
|
|
843 num = htonl (params->id++);
|
|
844 memcpy (tempstr, &num, 4);
|
|
845
|
|
846 num = htonl (len);
|
|
847 memcpy (tempstr + 4, &num, 4);
|
84
|
848 if ((ret = sshv2_send_command (request, SSH_FXP_REALPATH, tempstr,
|
|
849 len + 8)) < 0)
|
48
|
850 {
|
|
851 g_free (tempstr);
|
84
|
852 return (ret);
|
48
|
853 }
|
|
854
|
|
855 g_free (tempstr);
|
|
856 if (request->directory)
|
|
857 {
|
|
858 g_free (request->directory);
|
|
859 request->directory = NULL;
|
|
860 }
|
|
861
|
|
862 memset (&message, 0, sizeof (message));
|
64
|
863 ret = sshv2_read_response (request, &message, -1);
|
84
|
864 if (ret < 0)
|
|
865 return (ret);
|
|
866 else if (ret == SSH_FXP_STATUS)
|
64
|
867 {
|
|
868 sshv2_message_free (&message);
|
84
|
869 return (GFTP_ERETRYABLE);
|
64
|
870 }
|
|
871 else if (ret != SSH_FXP_NAME)
|
48
|
872 {
|
186
|
873 request->logging_function (gftp_logging_error, request,
|
48
|
874 _("Received wrong response from server, disconnecting\n"));
|
|
875 sshv2_message_free (&message);
|
|
876 gftp_disconnect (request);
|
84
|
877 return (GFTP_EFATAL);
|
48
|
878 }
|
|
879
|
|
880 message.pos += 4;
|
84
|
881 if ((ret = sshv2_buffer_get_int32 (request, &message, 1)) < 0)
|
|
882 return (ret);
|
48
|
883
|
|
884 if ((request->directory = sshv2_buffer_get_string (request, &message)) == NULL)
|
84
|
885 return (GFTP_EFATAL);
|
64
|
886
|
48
|
887 sshv2_message_free (&message);
|
|
888 return (0);
|
|
889 }
|
|
890
|
|
891
|
124
|
892 static void
|
|
893 sshv2_free_args (char **args)
|
|
894 {
|
|
895 int i;
|
|
896
|
|
897 for (i=0; args[i] != NULL; i++)
|
|
898 g_free (args[i]);
|
|
899 g_free (args);
|
|
900 }
|
|
901
|
|
902
|
1
|
903 static int
|
|
904 sshv2_connect (gftp_request * request)
|
|
905 {
|
458
|
906 char **args, *p1, p2, *exepath, *ssh2_sftp_path;
|
|
907 intptr_t sshv2_use_sftp_subsys;
|
|
908 int version, ret, fdm, ptymfd;
|
124
|
909 struct servent serv_struct;
|
219
|
910 sshv2_params * params;
|
1
|
911 sshv2_message message;
|
|
912 pid_t child;
|
|
913
|
84
|
914 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
915 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
|
916 g_return_val_if_fail (request->hostname != NULL, GFTP_EFATAL);
|
1
|
917
|
169
|
918 if (request->datafd > 0)
|
1
|
919 return (0);
|
|
920
|
219
|
921 params = request->protocol_data;
|
|
922
|
186
|
923 request->logging_function (gftp_logging_misc, request,
|
1
|
924 _("Opening SSH connection to %s\n"),
|
|
925 request->hostname);
|
|
926
|
122
|
927 gftp_lookup_request_option (request, "ssh2_sftp_path", &ssh2_sftp_path);
|
|
928 gftp_lookup_request_option (request, "sshv2_use_sftp_subsys",
|
|
929 &sshv2_use_sftp_subsys);
|
|
930
|
|
931 if (ssh2_sftp_path == NULL || *ssh2_sftp_path == '\0')
|
1
|
932 {
|
|
933 p1 = "";
|
|
934 p2 = ' ';
|
|
935 }
|
|
936 else
|
|
937 {
|
122
|
938 p1 = ssh2_sftp_path;
|
1
|
939 p2 = '/';
|
|
940 }
|
|
941
|
124
|
942 if (request->port == 0)
|
|
943 {
|
|
944 if (!r_getservbyname ("ssh", "tcp", &serv_struct, NULL))
|
|
945 {
|
186
|
946 request->logging_function (gftp_logging_error, request,
|
124
|
947 _("Cannot look up service name %s/tcp. Please check your services file\n"),
|
|
948 "ssh");
|
|
949 }
|
|
950 else
|
|
951 request->port = ntohs (serv_struct.s_port);
|
|
952 }
|
|
953
|
458
|
954 exepath = g_strdup_printf ("%s%csftp-server", p1, p2);
|
124
|
955 args = sshv2_gen_exec_args (request, exepath, sshv2_use_sftp_subsys);
|
1
|
956
|
458
|
957 child = gftp_exec (request, &fdm, &ptymfd, args);
|
210
|
958
|
|
959 if (child == 0)
|
|
960 exit (0);
|
1
|
961
|
210
|
962 sshv2_free_args (args);
|
|
963 g_free (exepath);
|
1
|
964
|
458
|
965 if (child < 0)
|
|
966 return (GFTP_ERETRYABLE);
|
|
967
|
210
|
968 request->datafd = fdm;
|
84
|
969
|
210
|
970 version = htonl (SSH_MY_VERSION);
|
|
971 if ((ret = sshv2_send_command (request, SSH_FXP_INIT, (char *)
|
|
972 &version, 4)) < 0)
|
|
973 return (ret);
|
1
|
974
|
458
|
975 ret = sshv2_start_login_sequence (request, fdm, ptymfd);
|
|
976 if (ret < 0)
|
|
977 return (ret);
|
|
978
|
210
|
979 memset (&message, 0, sizeof (message));
|
219
|
980 ret = sshv2_read_response (request, &message, -1);
|
|
981 if (ret < 0)
|
|
982 {
|
|
983 sshv2_message_free (&message);
|
|
984 return (ret);
|
|
985 }
|
|
986 else if (ret != SSH_FXP_VERSION)
|
1
|
987 {
|
186
|
988 request->logging_function (gftp_logging_error, request,
|
219
|
989 _("Received wrong response from server, disconnecting\n"));
|
210
|
990 sshv2_message_free (&message);
|
|
991 gftp_disconnect (request);
|
|
992
|
219
|
993 return (GFTP_EFATAL);
|
1
|
994 }
|
219
|
995
|
210
|
996 sshv2_message_free (&message);
|
|
997
|
219
|
998 params->initialized = 1;
|
210
|
999 request->logging_function (gftp_logging_misc, request,
|
|
1000 _("Successfully logged into SSH server %s\n"),
|
|
1001 request->hostname);
|
1
|
1002
|
64
|
1003 if (sshv2_getcwd (request) < 0)
|
|
1004 {
|
|
1005 if (request->directory)
|
|
1006 g_free (request->directory);
|
|
1007
|
|
1008 request->directory = g_strdup (".");
|
84
|
1009 if ((ret = sshv2_getcwd (request)) < 0)
|
64
|
1010 {
|
|
1011 gftp_disconnect (request);
|
84
|
1012 return (ret);
|
64
|
1013 }
|
|
1014 }
|
1
|
1015
|
|
1016 return (0);
|
|
1017 }
|
|
1018
|
|
1019
|
|
1020 static void
|
|
1021 sshv2_disconnect (gftp_request * request)
|
|
1022 {
|
|
1023 sshv2_params * params;
|
|
1024
|
|
1025 g_return_if_fail (request != NULL);
|
|
1026 g_return_if_fail (request->protonum == GFTP_SSHV2_NUM);
|
|
1027
|
|
1028 params = request->protocol_data;
|
|
1029
|
169
|
1030 if (request->datafd > 0)
|
1
|
1031 {
|
186
|
1032 request->logging_function (gftp_logging_misc, request,
|
1
|
1033 _("Disconnecting from site %s\n"),
|
|
1034 request->hostname);
|
58
|
1035
|
169
|
1036 if (close (request->datafd) < 0)
|
186
|
1037 request->logging_function (gftp_logging_error, request,
|
58
|
1038 _("Error closing file descriptor: %s\n"),
|
|
1039 g_strerror (errno));
|
|
1040
|
169
|
1041 request->datafd = -1;
|
1
|
1042 }
|
|
1043
|
|
1044 if (params->message.buffer != NULL)
|
|
1045 sshv2_message_free (¶ms->message);
|
|
1046 }
|
|
1047
|
|
1048
|
|
1049 static int
|
|
1050 sshv2_end_transfer (gftp_request * request)
|
|
1051 {
|
|
1052 sshv2_params * params;
|
|
1053 sshv2_message message;
|
|
1054 gint32 len;
|
84
|
1055 int ret;
|
1
|
1056
|
84
|
1057 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
1058 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
1
|
1059
|
|
1060 params = request->protocol_data;
|
|
1061 if (params->message.buffer != NULL)
|
|
1062 {
|
|
1063 sshv2_message_free (¶ms->message);
|
|
1064 params->count = 0;
|
|
1065 }
|
|
1066
|
|
1067 if (params->handle_len > 0)
|
|
1068 {
|
|
1069 len = htonl (params->id++);
|
|
1070 memcpy (params->handle, &len, 4);
|
|
1071
|
84
|
1072 if ((ret = sshv2_send_command (request, SSH_FXP_CLOSE, params->handle,
|
|
1073 params->handle_len)) < 0)
|
|
1074 return (ret);
|
1
|
1075
|
|
1076 memset (&message, 0, sizeof (message));
|
84
|
1077 if ((ret = sshv2_read_response (request, &message, -1)) != SSH_FXP_STATUS)
|
1
|
1078 {
|
186
|
1079 request->logging_function (gftp_logging_error, request,
|
1
|
1080 _("Received wrong response from server, disconnecting\n"));
|
|
1081 sshv2_message_free (&message);
|
|
1082 gftp_disconnect (request);
|
84
|
1083 if (ret < 0)
|
|
1084 return (ret);
|
|
1085 else
|
|
1086 return (GFTP_ERETRYABLE);
|
1
|
1087 }
|
|
1088 sshv2_message_free (&message);
|
|
1089 params->handle_len = 0;
|
|
1090 }
|
|
1091
|
|
1092 if (params->read_buffer != NULL)
|
|
1093 {
|
|
1094 g_free (params->read_buffer);
|
|
1095 params->read_buffer = NULL;
|
|
1096 }
|
|
1097
|
|
1098 return (0);
|
|
1099 }
|
|
1100
|
|
1101
|
|
1102 static int
|
|
1103 sshv2_list_files (gftp_request * request)
|
|
1104 {
|
|
1105 sshv2_params * params;
|
|
1106 sshv2_message message;
|
|
1107 char *tempstr;
|
|
1108 gint32 len;
|
64
|
1109 int ret;
|
1
|
1110
|
84
|
1111 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
1112 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
169
|
1113 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
|
1
|
1114
|
|
1115 params = request->protocol_data;
|
|
1116
|
186
|
1117 request->logging_function (gftp_logging_misc, request,
|
1
|
1118 _("Retrieving directory listing...\n"));
|
|
1119
|
|
1120 tempstr = g_malloc (strlen (request->directory) + 9);
|
|
1121
|
|
1122 len = htonl (params->id++);
|
|
1123 memcpy (tempstr, &len, 4);
|
|
1124
|
|
1125 len = htonl (strlen (request->directory));
|
|
1126 memcpy (tempstr + 4, &len, 4);
|
|
1127 strcpy (tempstr + 8, request->directory);
|
84
|
1128 if ((ret = sshv2_send_command (request, SSH_FXP_OPENDIR, tempstr,
|
|
1129 strlen (request->directory) + 8)) < 0)
|
1
|
1130 {
|
|
1131 g_free (tempstr);
|
84
|
1132 return (ret);
|
1
|
1133 }
|
|
1134 g_free (tempstr);
|
|
1135
|
|
1136 memset (&message, 0, sizeof (message));
|
64
|
1137 ret = sshv2_read_response (request, &message, -1);
|
84
|
1138 if (ret < 0)
|
|
1139 return (ret);
|
|
1140 else if (ret == SSH_FXP_STATUS)
|
64
|
1141 {
|
|
1142 sshv2_message_free (&message);
|
84
|
1143 return (GFTP_ERETRYABLE);
|
64
|
1144 }
|
|
1145 else if (ret != SSH_FXP_HANDLE)
|
1
|
1146 {
|
186
|
1147 request->logging_function (gftp_logging_error, request,
|
1
|
1148 _("Received wrong response from server, disconnecting\n"));
|
|
1149 sshv2_message_free (&message);
|
|
1150 gftp_disconnect (request);
|
84
|
1151 return (GFTP_EFATAL);
|
1
|
1152 }
|
|
1153
|
|
1154 if (message.length - 4 > SSH_MAX_HANDLE_SIZE)
|
|
1155 {
|
186
|
1156 request->logging_function (gftp_logging_error, request,
|
1
|
1157 _("Error: Message size %d too big from server\n"),
|
|
1158 message.length - 4);
|
|
1159 sshv2_message_free (&message);
|
|
1160 gftp_disconnect (request);
|
84
|
1161 return (GFTP_EFATAL);
|
1
|
1162 }
|
|
1163
|
|
1164 memset (params->handle, 0, 4);
|
|
1165 memcpy (params->handle + 4, message.buffer + 4, message.length - 5);
|
|
1166 params->handle_len = message.length - 1;
|
|
1167 sshv2_message_free (&message);
|
|
1168 params->count = 0;
|
|
1169 return (0);
|
|
1170 }
|
|
1171
|
|
1172
|
|
1173 static int
|
58
|
1174 sshv2_get_next_file (gftp_request * request, gftp_file * fle, int fd)
|
1
|
1175 {
|
|
1176 gint32 len, attrs, longnamelen;
|
|
1177 int ret, i, count, retsize;
|
|
1178 sshv2_params *params;
|
|
1179 char *longname;
|
|
1180
|
84
|
1181 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
1182 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
|
1183 g_return_val_if_fail (fle != NULL, GFTP_EFATAL);
|
1
|
1184
|
|
1185 params = request->protocol_data;
|
|
1186
|
|
1187 if (request->last_dir_entry)
|
|
1188 {
|
|
1189 g_free (request->last_dir_entry);
|
|
1190 request->last_dir_entry = NULL;
|
|
1191 request->last_dir_entry_len = 0;
|
|
1192 }
|
|
1193 retsize = 0;
|
|
1194
|
|
1195 if (params->count > 0)
|
|
1196 ret = SSH_FXP_NAME;
|
|
1197 else
|
|
1198 {
|
|
1199 if (!request->cached)
|
|
1200 {
|
|
1201 if (params->message.buffer != NULL)
|
|
1202 sshv2_message_free (¶ms->message);
|
|
1203
|
|
1204 len = htonl (params->id++);
|
|
1205 memcpy (params->handle, &len, 4);
|
|
1206
|
84
|
1207 if ((ret = sshv2_send_command (request, SSH_FXP_READDIR,
|
|
1208 params->handle,
|
|
1209 params->handle_len)) < 0)
|
|
1210 return (ret);
|
1
|
1211 }
|
|
1212
|
|
1213 if ((ret = sshv2_read_response (request, ¶ms->message, fd)) < 0)
|
84
|
1214 return (ret);
|
1
|
1215
|
|
1216 if (!request->cached)
|
|
1217 {
|
|
1218 request->last_dir_entry = g_malloc (params->message.length + 4);
|
|
1219 len = htonl (params->message.length);
|
|
1220 memcpy (request->last_dir_entry, &len, 4);
|
|
1221 request->last_dir_entry[4] = params->message.command;
|
|
1222 memcpy (request->last_dir_entry + 5, params->message.buffer,
|
|
1223 params->message.length - 1);
|
|
1224 request->last_dir_entry_len = params->message.length + 4;
|
|
1225 }
|
|
1226
|
|
1227 if (ret == SSH_FXP_NAME)
|
|
1228 {
|
|
1229 params->message.pos = params->message.buffer + 4;
|
|
1230 if ((params->count = sshv2_buffer_get_int32 (request,
|
|
1231 ¶ms->message, -1)) < 0)
|
84
|
1232 return (params->count);
|
1
|
1233 }
|
|
1234 }
|
|
1235
|
|
1236 if (ret == SSH_FXP_NAME)
|
|
1237 {
|
|
1238 if ((len = sshv2_buffer_get_int32 (request, ¶ms->message, -1)) < 0 ||
|
|
1239 params->message.pos + len > params->message.end)
|
84
|
1240 return (GFTP_EFATAL);
|
1
|
1241
|
|
1242 params->message.pos += len;
|
|
1243
|
|
1244 if ((longnamelen = sshv2_buffer_get_int32 (request,
|
|
1245 ¶ms->message, -1)) < 0 ||
|
|
1246 params->message.pos + longnamelen > params->message.end)
|
84
|
1247 return (GFTP_EFATAL);
|
1
|
1248
|
|
1249 longname = params->message.pos;
|
|
1250 params->message.pos += longnamelen;
|
|
1251
|
|
1252 if ((attrs = sshv2_buffer_get_int32 (request, ¶ms->message, -1)) < 0)
|
84
|
1253 return (attrs);
|
1
|
1254
|
|
1255 if (attrs & SSH_FILEXFER_ATTR_SIZE)
|
|
1256 {
|
|
1257 params->message.pos += 8;
|
|
1258 if (params->message.pos > params->message.end)
|
|
1259 {
|
186
|
1260 request->logging_function (gftp_logging_error, request,
|
1
|
1261 _("Received wrong response from server, disconnecting\n"));
|
|
1262 sshv2_message_free (¶ms->message);
|
|
1263 gftp_disconnect (request);
|
84
|
1264 return (GFTP_EFATAL);
|
1
|
1265 }
|
|
1266 }
|
|
1267
|
|
1268 if (attrs & SSH_FILEXFER_ATTR_UIDGID)
|
|
1269 {
|
|
1270 params->message.pos += 8;
|
|
1271 if (params->message.pos > params->message.end)
|
|
1272 {
|
186
|
1273 request->logging_function (gftp_logging_error, request,
|
1
|
1274 _("Received wrong response from server, disconnecting\n"));
|
|
1275 sshv2_message_free (¶ms->message);
|
|
1276 gftp_disconnect (request);
|
84
|
1277 return (GFTP_EFATAL);
|
1
|
1278 }
|
|
1279 }
|
|
1280
|
|
1281 if (attrs & SSH_FILEXFER_ATTR_PERMISSIONS)
|
|
1282 {
|
|
1283 params->message.pos += 4;
|
|
1284 if (params->message.pos > params->message.end)
|
|
1285 {
|
186
|
1286 request->logging_function (gftp_logging_error, request,
|
1
|
1287 _("Received wrong response from server, disconnecting\n"));
|
|
1288 sshv2_message_free (¶ms->message);
|
|
1289 gftp_disconnect (request);
|
84
|
1290 return (GFTP_EFATAL);
|
1
|
1291 }
|
|
1292 }
|
|
1293
|
|
1294 if (attrs & SSH_FILEXFER_ATTR_ACMODTIME)
|
|
1295 {
|
|
1296 params->message.pos += 8;
|
|
1297 if (params->message.pos > params->message.end)
|
|
1298 {
|
186
|
1299 request->logging_function (gftp_logging_error, request,
|
1
|
1300 _("Received wrong response from server, disconnecting\n"));
|
|
1301 sshv2_message_free (¶ms->message);
|
|
1302 gftp_disconnect (request);
|
84
|
1303 return (GFTP_EFATAL);
|
1
|
1304 }
|
|
1305 }
|
|
1306
|
|
1307 if (attrs & SSH_FILEXFER_ATTR_EXTENDED)
|
|
1308 {
|
|
1309 if ((count = sshv2_buffer_get_int32 (request,
|
|
1310 ¶ms->message, -1)) < 0)
|
84
|
1311 return (GFTP_EFATAL);
|
1
|
1312
|
|
1313 for (i=0; i<count; i++)
|
|
1314 {
|
|
1315 if ((len = sshv2_buffer_get_int32 (request,
|
|
1316 ¶ms->message, -1)) < 0 ||
|
|
1317 params->message.pos + len + 4 > params->message.end)
|
84
|
1318 return (GFTP_EFATAL);
|
1
|
1319
|
|
1320 params->message.pos += len + 4;
|
|
1321
|
|
1322 if ((len = sshv2_buffer_get_int32 (request,
|
|
1323 ¶ms->message, -1)) < 0 ||
|
|
1324 params->message.pos + len + 4 > params->message.end)
|
84
|
1325 return (GFTP_EFATAL);
|
1
|
1326
|
|
1327 params->message.pos += len + 4;
|
|
1328 }
|
|
1329 }
|
|
1330
|
|
1331 longname[longnamelen] = '\0';
|
|
1332
|
|
1333 /* The commercial SSH2 puts a / and * after some entries */
|
|
1334 if (longname[longnamelen - 1] == '*')
|
|
1335 longname[--longnamelen] = '\0';
|
|
1336 if (longname[longnamelen - 1] == '/')
|
|
1337 longname[--longnamelen] = '\0';
|
|
1338
|
91
|
1339 if ((ret = gftp_parse_ls (request, longname, fle)) < 0)
|
1
|
1340 {
|
|
1341 gftp_file_destroy (fle);
|
84
|
1342 return (ret);
|
1
|
1343 }
|
|
1344 retsize = strlen (longname);
|
|
1345
|
|
1346 params->count--;
|
|
1347 }
|
|
1348 else if (ret == SSH_FXP_STATUS)
|
|
1349 {
|
|
1350 sshv2_message_free (¶ms->message);
|
|
1351 return (0);
|
|
1352 }
|
|
1353 else
|
|
1354 {
|
186
|
1355 request->logging_function (gftp_logging_error, request,
|
1
|
1356 _("Received wrong response from server, disconnecting\n"));
|
|
1357 sshv2_message_free (¶ms->message);
|
|
1358 gftp_disconnect (request);
|
84
|
1359 return (GFTP_EFATAL);
|
1
|
1360 }
|
|
1361
|
|
1362 return (retsize);
|
|
1363 }
|
|
1364
|
|
1365
|
|
1366 static int
|
|
1367 sshv2_chdir (gftp_request * request, const char *directory)
|
|
1368 {
|
|
1369 sshv2_message message;
|
|
1370 sshv2_params * params;
|
|
1371 char *tempstr, *dir;
|
|
1372 gint32 num;
|
|
1373 size_t len;
|
64
|
1374 int ret;
|
1
|
1375
|
84
|
1376 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
1377 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
1
|
1378
|
|
1379 params = request->protocol_data;
|
|
1380 if (request->directory != directory)
|
|
1381 {
|
|
1382 if (*directory == '/')
|
|
1383 {
|
|
1384 len = strlen (directory) + 8;
|
|
1385 tempstr = g_malloc (len + 1);
|
|
1386 strcpy (tempstr + 8, directory);
|
|
1387 }
|
|
1388 else
|
|
1389 {
|
|
1390 len = strlen (directory) + strlen (request->directory) + 9;
|
|
1391 tempstr = g_malloc (len + 1);
|
|
1392 strcpy (tempstr + 8, request->directory);
|
|
1393 strcat (tempstr + 8, "/");
|
|
1394 strcat (tempstr + 8, directory);
|
|
1395 }
|
|
1396
|
|
1397 num = htonl (params->id++);
|
|
1398 memcpy (tempstr, &num, 4);
|
|
1399
|
|
1400 num = htonl (len - 8);
|
|
1401 memcpy (tempstr + 4, &num, 4);
|
84
|
1402 if ((ret = sshv2_send_command (request, SSH_FXP_REALPATH, tempstr, len)) < 0)
|
1
|
1403 {
|
|
1404 g_free (tempstr);
|
84
|
1405 return (ret);
|
1
|
1406 }
|
|
1407 g_free (tempstr);
|
|
1408
|
|
1409 memset (&message, 0, sizeof (message));
|
64
|
1410 ret = sshv2_read_response (request, &message, -1);
|
84
|
1411 if (ret < 0)
|
|
1412 return (ret);
|
|
1413 else if (ret == SSH_FXP_STATUS)
|
64
|
1414 {
|
|
1415 sshv2_message_free (&message);
|
84
|
1416 return (GFTP_ERETRYABLE);
|
64
|
1417 }
|
|
1418 else if (ret != SSH_FXP_NAME)
|
1
|
1419 {
|
186
|
1420 request->logging_function (gftp_logging_error, request,
|
1
|
1421 _("Received wrong response from server, disconnecting\n"));
|
|
1422 sshv2_message_free (&message);
|
|
1423 gftp_disconnect (request);
|
84
|
1424 return (GFTP_EFATAL);
|
1
|
1425 }
|
|
1426
|
|
1427 message.pos += 4;
|
|
1428 if (sshv2_buffer_get_int32 (request, &message, 1) != 1)
|
84
|
1429 return (GFTP_EFATAL);
|
1
|
1430
|
|
1431 if ((dir = sshv2_buffer_get_string (request, &message)) == NULL)
|
84
|
1432 return (GFTP_EFATAL);
|
1
|
1433
|
|
1434 if (request->directory)
|
|
1435 g_free (request->directory);
|
|
1436 request->directory = dir;
|
|
1437 sshv2_message_free (&message);
|
64
|
1438 return (0);
|
1
|
1439 }
|
284
|
1440
|
|
1441 return (0);
|
1
|
1442 }
|
|
1443
|
|
1444
|
|
1445 static int
|
|
1446 sshv2_rmdir (gftp_request * request, const char *directory)
|
|
1447 {
|
|
1448 sshv2_params * params;
|
|
1449 sshv2_message message;
|
|
1450 char *tempstr;
|
|
1451 gint32 num;
|
|
1452 size_t len;
|
84
|
1453 int ret;
|
1
|
1454
|
84
|
1455 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
1456 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
|
1457 g_return_val_if_fail (directory != NULL, GFTP_EFATAL);
|
1
|
1458
|
|
1459 params = request->protocol_data;
|
|
1460
|
|
1461 if (*directory == '/')
|
|
1462 {
|
|
1463 len = strlen (directory) + 8;
|
|
1464 tempstr = g_malloc (len + 1);
|
|
1465 strcpy (tempstr + 8, directory);
|
|
1466 }
|
|
1467 else
|
|
1468 {
|
|
1469 len = strlen (directory) + strlen (request->directory) + 9;
|
|
1470 tempstr = g_malloc (len + 1);
|
|
1471 strcpy (tempstr + 8, request->directory);
|
|
1472 strcat (tempstr + 8, "/");
|
|
1473 strcat (tempstr + 8, directory);
|
|
1474 }
|
|
1475
|
|
1476 num = htonl (params->id++);
|
|
1477 memcpy (tempstr, &num, 4);
|
|
1478
|
|
1479 num = htonl (len - 8);
|
|
1480 memcpy (tempstr + 4, &num, 4);
|
|
1481
|
|
1482 if (sshv2_send_command (request, SSH_FXP_RMDIR, tempstr, len) < 0)
|
|
1483 {
|
|
1484 g_free (tempstr);
|
84
|
1485 return (GFTP_ERETRYABLE);
|
1
|
1486 }
|
|
1487 g_free (tempstr);
|
|
1488
|
|
1489 memset (&message, 0, sizeof (message));
|
84
|
1490 if ((ret = sshv2_read_response (request, &message, -1)) < 0)
|
|
1491 return (ret);
|
1
|
1492
|
|
1493 message.pos += 4;
|
84
|
1494 if ((ret = sshv2_buffer_get_int32 (request, &message, SSH_FX_OK)) < 0)
|
|
1495 return (ret);
|
1
|
1496
|
|
1497 sshv2_message_free (&message);
|
|
1498
|
|
1499 return (0);
|
|
1500 }
|
|
1501
|
|
1502
|
|
1503 static int
|
|
1504 sshv2_rmfile (gftp_request * request, const char *file)
|
|
1505 {
|
|
1506 sshv2_params * params;
|
|
1507 sshv2_message message;
|
|
1508 char *tempstr;
|
|
1509 gint32 num;
|
|
1510 size_t len;
|
84
|
1511 int ret;
|
1
|
1512
|
84
|
1513 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
1514 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
|
1515 g_return_val_if_fail (file != NULL, GFTP_EFATAL);
|
1
|
1516
|
|
1517 params = request->protocol_data;
|
|
1518
|
|
1519 if (*file == '/')
|
|
1520 {
|
|
1521 len = strlen (file) + 8;
|
|
1522 tempstr = g_malloc (len + 1);
|
|
1523 strcpy (tempstr + 8, file);
|
|
1524 }
|
|
1525 else
|
|
1526 {
|
|
1527 len = strlen (file) + strlen (request->directory) + 9;
|
|
1528 tempstr = g_malloc (len + 1);
|
|
1529 strcpy (tempstr + 8, request->directory);
|
|
1530 strcat (tempstr + 8, "/");
|
|
1531 strcat (tempstr + 8, file);
|
|
1532 }
|
|
1533
|
|
1534 num = htonl (params->id++);
|
|
1535 memcpy (tempstr, &num, 4);
|
|
1536
|
|
1537 num = htonl (len - 8);
|
|
1538 memcpy (tempstr + 4, &num, 4);
|
|
1539
|
|
1540 if (sshv2_send_command (request, SSH_FXP_REMOVE, tempstr, len) < 0)
|
|
1541 {
|
|
1542 g_free (tempstr);
|
84
|
1543 return (GFTP_ERETRYABLE);
|
1
|
1544 }
|
|
1545 g_free (tempstr);
|
|
1546
|
|
1547 memset (&message, 0, sizeof (message));
|
84
|
1548 if ((ret = sshv2_read_response (request, &message, -1)) < 0)
|
|
1549 return (ret);
|
1
|
1550
|
|
1551 message.pos += 4;
|
84
|
1552 if ((ret = sshv2_buffer_get_int32 (request, &message, SSH_FX_OK)) < 0)
|
|
1553 return (ret);
|
1
|
1554
|
|
1555 sshv2_message_free (&message);
|
|
1556
|
|
1557 return (0);
|
|
1558 }
|
|
1559
|
|
1560
|
|
1561 static int
|
|
1562 sshv2_chmod (gftp_request * request, const char *file, int mode)
|
|
1563 {
|
|
1564 char *tempstr, buf[10];
|
|
1565 sshv2_params * params;
|
|
1566 sshv2_message message;
|
|
1567 gint32 num;
|
|
1568 size_t len;
|
84
|
1569 int ret;
|
1
|
1570
|
84
|
1571 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
1572 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
|
1573 g_return_val_if_fail (file != NULL, GFTP_EFATAL);
|
1
|
1574
|
|
1575 params = request->protocol_data;
|
|
1576
|
|
1577 if (*file == '/')
|
|
1578 {
|
|
1579 len = strlen (file) + 16;
|
|
1580 tempstr = g_malloc (len + 1);
|
|
1581 strcpy (tempstr + 8, file);
|
|
1582 }
|
|
1583 else
|
|
1584 {
|
|
1585 len = strlen (file) + strlen (request->directory) + 17;
|
|
1586 tempstr = g_malloc (len + 1);
|
|
1587 strcpy (tempstr + 8, request->directory);
|
|
1588 strcat (tempstr + 8, "/");
|
|
1589 strcat (tempstr + 8, file);
|
|
1590 }
|
|
1591
|
|
1592 num = htonl (params->id++);
|
|
1593 memcpy (tempstr, &num, 4);
|
|
1594
|
|
1595 num = htonl (len - 16);
|
|
1596 memcpy (tempstr + 4, &num, 4);
|
|
1597
|
|
1598 num = htonl (SSH_FILEXFER_ATTR_PERMISSIONS);
|
|
1599 memcpy (tempstr + len - 8, &num, 4);
|
|
1600
|
|
1601 g_snprintf (buf, sizeof (buf), "%d", mode);
|
|
1602 num = htonl (strtol (buf, NULL, 8));
|
|
1603 memcpy (tempstr + len - 4, &num, 4);
|
|
1604
|
|
1605 if (sshv2_send_command (request, SSH_FXP_SETSTAT, tempstr, len) < 0)
|
|
1606 {
|
|
1607 g_free (tempstr);
|
84
|
1608 return (GFTP_ERETRYABLE);
|
1
|
1609 }
|
|
1610 g_free (tempstr);
|
|
1611
|
|
1612 memset (&message, 0, sizeof (message));
|
84
|
1613 if ((ret = sshv2_read_response (request, &message, -1)) < 0)
|
|
1614 return (ret);
|
1
|
1615
|
|
1616 message.pos += 4;
|
84
|
1617 if ((ret = sshv2_buffer_get_int32 (request, &message, SSH_FX_OK)) < 0)
|
|
1618 return (ret);
|
1
|
1619
|
|
1620 sshv2_message_free (&message);
|
|
1621
|
|
1622 return (0);
|
|
1623 }
|
|
1624
|
|
1625
|
|
1626 static int
|
|
1627 sshv2_mkdir (gftp_request * request, const char *newdir)
|
|
1628 {
|
|
1629 sshv2_params * params;
|
|
1630 sshv2_message message;
|
|
1631 char *tempstr;
|
|
1632 gint32 num;
|
|
1633 size_t len;
|
84
|
1634 int ret;
|
1
|
1635
|
84
|
1636 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
1637 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
|
1638 g_return_val_if_fail (newdir != NULL, GFTP_EFATAL);
|
1
|
1639
|
|
1640 params = request->protocol_data;
|
|
1641
|
|
1642 if (*newdir == '/')
|
|
1643 {
|
|
1644 len = strlen (newdir) + 12;
|
|
1645 tempstr = g_malloc (len + 1);
|
|
1646 strcpy (tempstr + 8, newdir);
|
|
1647 }
|
|
1648 else
|
|
1649 {
|
|
1650 len = strlen (newdir) + strlen (request->directory) + 13;
|
|
1651 tempstr = g_malloc (len + 1);
|
|
1652 strcpy (tempstr + 8, request->directory);
|
|
1653 strcat (tempstr + 8, "/");
|
|
1654 strcat (tempstr + 8, newdir);
|
|
1655 }
|
|
1656
|
|
1657 num = htonl (params->id++);
|
|
1658 memcpy (tempstr, &num, 4);
|
|
1659
|
|
1660 num = htonl (len - 12);
|
|
1661 memcpy (tempstr + 4, &num, 4);
|
|
1662 memset (tempstr + len - 4, 0, 4); /* attributes */
|
|
1663
|
|
1664 if (sshv2_send_command (request, SSH_FXP_MKDIR, tempstr, len) < 0)
|
|
1665 {
|
|
1666 g_free (tempstr);
|
84
|
1667 return (GFTP_ERETRYABLE);
|
1
|
1668 }
|
|
1669 g_free (tempstr);
|
|
1670
|
|
1671 memset (&message, 0, sizeof (message));
|
84
|
1672 if ((ret = sshv2_read_response (request, &message, -1)) < 0)
|
|
1673 return (ret);
|
1
|
1674
|
|
1675 message.pos += 4;
|
84
|
1676 if ((ret = sshv2_buffer_get_int32 (request, &message, SSH_FX_OK)) < 0)
|
|
1677 return (ret);
|
1
|
1678
|
|
1679 sshv2_message_free (&message);
|
|
1680
|
|
1681 return (0);
|
|
1682 }
|
|
1683
|
|
1684
|
|
1685 static int
|
|
1686 sshv2_rename (gftp_request * request, const char *oldname, const char *newname)
|
|
1687 {
|
|
1688 char *tempstr, *oldstr, *newstr;
|
|
1689 sshv2_params * params;
|
|
1690 sshv2_message message;
|
84
|
1691 size_t oldlen, newlen;
|
1
|
1692 gint32 num;
|
84
|
1693 int ret;
|
1
|
1694
|
84
|
1695 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
1696 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
|
1697 g_return_val_if_fail (oldname != NULL, GFTP_EFATAL);
|
|
1698 g_return_val_if_fail (newname != NULL, GFTP_EFATAL);
|
1
|
1699
|
|
1700 params = request->protocol_data;
|
|
1701
|
|
1702 if (*oldname == '/')
|
|
1703 {
|
|
1704 oldlen = strlen (oldname);
|
56
|
1705 oldstr = g_strdup (oldname);
|
1
|
1706 }
|
|
1707 else
|
|
1708 {
|
|
1709 oldlen = strlen (request->directory) + strlen (oldname) + 1;
|
245
|
1710 oldstr = gftp_build_path (request->directory, oldname, NULL);
|
1
|
1711 }
|
|
1712
|
|
1713 if (*newname == '/')
|
|
1714 {
|
|
1715 newlen = strlen (newname);
|
56
|
1716 newstr = g_strdup (newname);
|
1
|
1717 }
|
|
1718 else
|
|
1719 {
|
|
1720 newlen = strlen (request->directory) + strlen (newname) + 1;
|
245
|
1721 newstr = gftp_build_path (request->directory, newname, NULL);
|
1
|
1722 }
|
|
1723
|
|
1724 tempstr = g_malloc (oldlen + newlen + 13);
|
|
1725 num = htonl (params->id++);
|
|
1726 memcpy (tempstr, &num, 4);
|
|
1727
|
|
1728 num = htonl (oldlen);
|
|
1729 memcpy (tempstr + 4, &num, 4);
|
|
1730 strcpy (tempstr + 8, oldstr);
|
|
1731
|
|
1732 num = htonl (newlen);
|
|
1733 memcpy (tempstr + 8 + oldlen, &num, 4);
|
|
1734 strcpy (tempstr + 12 + oldlen, newstr);
|
|
1735
|
|
1736 if (sshv2_send_command (request, SSH_FXP_RENAME, tempstr, oldlen + newlen + 12) < 0)
|
|
1737 {
|
|
1738 g_free (tempstr);
|
84
|
1739 return (GFTP_ERETRYABLE);
|
1
|
1740 }
|
|
1741 g_free (tempstr);
|
|
1742
|
|
1743 memset (&message, 0, sizeof (message));
|
84
|
1744 if ((ret = sshv2_read_response (request, &message, -1)) < 0)
|
|
1745 return (ret);
|
1
|
1746
|
|
1747 message.pos += 4;
|
84
|
1748 if ((ret = sshv2_buffer_get_int32 (request, &message, SSH_FX_OK)) < 0)
|
|
1749 return (ret);
|
1
|
1750
|
|
1751 sshv2_message_free (&message);
|
|
1752
|
|
1753 return (0);
|
|
1754 }
|
|
1755
|
|
1756
|
|
1757 static int
|
|
1758 sshv2_set_file_time (gftp_request * request, const char *file, time_t datetime)
|
|
1759 {
|
|
1760 sshv2_params * params;
|
|
1761 sshv2_message message;
|
|
1762 char *tempstr;
|
|
1763 gint32 num;
|
|
1764 size_t len;
|
84
|
1765 int ret;
|
1
|
1766
|
84
|
1767 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
1768 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
|
1769 g_return_val_if_fail (file != NULL, GFTP_EFATAL);
|
1
|
1770
|
|
1771 params = request->protocol_data;
|
|
1772
|
|
1773 if (*file == '/')
|
|
1774 {
|
|
1775 len = strlen (file) + 20;
|
|
1776 tempstr = g_malloc (len + 1);
|
|
1777 strcpy (tempstr + 8, file);
|
|
1778 }
|
|
1779 else
|
|
1780 {
|
|
1781 len = strlen (file) + strlen (request->directory) + 21;
|
|
1782 tempstr = g_malloc (len + 1);
|
|
1783 strcpy (tempstr + 8, request->directory);
|
|
1784 strcat (tempstr + 8, "/");
|
|
1785 strcat (tempstr + 8, file);
|
|
1786 }
|
|
1787
|
|
1788 num = htonl (params->id++);
|
|
1789 memcpy (tempstr, &num, 4);
|
|
1790
|
|
1791 num = htonl (len - 20);
|
|
1792 memcpy (tempstr + 4, &num, 4);
|
|
1793
|
|
1794 num = htonl (SSH_FILEXFER_ATTR_ACMODTIME);
|
|
1795 memcpy (tempstr + len - 12, &num, 4);
|
|
1796
|
|
1797 num = htonl (datetime);
|
|
1798 memcpy (tempstr + len - 8, &num, 4);
|
|
1799
|
|
1800 num = htonl (datetime);
|
|
1801 memcpy (tempstr + len - 4, &num, 4);
|
|
1802
|
|
1803 if (sshv2_send_command (request, SSH_FXP_SETSTAT, tempstr, len) < 0)
|
|
1804 {
|
|
1805 g_free (tempstr);
|
84
|
1806 return (GFTP_ERETRYABLE);
|
1
|
1807 }
|
|
1808 g_free (tempstr);
|
|
1809
|
|
1810 memset (&message, 0, sizeof (message));
|
84
|
1811 if ((ret = sshv2_read_response (request, &message, -1)) < 0)
|
|
1812 return (ret);
|
1
|
1813
|
|
1814 message.pos += 4;
|
84
|
1815 if ((ret = sshv2_buffer_get_int32 (request, &message, SSH_FX_OK)) < 0)
|
|
1816 return (ret);
|
1
|
1817
|
|
1818 sshv2_message_free (&message);
|
|
1819
|
|
1820 return (0);
|
|
1821 }
|
|
1822
|
|
1823
|
|
1824 static off_t
|
|
1825 sshv2_get_file_size (gftp_request * request, const char *file)
|
|
1826 {
|
|
1827 gint32 len, highnum, lownum, attrs, num;
|
|
1828 sshv2_params * params;
|
|
1829 char *tempstr;
|
64
|
1830 int serv_ret;
|
1
|
1831 #ifdef G_HAVE_GINT64
|
|
1832 gint64 ret;
|
|
1833 #endif
|
|
1834
|
84
|
1835 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
1836 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
|
1837 g_return_val_if_fail (file != NULL, GFTP_EFATAL);
|
1
|
1838
|
|
1839 params = request->protocol_data;
|
|
1840
|
|
1841 if (*file == '/')
|
|
1842 {
|
|
1843 len = strlen (file);
|
|
1844 tempstr = g_malloc (len + 9);
|
|
1845 strcpy (tempstr + 8, file);
|
|
1846 }
|
|
1847 else
|
|
1848 {
|
|
1849 len = strlen (file) + strlen (request->directory) + 1;
|
|
1850 tempstr = g_malloc (len + 9);
|
|
1851 strcpy (tempstr + 8, request->directory);
|
|
1852 strcat (tempstr + 8, "/");
|
|
1853 strcat (tempstr + 8, file);
|
|
1854 }
|
|
1855
|
|
1856 num = htonl (params->id++);
|
|
1857 memcpy (tempstr, &num, 4);
|
|
1858
|
|
1859 num = htonl (len);
|
|
1860 memcpy (tempstr + 4, &num, 4);
|
|
1861
|
|
1862 if (sshv2_send_command (request, SSH_FXP_STAT, tempstr, len + 8) < 0)
|
|
1863 {
|
|
1864 g_free (tempstr);
|
84
|
1865 return (GFTP_ERETRYABLE);
|
1
|
1866 }
|
|
1867 g_free (tempstr);
|
|
1868
|
|
1869 memset (¶ms->message, 0, sizeof (params->message));
|
64
|
1870 serv_ret = sshv2_read_response (request, ¶ms->message, -1);
|
84
|
1871 if (serv_ret < 0)
|
|
1872 return (serv_ret);
|
|
1873 else if (serv_ret == SSH_FXP_STATUS)
|
64
|
1874 {
|
|
1875 sshv2_message_free (¶ms->message);
|
84
|
1876 return (GFTP_ERETRYABLE);
|
64
|
1877 }
|
|
1878 else if (serv_ret != SSH_FXP_ATTRS)
|
1
|
1879 {
|
186
|
1880 request->logging_function (gftp_logging_error, request,
|
1
|
1881 _("Received wrong response from server, disconnecting\n"));
|
|
1882 sshv2_message_free (¶ms->message);
|
|
1883 gftp_disconnect (request);
|
84
|
1884 return (GFTP_ERETRYABLE);
|
1
|
1885 }
|
|
1886
|
|
1887 if (params->message.length < 5)
|
84
|
1888 return (GFTP_ERETRYABLE);
|
1
|
1889 params->message.pos += 4;
|
|
1890
|
|
1891 if ((attrs = sshv2_buffer_get_int32 (request, ¶ms->message, -1)) < 0)
|
84
|
1892 return (GFTP_ERETRYABLE);
|
1
|
1893
|
|
1894 if (attrs & SSH_FILEXFER_ATTR_SIZE)
|
|
1895 {
|
|
1896 if ((highnum = sshv2_buffer_get_int32 (request, ¶ms->message, -1)) < 0)
|
84
|
1897 return (GFTP_ERETRYABLE);
|
1
|
1898
|
|
1899 if ((lownum = sshv2_buffer_get_int32 (request, ¶ms->message, -1)) < 0)
|
84
|
1900 return (GFTP_ERETRYABLE);
|
1
|
1901
|
|
1902 sshv2_message_free (¶ms->message);
|
|
1903
|
|
1904 #if G_HAVE_GINT64
|
|
1905 ret = (gint64) lownum | ((gint64) highnum >> 32);
|
|
1906 return (ret);
|
|
1907 #else
|
|
1908 return (lownum);
|
|
1909 #endif
|
|
1910 }
|
|
1911
|
|
1912 sshv2_message_free (¶ms->message);
|
|
1913
|
|
1914 return (0);
|
|
1915
|
|
1916 }
|
|
1917
|
|
1918
|
58
|
1919 static off_t
|
|
1920 sshv2_get_file (gftp_request * request, const char *file, int fd,
|
1
|
1921 off_t startsize)
|
|
1922 {
|
|
1923 sshv2_params * params;
|
|
1924 sshv2_message message;
|
321
|
1925 char *tempstr, *path;
|
1
|
1926 size_t stlen;
|
|
1927 gint32 num;
|
64
|
1928 int ret;
|
1
|
1929
|
84
|
1930 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
1931 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
169
|
1932 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
|
1
|
1933 /* fd ignored for this protocol */
|
|
1934
|
|
1935 params = request->protocol_data;
|
|
1936 params->offset = startsize;
|
|
1937
|
|
1938 if (*file == '/')
|
|
1939 {
|
|
1940 stlen = strlen (file);
|
|
1941 tempstr = g_malloc (stlen + 16);
|
|
1942 strcpy (tempstr + 8, file);
|
|
1943 }
|
|
1944 else
|
|
1945 {
|
321
|
1946 path = gftp_build_path (request->directory, file, NULL);
|
|
1947 stlen = strlen (path);
|
1
|
1948 tempstr = g_malloc (stlen + 16);
|
321
|
1949 strcpy (tempstr + 8, path);
|
|
1950 g_free (path);
|
1
|
1951 }
|
|
1952
|
|
1953 num = htonl (params->id++);
|
|
1954 memcpy (tempstr, &num, 4);
|
|
1955
|
|
1956 num = htonl (stlen);
|
|
1957 memcpy (tempstr + 4, &num, 4);
|
|
1958
|
|
1959 num = htonl (SSH_FXF_READ);
|
|
1960 memcpy (tempstr + 8 + stlen, &num, 4);
|
|
1961
|
321
|
1962 num = 0;
|
|
1963 memcpy (tempstr + 12 + stlen, &num, 4);
|
1
|
1964
|
|
1965 if (sshv2_send_command (request, SSH_FXP_OPEN, tempstr, stlen + 16) < 0)
|
|
1966 {
|
|
1967 g_free (tempstr);
|
84
|
1968 return (GFTP_ERETRYABLE);
|
1
|
1969 }
|
|
1970
|
|
1971 g_free (tempstr);
|
|
1972 memset (&message, 0, sizeof (message));
|
64
|
1973 ret = sshv2_read_response (request, &message, -1);
|
84
|
1974 if (ret < 0)
|
|
1975 return (ret);
|
|
1976 else if (ret == SSH_FXP_STATUS)
|
64
|
1977 {
|
|
1978 sshv2_message_free (&message);
|
84
|
1979 return (GFTP_ERETRYABLE);
|
64
|
1980 }
|
|
1981 else if (ret != SSH_FXP_HANDLE)
|
1
|
1982 {
|
186
|
1983 request->logging_function (gftp_logging_error, request,
|
1
|
1984 _("Received wrong response from server, disconnecting\n"));
|
|
1985 sshv2_message_free (&message);
|
|
1986 gftp_disconnect (request);
|
84
|
1987 return (GFTP_ERETRYABLE);
|
1
|
1988 }
|
|
1989
|
|
1990 if (message.length - 4 > SSH_MAX_HANDLE_SIZE)
|
|
1991 {
|
186
|
1992 request->logging_function (gftp_logging_error, request,
|
1
|
1993 _("Error: Message size %d too big from server\n"),
|
|
1994 message.length - 4);
|
|
1995 sshv2_message_free (&message);
|
|
1996 gftp_disconnect (request);
|
84
|
1997 return (GFTP_ERETRYABLE);
|
1
|
1998
|
|
1999 }
|
|
2000
|
|
2001 memset (params->handle, 0, 4);
|
|
2002 memcpy (params->handle + 4, message.buffer+ 4, message.length - 5);
|
|
2003 params->handle_len = message.length - 1;
|
|
2004 sshv2_message_free (&message);
|
|
2005
|
|
2006 return (sshv2_get_file_size (request, file));
|
|
2007 }
|
|
2008
|
|
2009
|
|
2010 static int
|
58
|
2011 sshv2_put_file (gftp_request * request, const char *file, int fd,
|
1
|
2012 off_t startsize, off_t totalsize)
|
|
2013 {
|
|
2014 sshv2_params * params;
|
|
2015 sshv2_message message;
|
321
|
2016 char *tempstr, *path;
|
1
|
2017 size_t stlen;
|
|
2018 gint32 num;
|
64
|
2019 int ret;
|
1
|
2020
|
84
|
2021 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
2022 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
169
|
2023 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
|
1
|
2024 /* fd ignored for this protocol */
|
|
2025
|
|
2026 params = request->protocol_data;
|
399
|
2027 params->offset = startsize;
|
1
|
2028
|
|
2029 if (*file == '/')
|
|
2030 {
|
|
2031 stlen = strlen (file);
|
|
2032 tempstr = g_malloc (stlen + 16);
|
|
2033 strcpy (tempstr + 8, file);
|
|
2034 }
|
|
2035 else
|
|
2036 {
|
321
|
2037 path = gftp_build_path (request->directory, file, NULL);
|
|
2038 stlen = strlen (path);
|
1
|
2039 tempstr = g_malloc (stlen + 16);
|
321
|
2040 strcpy (tempstr + 8, path);
|
|
2041 g_free (path);
|
1
|
2042 }
|
|
2043
|
|
2044 num = htonl (params->id++);
|
|
2045 memcpy (tempstr, &num, 4);
|
|
2046
|
|
2047 num = htonl (stlen);
|
|
2048 memcpy (tempstr + 4, &num, 4);
|
|
2049
|
|
2050 if (startsize > 0)
|
|
2051 num = htonl (SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_APPEND);
|
|
2052 else
|
|
2053 num = htonl (SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_TRUNC);
|
|
2054 memcpy (tempstr + 8 + stlen, &num, 4);
|
|
2055
|
321
|
2056 num = 0;
|
|
2057 memcpy (tempstr + 12 + stlen, &num, 4);
|
1
|
2058
|
|
2059 if (sshv2_send_command (request, SSH_FXP_OPEN, tempstr, stlen + 16) < 0)
|
|
2060 {
|
|
2061 g_free (tempstr);
|
84
|
2062 return (GFTP_ERETRYABLE);
|
1
|
2063 }
|
|
2064
|
|
2065 g_free (tempstr);
|
|
2066 memset (&message, 0, sizeof (message));
|
64
|
2067 ret = sshv2_read_response (request, &message, -1);
|
84
|
2068 if (ret < 0)
|
|
2069 return (ret);
|
|
2070 else if (ret == SSH_FXP_STATUS)
|
64
|
2071 {
|
|
2072 sshv2_message_free (&message);
|
84
|
2073 return (GFTP_ERETRYABLE);
|
64
|
2074 }
|
|
2075 else if (ret != SSH_FXP_HANDLE)
|
1
|
2076 {
|
186
|
2077 request->logging_function (gftp_logging_error, request,
|
1
|
2078 _("Received wrong response from server, disconnecting\n"));
|
|
2079 sshv2_message_free (&message);
|
|
2080 gftp_disconnect (request);
|
84
|
2081 return (GFTP_ERETRYABLE);
|
1
|
2082 }
|
|
2083
|
|
2084 if (message.length - 4 > SSH_MAX_HANDLE_SIZE)
|
|
2085 {
|
186
|
2086 request->logging_function (gftp_logging_error, request,
|
1
|
2087 _("Error: Message size %d too big from server\n"),
|
|
2088 message.length - 4);
|
|
2089 sshv2_message_free (&message);
|
|
2090 gftp_disconnect (request);
|
84
|
2091 return (GFTP_ERETRYABLE);
|
1
|
2092
|
|
2093 }
|
|
2094
|
|
2095 memset (params->handle, 0, 4);
|
321
|
2096 memcpy (params->handle + 4, message.buffer + 4, message.length - 5);
|
1
|
2097 params->handle_len = message.length - 1;
|
|
2098 sshv2_message_free (&message);
|
|
2099
|
|
2100 return (0);
|
|
2101 }
|
|
2102
|
|
2103
|
58
|
2104 static ssize_t
|
1
|
2105 sshv2_get_next_file_chunk (gftp_request * request, char *buf, size_t size)
|
|
2106 {
|
|
2107 sshv2_params * params;
|
|
2108 sshv2_message message;
|
|
2109 gint32 num;
|
84
|
2110 int ret;
|
1
|
2111
|
|
2112 #ifdef G_HAVE_GINT64
|
|
2113 gint64 offset;
|
|
2114 #else
|
|
2115 gint32 offset;
|
|
2116 #endif
|
|
2117
|
84
|
2118 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
2119 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
169
|
2120 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
|
84
|
2121 g_return_val_if_fail (buf != NULL, GFTP_EFATAL);
|
1
|
2122
|
|
2123 params = request->protocol_data;
|
|
2124
|
|
2125 if (params->read_buffer == NULL)
|
|
2126 {
|
|
2127 params->read_buffer = g_malloc (params->handle_len + 12);
|
|
2128 num = htonl (params->handle_len);
|
|
2129 memcpy (params->read_buffer, params->handle, params->handle_len);
|
|
2130 }
|
|
2131
|
|
2132 num = htonl (params->id++);
|
|
2133 memcpy (params->read_buffer, &num, 4);
|
|
2134
|
|
2135 #ifdef G_HAVE_GINT64
|
|
2136 offset = hton64 (params->offset);
|
|
2137 memcpy (params->read_buffer + params->handle_len, &offset, 8);
|
|
2138 #else
|
|
2139 memset (params->read_buffer + params->handle_len, 0, 4);
|
|
2140 offset = htonl (params->offset);
|
|
2141 memcpy (params->read_buffer + params->handle_len + 4, &offset, 4);
|
|
2142 #endif
|
|
2143
|
|
2144 num = htonl (size);
|
|
2145 memcpy (params->read_buffer + params->handle_len + 8, &num, 4);
|
|
2146
|
|
2147 if (sshv2_send_command (request, SSH_FXP_READ, params->read_buffer, params->handle_len + 12) < 0)
|
84
|
2148 return (GFTP_ERETRYABLE);
|
1
|
2149
|
|
2150 memset (&message, 0, sizeof (message));
|
84
|
2151 if ((ret = sshv2_read_response (request, &message, -1)) != SSH_FXP_DATA)
|
1
|
2152 {
|
84
|
2153 if (ret < 0)
|
|
2154 return (ret);
|
|
2155
|
1
|
2156 message.pos += 4;
|
|
2157 if ((num = sshv2_buffer_get_int32 (request, &message, SSH_FX_OK)) < 0)
|
84
|
2158 return (num);
|
1
|
2159 sshv2_message_free (&message);
|
|
2160 if (num != SSH_FX_EOF)
|
|
2161 {
|
186
|
2162 request->logging_function (gftp_logging_error, request,
|
1
|
2163 _("Received wrong response from server, disconnecting\n"));
|
|
2164 gftp_disconnect (request);
|
84
|
2165 return (GFTP_ERETRYABLE);
|
1
|
2166 }
|
|
2167 return (0);
|
|
2168 }
|
|
2169
|
|
2170 memcpy (&num, message.buffer + 4, 4);
|
|
2171 num = ntohl (num);
|
|
2172 if (num > size)
|
|
2173 {
|
186
|
2174 request->logging_function (gftp_logging_error, request,
|
1
|
2175 _("Error: Message size %d too big from server\n"),
|
|
2176 num);
|
|
2177 sshv2_message_free (&message);
|
|
2178 gftp_disconnect (request);
|
84
|
2179 return (GFTP_ERETRYABLE);
|
1
|
2180
|
|
2181 }
|
|
2182
|
|
2183 memcpy (buf, message.buffer + 8, num);
|
|
2184 sshv2_message_free (&message);
|
|
2185 params->offset += num;
|
|
2186 return (num);
|
|
2187 }
|
|
2188
|
|
2189
|
58
|
2190 static ssize_t
|
1
|
2191 sshv2_put_next_file_chunk (gftp_request * request, char *buf, size_t size)
|
|
2192 {
|
|
2193 sshv2_params * params;
|
|
2194 sshv2_message message;
|
380
|
2195 char tempstr[32768];
|
1
|
2196 gint32 num;
|
321
|
2197 size_t len;
|
1
|
2198 int ret;
|
|
2199
|
|
2200 #ifdef G_HAVE_GINT64
|
|
2201 gint64 offset;
|
|
2202 #else
|
|
2203 gint32 offset;
|
|
2204 #endif
|
|
2205
|
84
|
2206 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
|
2207 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, GFTP_EFATAL);
|
169
|
2208 g_return_val_if_fail (request->datafd > 0, GFTP_EFATAL);
|
84
|
2209 g_return_val_if_fail (buf != NULL, GFTP_EFATAL);
|
|
2210 g_return_val_if_fail (size <= 32500, GFTP_EFATAL);
|
1
|
2211
|
|
2212 params = request->protocol_data;
|
|
2213
|
|
2214 memcpy (tempstr, params->handle, params->handle_len);
|
|
2215
|
|
2216 num = htonl (params->id++);
|
|
2217 memcpy (tempstr, &num, 4);
|
|
2218
|
|
2219 #ifdef G_HAVE_GINT64
|
|
2220 offset = hton64 (params->offset);
|
|
2221 memcpy (tempstr + params->handle_len, &offset, 8);
|
|
2222 #else
|
|
2223 memset (tempstr + params->handle_len, 0, 4);
|
|
2224 offset = htonl (params->offset);
|
|
2225 memcpy (tempstr + params->handle_len + 4, &offset, 4);
|
|
2226 #endif
|
|
2227
|
|
2228 num = htonl (size);
|
|
2229 memcpy (tempstr + params->handle_len + 8, &num, 4);
|
|
2230 memcpy (tempstr + params->handle_len + 12, buf, size);
|
|
2231
|
321
|
2232 len = params->handle_len + size + 12;
|
|
2233 if (sshv2_send_command (request, SSH_FXP_WRITE, tempstr, len) < 0)
|
1
|
2234 {
|
|
2235 g_free (tempstr);
|
84
|
2236 return (GFTP_ERETRYABLE);
|
1
|
2237 }
|
|
2238
|
|
2239 memset (&message, 0, sizeof (message));
|
|
2240 params->dont_log_status = 1;
|
58
|
2241 ret = sshv2_read_response (request, &message, -1);
|
84
|
2242 if (ret < 0)
|
|
2243 return (ret);
|
|
2244
|
1
|
2245 params->dont_log_status = 0;
|
|
2246 if (ret != SSH_FXP_STATUS)
|
|
2247 {
|
186
|
2248 request->logging_function (gftp_logging_error, request,
|
1
|
2249 _("Received wrong response from server, disconnecting\n"));
|
|
2250 sshv2_message_free (&message);
|
|
2251 gftp_disconnect (request);
|
84
|
2252 return (GFTP_ERETRYABLE);
|
1
|
2253 }
|
|
2254
|
|
2255 message.pos += 4;
|
|
2256 if ((num = sshv2_buffer_get_int32 (request, &message, SSH_FX_OK)) < 0)
|
84
|
2257 return (GFTP_ERETRYABLE);
|
1
|
2258 sshv2_message_free (&message);
|
|
2259
|
|
2260 if (num == SSH_FX_EOF)
|
|
2261 return (0);
|
|
2262 else if (num != SSH_FX_OK)
|
84
|
2263 return (GFTP_ERETRYABLE);
|
1
|
2264
|
|
2265 params->offset += size;
|
|
2266 return (size);
|
|
2267 }
|
|
2268
|
48
|
2269
|
177
|
2270 static int
|
58
|
2271 sshv2_set_config_options (gftp_request * request)
|
|
2272 {
|
325
|
2273 intptr_t ssh_need_userpass;
|
58
|
2274
|
122
|
2275 gftp_lookup_request_option (request, "ssh_need_userpass", &ssh_need_userpass);
|
58
|
2276 request->need_userpass = ssh_need_userpass;
|
177
|
2277 return (0);
|
58
|
2278 }
|
|
2279
|
|
2280
|
63
|
2281 static void
|
|
2282 sshv2_swap_socks (gftp_request * dest, gftp_request * source)
|
|
2283 {
|
|
2284 sshv2_params * sparams, * dparams;
|
|
2285
|
|
2286 sparams = source->protocol_data;
|
|
2287 dparams = dest->protocol_data;
|
|
2288 dparams->id = sparams->id;
|
|
2289 }
|
|
2290
|
|
2291
|
122
|
2292 void
|
|
2293 sshv2_register_module (void)
|
|
2294 {
|
|
2295 gftp_register_config_vars (config_vars);
|
|
2296 }
|
|
2297
|
|
2298
|
173
|
2299 int
|
48
|
2300 sshv2_init (gftp_request * request)
|
|
2301 {
|
|
2302 sshv2_params * params;
|
|
2303
|
173
|
2304 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
|
48
|
2305
|
|
2306 request->protonum = GFTP_SSHV2_NUM;
|
|
2307 request->init = sshv2_init;
|
309
|
2308 request->copy_param_options = NULL;
|
48
|
2309 request->destroy = sshv2_destroy;
|
168
|
2310 request->read_function = gftp_fd_read;
|
|
2311 request->write_function = gftp_fd_write;
|
48
|
2312 request->connect = sshv2_connect;
|
168
|
2313 request->post_connect = NULL;
|
48
|
2314 request->disconnect = sshv2_disconnect;
|
|
2315 request->get_file = sshv2_get_file;
|
|
2316 request->put_file = sshv2_put_file;
|
|
2317 request->transfer_file = NULL;
|
|
2318 request->get_next_file_chunk = sshv2_get_next_file_chunk;
|
|
2319 request->put_next_file_chunk = sshv2_put_next_file_chunk;
|
|
2320 request->end_transfer = sshv2_end_transfer;
|
|
2321 request->abort_transfer = sshv2_end_transfer; /* NOTE: uses sshv2_end_transfer */
|
|
2322 request->list_files = sshv2_list_files;
|
|
2323 request->get_next_file = sshv2_get_next_file;
|
|
2324 request->get_file_size = sshv2_get_file_size;
|
|
2325 request->chdir = sshv2_chdir;
|
|
2326 request->rmdir = sshv2_rmdir;
|
|
2327 request->rmfile = sshv2_rmfile;
|
|
2328 request->mkdir = sshv2_mkdir;
|
|
2329 request->rename = sshv2_rename;
|
|
2330 request->chmod = sshv2_chmod;
|
|
2331 request->set_file_time = sshv2_set_file_time;
|
|
2332 request->site = NULL;
|
|
2333 request->parse_url = NULL;
|
58
|
2334 request->set_config_options = sshv2_set_config_options;
|
63
|
2335 request->swap_socks = sshv2_swap_socks;
|
48
|
2336 request->url_prefix = "ssh2";
|
|
2337 request->need_hostport = 1;
|
122
|
2338 request->need_userpass = 1;
|
48
|
2339 request->use_cache = 1;
|
|
2340 request->always_connected = 0;
|
|
2341 request->protocol_data = g_malloc0 (sizeof (sshv2_params));
|
122
|
2342 request->server_type = GFTP_DIRTYPE_UNIX;
|
48
|
2343
|
|
2344 params = request->protocol_data;
|
|
2345 params->id = 1;
|
173
|
2346
|
177
|
2347 return (gftp_set_config_options (request));
|
48
|
2348 }
|