Added some data channel safety checks.
[uftps.git] / init_session.c
blob23d2e5cb847260e69f121d7903c346f2c2997cc1
1 /*
2 * User FTP Server, Share folders over FTP without being root.
3 * Copyright (C) 2008 Isaac Jurado
5 * This program is free software; you can redistribute it and/or modify it under
6 * the terms of the GNU General Public License as published by the Free Software
7 * Foundation; either version 2 of the License, or (at your option) any later
8 * version.
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
13 * details.
15 * You should have received a copy of the GNU General Public License along with
16 * this program; if not, write to the Free Software Foundation, Inc.,
17 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
20 #include "uftps.h"
21 #include <arpa/inet.h>
24 void init_session (int control_sk)
26 int e;
27 socklen_t sai_len;
29 /* Basic initializations */
30 SS.control_sk = control_sk;
31 SS.passive_sk = -1;
32 SS.data_sk = -1;
33 SS.input_offset = 0;
34 SS.input_len = 0;
35 SS.passive_mode = 0;
36 SS.file_offset = 0;
37 SS.arg = NULL;
39 /* Set CWD to root */
40 SS.cwd[0] = '.';
41 SS.cwd[1] = '/';
42 SS.cwd[2] = '\0';
43 SS.cwd_len = 3;
45 /* Get local an remote addresses to perform some safety checks when
46 * opening data connections */
47 sai_len = sizeof(struct sockaddr_in);
48 e = getsockname(control_sk, (struct sockaddr *) &SS.local_address,
49 &sai_len);
50 if (e == -1)
51 fatal("Getting local socket address");
53 sai_len = sizeof(struct sockaddr_in);
54 e = getpeername(control_sk, (struct sockaddr *) &SS.client_address,
55 &sai_len);
56 if (e == -1)
57 fatal("Getting remote socket address");
59 notice("Attending new client from %s",
60 inet_ntoa(SS.client_address.sin_addr));
61 reply_c("220 User FTP Server ready.\r\n");