PASV/PORT work in harmony :thumbs_up:

This commit is contained in:
Jack Halford 2017-11-08 17:31:38 +01:00
parent 5b370b6a43
commit 2213d5fcb9
10 changed files with 48 additions and 59 deletions

2
ftp/.gitignore vendored
View file

@ -1,2 +1,4 @@
client client
server server
!srcs/client
!srcs/server

View file

@ -31,12 +31,13 @@ INC_DIR = includes/
OBJ_DIR = objs/ OBJ_DIR = objs/
SRC_BASE = \ SRC_BASE = \
client/cli_ls.c\
client/client.c\ client/client.c\
console_msg.c\ console_msg.c\
crlf.c\ crlf.c\
ftp_dataconn.c\
server/cmd_cwd.c\ server/cmd_cwd.c\
server/cmd_list.c\ server/cmd_list.c\
server/cmd_pasv.c\
server/cmd_port.c\ server/cmd_port.c\
server/cmd_pwd.c\ server/cmd_pwd.c\
server/cmd_quit.c\ server/cmd_quit.c\
@ -44,6 +45,7 @@ server/cmd_retr.c\
server/cmd_stor.c\ server/cmd_stor.c\
server/cmd_type.c\ server/cmd_type.c\
server/cmd_user.c\ server/cmd_user.c\
server/dconn.c\
server/server.c server/server.c
SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE)) SRCS = $(addprefix $(SRC_DIR), $(SRC_BASE))

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/01 15:50:56 by jhalford #+# #+# */ /* Created: 2017/11/01 15:50:56 by jhalford #+# #+# */
/* Updated: 2017/11/01 17:12:03 by jhalford ### ########.fr */ /* Updated: 2017/11/08 13:48:11 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -37,13 +37,14 @@ extern t_cmd_map g_cli_cmd[];
t_cmd_map *get_cmd(char *cmd); t_cmd_map *get_cmd(char *cmd);
int cli_do_sh(int sock, char **av); int cli_ls(int sock, char **av);
int cli_do_get(int sock, char **av); int cli_sh(int sock, char **av);
int cli_do_put(int sock, char **av); int cli_get(int sock, char **av);
int cli_do_cd(int sock, char **av); int cli_put(int sock, char **av);
int cli_cd(int sock, char **av);
int cli_do_help(int sock, char **av); int cli_help(int sock, char **av);
int cli_do_debug(int sock, char **av); int cli_debug(int sock, char **av);
int cli_do_local(int sock, char **av); int cli_local(int sock, char **av);
#endif #endif

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/01 15:56:59 by jhalford #+# #+# */ /* Created: 2017/11/01 15:56:59 by jhalford #+# #+# */
/* Updated: 2017/11/02 16:33:37 by jhalford ### ########.fr */ /* Updated: 2017/11/08 17:03:08 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -31,26 +31,37 @@
typedef struct s_ftp t_ftp; typedef struct s_ftp t_ftp;
typedef struct s_ftp_cmd t_ftp_cmd; typedef struct s_ftp_cmd t_ftp_cmd;
struct s_ftp enum e_dstate
{
DATA_PASV,
DATA_ACTV,
};
enum e_lstate
{
LOG_NONE,
LOG_YES,
};
struct s_ftp
{ {
int cmd_sock; int cmd_sock;
struct sockaddr_in data_sin; enum e_lstate log_state;
char username[100]; char username[100];
char path[100]; char path[100];
int state; enum e_dstate data_state;
union {
struct sockaddr_in sin;
int sock;
} dconn;
int d_sock;
}; };
enum e_state struct s_ftp_cmd
{ {
IDLE, char *name;
LOGGED_IN, int (*f)();
}; enum e_lstate statelock;
struct s_ftp_cmd
{
char *name;
int (*f)();
int statelock;
}; };
@ -60,16 +71,17 @@ extern char g_rootdir[PATH_MAX];
int ftp_send(int sock, char *msg, ...); int ftp_send(int sock, char *msg, ...);
int ftp_recv(int sock, char **msg); int ftp_recv(int sock, char **msg);
int ftp_dataconn(t_ftp *ftp); int dconn_open(t_ftp *ftp);
int dconn_close(t_ftp *ftp);
int console_msg(int level, char *str, ...); int console_msg(int level, char *str, ...);
int ftp_login(t_ftp *ftp);
int cmd_user(t_ftp *ftp, char **av); int cmd_user(t_ftp *ftp, char **av);
int cmd_quit(t_ftp *ftp, char **av); int cmd_quit(t_ftp *ftp, char **av);
int cmd_retr(t_ftp *ftp, char **av); int cmd_retr(t_ftp *ftp, char **av);
int cmd_stor(t_ftp *ftp, char **av); int cmd_stor(t_ftp *ftp, char **av);
int cmd_cwd(t_ftp *ftp, char **av); int cmd_cwd(t_ftp *ftp, char **av);
int cmd_pwd(t_ftp *ftp, char **av); int cmd_pwd(t_ftp *ftp, char **av);
int cmd_pasv(t_ftp *ftp, char **av);
int cmd_port(t_ftp *ftp, char **av); int cmd_port(t_ftp *ftp, char **av);
int cmd_type(t_ftp *ftp, char **av); int cmd_type(t_ftp *ftp, char **av);
int cmd_list(t_ftp *ftp, char **av); int cmd_list(t_ftp *ftp, char **av);

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/10/08 12:04:11 by jhalford #+# #+# */ /* Created: 2017/10/08 12:04:11 by jhalford #+# #+# */
/* Updated: 2017/11/02 17:09:42 by jhalford ### ########.fr */ /* Updated: 2017/11/08 14:54:32 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -1,27 +0,0 @@
/* ************************************************************************** */
/* */
/* ::: :::::::: */
/* ftp_dataconn.c :+: :+: :+: */
/* +:+ +:+ +:+ */
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/02 13:30:18 by jhalford #+# #+# */
/* Updated: 2017/11/02 15:40:05 by jhalford ### ########.fr */
/* */
/* ************************************************************************** */
#include "ftp_server.h"
int ftp_dataconn(t_ftp *ftp)
{
char buf[INET_ADDRSTRLEN];
int sock;
sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
ftp_ret(ftp, "150 about to open data conn");
if (connect(sock, (struct sockaddr*)&ftp->data_sin,
sizeof(ftp->data_sin)) < 0)
return(ftp_ret(ftp, "425 can't open data conn"));
console_msg(1, "dataconn @ %s:%i", inet_ntop(AF_INET, &ftp->data_sin.sin_addr, buf, sizeof(struct sockaddr_in)), ntohs(ftp->data_sin.sin_port));
return (sock);
}

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/01 19:22:12 by jhalford #+# #+# */ /* Created: 2017/11/01 19:22:12 by jhalford #+# #+# */
/* Updated: 2017/11/08 17:19:24 by jhalford ### ########.fr */ /* Updated: 2017/11/08 17:30:24 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 13:54:57 by jhalford #+# #+# */ /* Created: 2017/11/08 13:54:57 by jhalford #+# #+# */
/* Updated: 2017/11/08 17:15:09 by jhalford ### ########.fr */ /* Updated: 2017/11/08 17:31:19 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -19,7 +19,6 @@ int cmd_pasv(t_ftp *ftp, char **av)
struct sockaddr_in sin; struct sockaddr_in sin;
(void)av; (void)av;
return (ftp_ret(ftp, "502 not implemented"));
sin.sin_family = AF_INET; sin.sin_family = AF_INET;
sin.sin_addr.s_addr = inet_addr("127.0.0.1"); sin.sin_addr.s_addr = inet_addr("127.0.0.1");
port = 35000; port = 35000;

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/01 18:42:50 by jhalford #+# #+# */ /* Created: 2017/11/01 18:42:50 by jhalford #+# #+# */
/* Updated: 2017/11/08 17:17:44 by jhalford ### ########.fr */ /* Updated: 2017/11/08 17:30:18 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */

View file

@ -6,7 +6,7 @@
/* By: jhalford <jack@crans.org> +#+ +:+ +#+ */ /* By: jhalford <jack@crans.org> +#+ +:+ +#+ */
/* +#+#+#+#+#+ +#+ */ /* +#+#+#+#+#+ +#+ */
/* Created: 2017/11/08 14:55:15 by jhalford #+# #+# */ /* Created: 2017/11/08 14:55:15 by jhalford #+# #+# */
/* Updated: 2017/11/08 17:22:37 by jhalford ### ########.fr */ /* Updated: 2017/11/08 17:30:21 by jhalford ### ########.fr */
/* */ /* */
/* ************************************************************************** */ /* ************************************************************************** */
@ -62,7 +62,7 @@ int dconn_open(t_ftp *ftp)
int dconn_close(t_ftp *ftp) int dconn_close(t_ftp *ftp)
{ {
return (ftp_ret(ftp, "226 closing dataconn")); ftp_ret(ftp, "226 closing dataconn");
close(ftp->d_sock); close(ftp->d_sock);
ftp->d_sock = 0; ftp->d_sock = 0;
return (0); return (0);