stuff
This commit is contained in:
parent
e78c41d420
commit
cd99c04ca5
4 changed files with 56 additions and 14 deletions
|
|
@ -27,6 +27,8 @@
|
||||||
# include <sys/wait.h>
|
# include <sys/wait.h>
|
||||||
# include <limits.h>
|
# include <limits.h>
|
||||||
|
|
||||||
|
# include <pwd.h>
|
||||||
|
|
||||||
typedef struct s_cmd_map t_cmd_map;
|
typedef struct s_cmd_map t_cmd_map;
|
||||||
|
|
||||||
struct s_cmd_map
|
struct s_cmd_map
|
||||||
|
|
@ -67,6 +69,9 @@ int ftp_daemon(int sock);
|
||||||
int ftp_spawn(int sock);
|
int ftp_spawn(int sock);
|
||||||
int ftp_cmd(int sock, int req);
|
int ftp_cmd(int sock, int req);
|
||||||
|
|
||||||
|
int ftp_send(int sock, char *msg, size_t size);
|
||||||
|
int ftp_recv(int sock, char buf[], size_t size);
|
||||||
|
|
||||||
int serv_do_get(int sock);
|
int serv_do_get(int sock);
|
||||||
int serv_do_put(int sock);
|
int serv_do_put(int sock);
|
||||||
int serv_do_sh(int sock);
|
int serv_do_sh(int sock);
|
||||||
|
|
|
||||||
|
|
@ -21,7 +21,7 @@
|
||||||
*/
|
*/
|
||||||
# define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
|
# define DG_MSG "{inv}{ran}%5i{yel}%21s {bol}{blu}%-3d{eoc}"
|
||||||
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
|
# define DG_ARGS getpid(), getpid(), ft_path_notdir(__FILE__), __LINE__
|
||||||
# define DG(s, ...) ft_dprintf(STDBUG,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__)
|
# define DG(s, ...) ft_dprintf(STDERR,DG_MSG s "{eoc}\n",DG_ARGS,##__VA_ARGS__)
|
||||||
|
|
||||||
/*
|
/*
|
||||||
** DEBUG with no malloc
|
** DEBUG with no malloc
|
||||||
|
|
|
||||||
|
|
@ -14,11 +14,31 @@
|
||||||
|
|
||||||
int read_req(int sock)
|
int read_req(int sock)
|
||||||
{
|
{
|
||||||
int req;
|
(void)sock;
|
||||||
|
return (0);
|
||||||
if (read(sock, (char*)&req, sizeof(req)) < 0)
|
}
|
||||||
return (0);
|
|
||||||
req = ntohs(req);
|
int ftp_recv(int sock, char buf[], size_t size)
|
||||||
console_msg(0, "%i RECEIVED", req);
|
{
|
||||||
return (req);
|
int ret;
|
||||||
|
|
||||||
|
if ((ret = recv(sock, buf, size, 0)) < 0)
|
||||||
|
return (0);
|
||||||
|
if (ret >= 2)
|
||||||
|
buf[ret - 2] = 0;
|
||||||
|
else
|
||||||
|
buf[ret] = 0;
|
||||||
|
/* req = ntohs(req); */
|
||||||
|
console_msg(0, "%-5i<--- %s (%i)", getpid(), buf, ret);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
|
int ftp_send(int sock, char *msg, size_t size)
|
||||||
|
{
|
||||||
|
int err;
|
||||||
|
if ((err = send(sock, msg, size, 0)) < 0)
|
||||||
|
return (err);
|
||||||
|
msg[ft_strlen(msg) - 1] = 0;
|
||||||
|
console_msg(0, "%-5i---> %s", getpid(), msg);
|
||||||
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -50,18 +50,35 @@ int ftp_cmd(int sock, int req)
|
||||||
return (1);
|
return (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int ftp_login(int sock)
|
||||||
|
{
|
||||||
|
char buf[100];
|
||||||
|
|
||||||
|
ftp_send(sock, "220 \r\n", 6);
|
||||||
|
ftp_recv(sock, buf, sizeof(buf));
|
||||||
|
if (ft_strncmp(buf, "USER ", 5) != 0)
|
||||||
|
console_msg(0, "expected USER");
|
||||||
|
if (ft_strncmp(buf + 5, "jack", 4) != 0)
|
||||||
|
console_msg(0, "wrong user");
|
||||||
|
DG("sending 331");
|
||||||
|
ftp_send(sock, "331 \r\n", 6);
|
||||||
|
ftp_recv(sock, buf, sizeof(buf));
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
int ftp_spawn(int sock)
|
int ftp_spawn(int sock)
|
||||||
{
|
{
|
||||||
int req;
|
int req;
|
||||||
|
|
||||||
DG("new connection");
|
ftp_login(sock);
|
||||||
while ((req = read_req(sock)))
|
while (1)
|
||||||
{
|
{
|
||||||
DG("==== %i NEW REQUEST ====", req);
|
break ;
|
||||||
ftp_cmd(sock, req);
|
(void)req;
|
||||||
DG("==== DONE ====");
|
/* DG("==== %i NEW REQUEST ====", req); */
|
||||||
|
/* ftp_cmd(sock, req); */
|
||||||
|
/* DG("==== DONE ===="); */
|
||||||
}
|
}
|
||||||
DG("end of connection");
|
|
||||||
close(sock);
|
close(sock);
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue