2023-03-17 15:10:52 +03:00
|
|
|
/**
|
|
|
|
* xrdp: A Remote Desktop Protocol server.
|
|
|
|
*
|
2023-04-24 17:32:00 +03:00
|
|
|
* Copyright (C) Jay Sorg 2004-2023
|
2023-03-17 15:10:52 +03:00
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
2023-03-09 18:40:56 +03:00
|
|
|
* @file session_list.h
|
|
|
|
* @brief Session list management definitions
|
2023-03-17 15:10:52 +03:00
|
|
|
* @author Jay Sorg, Simone Fedele
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
2023-03-09 18:40:56 +03:00
|
|
|
#ifndef SESSION_LIST_H
|
|
|
|
#define SESSION_LIST_H
|
2023-03-17 15:10:52 +03:00
|
|
|
|
2023-04-24 17:32:00 +03:00
|
|
|
#include <sys/types.h>
|
2023-03-17 15:10:52 +03:00
|
|
|
|
|
|
|
#include "guid.h"
|
|
|
|
#include "scp_application_types.h"
|
|
|
|
#include "xrdp_constants.h"
|
|
|
|
|
2023-04-24 17:32:00 +03:00
|
|
|
enum session_state
|
2023-03-17 15:10:52 +03:00
|
|
|
{
|
2023-04-24 17:32:00 +03:00
|
|
|
/**
|
|
|
|
* Session definition is little more than a sesexec process. We're
|
|
|
|
* waiting for more details of the session from sesexec */
|
|
|
|
E_SESSION_STARTING,
|
|
|
|
/** Session is fully active */
|
|
|
|
E_SESSION_RUNNING
|
2023-03-17 15:10:52 +03:00
|
|
|
};
|
|
|
|
|
2023-03-09 18:40:56 +03:00
|
|
|
/**
|
|
|
|
* Object describing a session
|
2023-04-24 17:32:00 +03:00
|
|
|
*
|
|
|
|
* Unless otherwide noted, fields are only valid if
|
|
|
|
* the status is E_SESSION_RUNNING
|
2023-03-09 18:40:56 +03:00
|
|
|
*/
|
2023-03-17 15:10:52 +03:00
|
|
|
struct session_item
|
|
|
|
{
|
2023-04-24 17:32:00 +03:00
|
|
|
enum session_state state;
|
|
|
|
struct trans *sesexec_trans; // trans for sesexec process. Always valid.
|
|
|
|
pid_t sesexec_pid; // pid for sesexec process. Always valid
|
|
|
|
/**
|
|
|
|
* May be valid if known when the session is starting, otherwise -1 */
|
2023-03-17 15:10:52 +03:00
|
|
|
int display;
|
2023-04-24 17:32:00 +03:00
|
|
|
uid_t uid;
|
2023-03-17 15:10:52 +03:00
|
|
|
enum scp_session_type type;
|
2023-04-24 17:32:00 +03:00
|
|
|
unsigned short start_width;
|
|
|
|
unsigned short start_height;
|
|
|
|
unsigned char bpp;
|
2023-03-17 15:10:52 +03:00
|
|
|
struct guid guid;
|
2023-04-24 17:32:00 +03:00
|
|
|
char start_ip_addr[MAX_PEER_ADDRSTRLEN];
|
|
|
|
time_t start_time;
|
2023-03-17 15:10:52 +03:00
|
|
|
};
|
|
|
|
|
2023-03-22 19:25:28 +03:00
|
|
|
/**
|
|
|
|
* Initialise the module
|
|
|
|
* @return 0 for success
|
|
|
|
*
|
|
|
|
* Errors are logged
|
|
|
|
*/
|
|
|
|
int
|
2023-04-24 17:32:00 +03:00
|
|
|
session_list_init(void);
|
2023-03-22 19:25:28 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Clean up the module on program exit
|
|
|
|
*/
|
|
|
|
void
|
2023-04-24 17:32:00 +03:00
|
|
|
session_list_cleanup(void);
|
2023-03-17 15:10:52 +03:00
|
|
|
|
2023-03-09 18:40:56 +03:00
|
|
|
/**
|
|
|
|
* Returns the number of sessions currently active
|
|
|
|
* @return Session count
|
|
|
|
*/
|
|
|
|
unsigned int
|
2023-03-24 13:53:23 +03:00
|
|
|
session_list_get_count(void);
|
2023-03-17 15:10:52 +03:00
|
|
|
|
|
|
|
/**
|
2023-04-24 17:32:00 +03:00
|
|
|
* Allocates a new session on the list
|
2023-03-22 19:25:28 +03:00
|
|
|
*
|
2023-04-24 17:32:00 +03:00
|
|
|
* state will be E_SESSION_STARTING. Other data must be filled in by
|
|
|
|
* the caller as appropriate.
|
2023-03-22 19:25:28 +03:00
|
|
|
*
|
|
|
|
* @return pointer to new session object or NULL for no memory
|
|
|
|
*
|
2023-04-24 17:32:00 +03:00
|
|
|
* After allocating the session, you must initialise the sesexec_trans field
|
|
|
|
* with a valid transport.
|
2023-03-22 19:25:28 +03:00
|
|
|
*
|
2023-04-24 17:32:00 +03:00
|
|
|
* The session is removed by session_check_wait_objs() when the transport
|
|
|
|
* goes down (or wasn't allocated in the first place).
|
2023-03-17 15:10:52 +03:00
|
|
|
*/
|
2023-03-22 19:25:28 +03:00
|
|
|
struct session_item *
|
2023-04-24 17:32:00 +03:00
|
|
|
session_list_new(void);
|
2023-03-17 15:10:52 +03:00
|
|
|
|
|
|
|
/**
|
2023-03-09 18:40:56 +03:00
|
|
|
* Get the next available display
|
2023-04-24 17:32:00 +03:00
|
|
|
*
|
|
|
|
* The display isn't reserved until the caller has allocated a new session
|
|
|
|
* (with session_list_new()) and put the new display in it.
|
2023-03-17 15:10:52 +03:00
|
|
|
*/
|
2023-03-09 18:40:56 +03:00
|
|
|
int
|
2023-03-24 13:53:23 +03:00
|
|
|
session_list_get_available_display(void);
|
2023-03-09 18:40:56 +03:00
|
|
|
|
2023-03-17 15:10:52 +03:00
|
|
|
/**
|
|
|
|
*
|
2023-03-09 18:40:56 +03:00
|
|
|
* @brief finds a session matching the supplied parameters
|
|
|
|
* @return session data or 0
|
2023-03-17 15:10:52 +03:00
|
|
|
*
|
|
|
|
*/
|
2023-03-09 18:40:56 +03:00
|
|
|
struct session_item *
|
2023-03-24 13:53:23 +03:00
|
|
|
session_list_get_bydata(uid_t uid,
|
|
|
|
enum scp_session_type type,
|
|
|
|
unsigned short width,
|
|
|
|
unsigned short height,
|
|
|
|
unsigned char bpp,
|
|
|
|
const char *ip_addr);
|
2023-03-17 15:10:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief retrieves session descriptions
|
2023-04-24 17:32:00 +03:00
|
|
|
* @param uid the UID for the descriptions
|
|
|
|
* @param[out] cnt The number of sessions returned
|
|
|
|
* @param flags Future expansion
|
2023-03-17 15:10:52 +03:00
|
|
|
* @return A block of session descriptions
|
|
|
|
*
|
|
|
|
* Pass the return result to free_session_info_list() after use
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
struct scp_session_info *
|
2023-04-24 17:32:00 +03:00
|
|
|
session_list_get_byuid(uid_t uid, unsigned int *cnt, unsigned int flags);
|
2023-03-17 15:10:52 +03:00
|
|
|
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @brief Frees the result of session_get_byuser()
|
|
|
|
* @param sesslist Resuit of session_get_byuser()
|
|
|
|
* @param cnt Number of entries in sess
|
|
|
|
*/
|
|
|
|
void
|
|
|
|
free_session_info_list(struct scp_session_info *sesslist, unsigned int cnt);
|
|
|
|
|
2023-04-24 17:32:00 +03:00
|
|
|
/**
|
|
|
|
* @brief Get the wait objs for the session list module
|
|
|
|
* @param @robjs Objects array to update
|
|
|
|
* @param robjs_count Elements in robjs (by reference)
|
|
|
|
* @return 0 for success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
session_list_get_wait_objs(tbus robjs[], int *robjs_count);
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @brief Check the wait objs for the session list module
|
|
|
|
* @return 0 for success
|
|
|
|
*/
|
|
|
|
int
|
|
|
|
session_list_check_wait_objs(void);
|
|
|
|
|
2023-03-09 18:40:56 +03:00
|
|
|
#endif // SESSION_LIST_H
|