annotate lib/sshv2.c @ 56:a12bcbc2fce4

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