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