annotate lib/sshv2.c @ 380:05ee37a5558b

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