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