Exemplo n.º 1
0
  /**
   * \brief Function to treat the ListLocalAccountsServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListLocalAccountsServer options
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void processOptions(UserServer userServer, const UMS_Data::ListLocalAccOptions_ptr& options, std::string& sqlRequest)
  {

    if (! userServer.isAdmin()
        && (! options->getUserId().empty() || options->isAdminListOption())) {
      throw UMSVishnuException(ERRCODE_NO_ADMIN);
    }

    if(! options->isAdminListOption()) {
      addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
    }

    //The admin option
    if (! options->getUserId().empty()) {
      addOptionRequest("users.userid", options->getUserId(), sqlRequest);
    }

    if (! options->getMachineId().empty()) {
      addOptionRequest("machine.machineid", options->getMachineId(), sqlRequest);

      if (! options->isAdminListOption()
          && options->getUserId().empty()) {
        addOptionRequest("users.userid", userServer.getData().getUserId(), sqlRequest);
      }
    }
  }
Exemplo n.º 2
0
/**
 * \brief Function to connect the session
 * \param user The object which manipulates user information
 * \param host The object which manipulates client machine information
 * \param connectOpt The options data structure for connection
 * \return raises an exception on error
 */
int
SessionServer::connectSession(UserServer user, MachineClientServer host, UMS_Data::ConnectOptions* connectOpt) {
  std::string numSubstituteUserId;
  std::string numUserIdToconnect;

  //To record the connection identifier
  msession.setAuthenId(user.getData().getUserId());

  //if the user exist
  if (user.isAuthenticate()) {
    //if a user to substitute is defined
    if (connectOpt->getSubstituteUserId().size() != 0) {
      // if the user is admin
      if (user.isAdmin()) {
        numSubstituteUserId = user.getAttribut("where "
                                               "userid='"+mdatabaseVishnu->escapeData(connectOpt->getSubstituteUserId())+"'");
        //If the user to substitute exist
        if (! user.getNumUserId(connectOpt->getSubstituteUserId()).empty()) {
          numUserIdToconnect = numSubstituteUserId;
          msession.setUserId(connectOpt->getSubstituteUserId());
        } //End If the user to substitute exist
        else {
          UMSVishnuException e(ERRCODE_UNKNOWN_USERID);
          throw e;
        }
      } // END if the user is admin
      else {
        UMSVishnuException e(ERRCODE_NO_ADMIN);
        throw e;
      }
    } //End if a user to substitute is defined

    //if there is not a numSubstituteUserId
    if (numUserIdToconnect.size() == 0) {
      numUserIdToconnect = user.getAttribut("where userid='"+mdatabaseVishnu->escapeData(user.getData().getUserId())+"'"
                                            " and pwd='"+mdatabaseVishnu->escapeData(user.getData().getPassword())+"'");
      msession.setUserId(user.getData().getUserId());
    } //END if There is not a numSubstituteUserId

    generateSessionKey(user.getData().getUserId());
    generateSessionId(user.getData().getUserId());

    //To solve the connection mode
    solveConnectionMode(connectOpt, numUserIdToconnect);

    host.recordMachineClient();
    recordSessionServer(host.getId(), numUserIdToconnect);

  } // END if the user exist
  else {
    UMSVishnuException e(ERRCODE_UNKNOWN_USER);
    throw e;
  }
  return 0;
}//END: connectSession(UserServer, MachineClientServer, ConnectOptions*)
Exemplo n.º 3
0
/**
 * \brief Function to reconnect the session
 * \param user The object which manipulates user information
 * \param host The object which manipulates client machine information
 * \param sessionId The session identifier
 * \return raises an exception on error
 */
