annotate lib/sshv2.c @ 460:075f89b4395c

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