annotate lib/ftps.c @ 508:a95c5acdacf6

2004-7-19 Brian Masney <masneyb@gftp.org> * src/gtk/transfer.c src/uicommon/gftpui.h - use the new thread callback functions for retrieving the list of subdirectories
author masneyb
date Tue, 20 Jul 2004 02:00:59 +0000
parents 83cfffb2878a
children fbb5a02beddb
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
389
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
1 /*****************************************************************************/
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
2 /* ftps.c - General purpose routines for the FTPS protocol */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
3 /* Copyright (C) 1998-2003 Brian Masney <masneyb@gftp.org> */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
4 /* */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
5 /* This program is free software; you can redistribute it and/or modify */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
6 /* it under the terms of the GNU General Public License as published by */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
7 /* the Free Software Foundation; either version 2 of the License, or */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
8 /* (at your option) any later version. */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
9 /* */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
10 /* This program is distributed in the hope that it will be useful, */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
11 /* but WITHOUT ANY WARRANTY; without even the implied warranty of */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
12 /* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
13 /* GNU General Public License for more details. */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
14 /* */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
15 /* You should have received a copy of the GNU General Public License */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
16 /* along with this program; if not, write to the Free Software */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
17 /* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111 USA */
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
18 /*****************************************************************************/
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
19
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
20 #include "gftp.h"
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
21 #include "ftpcommon.h"
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
22
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
23 static const char cvsid[] = "$Id$";
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
24
397
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
25 #ifdef USE_SSL
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
26 static int
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
27 ftps_get_next_file (gftp_request * request, gftp_file * fle, int fd)
389
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
28 {
397
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
29 rfc959_parms * params;
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
30 int ret, resetptr;
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
31
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
32 params = request->protocol_data;
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
33 if (request->cached)
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
34 {
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
35 request->read_function = gftp_fd_read;
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
36 request->write_function = gftp_fd_write;
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
37 resetptr = 1;
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
38 }
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
39 else
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
40 resetptr = 0;
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
41
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
42 ret = rfc959_get_next_file (request, fle, fd);
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
43
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
44 if (resetptr)
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
45 {
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
46 request->read_function = gftp_ssl_read;
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
47 request->write_function = gftp_ssl_write;
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
48 }
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
49
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
50 return (ret);
389
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
51 }
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
52
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
53
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
54 static int
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
55 ftps_auth_tls_start (gftp_request * request)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
56 {
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
57 rfc959_parms * params;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
58 int ret;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
59
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
60 params = request->protocol_data;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
61
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
62 ret = rfc959_send_command (request, "AUTH TLS\r\n", 1);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
63 if (ret < 0)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
64 return (ret);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
65 else if (ret != '2')
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
66 return (0);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
67
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
68 if ((ret = gftp_ssl_session_setup (request)) < 0)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
69 return (ret);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
70
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
71 request->read_function = gftp_ssl_read;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
72 request->write_function = gftp_ssl_write;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
73
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
74 ret = rfc959_send_command (request, "PBSZ 0\r\n", 1);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
75 if (ret < 0)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
76 return (ret);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
77
390
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
78 ret = '5'; /* FIXME */
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
79 /* ret = rfc959_send_command (request, "PROT P\r\n", 1); */
389
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
80 if (ret < 0)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
81 return (ret);
390
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
82 else if (ret == '2')
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
83 {
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
84 params->data_conn_read = gftp_ssl_read;
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
85 params->data_conn_write = gftp_ssl_write;
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
86 }
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
87 else
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
88 {
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
89 ret = rfc959_send_command (request, "PROT C\r\n", 1);
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
90 if (ret < 0)
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
91 return (ret);
449
3fc895f61665 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 432
diff changeset
92 else if (ret != '2')
3fc895f61665 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 432
diff changeset
93 {
3fc895f61665 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 432
diff changeset
94 gftp_disconnect (request);
3fc895f61665 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 432
diff changeset
95 return (GFTP_ERETRYABLE);
3fc895f61665 2004-3-21 Brian Masney <masneyb@gftp.org>
masneyb
parents: 432
diff changeset
96 }
390
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
97
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
98 params->data_conn_read = gftp_fd_read;
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
99 params->data_conn_write = gftp_fd_write;
0444232dc494 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents: 389
diff changeset
100 }
389
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
101
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
102 return (0);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
103 }
397
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
104 #endif
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
105
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
106
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
107 void
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
108 ftps_register_module (void)
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
109 {
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
110 #ifdef USE_SSL
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
111 ssl_register_module ();
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
112 #endif
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
113 }
389
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
114
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
115
451
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
116 static int
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
117 ftps_connect (gftp_request * request)
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
118 {
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
119 if (request->datafd > 0)
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
120 return (0);
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
121
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
122 request->read_function = gftp_fd_read;
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
123 request->write_function = gftp_fd_write;
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
124
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
125 return (rfc959_connect (request));
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
126 }
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
127
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
128
389
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
129 int
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
130 ftps_init (gftp_request * request)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
131 {
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
132 #ifdef USE_SSL
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
133 rfc959_parms * params;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
134 int ret;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
135
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
136 g_return_val_if_fail (request != NULL, GFTP_EFATAL);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
137
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
138 if ((ret = gftp_protocols[GFTP_FTP_NUM].init (request)) < 0)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
139 return (ret);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
140
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
141 params = request->protocol_data;
415
1ffdbc487a70 2004-3-1 Brian Masney <masneyb@gftp.org>
masneyb
parents: 397
diff changeset
142 request->protonum = GFTP_FTPS_NUM;
432
d7ff8d2d43aa 2004-3-17 Brian Masney <masneyb@gftp.org>
masneyb
parents: 415
diff changeset
143 request->init = ftps_init;
451
83cfffb2878a 2004-3-26 Brian Masney <masneyb@gftp.org>
masneyb
parents: 449
diff changeset
144 request->connect = ftps_connect;
389
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
145 params->auth_tls_start = ftps_auth_tls_start;
397
14ef37b62c20 2004-2-8 Brian Masney <masneyb@gftp.org>
masneyb
parents: 390
diff changeset
146 request->get_next_file = ftps_get_next_file;
389
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
147 request->post_connect = NULL;
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
148 request->url_prefix = g_strdup ("ftps");
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
149
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
150 if ((ret = gftp_ssl_startup (NULL)) < 0)
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
151 return (ret);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
152
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
153 return (0);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
154 #else
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
155 request->logging_function (gftp_logging_error, request,
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
156 _("FTPS Support unavailable since SSL support was not compiled in. Aborting connection.\n"));
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
157
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
158 return (GFTP_EFATAL);
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
159 #endif
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
160 }
b39a312323ec 2003-2-3 Brian Masney <masneyb@gftp.org>
masneyb
parents:
diff changeset
161