annotate lib/sshv2.c @ 843:32dbed7e0dc4

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