Example #1
0
int DEFAULT_CC
send_logoff(int client, int session_id)
{
	struct session_item* sess;
	xmlNodePtr node, node2;
	xmlDocPtr doc;
	xmlChar* version;
	xmlChar* response;
	xmlChar* session;
	xmlChar* username;
	xmlChar* username_value;
	xmlChar* id;
	xmlChar* id_value;
	xmlChar* status;
	xmlChar* status_value;


	char prop[128];
	int display;

	if (session_id == 0) {
		log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[send_logoff]: "
				"%i is not a valid session id", session_id);
		return 1;
	}

	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[send_logoff]: "
			"request session %i logoff", session_id);

	lock_chain_acquire();
	sess = session_get_by_display(session_id);
	lock_chain_release();

	if( sess == NULL)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[send_logoff]: "
				"The session %i did not exist", session_id);
		xml_send_error(client, "the session id of the request did not exist");
		return 1;
	}

	session_update_status_by_user(sess->name, SESMAN_SESSION_STATUS_TO_DESTROY);
	version = xmlCharStrdup("1.0");
	doc = xmlNewDoc(version);
	if (doc == NULL)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "sesman[send_logoff]: "
				"Unable to create the document");
		g_free(sess);
		xmlFree(version);
		xmlFreeDoc(doc);
		return 1;
	}
	doc->encoding = xmlCharStrdup("UTF-8");
	response = xmlCharStrdup("response");
	session = xmlCharStrdup("session");
	node = xmlNewNode(NULL, response);
	node2 = xmlNewNode(NULL, session);
	sprintf(prop, "%i", display);

	id = xmlCharStrdup("id");
	id_value = xmlCharStrdup(prop);
	username = xmlCharStrdup("username");
	username_value = xmlCharStrdup(sess->name);
	status = xmlCharStrdup("status");
	status_value = xmlCharStrdup("CLOSED");
	xmlSetProp(node2, id, id_value);
	xmlSetProp(node2, username, username_value);
	xmlSetProp(node2, status, status_value);
	xmlAddChild(node, node2);
	xmlDocSetRootElement(doc, node);
	xml_send_info(client, doc);

	xmlFreeDoc(doc);
	xmlFree(version);
	xmlFree(response);
	xmlFree(session);
	xmlFree(username);
	xmlFree(username_value);
	xmlFree(id);
	xmlFree(id_value);
	xmlFree(status);
	xmlFree(status_value);
	g_free(sess);
	return 0;
}
Example #2
0
int
process_request(int client)
{
	int session_id = 0;
	char request_type[128];
	char request_action[128];
	char session_id_string[12];
	char username[256];
	xmlDocPtr doc;

	doc = xml_receive_message(client);
	if ( doc == NULL)
	{
		return close_management_connection(NULL, client);
	}

	if (xml_get_xpath(doc, "/request/@type", request_type) == 1)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[process_request]: "
				"Unable to get the request type");
		xml_send_error(client, "Unable to get the request type");
		return close_management_connection(doc, client);
	}

	if (xml_get_xpath(doc, "/request/@action", request_action) == 1)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[process_request]: "
				"Unable to get the request action");
		xml_send_error(client, "Unable to get the request type");
		return close_management_connection(doc, client);
	}
	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[process_request]: "
				"Request_type : '%s' ", request_type);
	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG_PLUS, "sesman[process_request]: "
				"Request_action : '%s' ", request_action);

	if( g_strcmp(request_type, "sessions") == 0)
	{
		if( g_strcmp(request_action, "list") != 0)
		{
			xml_send_error(client, "For session request type only"
					"the list action is supported");
			return close_management_connection(doc, client);
		}
		send_sessions(client);
		//xml_send_error(client,"test");
		return close_management_connection(doc, client);
	}

	if( g_strcmp(request_type, "session") == 0)
	{
		if (xml_get_xpath(doc, "/request/@id", session_id_string) == 1)
		{
			session_id_string[0] = '\0';
		}
		if (xml_get_xpath(doc, "/request/@username", username) == 1)
		{
			username[0] = '\0';
		}
		if (session_id_string[0] != '\0')
		{
			session_id = g_atoi(session_id_string);
			if(session_id == 0)
			{
				log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
						"%i is not a numeric value", session_id);
				xml_send_error(client, "Unable to convert the session id");
				return close_management_connection(doc, client);
			}
		}
		if( g_strcmp(request_action, "status") == 0)
		{
			send_session(client, session_id, username);
			return close_management_connection(doc, client);
		}
		if( g_strcmp(request_action, "logoff") == 0)
		{
			send_logoff(client, session_id);
			return close_management_connection(doc, client);
		}
		xml_send_error(client, "Unknown message for session");
		return close_management_connection(doc, client);
	}
	if( g_strcmp(request_type, "internal") == 0)
	{
		char username[256];
		if( g_strcmp(request_action, "disconnect") == 0)
		{
			if (xml_get_xpath(doc, "/request/@username", username) == 1)
			{
				log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
						"Unable to get the username\n");
				xml_send_error(client, "Unable to get the username");
				return close_management_connection(doc, client);
			}
			session_update_status_by_user(username, SESMAN_SESSION_STATUS_DISCONNECTED);
			return close_management_connection(doc, client);
		}
		if( g_strcmp(request_action, "logoff") == 0)
		{
			if (xml_get_xpath(doc, "/request/@username", username) == 1)
			{
				log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
						"Unable to get the username\n");
				xml_send_error(client, "Unable to get the username");
				return close_management_connection(doc, client);
			}
			session_update_status_by_user(username, SESMAN_SESSION_STATUS_TO_DESTROY);
			return close_management_connection(doc, client);
		}
		xml_send_error(client, "Unknown message for internal");
		return close_management_connection(doc, client);
	}
	if( g_strcmp(request_type, "user_conf") == 0)
	{
		char username[256];
		char key[128];
		char value[256];
		if (xml_get_xpath(doc, "/request/@username", username) == 1)
		{
			log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
					"Unable to get the username\n");
			xml_send_error(client, "Unable to get the username");
			return close_management_connection(doc, client);
		}
		if (xml_get_xpath(doc, "/request/@key", key) == 1)
		{
			log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
					"Unable to get the key in the request");
			xml_send_error(client, "Unable to get the key in the request");
			return close_management_connection(doc, client);
		}
		if( g_strcmp(request_action, "set") == 0)
		{
			if (xml_get_xpath(doc, "/request/@value", value) == 1)
			{
				log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "sesman[process_request]: "
						"Unable to get the value int the request\n");
				xml_send_error(client, "Unable to get the value in the request");
				return close_management_connection(doc, client);
			}
			if (session_set_user_pref(username, key, value) == 0 )
			{
				xml_send_success(client, "SUCCESS");
			}
			else
			{
				xml_send_error(client, "Unable to set preference");
			}
			return close_management_connection(doc, client);
		}

		if( g_strcmp(request_action, "get") == 0)
		{
			if(session_get_user_pref(username, key, value) == 0)
			{
				xml_send_key_value(client, username, key, value);
			}
			else
			{
				xml_send_error(client, "Unable to get preference");
			}
			return close_management_connection(doc, client);
		}
		xml_send_error(client, "Unknown message for internal");
		return close_management_connection(doc, client);
	}
	xml_send_error(client, "Unknown message");
	return close_management_connection(doc, client);
}
Example #3
0
void DEFAULT_CC
scp_v0_process(struct SCP_CONNECTION* c, struct SCP_SESSION* s)
{
	int display = 0;
	tbus data;
	struct session_item* s_item;

	tc_mutex_lock(session_creation_lock);
	data = auth_userpass(NULL, s->username, s->password);

	#ifdef CHECK_PREMIUM_EDITION
	bool valid = true;
	if (get_module_version(get_module_name()) & PREMIUM_EDITION) {
	  printf("%s %i %i  %i \n", __FUNCTION__, g_time3(), last_time_premium_edition_check, CHECK_INTERVAL);
	  if (((g_time3() - last_time_premium_edition_check) > CHECK_INTERVAL) ||  last_time_premium_edition_check == 0) {
	    printf("%s FOFOFOOF\n", __FUNCTION__);
	    valid = check_premium_edition();
	  }
	}
	if (!valid) {
	  data = 0;
	  scp_v0s_deny_connection(c, "Unable to launch the session\nInvalid License\nPlease contact your administrator\n");
	  tc_mutex_unlock(session_creation_lock);
	  return;
	}
#endif

	if (data == 0)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "User %s failed to authenticate", s->username);
		scp_v0s_deny_connection(c, "Your username or \nyour password is invalid");
		tc_mutex_unlock(session_creation_lock);
		return;
	}
	lock_chain_acquire();
	s_item = session_get_bydata(s->username);
	lock_chain_release();

	if (s_item != 0)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_INFO, "A session for User %s already exist", s->username);
		display = s_item->display;
		if (s_item->status == SESMAN_SESSION_STATUS_TO_DESTROY)
		{
			log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "Session for user %s is in destroy, unable to initialize a new session", s->username);
			scp_v0s_deny_connection(c, "Your last session is currently \nended, retry later");
		}
		else
		{
			session_update_status_by_user(s_item->name, SESMAN_SESSION_STATUS_ACTIVE);
			log_message(&(g_cfg->log), LOG_LEVEL_INFO, "switch from status DISCONNECTED to ACTIVE");
			session_switch_resolution(s->width, s->height, display);
			session_add_client_pid(s_item->name, s->client_pid);

			scp_v0s_allow_connection(c, display);
		}

		auth_end(data);
		tc_mutex_unlock(session_creation_lock);
		return;
	}
	log_message(&(g_cfg->log), LOG_LEVEL_DEBUG, "No session already started for the user %s", s->username);
	if (access_login_allowed(s->username) == 0)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_WARNING, "User %s is not allow to start session", s->username);
		display = 0;
		scp_v0s_deny_connection(c, "You are not allowed\nto start a session\n");

		auth_end(data);
		tc_mutex_unlock(session_creation_lock);
		return;
	}

	log_message(&(g_cfg->log), LOG_LEVEL_INFO, "granted TS access to user %s", s->username);
	if (SCP_SESSION_TYPE_XVNC == s->type)
	{
		log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting Xvnc session for the user %s ...", s->username);
		display = session_start(s->width, s->height, s->bpp, s->username,
				s->password, data, SESMAN_SESSION_TYPE_XVNC,
				s->domain, s->program, s->directory, s->keylayout, s->client_pid, s->use_scim);
	}
	else
	{
		log_message(&(g_cfg->log), LOG_LEVEL_INFO, "starting X11rdp session for the user %s ...", s->username);
		display = session_start(s->width, s->height, s->bpp, s->username,
				s->password, data, SESMAN_SESSION_TYPE_XRDP,
				s->domain, s->program, s->directory, s->keylayout, s->client_pid, s->use_scim);
	}

	auth_end(data);
	if (display == 0)
	{
		data = 0;
		scp_v0s_deny_connection(c, "Unable to launch the session\nPlease contact\nyour administrator\n");
	}
	else
	{
		scp_v0s_allow_connection(c, display);
	}

	tc_mutex_unlock(session_creation_lock);
}