annotate lib/sshv2.c @ 218:de6a2e8e51cb

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