int
SessionServer::reconnect(UserServer user, MachineClientServer clientMachineServer,
                         std::string sessionId) {
  msession.setSessionId(sessionId);

  if (! user.isAuthenticate()) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_USER);
  }

  int state = getState(true);
  if (state < 0) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_SESSION_ID);
  }

  if (state != vishnu::SESSION_ACTIVE) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_SESSION_ID);
  }

  int existSessionKey = getSessionkey(clientMachineServer.getId(),
                                      user.getNumUserFromLoginInfo(user.getData().getUserId(),user.getData().getPassword()),
                                      user.isAdmin());

  if (existSessionKey == -1) {
    throw UMSVishnuException (ERRCODE_SESSIONKEY_NOT_FOUND);
  }

  return 0;
}
Exemplo n.º 4
0
  /**
   * \brief Function to treat the listSessionServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListSessionServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListSessionOptions_ptr& options, std::string& query)
  {
    boost::posix_time::ptime pt;
    bool listAll = options->isAdminListOption();

    if (! userServer.isAdmin()
        && (! options->getUserId().empty() || listAll)) {
      throw UMSVishnuException (ERRCODE_NO_ADMIN);
    }

    if(! options->getMachineId().empty()) {
      addOptionRequest("clmachine.name", options->getMachineId(), query);
    }

    if(! options->getUserId().empty()) {
      addOptionRequest("users.userid", options->getUserId(), query);
    } else {
      if (! listAll) {
        addOptionRequest("users.userid", userServer.getData().getUserId(), query);
      }
    }

    int status = options->getStatus();
    if (status == vishnu::STATUS_UNDEFINED) {
      status = vishnu::STATUS_ACTIVE;
    }

    addIntegerOptionRequest("state", status, query);

    if (options->getSessionClosePolicy()) {
      addIntegerOptionRequest("closepolicy", options->getSessionClosePolicy(), query);
    }

    if (options->getSessionInactivityDelay() < 0) {
      throw UMSVishnuException(ERRCODE_INCORRECT_TIMEOUT);
    }

    if (options->getSessionInactivityDelay()) {
      addIntegerOptionRequest("timeout", options->getSessionInactivityDelay(), query);
    }

    if (! options->getSessionId().empty()) {
      addOptionRequest("vsessionid", options->getSessionId(), query);
    }

    time_t startDate = static_cast<time_t>(options->getStartDateOption());
    if (startDate > 0) {
      addTimeRequest("creation", vishnu::timeToTimestamp(startDate), query, ">=");
    }

    time_t endDate = static_cast<time_t>(options->getEndDateOption());
    if (endDate > 0) {
      addTimeRequest("closure", vishnu::timeToTimestamp(endDate), query, "<=");
    }
  }
Exemplo n.º 5
0
/**
 * \brief Function to change the closure connection mode disconnet to timeout
 * \param user The object which manipulates user information
 * \return the new connection parameters are registered on the session data structure
 */
int
SessionServer::disconnetToTimeout(UserServer user) {

  OptionValueServer optionValueServer;
  std::string numuserId;

  //To change the session close policy on CLOSE_ON_TIMEOUT on the database
  mdatabaseVishnu->process("UPDATE vsession SET closepolicy=1"
                           " WHERE sessionkey='"+mdatabaseVishnu->escapeData(msession.getSessionKey())+"';");

  //To change the session close policy on CLOSE_ON_TIMEOUT on the msession object
  msession.setClosePolicy(1);

  numuserId = user.getAttribut("where userid='"+mdatabaseVishnu->escapeData(user.getData().getUserId())+"'"
                               " and pwd='"+mdatabaseVishnu->escapeData(user.getData().getPassword())+"'");

  //To get the timeout
  msession.setTimeout(optionValueServer.getOptionValueForUser(numuserId, TIMEOUT_OPT));
  mdatabaseVishnu->process("UPDATE vsession SET timeout="+convertToString(msession.getTimeout())+
                           " WHERE sessionkey='"+mdatabaseVishnu->escapeData(msession.getSessionKey())+"';");

  return 0;
}
Exemplo n.º 6
0
/**
 * \brief Function to treat the Stop file transfer options
 * \param options the object which contains the Stop file transfers options values
 * \param sqlRequest the sql data base request
 * \return raises an exception on error
 */
