annotate lib/sshv2.c @ 33:c8ec7877432e

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