annotate lib/sshv2.c @ 64:29128554eb86

2002-11-23 Brian Masney <masneyb@gftp.org> * lib/sshv2.c - added more error checking so that the user won't get disconnected if they enter files or directories that don't exist
author masneyb
date Sat, 23 Nov 2002 14:34:25 +0000
parents 41b71c4e5076
children 7ef60ce2bdb2
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: ");
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
301 for (clen=0; clen<len + 5; clen++)
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
302 printf ("%x ", buf[clen] & 0xff);
48
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
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
308 if (gftp_write (request, buf, len + 5, request->sockfd) < 0)
48
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,
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
317 int fd)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
318 {
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
319 ssize_t numread, rem;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
320 char buf[5], *pos;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
321
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
322 if (fd <= 0)
48
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
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
325 pos = buf;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
326 rem = 5;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
327 while (rem > 0)
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
328 {
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
329 if ((numread = gftp_read (request, pos, rem, fd)) < 0)
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
330 return (-2);
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
331 rem -= numread;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
332 pos += numread;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
333 }
48
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 memcpy (&message->length, buf, 4);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
336 message->length = ntohl (message->length);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
337 if (message->length > 34000)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
338 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
339 request->logging_function (gftp_logging_error, request->user_data,
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
340 _("Error: Message size %d too big from server\n"),
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
341 message->length);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
342 memset (message, 0, sizeof (*message));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
343 gftp_disconnect (request);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
344 return (-1);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
345 }
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
346
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
347 message->command = buf[4];
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
348 message->buffer = g_malloc (message->length + 1);
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
349
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
350 message->pos = message->buffer;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
351 message->end = message->buffer + message->length - 1;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
352
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
353 pos = message->buffer;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
354 rem = message->length - 1;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
355 while (rem > 0)
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
356 {
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
357 if ((numread = gftp_read (request, pos, rem, fd)) < 0)
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
358 return (-2);
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
359 rem -= numread;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
360 pos += numread;
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
361 }
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
362
61
42df9e4be8e0 2002-11-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 58
diff changeset
363 message->buffer[message->length] = '\0';
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
364
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
365 sshv2_log_command (request, gftp_logging_recv, message->command,
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
366 message->buffer, message->length);
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 return (message->command);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
369 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
370
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
371
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
372 static void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
373 sshv2_destroy (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
374 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
375 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
376 g_return_if_fail (request->protonum == GFTP_SSHV2_NUM);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
377
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
378 g_free (request->protocol_data);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
379 request->protocol_data = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
380 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
381
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
382
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
383 static void
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
384 sshv2_message_free (sshv2_message * message)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
385 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
386 if (message->buffer)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
387 g_free (message->buffer);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
388 memset (message, 0, sizeof (*message));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
389 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
390
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
391
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
392 static gint32
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
393 sshv2_buffer_get_int32 (gftp_request * request, sshv2_message * message,
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
394 int expected_response)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
395 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
396 gint32 ret;
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->end - message->pos < 4)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
399 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
400 request->logging_function (gftp_logging_error, request->user_data,
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
401 _("Received wrong response from server, disconnecting\n"));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
402 sshv2_message_free (message);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
403 gftp_disconnect (request);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
404 return (-2);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
405 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
406
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
407 memcpy (&ret, message->pos, 4);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
408 ret = ntohl (ret);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
409 message->pos += 4;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
410
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
411 if (expected_response > 0 && ret != expected_response)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
412 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
413 request->logging_function (gftp_logging_error, request->user_data,
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
414 _("Received wrong response from server, disconnecting\n"));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
415 sshv2_message_free (message);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
416 gftp_disconnect (request);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
417 return (-2);
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
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
420 return (ret);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
421 }
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
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
424 static char *
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
425 sshv2_buffer_get_string (gftp_request * request, sshv2_message * message)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
426 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
427 char *string;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
428 gint32 len;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
429
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
430 if ((len = sshv2_buffer_get_int32 (request, message, -1)) < 0)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
431 return (NULL);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
432
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
433 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
434 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
435 request->logging_function (gftp_logging_error, request->user_data,
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
436 _("Received wrong response from server, disconnecting\n"));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
437 sshv2_message_free (message);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
438 gftp_disconnect (request);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
439 return (NULL);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
440 }
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 string = g_malloc (len + 1);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
443 memcpy (string, message->pos, len);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
444 string[len] = '\0';
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
445 message->pos += len;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
446 return (string);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
447 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
448
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
449
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
450 static int
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
451 sshv2_getcwd (gftp_request * request)
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 sshv2_message message;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
454 sshv2_params * params;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
455 char *tempstr, *dir;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
456 gint32 num;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
457 size_t len;
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
458 int ret;
48
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 g_return_val_if_fail (request != NULL, -2);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
461 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
462
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
463 if (request->directory == NULL || *request->directory == '\0')
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
464 dir = ".";
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
465 else
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
466 dir = request->directory;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
467
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
468 params = request->protocol_data;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
469 len = strlen (dir);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
470 tempstr = g_malloc (len + 9);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
471 strcpy (tempstr + 8, dir);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
472
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
473 num = htonl (params->id++);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
474 memcpy (tempstr, &num, 4);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
475
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
476 num = htonl (len);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
477 memcpy (tempstr + 4, &num, 4);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
478 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
479 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
480 g_free (tempstr);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
481 return (-2);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
482 }
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 g_free (tempstr);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
485 if (request->directory)
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 g_free (request->directory);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
488 request->directory = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
489 }
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 memset (&message, 0, sizeof (message));
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
492 ret = sshv2_read_response (request, &message, -1);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
493 if (ret == SSH_FXP_STATUS)
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
494 {
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
495 sshv2_message_free (&message);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
496 return (-2);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
497 }
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
498 else if (ret != SSH_FXP_NAME)
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
499 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
500 request->logging_function (gftp_logging_error, request->user_data,
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
501 _("Received wrong response from server, disconnecting\n"));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
502 sshv2_message_free (&message);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
503 gftp_disconnect (request);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
504 return (-2);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
505 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
506
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
507 message.pos += 4;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
508 if (sshv2_buffer_get_int32 (request, &message, 1) < 0)
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 if ((request->directory = sshv2_buffer_get_string (request, &message)) == NULL)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
512 return (-2);
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
513
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
514 sshv2_message_free (&message);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
515 return (0);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
516 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
517
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
518
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
519 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
520 sshv2_connect (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
521 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
522 char **args, *tempstr, pts_name[20], *p1, p2, *exepath, port[6];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
523 int version, fdm, fds, s[2];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
524 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
525 pid_t child;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
526
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
527 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
528 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
529 g_return_val_if_fail (request->hostname != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
530
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
531 if (request->sockfd > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
532 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
533
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
534 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
535 _("Opening SSH connection to %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
536 request->hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
537
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
538 /* Ugh!! We don't get a login banner from sftp-server, and if we are
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
539 using ssh-agent to cache a users password, then we won't receive
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
540 any initial text from the server, and we'll block. So I just send a
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
541 xsftp server banner over. I hope this works on most Unices */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
542
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
543 if (request->sftpserv_path == NULL ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
544 *request->sftpserv_path == '\0')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
545 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
546 p1 = "";
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
547 p2 = ' ';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
548 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
549 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
550 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
551 p1 = request->sftpserv_path;
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
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
555 *port = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
556 exepath = g_strdup_printf ("echo -n xsftp ; %s%csftp-server", p1, p2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
557 args = make_ssh_exec_args (request, exepath, sshv2_use_sftp_subsys, port);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
558
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
559 if (ssh_use_askpass || sshv2_use_sftp_subsys)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
560 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
561 fdm = fds = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
562 if (socketpair (AF_LOCAL, SOCK_STREAM, 0, s) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
563 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
564 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
565 _("Cannot create a socket pair: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
566 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
567 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
568 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
569 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
570 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
571 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
572 s[0] = s[1] = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
573 if ((fdm = ptym_open (pts_name)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
574 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
575 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
576 _("Cannot open master pty %s: %s\n"), pts_name,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
577 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
578 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
579 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
580 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
581
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
582 if ((child = fork ()) == 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
583 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
584 setsid ();
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
585 if (ssh_use_askpass || sshv2_use_sftp_subsys)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
586 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
587 close (s[0]);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
588 fds = s[1];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
589 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
590 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
591 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
592 if ((fds = ptys_open (fdm, pts_name)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
593 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
594 printf ("Cannot open slave pts %s: %s\n", pts_name,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
595 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
596 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
597 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
598 close (fdm);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
599 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
600
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
601 tty_raw (fds);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
602 dup2 (fds, 0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
603 dup2 (fds, 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
604 dup2 (fds, 2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
605 if (!ssh_use_askpass && fds > 2)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
606 close (fds);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
607 execvp (ssh_prog_name != NULL && *ssh_prog_name != '\0' ?
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
608 ssh_prog_name : "ssh", args);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
609
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
610 printf (_("Error: Cannot execute ssh: %s\n"), g_strerror (errno));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
611 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
612 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
613 else if (child > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
614 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
615 if (ssh_use_askpass || sshv2_use_sftp_subsys)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
616 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
617 close (s[1]);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
618 fdm = s[0];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
619 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
620 tty_raw (fdm);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
621 if (!sshv2_use_sftp_subsys)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
622 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
623 tempstr = ssh_start_login_sequence (request, fdm);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
624 if (!tempstr ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
625 !(strlen (tempstr) > 4 && strcmp (tempstr + strlen (tempstr) - 5,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
626 "xsftp") == 0))
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
627 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
628 g_free (args);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
629 g_free (exepath);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
630 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
631 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
632 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
633 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
634 g_free (args);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
635 g_free (exepath);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
636
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
637 request->sockfd = fdm;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
638
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
639 version = htonl (SSH_MY_VERSION);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
640 if (sshv2_send_command (request, SSH_FXP_INIT, (char *) &version, 4) < 0)
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 memset (&message, 0, sizeof (message));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
644 if (sshv2_read_response (request, &message, -1) != SSH_FXP_VERSION)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
645 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
646 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
647 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
648 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
649 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
650 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
651 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
652 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
653
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
654 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
655 _("Successfully logged into SSH server %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
656 request->hostname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
657 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
658 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
659 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
660 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
661 _("Cannot fork another process: %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
662 g_strerror (errno));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
663 g_free (args);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
664 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
665 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
666
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
667 if (sshv2_getcwd (request) < 0)
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
668 {
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
669 if (request->directory)
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
670 g_free (request->directory);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
671
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
672 request->directory = g_strdup (".");
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
673 if (sshv2_getcwd (request) < 0)
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
674 {
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
675 gftp_disconnect (request);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
676 return (-2);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
677 }
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
678 }
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
679
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
680 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
681 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
682
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
683
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
684 static void
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
685 sshv2_disconnect (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
686 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
687 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
688
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
689 g_return_if_fail (request != NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
690 g_return_if_fail (request->protonum == GFTP_SSHV2_NUM);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
691
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
692 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
693
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
694 if (request->sockfd > 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
695 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
696 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
697 _("Disconnecting from site %s\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
698 request->hostname);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
699
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
700 if (close (request->sockfd) < 0)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
701 request->logging_function (gftp_logging_error, request->user_data,
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
702 _("Error closing file descriptor: %s\n"),
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
703 g_strerror (errno));
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
704
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
705 request->sockfd = -1;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
706 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
707
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
708 if (params->message.buffer != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
709 sshv2_message_free (&params->message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
710 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
711
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
712
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
713 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
714 sshv2_end_transfer (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
715 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
716 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
717 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
718 gint32 len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
719
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
720 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
721 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
722
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
723 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
724 if (params->message.buffer != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
725 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
726 sshv2_message_free (&params->message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
727 params->count = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
728 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
729
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
730 if (params->handle_len > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
731 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
732 len = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
733 memcpy (params->handle, &len, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
734
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
735 if (sshv2_send_command (request, SSH_FXP_CLOSE, params->handle,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
736 params->handle_len) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
737 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
738
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
739 memset (&message, 0, sizeof (message));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
740 if (sshv2_read_response (request, &message, -1) != SSH_FXP_STATUS)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
741 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
742 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
743 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
744 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
745 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
746 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
747 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
748 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
749 params->handle_len = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
750 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
751
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
752 if (params->read_buffer != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
753 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
754 g_free (params->read_buffer);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
755 params->read_buffer = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
756 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
757
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
758 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
759 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
760
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
761
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
762 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
763 sshv2_list_files (gftp_request * request)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
764 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
765 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
766 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
767 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
768 gint32 len;
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
769 int ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
770
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
771 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
772 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
773 g_return_val_if_fail (request->sockfd > 0, -2);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
774
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
775 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
776
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
777 request->logging_function (gftp_logging_misc, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
778 _("Retrieving directory listing...\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
779
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
780 tempstr = g_malloc (strlen (request->directory) + 9);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
781
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
782 len = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
783 memcpy (tempstr, &len, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
784
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
785 len = htonl (strlen (request->directory));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
786 memcpy (tempstr + 4, &len, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
787 strcpy (tempstr + 8, request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
788 if (sshv2_send_command (request, SSH_FXP_OPENDIR, tempstr,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
789 strlen (request->directory) + 8) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
790 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
791 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
792 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
793 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
794 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
795
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
796 memset (&message, 0, sizeof (message));
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
797 ret = sshv2_read_response (request, &message, -1);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
798 if (ret == SSH_FXP_STATUS)
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
799 {
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
800 sshv2_message_free (&message);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
801 return (-2);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
802 }
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
803 else if (ret != SSH_FXP_HANDLE)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
804 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
805 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
806 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
807 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
808 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
809 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
810 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
811
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
812 if (message.length - 4 > SSH_MAX_HANDLE_SIZE)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
813 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
814 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
815 _("Error: Message size %d too big from server\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
816 message.length - 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
817 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
818 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
819 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
820
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
821 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
822
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
823 memset (params->handle, 0, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
824 memcpy (params->handle + 4, message.buffer + 4, message.length - 5);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
825 params->handle_len = message.length - 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
826 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
827 params->count = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
828 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
829 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
830
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
831
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
832 static int
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
833 sshv2_get_next_file (gftp_request * request, gftp_file * fle, int fd)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
834 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
835 gint32 len, attrs, longnamelen;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
836 int ret, i, count, retsize;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
837 sshv2_params *params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
838 char *longname;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
839
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
840 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
841 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
842 g_return_val_if_fail (fle != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
843
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
844 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
845
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
846 if (request->last_dir_entry)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
847 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
848 g_free (request->last_dir_entry);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
849 request->last_dir_entry = NULL;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
850 request->last_dir_entry_len = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
851 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
852 retsize = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
853
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
854 if (params->count > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
855 ret = SSH_FXP_NAME;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
856 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
857 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
858 if (!request->cached)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
859 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
860 if (params->message.buffer != NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
861 sshv2_message_free (&params->message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
862
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
863 len = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
864 memcpy (params->handle, &len, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
865
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
866 if (sshv2_send_command (request, SSH_FXP_READDIR, params->handle,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
867 params->handle_len) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
868 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
869 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
870
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
871 if ((ret = sshv2_read_response (request, &params->message, fd)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
872 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
873
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
874 if (!request->cached)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
875 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
876 request->last_dir_entry = g_malloc (params->message.length + 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
877 len = htonl (params->message.length);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
878 memcpy (request->last_dir_entry, &len, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
879 request->last_dir_entry[4] = params->message.command;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
880 memcpy (request->last_dir_entry + 5, params->message.buffer,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
881 params->message.length - 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
882 request->last_dir_entry_len = params->message.length + 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
883 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
884
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
885 if (ret == SSH_FXP_NAME)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
886 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
887 params->message.pos = params->message.buffer + 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
888 if ((params->count = sshv2_buffer_get_int32 (request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
889 &params->message, -1)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
890 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
891 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
892 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
893
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
894 if (ret == SSH_FXP_NAME)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
895 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
896 if ((len = sshv2_buffer_get_int32 (request, &params->message, -1)) < 0 ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
897 params->message.pos + len > params->message.end)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
898 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
899
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
900 params->message.pos += len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
901
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
902 if ((longnamelen = sshv2_buffer_get_int32 (request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
903 &params->message, -1)) < 0 ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
904 params->message.pos + longnamelen > params->message.end)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
905 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
906
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
907 longname = params->message.pos;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
908 params->message.pos += longnamelen;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
909
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
910 if ((attrs = sshv2_buffer_get_int32 (request, &params->message, -1)) < 0)
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 if (attrs & SSH_FILEXFER_ATTR_SIZE)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
914 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
915 params->message.pos += 8;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
916 if (params->message.pos > params->message.end)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
917 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
918 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
919 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
920 sshv2_message_free (&params->message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
921 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
922 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
923 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
924 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
925
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
926 if (attrs & SSH_FILEXFER_ATTR_UIDGID)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
927 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
928 params->message.pos += 8;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
929 if (params->message.pos > params->message.end)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
930 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
931 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
932 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
933 sshv2_message_free (&params->message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
934 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
935 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
936 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
937 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
938
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
939 if (attrs & SSH_FILEXFER_ATTR_PERMISSIONS)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
940 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
941 params->message.pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
942 if (params->message.pos > params->message.end)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
943 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
944 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
945 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
946 sshv2_message_free (&params->message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
947 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
948 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
949 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
950 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
951
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
952 if (attrs & SSH_FILEXFER_ATTR_ACMODTIME)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
953 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
954 params->message.pos += 8;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
955 if (params->message.pos > params->message.end)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
956 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
957 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
958 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
959 sshv2_message_free (&params->message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
960 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
961 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
962 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
963 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
964
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
965 if (attrs & SSH_FILEXFER_ATTR_EXTENDED)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
966 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
967 if ((count = sshv2_buffer_get_int32 (request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
968 &params->message, -1)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
969 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
970
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
971 for (i=0; i<count; i++)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
972 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
973 if ((len = 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 params->message.pos + len + 4 > params->message.end)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
976 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
977
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
978 params->message.pos += len + 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
979
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
980 if ((len = sshv2_buffer_get_int32 (request,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
981 &params->message, -1)) < 0 ||
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
982 params->message.pos + len + 4 > params->message.end)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
983 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
984
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
985 params->message.pos += len + 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
986 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
987 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
988
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
989 longname[longnamelen] = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
990
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
991 /* The commercial SSH2 puts a / and * after some entries */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
992 if (longname[longnamelen - 1] == '*')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
993 longname[--longnamelen] = '\0';
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
994 if (longname[longnamelen - 1] == '/')
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 if (gftp_parse_ls (longname, fle) != 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
998 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
999 gftp_file_destroy (fle);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1000 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1001 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1002 retsize = strlen (longname);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1003
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1004 params->count--;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1005 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1006 else if (ret == SSH_FXP_STATUS)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1007 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1008 sshv2_message_free (&params->message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1009 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1010 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1011 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1012 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1013 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1014 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1015 sshv2_message_free (&params->message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1016 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1017 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1018 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1019
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1020 return (retsize);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1021 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1022
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1023
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1024 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1025 sshv2_chdir (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1026 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1027 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1028 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1029 char *tempstr, *dir;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1030 gint32 num;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1031 size_t len;
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1032 int ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1033
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1034 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1035 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1036
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1037 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1038 if (request->directory != directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1039 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1040 if (*directory == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1041 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1042 len = strlen (directory) + 8;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1043 tempstr = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1044 strcpy (tempstr + 8, directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1045 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1046 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1047 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1048 len = strlen (directory) + strlen (request->directory) + 9;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1049 tempstr = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1050 strcpy (tempstr + 8, request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1051 strcat (tempstr + 8, "/");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1052 strcat (tempstr + 8, directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1053 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1054
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1055 num = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1056 memcpy (tempstr, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1057
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1058 num = htonl (len - 8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1059 memcpy (tempstr + 4, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1060 if (sshv2_send_command (request, SSH_FXP_REALPATH, tempstr, len) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1061 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1062 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1063 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1064 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1065 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1066
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1067 memset (&message, 0, sizeof (message));
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1068 ret = sshv2_read_response (request, &message, -1);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1069 if (ret == SSH_FXP_STATUS)
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1070 {
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1071 sshv2_message_free (&message);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1072 return (-2);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1073 }
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1074 else if (ret != SSH_FXP_NAME)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1075 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1076 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1077 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1078 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1079 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1080 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1081 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1082
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1083 message.pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1084 if (sshv2_buffer_get_int32 (request, &message, 1) != 1)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1085 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1086
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1087 if ((dir = sshv2_buffer_get_string (request, &message)) == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1088 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1089
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1090 if (request->directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1091 g_free (request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1092 request->directory = dir;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1093 sshv2_message_free (&message);
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1094 return (0);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1095 }
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1096 else
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1097 return (sshv2_getcwd (request));
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1098 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1099
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1100
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1101 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1102 sshv2_rmdir (gftp_request * request, const char *directory)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1103 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1104 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1105 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1106 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1107 gint32 num;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1108 size_t len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1109
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1110 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1111 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1112 g_return_val_if_fail (directory != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1113
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1114 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1115
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1116 if (*directory == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1117 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1118 len = strlen (directory) + 8;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1119 tempstr = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1120 strcpy (tempstr + 8, directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1121 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1122 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1123 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1124 len = strlen (directory) + strlen (request->directory) + 9;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1125 tempstr = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1126 strcpy (tempstr + 8, request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1127 strcat (tempstr + 8, "/");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1128 strcat (tempstr + 8, directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1129 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1130
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1131 num = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1132 memcpy (tempstr, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1133
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1134 num = htonl (len - 8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1135 memcpy (tempstr + 4, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1136
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1137 if (sshv2_send_command (request, SSH_FXP_RMDIR, tempstr, len) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1138 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1139 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1140 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1141 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1142 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1143
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1144 memset (&message, 0, sizeof (message));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1145 if (sshv2_read_response (request, &message, -1) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1146 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1147
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1148 message.pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1149 if (sshv2_buffer_get_int32 (request, &message, SSH_FX_OK) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1150 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1151
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1152 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1153
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1154 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1155 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1156
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1157
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1158 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1159 sshv2_rmfile (gftp_request * request, const char *file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1160 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1161 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1162 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1163 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1164 gint32 num;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1165 size_t len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1166
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1167 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1168 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1169 g_return_val_if_fail (file != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1170
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1171 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1172
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1173 if (*file == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1174 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1175 len = strlen (file) + 8;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1176 tempstr = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1177 strcpy (tempstr + 8, file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1178 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1179 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1180 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1181 len = strlen (file) + strlen (request->directory) + 9;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1182 tempstr = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1183 strcpy (tempstr + 8, request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1184 strcat (tempstr + 8, "/");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1185 strcat (tempstr + 8, file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1186 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1187
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1188 num = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1189 memcpy (tempstr, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1190
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1191 num = htonl (len - 8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1192 memcpy (tempstr + 4, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1193
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1194 if (sshv2_send_command (request, SSH_FXP_REMOVE, tempstr, len) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1195 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1196 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1197 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1198 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1199 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1200
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1201 memset (&message, 0, sizeof (message));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1202 if (sshv2_read_response (request, &message, -1) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1203 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1204
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1205 message.pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1206 if (sshv2_buffer_get_int32 (request, &message, SSH_FX_OK) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1207 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1208
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1209 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1210
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1211 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1212 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1213
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1214
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1215 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1216 sshv2_chmod (gftp_request * request, const char *file, int mode)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1217 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1218 char *tempstr, buf[10];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1219 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1220 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1221 gint32 num;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1222 size_t len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1223
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1224 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1225 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1226 g_return_val_if_fail (file != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1227
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1228 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1229
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1230 if (*file == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1231 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1232 len = strlen (file) + 16;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1233 tempstr = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1234 strcpy (tempstr + 8, file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1235 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1236 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1237 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1238 len = strlen (file) + strlen (request->directory) + 17;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1239 tempstr = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1240 strcpy (tempstr + 8, request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1241 strcat (tempstr + 8, "/");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1242 strcat (tempstr + 8, file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1243 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1244
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1245 num = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1246 memcpy (tempstr, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1247
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1248 num = htonl (len - 16);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1249 memcpy (tempstr + 4, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1250
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1251 num = htonl (SSH_FILEXFER_ATTR_PERMISSIONS);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1252 memcpy (tempstr + len - 8, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1253
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1254 g_snprintf (buf, sizeof (buf), "%d", mode);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1255 num = htonl (strtol (buf, NULL, 8));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1256 memcpy (tempstr + len - 4, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1257
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1258 if (sshv2_send_command (request, SSH_FXP_SETSTAT, tempstr, len) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1259 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1260 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1261 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1262 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1263 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1264
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1265 memset (&message, 0, sizeof (message));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1266 if (sshv2_read_response (request, &message, -1) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1267 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1268
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1269 message.pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1270 if (sshv2_buffer_get_int32 (request, &message, SSH_FX_OK) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1271 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1272
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1273 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1274
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1275 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1276 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1277
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1278
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1279 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1280 sshv2_mkdir (gftp_request * request, const char *newdir)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1281 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1282 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1283 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1284 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1285 gint32 num;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1286 size_t len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1287
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1288 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1289 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1290 g_return_val_if_fail (newdir != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1291
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1292 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1293
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1294 if (*newdir == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1295 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1296 len = strlen (newdir) + 12;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1297 tempstr = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1298 strcpy (tempstr + 8, newdir);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1299 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1300 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1301 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1302 len = strlen (newdir) + strlen (request->directory) + 13;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1303 tempstr = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1304 strcpy (tempstr + 8, request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1305 strcat (tempstr + 8, "/");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1306 strcat (tempstr + 8, newdir);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1307 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1308
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1309 num = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1310 memcpy (tempstr, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1311
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1312 num = htonl (len - 12);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1313 memcpy (tempstr + 4, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1314 memset (tempstr + len - 4, 0, 4); /* attributes */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1315
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1316 if (sshv2_send_command (request, SSH_FXP_MKDIR, tempstr, len) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1317 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1318 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1319 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1320 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1321 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1322
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1323 memset (&message, 0, sizeof (message));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1324 if (sshv2_read_response (request, &message, -1) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1325 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1326
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1327 message.pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1328 if (sshv2_buffer_get_int32 (request, &message, SSH_FX_OK) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1329 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1330
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1331 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1332
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1333 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1334 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1335
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1336
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1337 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1338 sshv2_rename (gftp_request * request, const char *oldname, const char *newname)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1339 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1340 char *tempstr, *oldstr, *newstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1341 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1342 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1343 gint32 num;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1344 size_t oldlen, newlen;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1345
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1346 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1347 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1348 g_return_val_if_fail (oldname != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1349 g_return_val_if_fail (newname != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1350
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1351 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1352
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1353 if (*oldname == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1354 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1355 oldlen = strlen (oldname);
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1356 oldstr = g_strdup (oldname);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1357 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1358 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1359 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1360 oldlen = strlen (request->directory) + strlen (oldname) + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1361 oldstr = g_strconcat (request->directory, "/", oldname, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1362 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1363
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1364 if (*newname == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1365 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1366 newlen = strlen (newname);
56
a12bcbc2fce4 2002-11-11 Brian Masney <masneyb@gftp.org>
masneyb
parents: 48
diff changeset
1367 newstr = g_strdup (newname);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1368 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1369 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1370 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1371 newlen = strlen (request->directory) + strlen (newname) + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1372 newstr = g_strconcat (request->directory, "/", newname, NULL);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1373 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1374
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1375 tempstr = g_malloc (oldlen + newlen + 13);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1376 num = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1377 memcpy (tempstr, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1378
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1379 num = htonl (oldlen);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1380 memcpy (tempstr + 4, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1381 strcpy (tempstr + 8, oldstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1382
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1383 num = htonl (newlen);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1384 memcpy (tempstr + 8 + oldlen, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1385 strcpy (tempstr + 12 + oldlen, newstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1386
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1387 if (sshv2_send_command (request, SSH_FXP_RENAME, tempstr, oldlen + newlen + 12) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1388 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1389 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1390 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1391 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1392 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1393
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1394 memset (&message, 0, sizeof (message));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1395 if (sshv2_read_response (request, &message, -1) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1396 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1397
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1398 message.pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1399 if (sshv2_buffer_get_int32 (request, &message, SSH_FX_OK) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1400 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1401
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1402 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1403
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1404 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1405 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1406
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1407
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1408 static int
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1409 sshv2_set_file_time (gftp_request * request, const char *file, time_t datetime)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1410 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1411 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1412 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1413 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1414 gint32 num;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1415 size_t len;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1416
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1417 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1418 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1419 g_return_val_if_fail (file != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1420
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1421 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1422
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1423 if (*file == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1424 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1425 len = strlen (file) + 20;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1426 tempstr = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1427 strcpy (tempstr + 8, file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1428 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1429 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1430 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1431 len = strlen (file) + strlen (request->directory) + 21;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1432 tempstr = g_malloc (len + 1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1433 strcpy (tempstr + 8, request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1434 strcat (tempstr + 8, "/");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1435 strcat (tempstr + 8, file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1436 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1437
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1438 num = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1439 memcpy (tempstr, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1440
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1441 num = htonl (len - 20);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1442 memcpy (tempstr + 4, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1443
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1444 num = htonl (SSH_FILEXFER_ATTR_ACMODTIME);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1445 memcpy (tempstr + len - 12, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1446
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1447 num = htonl (datetime);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1448 memcpy (tempstr + len - 8, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1449
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1450 num = htonl (datetime);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1451 memcpy (tempstr + len - 4, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1452
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1453 if (sshv2_send_command (request, SSH_FXP_SETSTAT, tempstr, len) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1454 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1455 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1456 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1457 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1458 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1459
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1460 memset (&message, 0, sizeof (message));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1461 if (sshv2_read_response (request, &message, -1) < 0)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1462 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1463
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1464 message.pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1465 if (sshv2_buffer_get_int32 (request, &message, SSH_FX_OK) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1466 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1467
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1468 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1469
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1470 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1471 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1472
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1473
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1474 static off_t
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1475 sshv2_get_file_size (gftp_request * request, const char *file)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1476 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1477 gint32 len, highnum, lownum, attrs, num;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1478 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1479 char *tempstr;
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1480 int serv_ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1481 #ifdef G_HAVE_GINT64
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1482 gint64 ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1483 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1484
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1485 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1486 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1487 g_return_val_if_fail (file != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1488
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1489 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1490
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1491 if (*file == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1492 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1493 len = strlen (file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1494 tempstr = g_malloc (len + 9);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1495 strcpy (tempstr + 8, file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1496 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1497 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1498 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1499 len = strlen (file) + strlen (request->directory) + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1500 tempstr = g_malloc (len + 9);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1501 strcpy (tempstr + 8, request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1502 strcat (tempstr + 8, "/");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1503 strcat (tempstr + 8, file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1504 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1505
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1506 num = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1507 memcpy (tempstr, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1508
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1509 num = htonl (len);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1510 memcpy (tempstr + 4, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1511
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1512 if (sshv2_send_command (request, SSH_FXP_STAT, tempstr, len + 8) < 0)
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 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1516 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1517 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1518
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1519 memset (&params->message, 0, sizeof (params->message));
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1520 serv_ret = sshv2_read_response (request, &params->message, -1);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1521 if (serv_ret == SSH_FXP_STATUS)
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1522 {
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1523 sshv2_message_free (&params->message);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1524 return (-2);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1525 }
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1526 else if (serv_ret != SSH_FXP_ATTRS)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1527 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1528 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1529 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1530 sshv2_message_free (&params->message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1531 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1532 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1533 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1534
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1535 if (params->message.length < 5)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1536 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1537 params->message.pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1538
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1539 if ((attrs = sshv2_buffer_get_int32 (request, &params->message, -1)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1540 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1541
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1542 if (attrs & SSH_FILEXFER_ATTR_SIZE)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1543 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1544 if ((highnum = sshv2_buffer_get_int32 (request, &params->message, -1)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1545 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1546
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1547 if ((lownum = sshv2_buffer_get_int32 (request, &params->message, -1)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1548 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1549
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1550 sshv2_message_free (&params->message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1551
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1552 #if G_HAVE_GINT64
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1553 ret = (gint64) lownum | ((gint64) highnum >> 32);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1554 return (ret);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1555 #else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1556 return (lownum);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1557 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1558 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1559
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1560 sshv2_message_free (&params->message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1561
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1562 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1563
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1564 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1565
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1566
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1567 static off_t
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1568 sshv2_get_file (gftp_request * request, const char *file, int fd,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1569 off_t startsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1570 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1571 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1572 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1573 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1574 size_t stlen;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1575 gint32 num;
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1576 int ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1577
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1578 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1579 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1580 g_return_val_if_fail (request->sockfd > 0, -2);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1581 /* fd ignored for this protocol */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1582
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1583 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1584 params->offset = startsize;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1585
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1586 if (*file == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1587 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1588 stlen = strlen (file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1589 tempstr = g_malloc (stlen + 16);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1590 strcpy (tempstr + 8, file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1591 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1592 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1593 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1594 stlen = strlen (file) + strlen (request->directory) + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1595 tempstr = g_malloc (stlen + 16);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1596 strcpy (tempstr + 8, request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1597 strcat (tempstr + 8, "/");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1598 strcat (tempstr + 8, file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1599 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1600
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1601 num = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1602 memcpy (tempstr, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1603
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1604 num = htonl (stlen);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1605 memcpy (tempstr + 4, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1606
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1607 num = htonl (SSH_FXF_READ);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1608 memcpy (tempstr + 8 + stlen, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1609
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1610 memset (tempstr + 12 + stlen, 0, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1611
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1612 if (sshv2_send_command (request, SSH_FXP_OPEN, tempstr, stlen + 16) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1613 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1614 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1615 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1616 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1617
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1618 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1619 memset (&message, 0, sizeof (message));
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1620 ret = sshv2_read_response (request, &message, -1);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1621 if (ret == SSH_FXP_STATUS)
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1622 {
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1623 sshv2_message_free (&message);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1624 return (-2);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1625 }
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1626 else if (ret != SSH_FXP_HANDLE)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1627 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1628 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1629 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1630 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1631 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1632 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1633 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1634
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1635 if (message.length - 4 > SSH_MAX_HANDLE_SIZE)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1636 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1637 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1638 _("Error: Message size %d too big from server\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1639 message.length - 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1640 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1641 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1642 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1643
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1644 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1645
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1646 memset (params->handle, 0, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1647 memcpy (params->handle + 4, message.buffer+ 4, message.length - 5);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1648 params->handle_len = message.length - 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1649 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1650
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1651 return (sshv2_get_file_size (request, file));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1652 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1653
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1654
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1655 static int
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1656 sshv2_put_file (gftp_request * request, const char *file, int fd,
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1657 off_t startsize, off_t totalsize)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1658 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1659 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1660 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1661 char *tempstr;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1662 size_t stlen;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1663 gint32 num;
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1664 int ret;
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1665
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1666 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1667 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1668 g_return_val_if_fail (request->sockfd > 0, -2);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1669 /* fd ignored for this protocol */
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1670
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1671 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1672 params->offset = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1673
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1674 if (*file == '/')
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1675 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1676 stlen = strlen (file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1677 tempstr = g_malloc (stlen + 16);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1678 strcpy (tempstr + 8, file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1679 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1680 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1681 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1682 stlen = strlen (file) + strlen (request->directory) + 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1683 tempstr = g_malloc (stlen + 16);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1684 strcpy (tempstr + 8, request->directory);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1685 strcat (tempstr + 8, "/");
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1686 strcat (tempstr + 8, file);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1687 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1688
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1689 num = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1690 memcpy (tempstr, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1691
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1692 num = htonl (stlen);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1693 memcpy (tempstr + 4, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1694
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1695 if (startsize > 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1696 num = htonl (SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_APPEND);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1697 else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1698 num = htonl (SSH_FXF_WRITE | SSH_FXF_CREAT | SSH_FXF_TRUNC);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1699 memcpy (tempstr + 8 + stlen, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1700
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1701 memset (tempstr + 12 + stlen, 0, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1702
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1703 if (sshv2_send_command (request, SSH_FXP_OPEN, tempstr, stlen + 16) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1704 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1705 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1706 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1707 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1708
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1709 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1710 memset (&message, 0, sizeof (message));
64
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1711 ret = sshv2_read_response (request, &message, -1);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1712 if (ret == SSH_FXP_STATUS)
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1713 {
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1714 sshv2_message_free (&message);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1715 return (-2);
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1716 }
29128554eb86 2002-11-23 Brian Masney <masneyb@gftp.org>
masneyb
parents: 63
diff changeset
1717 else if (ret != SSH_FXP_HANDLE)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1718 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1719 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1720 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1721 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1722 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1723 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1724 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1725
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1726 if (message.length - 4 > SSH_MAX_HANDLE_SIZE)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1727 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1728 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1729 _("Error: Message size %d too big from server\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1730 message.length - 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1731 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1732 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1733 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1734
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1735 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1736
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1737 memset (params->handle, 0, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1738 memcpy (params->handle + 4, message.buffer+ 4, message.length - 5);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1739 params->handle_len = message.length - 1;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1740 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1741
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1742 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1743 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1744
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1745
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1746 static ssize_t
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1747 sshv2_get_next_file_chunk (gftp_request * request, char *buf, size_t size)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1748 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1749 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1750 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1751 gint32 num;
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 gint64 offset;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1755 #else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1756 gint32 offset;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1757 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1758
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1759 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1760 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1761 g_return_val_if_fail (request->sockfd > 0, -2);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1762 g_return_val_if_fail (buf != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1763
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1764 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1765
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1766 if (params->read_buffer == NULL)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1767 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1768 params->read_buffer = g_malloc (params->handle_len + 12);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1769 num = htonl (params->handle_len);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1770 memcpy (params->read_buffer, params->handle, params->handle_len);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1771 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1772
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1773 num = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1774 memcpy (params->read_buffer, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1775
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1776 #ifdef G_HAVE_GINT64
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1777 offset = hton64 (params->offset);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1778 memcpy (params->read_buffer + params->handle_len, &offset, 8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1779 #else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1780 memset (params->read_buffer + params->handle_len, 0, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1781 offset = htonl (params->offset);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1782 memcpy (params->read_buffer + params->handle_len + 4, &offset, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1783 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1784
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1785 num = htonl (size);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1786 memcpy (params->read_buffer + params->handle_len + 8, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1787
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1788 if (sshv2_send_command (request, SSH_FXP_READ, params->read_buffer, params->handle_len + 12) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1789 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1790
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1791 memset (&message, 0, sizeof (message));
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1792 if (sshv2_read_response (request, &message, -1) != SSH_FXP_DATA)
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1793 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1794 message.pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1795 if ((num = sshv2_buffer_get_int32 (request, &message, SSH_FX_OK)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1796 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1797 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1798 if (num != SSH_FX_EOF)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1799 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1800 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1801 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1802 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1803 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1804 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1805 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1806 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1807
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1808 memcpy (&num, message.buffer + 4, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1809 num = ntohl (num);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1810 if (num > size)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1811 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1812 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1813 _("Error: Message size %d too big from server\n"),
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1814 num);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1815 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1816 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1817 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1818
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1819 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1820
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1821 memcpy (buf, message.buffer + 8, num);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1822 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1823 params->offset += num;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1824 return (num);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1825 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1826
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1827
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1828 static ssize_t
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1829 sshv2_put_next_file_chunk (gftp_request * request, char *buf, size_t size)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1830 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1831 sshv2_params * params;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1832 sshv2_message message;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1833 char tempstr[32768];
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1834 gint32 num;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1835 int ret;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1836
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1837 #ifdef G_HAVE_GINT64
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1838 gint64 offset;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1839 #else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1840 gint32 offset;
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 g_return_val_if_fail (request != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1844 g_return_val_if_fail (request->protonum == GFTP_SSHV2_NUM, -2);
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1845 g_return_val_if_fail (request->sockfd > 0, -2);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1846 g_return_val_if_fail (buf != NULL, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1847 g_return_val_if_fail (size <= 32500, -2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1848
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1849 params = request->protocol_data;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1850
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1851 num = htonl (params->handle_len);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1852 memcpy (tempstr, params->handle, params->handle_len);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1853
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1854 num = htonl (params->id++);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1855 memcpy (tempstr, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1856
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1857 #ifdef G_HAVE_GINT64
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1858 offset = hton64 (params->offset);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1859 memcpy (tempstr + params->handle_len, &offset, 8);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1860 #else
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1861 memset (tempstr + params->handle_len, 0, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1862 offset = htonl (params->offset);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1863 memcpy (tempstr + params->handle_len + 4, &offset, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1864 #endif
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1865
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1866 num = htonl (size);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1867 memcpy (tempstr + params->handle_len + 8, &num, 4);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1868 memcpy (tempstr + params->handle_len + 12, buf, size);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1869
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1870 if (sshv2_send_command (request, SSH_FXP_WRITE, tempstr, params->handle_len + size + 12) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1871 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1872 g_free (tempstr);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1873 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1874 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1875
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1876 memset (&message, 0, sizeof (message));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1877 params->dont_log_status = 1;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1878 ret = sshv2_read_response (request, &message, -1);
1
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1879 params->dont_log_status = 0;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1880 if (ret != SSH_FXP_STATUS)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1881 {
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1882 request->logging_function (gftp_logging_error, request->user_data,
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1883 _("Received wrong response from server, disconnecting\n"));
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1884 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1885 gftp_disconnect (request);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1886 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1887 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1888
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1889 message.pos += 4;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1890 if ((num = sshv2_buffer_get_int32 (request, &message, SSH_FX_OK)) < 0)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1891 return (-2);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1892 sshv2_message_free (&message);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1893
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1894 if (num == SSH_FX_EOF)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1895 return (0);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1896 else if (num != SSH_FX_OK)
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1897 return (-1);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1898
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1899 params->offset += size;
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1900 return (size);
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1901 }
8b1883341c6f Initial revision
masneyb
parents:
diff changeset
1902
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1903
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1904 static void
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1905 sshv2_set_config_options (gftp_request * request)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1906 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1907 if (request->sftpserv_path != NULL)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1908 {
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1909 if (ssh2_sftp_path != NULL &&
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1910 strcmp (ssh2_sftp_path, request->sftpserv_path) == 0)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1911 return;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1912
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1913 g_free (request->sftpserv_path);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1914 request->sftpserv_path = NULL;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1915 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1916
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1917 if (ssh2_sftp_path != NULL)
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1918 request->sftpserv_path = g_strdup (ssh2_sftp_path);
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1919
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1920 request->need_userpass = ssh_need_userpass;
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1921 }
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1922
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1923
63
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 61
diff changeset
1924 static void
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 61
diff changeset
1925 sshv2_swap_socks (gftp_request * dest, gftp_request * source)
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 61
diff changeset
1926 {
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 61
diff changeset
1927 sshv2_params * sparams, * dparams;
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 61
diff changeset
1928
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 61
diff changeset
1929 sparams = source->protocol_data;
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 61
diff changeset
1930 dparams = dest->protocol_data;
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 61
diff changeset
1931 dparams->id = sparams->id;
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 61
diff changeset
1932 }
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 61
diff changeset
1933
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 61
diff changeset
1934
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1935 void
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1936 sshv2_init (gftp_request * request)
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1937 {
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1938 sshv2_params * params;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1939
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1940 g_return_if_fail (request != NULL);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1941
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1942 request->protonum = GFTP_SSHV2_NUM;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1943 request->init = sshv2_init;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1944 request->destroy = sshv2_destroy;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1945 request->connect = sshv2_connect;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1946 request->disconnect = sshv2_disconnect;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1947 request->get_file = sshv2_get_file;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1948 request->put_file = sshv2_put_file;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1949 request->transfer_file = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1950 request->get_next_file_chunk = sshv2_get_next_file_chunk;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1951 request->put_next_file_chunk = sshv2_put_next_file_chunk;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1952 request->end_transfer = sshv2_end_transfer;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1953 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
1954 request->list_files = sshv2_list_files;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1955 request->get_next_file = sshv2_get_next_file;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1956 request->set_data_type = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1957 request->get_file_size = sshv2_get_file_size;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1958 request->chdir = sshv2_chdir;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1959 request->rmdir = sshv2_rmdir;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1960 request->rmfile = sshv2_rmfile;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1961 request->mkdir = sshv2_mkdir;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1962 request->rename = sshv2_rename;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1963 request->chmod = sshv2_chmod;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1964 request->set_file_time = sshv2_set_file_time;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1965 request->site = NULL;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1966 request->parse_url = NULL;
58
c01d91c10f6c 2002-11-20 Brian Masney <masneyb@gftp.org>
masneyb
parents: 56
diff changeset
1967 request->set_config_options = sshv2_set_config_options;
63
41b71c4e5076 2002-11-2333 Brian Masney <masneyb@gftp.org>
masneyb
parents: 61
diff changeset
1968 request->swap_socks = sshv2_swap_socks;
48
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1969 request->url_prefix = "ssh2";
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1970 request->protocol_name = "SSH2";
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1971 request->need_hostport = 1;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1972 request->need_userpass = ssh_need_userpass;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1973 request->use_cache = 1;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1974 request->use_threads = 1;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1975 request->always_connected = 0;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1976 request->protocol_data = g_malloc0 (sizeof (sshv2_params));
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1977 gftp_set_config_options (request);
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1978
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1979 params = request->protocol_data;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1980 params->id = 1;
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1981 }
e5f6054590b5 2002-11-5 Brian Masney <masneyb@gftp.org>
masneyb
parents: 41
diff changeset
1982