void
FileTransferServer::processOptions(const FMS_Data::StopTransferOptions& options,
                                   std::string& sqlRequest) {

  std::string transferId(options.getTransferId()),machineName(options.getFromMachineId()),userId(options.getUserId());

  //To check if the transferId is defined
  if (transferId.size() != 0) {

    if (transferId.compare("all")!=0 && transferId.compare("ALL")!=0){
      //To check the transfer Id
      FileTransferServer::checkTransferId(options.getTransferId());
      //To add the transferId on the request
      FileTransferServer::addOptionRequest("transferId", options.getTransferId(), sqlRequest);

    }

  }

  //To check if the fromMachineId is defined
  if (machineName.size() != 0) {

    sqlRequest.append(" and (sourceMachineId='"+FileTransferServer::getDatabaseInstance()->escapeData(machineName)+"'"+" or destinationMachineId='"+FileTransferServer::getDatabaseInstance()->escapeData(machineName)+"')");
  }

  //Creation of the object user
  UserServer userServer = UserServer(msessionServer);

  userServer.init();

  //To check if the userId is defined
  if (userId.size() != 0) {

    if (!userServer.isAdmin()) {
      UMSVishnuException e (ERRCODE_NO_ADMIN);
      throw e;
    }

    if (userId.compare("all")!=0 && userId.compare("ALL")!=0){
      //To check the user Id
      FileTransferServer::checkUserId(options.getUserId());

      //To add the userId on the request
      FileTransferServer::addOptionRequest("userId", userId, sqlRequest);
    }
  } else {
    FileTransferServer::addOptionRequest("userId", userServer.getData().getUserId(), sqlRequest);
  }
}
Exemplo n.º 7
0
  /**
   * \brief Function to treat the ListMachinesServer options
   * \fn void processOptions(UserServer userServer,
   *                         const UMS_Data::ListMachineOptions_ptr& options,
   *                         std::string& sqlRequest)
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListMachinesServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void processOptions(UserServer userServer, const UMS_Data::ListMachineOptions_ptr& options, std::string& sqlRequest)
  {
    std::string sqlListofMachinesWithJointure = "SELECT machineid, name, site, machine.status, lang, description, userid "
    " from machine, description, account, users where machine.nummachineid = description.machine_nummachineid "
    " and account.machine_nummachineid=machine.nummachineid and account.users_numuserid=users.numuserid";

    std::string sqlListofMachinesIntial =  sqlRequest;

    size_t userIdSize = options->getUserId().size();
    size_t machineIdSize = options->getMachineId().size();
    bool isListAll = options->isListAllMachine();

    if ((!userServer.isAdmin()) && userIdSize!=0) {
      UMSVishnuException e (ERRCODE_NO_ADMIN);
      throw e;
    }

    if(!isListAll) {
       sqlRequest = sqlListofMachinesWithJointure;
       addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
    }

    //The admin option
    if(userIdSize!=0) {
      //To check if the user id is correct
      checkUserId(options->getUserId());

      sqlRequest = sqlListofMachinesWithJointure;
      addOptionRequest("userid", options->getUserId(), sqlRequest);
    }

    if(machineIdSize!=0) {
      //To check if the machine id is correct
      checkMachineId(options->getMachineId());

      if(!isListAll && userIdSize==0) {
         sqlRequest=sqlListofMachinesIntial;
      }
      addOptionRequest("machineid", options->getMachineId(), sqlRequest);
    }

 }
Exemplo n.º 8
0
  /**
   * \brief Function to treat the ListCommandsServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListCommandsServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListCmdOptions_ptr& options, std::string& sqlRequest)
  {
    boost::posix_time::ptime pt;
    bool listAll = options->isAdminListOption();

    if (! userServer.isAdmin()
        && (! options->getUserId().empty() || listAll)) {
      throw UMSVishnuException (ERRCODE_NO_ADMIN);
    }

    if(! options->getUserId().empty()) {
      addOptionRequest("users.numuserid", getNumUser(options->getUserId()), sqlRequest);
    } else {
      if(! listAll) {
        addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
      }
    }

    if (! options->getSessionId().empty()) {
      checkSessionId(options->getSessionId());

      addOptionRequest("vsessionid", options->getSessionId(), sqlRequest);
    }

    time_t startDate = static_cast<time_t>(options->getStartDateOption());
    if (startDate != -1) {
      pt =  boost::posix_time::from_time_t(startDate);
      std::string startDateStr =  boost::posix_time::to_iso_string(pt);
      addTimeRequest("starttime", startDateStr, sqlRequest, ">=");
    }

    time_t endDate = static_cast<time_t>(options->getEndDateOption());
    if(endDate!=-1) {
      pt =  boost::posix_time::from_time_t(endDate);
      std::string endDateStr =  boost::posix_time::to_iso_string(pt);
      addTimeRequest("endtime", endDateStr, sqlRequest, "<=");
    }
  }
Exemplo n.º 9
0
  /**
   * \brief Function to treat the ListMachinesServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListMachinesServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListMachineOptions_ptr& options, std::string& sqlRequest)
  {
    std::string sqlJoinLstMachines = boost::str(boost::format("SELECT DISTINCT machineid, address, machine.status, description, userid "
                                                              " FROM machine, account, users"
                                                              " WHERE account.machine_nummachineid = machine.nummachineid "
                                                              " AND account.users_numuserid = users.numuserid "
                                                              " AND machine.status != %1%"
                                                              " AND account.status != %1%"
                                                              " AND users.status   != %1%"
                                                              ) % vishnu::STATUS_DELETED);
    std::string sqlListofMachinesIntial = sqlRequest;
    bool isListAll = options->isListAllMachine();

    if (! userServer.isAdmin() && ! options->getUserId().empty()) {
      throw UMSVishnuException (ERRCODE_NO_ADMIN);
    }

    if(! isListAll) {
      sqlRequest = sqlJoinLstMachines;
      addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
    }

    //The admin option
    if (! options->getUserId().empty()) {
      sqlRequest = sqlJoinLstMachines;
      addOptionRequest("users.numuserid", getNumUser(options->getUserId()), sqlRequest);
    }

    if (! options->getMachineId().empty()) {
      getNumMachine( options->getMachineId() );

      if(! isListAll && options->getUserId().empty()) {
        sqlRequest = sqlListofMachinesIntial;
      }

      addOptionRequest("machineid", options->getMachineId(), sqlRequest);
    }
  }
Exemplo n.º 10
0
/**
 * \brief Function to connect the session
 * \param user The object which manipulates user information
 * \param host The object which manipulates client machine information
 * \param connectOpt The options data structure for connection
 * \return raises an exception on error
 */
