Fixed FEAT
Fixed PORT memory overflow allocation Added support for specifying directory on LIST/NLST
This commit is contained in:
@@ -129,8 +129,8 @@ public:
|
||||
} else if (cmd == "PORT") {
|
||||
data_sock = socket(AF_INET, SOCK_STREAM, 0);
|
||||
|
||||
unsigned char act_port[2];
|
||||
int act_ip[4], port_dec;
|
||||
unsigned char act_port[2] = {};
|
||||
int act_ip[4] = {}, port_dec;
|
||||
char ip_decimal[40];
|
||||
sscanf(argstr.c_str(), "%d,%d,%d,%d,%d,%d", &act_ip[0], &act_ip[1], &act_ip[2], &act_ip[3], (int*)&act_port[0], (int*)&act_port[1]);
|
||||
sprintf(ip_decimal, "%d.%d.%d.%d", act_ip[0], act_ip[1], act_ip[2], act_ip[3]);
|
||||
@@ -156,7 +156,10 @@ public:
|
||||
submit(550, "Access Denied "+std::to_string(ret));
|
||||
}
|
||||
} else if (cmd == "FEAT") {
|
||||
submit(211, ":\r\n211 END");
|
||||
submit("211-Extensions supported:");
|
||||
submit(" UTF8");
|
||||
submit(" SIZE");
|
||||
submit(211, "END");
|
||||
} else if (cmd == "NOOP") {
|
||||
submit(226, "OK");
|
||||
} else if (cmd == "DELE" || cmd == "RMD") {
|
||||
@@ -171,7 +174,10 @@ public:
|
||||
if (cmd == "LIST" || cmd == "NLST") {
|
||||
submit(150, "Transferring");
|
||||
|
||||
std::string output = filer->list();
|
||||
std::string dirname = "";
|
||||
if (argstr.find_first_of('/') != std::string::npos)
|
||||
dirname = argstr.substr(argstr.find_first_of('/'));
|
||||
std::string output = filer->list(dirname);
|
||||
char out[output.size()] = {0};
|
||||
strncpy(out, output.c_str(), output.size());
|
||||
data_submit(out, output.size());
|
||||
@@ -236,6 +242,17 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
int submit(std::string msg) {
|
||||
std::string out = msg+"\r\n";
|
||||
int bytes = send(control_sock, out.c_str(), out.size(), 0);
|
||||
if (bytes < 0) {
|
||||
logger->print(LOGLEVEL_ERROR, "C(%i) !< %s", control_sock, msg.c_str());
|
||||
return 1;
|
||||
}
|
||||
logger->print(LOGLEVEL_DEBUG, "C(%i) << %s", control_sock, msg.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int submit(int code, std::string msg) {
|
||||
std::string out = std::to_string(code)+" "+msg+"\r\n";
|
||||
int bytes = send(control_sock, out.c_str(), out.size(), 0);
|
||||
|
||||
@@ -166,13 +166,12 @@ public:
|
||||
return 0;
|
||||
}
|
||||
|
||||
// Gets a list of files and folders within current working directory.
|
||||
// Outputs in the format of 'ls -lA'.
|
||||
std::string list() {
|
||||
std::string list(std::string path) {
|
||||
fs::path fpath = fullPath(path);
|
||||
std::ostringstream listStream;
|
||||
// Not checking for pwd existence. If it doesn't exist and we
|
||||
// got this far, we fucked up anyway.
|
||||
for(fs::directory_entry const& p : fs::directory_iterator(fullPath())) {
|
||||
for(fs::directory_entry const& p : fs::directory_iterator(fpath)) {
|
||||
char *line;
|
||||
|
||||
// Stole part of this from here:
|
||||
@@ -222,6 +221,12 @@ public:
|
||||
return listStream.str();
|
||||
}
|
||||
|
||||
// Gets a list of files and folders within current working directory.
|
||||
// Outputs in the format of 'ls -lA'.
|
||||
std::string list() {
|
||||
return list("");
|
||||
}
|
||||
|
||||
private:
|
||||
fs::path root;
|
||||
};
|
||||
Reference in New Issue
Block a user