/* This file is part of SLS. Copyright (C) 2008 Sebastien LUTTRINGER SLS is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; version 2 of the License. SLS is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with SLS; if not, write to the Free Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */ #include "sls.hh" #include "client.hh" #include "client_console.hh" #include "client_daemon.hh" static inline Client *login_fail(Connection &c); /******************************************************************************* ** Method of Classes *******************************************************************************/ Client *Client::login(Connection &c) { // read login info string slogin = c.recvln(); string spass = c.recvln(); // FIXME: find better method than fucking magic number char clientbuf[512]; char loginbuf[512]; char passbuf[512]; // cut read data if (sscanf(slogin.c_str(), "%512s %512s\n", clientbuf, loginbuf) != 2) return login_fail(c); if (sscanf(spass.c_str(), "PASS %512s\n", passbuf) != 1) return login_fail(c); // create client Client *real_client; if (strcmp(clientbuf, "HOST") == 0) real_client = new Daemon(c); else if (strcmp(clientbuf, "USER") == 0) real_client = new Console(c); else return login_fail(c); // check login and password and register it in DB if success if (real_client->trust(loginbuf, passbuf) == false) { delete real_client; return login_fail(c); } // Print succefful login std::cout << "CId " << c.getid() << ": " << real_client->type() << " " << loginbuf << " logged from " << c.getremoteip() << " on port " << c.getremoteport() << ".\n"; return real_client; } /******************************************************************************* ** Public methods *******************************************************************************/ Client::Client(Connection &c) : c_ (c) {} Client::~Client() {} /******************************************************************************* ** Local functions *******************************************************************************/ static Client *login_fail(Connection &c) { std::cout << "CId " << c.getid() << ": Bad authentification.\n"; c.sendln("KO"); return 0; }