int
SessionServer::connectSession(UserServer user, MachineClientServer host, UMS_Data::ConnectOptions* connectOpt) {

  std::string numUserToconnect;

  msession.setAuthenId( user.getData().getUserId() );


  if (! user.isAuthenticate()) {
    throw UMSVishnuException(ERRCODE_UNKNOWN_USER);
  }

  if (! connectOpt->getSubstituteUserId().empty()) {

    user.checkUserId( connectOpt->getSubstituteUserId());

    if (! user.isAdmin()) {
      throw UMSVishnuException (ERRCODE_NO_ADMIN);
    }

    numUserToconnect = user.getNumUserFromId( connectOpt->getSubstituteUserId() );
    if (numUserToconnect.empty()) {
      throw UMSVishnuException(ERRCODE_UNKNOWN_USER, connectOpt->getSubstituteUserId());
    }

    msession.setUserId(connectOpt->getSubstituteUserId());
  }

  //if there is not a numSubstituteUserId
  if (numUserToconnect.empty()) {
    numUserToconnect = user.getNumUserFromLoginInfo(user.getData().getUserId(), user.getData().getPassword());
    msession.setUserId(user.getData().getUserId());
  }

  generateSessionKey(user.getData().getUserId());
  generateSessionId(user.getData().getUserId());

  //To solve the connection mode
  solveConnectionMode(connectOpt);

  host.recordMachineClient();
  recordSessionServer(host.getId(), numUserToconnect);

  return 0;
}
Exemplo n.º 11
0
/**
* \brief Function to close the session
* \return raises an exception on error
*/
int
SessionServer::close() {
  UserServer user = UserServer(SessionServer(msession.getSessionKey()));
  CommandServer commanderServer = CommandServer(SessionServer(msession.getSessionKey()));

  // initialize and check the user
  user.init();
  if (! user.exist()) {
    throw UMSVishnuException (ERRCODE_UNKNOWN_USER, user.getData().getUserId());
  }

  if (getState() == vishnu::SESSION_CLOSED) {
    throw UMSVishnuException (ERRCODE_SESSIONKEY_EXPIRED);
  }

  if (! commanderServer.isRunning()) {
    mdatabase->process(boost::str(boost::format("UPDATE vsession"
                                                " SET state=%1%"
                                                " WHERE sessionkey='%2%';")
                                  % vishnu::SESSION_CLOSED
                                  % mdatabase->escapeData(msession.getSessionKey())));

    mdatabase->process(boost::str(boost::format("UPDATE vsession"
                                                " SET closure=CURRENT_TIMESTAMP"
                                                " WHERE sessionkey='%1%';")
                                  % mdatabase->escapeData(msession.getSessionKey())));
  } else {
    int closePolicy = vishnu::convertToInt(getAttributFromSessionKey(msession.getSessionKey(), "closepolicy"));
    if (closePolicy == vishnu::CLOSE_ON_DISCONNECT) {
      disconnetToTimeout();
    } else {
      throw  UMSVishnuException (ERRCODE_COMMAND_RUNNING);
    }
  }

  return 0;
}
Exemplo n.º 12
0
bool
ShellExporter::isAllowed(string oldSession, UserServer muser) {
  bool res = false;
  string req = "select * from vsession, users where vsession.vsessionid='"+oldSession+"' and vsession.users_numuserid=users.numuserid and users.userid='"+muser.getData().getUserId()+"'";
  try {
    boost::scoped_ptr<DatabaseResult> result(mdatabase->getResult(req.c_str()));
    res = (result->getNbTuples()>0);
  } catch(SystemException &e) {
    return res;
  }
  return res;
}
Exemplo n.º 13
0
  /**
   * \brief Function to treat the listSessionServer options
   * \param userServer the object which encapsulates user information
   * \param options the object which contains the ListSessionServer options values
   * \param sqlRequest the sql data base request
   * \return raises an exception on error
   */
  void
  processOptions(UserServer userServer, const UMS_Data::ListSessionOptions_ptr& options, std::string& sqlRequest)
  {
    boost::posix_time::ptime pt;
    size_t userIdSize = options->getUserId().size();
    bool listAll = options->isAdminListOption();

    if ((!userServer.isAdmin()) && (userIdSize!=0 || listAll)) {
      UMSVishnuException e (ERRCODE_NO_ADMIN);
      throw e;
    }

    if(options->getMachineId().size()!=0) {
      //To check if the name of the machine is correct
      checkClientMachineName(options->getMachineId());

      sqlRequest = "SELECT vsessionid, userid, sessionkey, state, closepolicy, timeout, lastconnect,"
                   "creation, closure, authid from vsession, users, clmachine where vsession.users_numuserid=users.numuserid"
                   " and vsession.clmachine_numclmachineid=clmachine.numclmachineid";
      addOptionRequest("name", options->getMachineId(), sqlRequest);
    }

    if(userIdSize!=0) {
      //To check if the user id is correct
      checkUserId(options->getUserId());

      addOptionRequest("userid", options->getUserId(), sqlRequest);
    } else {
      if(!listAll) {
        addOptionRequest("userid", userServer.getData().getUserId(), sqlRequest);
      }
    }

    int status = options->getStatus();
    if (status == vishnu::STATUS_UNDEFINED) {
      status = vishnu::STATUS_ACTIVE;
    }
    //To check the status value
    checkStatus(status);

    addIntegerOptionRequest("state", status, sqlRequest);

    int closePolicy = options->getSessionClosePolicy();
    //To check the closePolicy value
    checkClosePolicy(closePolicy);

    if(closePolicy) {
      addIntegerOptionRequest("closepolicy", closePolicy, sqlRequest);
    }

    int timeOut = options->getSessionInactivityDelay();
    if(timeOut < 0) {
      throw UMSVishnuException(ERRCODE_INCORRECT_TIMEOUT);
    }
    if(timeOut) {
      addIntegerOptionRequest("timeout", timeOut, sqlRequest);
    }

    if(options->getSessionId().size()!=0) {
      //To check if the session id is correct
      checkSessionId(options->getSessionId());

      addOptionRequest("vsessionid", options->getSessionId(), sqlRequest);
    }

    time_t startDate = static_cast<time_t>(options->getStartDateOption());
    if(startDate!=-1) {
      pt =  boost::posix_time::from_time_t(startDate);
      std::string startDateStr =  boost::posix_time::to_iso_string(pt);
      addTimeRequest("creation", startDateStr, sqlRequest, ">=");
    }

    time_t endDate = static_cast<time_t>(options->getEndDateOption());
    if(endDate!=-1) {
      pt =  boost::posix_time::from_time_t(endDate);
      std::string endDateStr =  boost::posix_time::to_iso_string(pt);
      addTimeRequest("closure", endDateStr, sqlRequest, "<=");
    }

  }
