looks good. need to come back for norme and final testing
This commit is contained in:
parent
99972b4f8e
commit
e10ab459dc
4 changed files with 28 additions and 3 deletions
|
|
@ -25,6 +25,7 @@
|
||||||
|
|
||||||
# include <sys/mman.h>
|
# include <sys/mman.h>
|
||||||
# include <sys/wait.h>
|
# include <sys/wait.h>
|
||||||
|
# include <limits.h>
|
||||||
|
|
||||||
typedef struct s_cmd_map t_cmd_map;
|
typedef struct s_cmd_map t_cmd_map;
|
||||||
|
|
||||||
|
|
@ -46,6 +47,8 @@ enum e_ftp
|
||||||
FILENAME_OK = 700,
|
FILENAME_OK = 700,
|
||||||
NO_SUCH_FILE,
|
NO_SUCH_FILE,
|
||||||
TRANSFER_START,
|
TRANSFER_START,
|
||||||
|
CD_DIR_NOT_FOUND,
|
||||||
|
CD_RESTRICTED_DIR,
|
||||||
ABORT = 800,
|
ABORT = 800,
|
||||||
ERR_READ,
|
ERR_READ,
|
||||||
ERR_STAT,
|
ERR_STAT,
|
||||||
|
|
@ -57,6 +60,8 @@ enum e_ftp
|
||||||
extern char **g_av;
|
extern char **g_av;
|
||||||
extern int g_debug;
|
extern int g_debug;
|
||||||
extern t_cmd_map g_cli_cmd[];
|
extern t_cmd_map g_cli_cmd[];
|
||||||
|
extern char g_rootdir[PATH_MAX];
|
||||||
|
|
||||||
|
|
||||||
int ftp_daemon(int sock);
|
int ftp_daemon(int sock);
|
||||||
int ftp_spawn(int sock);
|
int ftp_spawn(int sock);
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ int cli_do_cd(int sock, char **av)
|
||||||
return (console_msg(-1, "usage: cd <path>"));
|
return (console_msg(-1, "usage: cd <path>"));
|
||||||
if (req_init(sock, REQUEST_CD))
|
if (req_init(sock, REQUEST_CD))
|
||||||
return (1);
|
return (1);
|
||||||
|
console_msg(0, "sending %s", av[1]);
|
||||||
write(sock, av[1], ft_strlen(av[1]));
|
write(sock, av[1], ft_strlen(av[1]));
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -1,17 +1,34 @@
|
||||||
#include "ft_p.h"
|
#include "ft_p.h"
|
||||||
|
|
||||||
|
char g_rootdir[PATH_MAX];
|
||||||
|
|
||||||
int serv_do_cd(int sock)
|
int serv_do_cd(int sock)
|
||||||
{
|
{
|
||||||
char *oldpwd;
|
|
||||||
char path[MAXLINE];
|
char path[MAXLINE];
|
||||||
|
char *abspath;
|
||||||
int ret;
|
int ret;
|
||||||
|
char *ok;
|
||||||
|
|
||||||
if ((ret = read(sock, path, MAXLINE)) < 0)
|
if ((ret = read(sock, path, MAXLINE)) < 0)
|
||||||
return (CMD_FAIL);
|
return (CMD_FAIL);
|
||||||
|
path[ret] = 0;
|
||||||
|
|
||||||
DG("received 'cd %s' command", path);
|
DG("received 'cd %s' command", path);
|
||||||
|
|
||||||
oldpwd = getcwd(NULL, 0);
|
ok = NULL;
|
||||||
(void)oldpwd;
|
if (!(abspath = realpath(path, ok)))
|
||||||
|
return (CD_DIR_NOT_FOUND);
|
||||||
|
|
||||||
|
ft_strcpy(path, abspath);
|
||||||
|
if (!*abspath)
|
||||||
|
return (CD_DIR_NOT_FOUND);
|
||||||
|
|
||||||
|
ft_strdel(&abspath);
|
||||||
|
|
||||||
|
DG("absolute path is '%s'", path);
|
||||||
|
DG("root dir is '%s'", g_rootdir);
|
||||||
|
|
||||||
|
if (!ft_strstr(path, g_rootdir))
|
||||||
|
return (CD_RESTRICTED_DIR);
|
||||||
return(chdir(path) ? CMD_FAIL : CMD_SUCCESS);
|
return(chdir(path) ? CMD_FAIL : CMD_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@
|
||||||
#define FTP_SERVER_USAGE "%s <port>"
|
#define FTP_SERVER_USAGE "%s <port>"
|
||||||
|
|
||||||
char **g_av = NULL;
|
char **g_av = NULL;
|
||||||
|
char g_rootdir[PATH_MAX];
|
||||||
t_itof g_ftp_cmd[] =
|
t_itof g_ftp_cmd[] =
|
||||||
{
|
{
|
||||||
{REQUEST_FILE, serv_do_get},
|
{REQUEST_FILE, serv_do_get},
|
||||||
|
|
@ -94,6 +95,7 @@ int main(int ac, char **av)
|
||||||
int sock;
|
int sock;
|
||||||
|
|
||||||
g_av = av;
|
g_av = av;
|
||||||
|
getcwd(g_rootdir, PATH_MAX);
|
||||||
if (ac != 2)
|
if (ac != 2)
|
||||||
ft_usage(FTP_SERVER_USAGE, av[0]);
|
ft_usage(FTP_SERVER_USAGE, av[0]);
|
||||||
port = ft_atoi(av[1]);
|
port = ft_atoi(av[1]);
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue