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