Beispiel #1
0
	void TaskSwitchTo::cleanUpOnError()
	{
		SessionPtr currentSession = APP_CONTEXT.getSessionStore()->getSession(m_NewSessionId);

		if (currentSession)
		{
			if (currentSession->getConnectState() == WTSActive)
			{
				// this was a new session for the connection, remove it
				currentSession->stopModule();
				APP_CONTEXT.getSessionStore()->removeSession(currentSession->getSessionId());
				WLog_Print(logger_taskSwitchTo, WLOG_INFO, "TaskSwitchTo: cleaning up session with sessionId %d", m_NewSessionId);
			}
			else if (currentSession->getConnectState() == WTSConnectQuery)
			{
				// was a previous disconnected session
				currentSession->setConnectState(WTSDisconnected);
			}
		}
		else
		{
			WLog_Print(logger_taskSwitchTo, WLOG_ERROR, "TaskSwitchTo: no session was found for sessionId %d!", m_NewSessionId);
		}

		ConnectionPtr connection = APP_CONTEXT.getConnectionStore()->getConnection(m_ConnectionId);

		if (connection) {
			connection->setAbout2SwitchSessionId(0);
		}
	}
Beispiel #2
0
	void TaskSwitchTo::run()
	{
		CallOutSwitchTo switchToCall;

		switchToCall.setServiceEndpoint(m_ServiceEndpoint);
		switchToCall.setConnectionId(m_ConnectionId);

		APP_CONTEXT.getRpcOutgoingQueue()->addElement(&switchToCall);
		WaitForSingleObject(switchToCall.getAnswerHandle(), INFINITE);

		if (switchToCall.getResult() != 0) {
			WLog_Print(logger_taskSwitchTo, WLOG_ERROR, "TaskSwitchTo answer: RPC error %d!", switchToCall.getResult());
			return cleanUpOnError();
		}

		if (switchToCall.decodeResponse()) {
			//
			WLog_Print(logger_taskSwitchTo, WLOG_ERROR, "TaskSwitchTo: decoding of switchto answer failed!");
			return cleanUpOnError();
		}
		if (!switchToCall.isSuccess()) {
			WLog_Print(logger_taskSwitchTo, WLOG_ERROR, "TaskSwitchTo: switching in FreeRDS failed!");
			return cleanUpOnError();
		}
		SessionPtr currentSession;

		if (m_OldSessionId != 0)
		{
			currentSession = APP_CONTEXT.getSessionStore()->getSession(m_OldSessionId);

			if (currentSession) {
				currentSession->stopModule();
				APP_CONTEXT.getSessionStore()->removeSession(currentSession->getSessionId());
				WLog_Print(logger_taskSwitchTo, WLOG_INFO, "TaskSwitchTo: session with sessionId %d was stopped!", m_OldSessionId);
			}
			else
			{
				WLog_Print(logger_taskSwitchTo, WLOG_ERROR, "TaskSwitchTo: no session was found for sessionId %d!", m_OldSessionId);
			}
		}
		else
		{
			WLog_Print(logger_taskSwitchTo, WLOG_ERROR, "TaskSwitchTo: no oldSessionId was set!");
		}

		ConnectionPtr connection = APP_CONTEXT.getConnectionStore()->getConnection(m_ConnectionId);

		if (connection) {
			connection->setSessionId(m_NewSessionId);
			connection->setAbout2SwitchSessionId(0);
		}

		return;
	}
Beispiel #3
0
	SessionPtr Application::startSession(Request& request, const char* login)
	{
		Synchronize on (*this);

		cleanSessionCache();

		SessionPtr out;
		db::ConnectionPtr db = request.dbConn();
		if (db.get())
			out = Session::startSession(db, m_userInfoFactory, login);
		// TODO: limits needed, or DoS eminent
		if (out.get())
			m_sessions.insert(std::make_pair(out->getSessionId(), std::make_pair(out->getStartTime(), out)));

		return out;
	}
	int CallInAuthenticateUser::getUserSession()
	{
		SessionPtr currentSession;
		bool reconnectAllowed;

		if (!APP_CONTEXT.getPropertyManager()->getPropertyBool("session.reconnect", reconnectAllowed)) {
			reconnectAllowed = true;
		}

		if (reconnectAllowed)
		{
			currentSession = APP_CONTEXT.getSessionStore()->getFirstDisconnectedSessionUserName(mUserName, mDomainName);
			if (currentSession)
			{
				WLog_Print(logger_CallInAuthenticateUser, WLOG_DEBUG,
					"found disconnected session - sessionId=%lu, state=%lu",
					currentSession->getSessionId(), currentSession->getConnectState());
			}
		}

		if ((!currentSession) || (currentSession->getConnectState() != WTSDisconnected))
		{
			// create new Session for this request
			currentSession = APP_CONTEXT.getSessionStore()->createSession();

			WLog_Print(logger_CallInAuthenticateUser, WLOG_DEBUG,
				"creating new session - sessionId=%lu",
				currentSession->getSessionId());

			currentSession->setUserName(mUserName);
			currentSession->setDomain(mDomainName);

			if (!currentSession->generateUserToken())
			{
				WLog_Print(logger_CallInAuthenticateUser, WLOG_ERROR,
					"generateUserToken failed for user %s with domain %s",
					mUserName.c_str(), mDomainName.c_str());
				mResult = 1;// will report error with answer
				return 1;
			}

			if (!currentSession->generateEnvBlockAndModify())
			{
				WLog_Print(logger_CallInAuthenticateUser, WLOG_ERROR,
					"generateEnvBlockAndModify failed for user %s with domain %s",
					mUserName.c_str(), mDomainName.c_str());
				mResult = 1;// will report error with answer
				return 1;
			}
			std::string moduleConfigName;

			if (!APP_CONTEXT.getPropertyManager()->getPropertyString("module", moduleConfigName)) {
				moduleConfigName = "X11";
			}
			currentSession->setModuleConfigName(moduleConfigName);
		}
		else
		{
			WLog_Print(logger_CallInAuthenticateUser, WLOG_DEBUG,
				"connecting to disconnected session - sessionId=%lu",
				currentSession->getSessionId());

			currentSession->setConnectState(WTSConnectQuery);
		}

		UINT32 connectionId = APP_CONTEXT.getConnectionStore()->getConnectionIdForSessionId(mSessionId);
		APP_CONTEXT.getConnectionStore()->getOrCreateConnection(connectionId)->setAbout2SwitchSessionId(currentSession->getSessionId());

		if (currentSession->getConnectState() == WTSDown)
		{
			std::string pipeName;
			if (!currentSession->startModule(pipeName))
			{
				WLog_Print(logger_CallInAuthenticateUser, WLOG_ERROR,
					"ModuleConfig %s does not start properly for user %s in domain %s",
					currentSession->getModuleConfigName().c_str(), mUserName.c_str(), mDomainName.c_str());
				mResult = 1;// will report error with answer
				return 1;
			}
		}

		WLog_Print(logger_CallInAuthenticateUser, WLOG_DEBUG,
			"switching from session %lu to session %lu",
			mSessionId, currentSession->getSessionId());

		TaskSwitchToPtr switchToTask = TaskSwitchToPtr(new TaskSwitchTo());
		switchToTask->setConnectionId(connectionId);
		switchToTask->setServiceEndpoint(currentSession->getPipeName());
		switchToTask->setOldSessionId(mSessionId);
		switchToTask->setNewSessionId(currentSession->getSessionId());
		APP_CONTEXT.addTask(switchToTask);

		return 0;
	}