| 213 | } |
| 214 | |
| 215 | void FtpServerConnection::onCommand(String cmd, String data) |
| 216 | { |
| 217 | auto command = parseCommand(cmd); |
| 218 | switch(command) { |
| 219 | // We ready to quit always :) |
| 220 | case Command::QUIT: |
| 221 | response(221); // Service closing control connection |
| 222 | close(); |
| 223 | break; |
| 224 | |
| 225 | // Strong security check :) |
| 226 | case Command::USER: |
| 227 | // Authenticate or re-authenticate, wiping existing credentials |
| 228 | user = User{}; |
| 229 | user.name = data; |
| 230 | response(331); // User name OK, need password |
| 231 | break; |
| 232 | |
| 233 | case Command::PASS: { |
| 234 | if(!user.name) { |
| 235 | response(332); // Need account for login |
| 236 | } else { |
| 237 | user.role = server.validateUser(user.name.c_str(), data.c_str()); |
| 238 | response(user.isValid() ? 230 : 430); |
| 239 | } |
| 240 | user.name = nullptr; |
| 241 | break; |
| 242 | } |
| 243 | |
| 244 | case Command::SYST: |
| 245 | response(215, F("Windows_NT: Sming Framework")); // Why not? It's look like Windows :) |
| 246 | break; |
| 247 | |
| 248 | case Command::PWD: |
| 249 | case Command::XPWD: { |
| 250 | String s; |
| 251 | s += "\"/"; |
| 252 | s += cwd.c_str(); |
| 253 | s += '"'; |
| 254 | response(257, s); |
| 255 | break; |
| 256 | } |
| 257 | |
| 258 | case Command::PORT: |
| 259 | cmdPort(data); |
| 260 | break; |
| 261 | |
| 262 | case Command::CWD: |
| 263 | case Command::XCWD: { |
| 264 | String path = resolvePath(data.c_str()); |
| 265 | if(!checkFileAccess(path.c_str(), IFS::OpenFlag::Read)) { |
| 266 | break; |
| 267 | } |
| 268 | debug_i("CWD: '%s'", path.c_str()); |
| 269 | FileStat stat; |
| 270 | if(getFileSystem()->stat(path, stat) == FS_OK && stat.isDir()) { |
| 271 | cwd = path; |
| 272 | response(250, F("directory changed to /") + cwd.c_str()); // OK |
nothing calls this directly
no test coverage detected