Exemplo n.º 14
0
/**
 * \brief Function to reconnect the session
 * \param user The object which manipulates user information
 * \param host The object which manipulates client machine information
 * \param sessionId The session identifier
 * \return raises an exception on error
 */
int
SessionServer::reconnect(UserServer user, MachineClientServer host,
                         std::string sessionId) {
  msession.setSessionId(sessionId);

  //If the user exists
  if (user.isAuthenticate()) {
    int state = getState(true);
    // -1 is an error code of getState when nohting has found
    if (state != -1) {
      //if the session is active
      if (state == 1) {
        int existSessionKey = 0;

        //if user is an admin
        if (user.isAdmin()) {
          existSessionKey = getSessionkey("", "", true);
        } //END if user is an admin
        else {
          existSessionKey = getSessionkey(host.getId(), user.getAttribut("where userid='"+mdatabaseVishnu->escapeData(user.getData().getUserId())+"'"
                                                                         " and pwd='"+mdatabaseVishnu->escapeData(user.getData().getPassword())+"'"));
        }
        //if there is no session key with the previous parameters
        if (existSessionKey == -1) {
          UMSVishnuException e(ERRCODE_SESSIONKEY_NOT_FOUND);
          throw e;
        }
      }//if the session is active
      else {
        UMSVishnuException e(ERRCODE_SESSIONKEY_EXPIRED);
        throw e;
      }
    }//END if state != -1
    else {
      UMSVishnuException e(ERRCODE_UNKNOWN_SESSION_ID);
      throw e;
    }
  } //END IF user.exist
  else {
    UMSVishnuException e(ERRCODE_UNKNOWN_USER);
    throw e;
  }
  return 0;
}//END: reconnect(UserServer, MachineClientServer, string sessionId)