Add initial CCP to libipm

This commit is contained in:
matt335672
2025-06-30 14:59:52 +01:00
parent 93707e976f
commit d09ebb2d10
6 changed files with 373 additions and 0 deletions
+4
View File
@@ -13,6 +13,10 @@ libipm_la_SOURCES = \
libipm_recv.c \
libipm_facilities.h \
libipm_private.h \
ccp.h \
ccp.c \
ccp_application_types.h \
ccp_application_types.c \
eicp.h \
eicp.c \
ercp.h \
+122
View File
@@ -0,0 +1,122 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2022, all xrdp contributors
*
* 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.
*/
/**
*
* @file libipm/ccp.c
* @brief CCP definitions
* @author Matt Burt
*/
#if defined(HAVE_CONFIG_H)
#include <config_ac.h>
#endif
#include <stddef.h>
#include <stdio.h>
#include "ccp.h"
#include "libipm.h"
#include "trans.h"
/*****************************************************************************/
static const char *
msgno_to_str(unsigned short n)
{
return
(n == E_CCP_CLOSE_CONNECTION_REQUEST) ? "E_CCP_CLOSE_CONNECTION_REQUEST" :
NULL;
}
/*****************************************************************************/
const char *
ccp_msgno_to_str(enum ccp_msg_code n, char *buff, unsigned int buff_size)
{
const char *str = msgno_to_str((unsigned short)n);
if (str == NULL)
{
(void)snprintf(buff, buff_size, "[code #%d]", (int)n);
}
else
{
(void)snprintf(buff, buff_size, "%s", str);
}
return buff;
}
/*****************************************************************************/
void
ccp_trans_from_scp_trans(struct trans *trans,
ttrans_data_in callback_func,
void *callback_data)
{
libipm_change_facility(trans, LIBIPM_FAC_SCP, LIBIPM_FAC_CCP);
trans->trans_data_in = callback_func;
trans->callback_data = callback_data;
}
/*****************************************************************************/
int
ccp_msg_in_check_available(struct trans *trans, int *available)
{
return libipm_msg_in_check_available(trans, available);
}
/*****************************************************************************/
enum ccp_msg_code
ccp_msg_in_get_msgno(const struct trans *trans)
{
return (enum ccp_msg_code)libipm_msg_in_get_msgno(trans);
}
/*****************************************************************************/
void
ccp_msg_in_reset(struct trans *trans)
{
libipm_msg_in_reset(trans);
}
/*****************************************************************************/
int
ccp_send_close_connection_request(struct trans *trans,
enum ccp_close_reason_type reason)
{
return libipm_msg_out_simple_send(
trans,
(int)E_CCP_CLOSE_CONNECTION_REQUEST,
"i", reason);
}
/*****************************************************************************/
int
ccp_get_close_connection_request(struct trans *trans,
enum ccp_close_reason_type *reason)
{
/* Intermediate values */
int32_t i_reason;
int rv = libipm_msg_in_parse( trans, "i", &i_reason);
if (rv == 0)
{
*reason = (enum ccp_close_reason_type)i_reason;
}
return rv;
}
+136
View File
@@ -0,0 +1,136 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2025, all xrdp contributors
*
* 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.
*/
/**
*
* @file libipm/ccp.h
* @brief CCP declarations
* @author Matt Burt
*
* Functions in this file use the following naming conventions:-
*
* E_CCP_{msg}_REQUEST is sent by ccp_send_{msg}_request()
* E_CCP_{msg}_REQUEST is parsed by ccp_get_{msg}_request()
* E_CCP_{msg}_RESPONSE is sent by ccp_send_{msg}_response()
* E_CCP_{msg}_RESPONSE is parsed by ccp_get_{msg}_response()
* E_CCP_{msg}_EVENT is sent by ccp_send_{msg}_event()
* E_CCP_{msg}_EVENT is parsed by ccp_get_{msg}_event()
*/
#ifndef CCP_H
#define CCP_H
#include "arch.h"
#include "trans.h"
#include "ccp_application_types.h"
/* Message codes */
enum ccp_msg_code
{
E_CCP_CLOSE_CONNECTION_REQUEST // sesexec -> xrdp
// No E_CCP_CLOSE_CONNECTION_RESPONSE
};
/* Common facilities */
/**
* Convert a message code to a string for output
* @param n Message code
* @param buff to contain string
* @param buff_size length of buff
* @return buff is returned for convenience.
*/
const char *
ccp_msgno_to_str(enum ccp_msg_code n, char *buff, unsigned int buff_size);
/* Connection management facilities */
/**
* Converts an SCP transport to an CCP transport.
*
* This is done following successful transmission or receipt of an
* E_SCP_CONNECT_SESSION_RESPONSE
*
* @param trans connected endpoint
* @param callback_func New callback function for CCP messages.
* @param callback_data New argument for callback function
*/
void
ccp_trans_from_scp_trans(struct trans *trans,
ttrans_data_in callback_func,
void *callback_data);
/**
* Checks an CCP transport to see if a complete message is
* available for parsing
*
* @param trans CCP transport
* @param[out] available != 0 if a complete message is available
* @return != 0 for error
*/
int
ccp_msg_in_check_available(struct trans *trans, int *available);
/**
* Gets the CCP message number of an incoming message
*
* @param trans CCP transport
* @return message in the buffer
*
* The results of calling this routine before ccp_msg_in_check_available()
* states a message is available are undefined.
*/
enum ccp_msg_code
ccp_msg_in_get_msgno(const struct trans *trans);
/**
* Resets an CCP message buffer ready to receive the next message
*
* @param trans libipm transport
*/
void
ccp_msg_in_reset(struct trans *trans);
/* -------------------- Session messages-------------------- */
/**
* Send an E_CCP_CLOSE_CONNECTION_REQUEST
*
* Direction : sesexec -> xrdp
*
* @param trans CCP transport
* @param reason reason_code
* @return != 0 for error
*/
int
ccp_send_close_connection_request(struct trans *trans,
enum ccp_close_reason_type reason);
/**
* Parse an incoming E_CCP_CLOSE_CONNECTION_REQUEST
*
* Direction : sesexec -> xrdp
*
* @param trans CCP transport
* @param[out] reason reason_code
* @return != 0 for error
*/
int
ccp_get_close_connection_request(struct trans *trans,
enum ccp_close_reason_type *reason);
#endif /* CCP_H */
+58
View File
@@ -0,0 +1,58 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2022, all xrdp contributors
*
* 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.
*/
/**
*
* @file libipm/ccp_application_types.c
* @brief Support routines for types in ccp_application_types.h
* @author Matt Burt
*/
#if defined(HAVE_CONFIG_H)
#include <config_ac.h>
#endif
#include <stdio.h>
#include "ccp_application_types.h"
/*****************************************************************************/
const char *
ccp_close_reason_to_str(enum ccp_close_reason_type n,
char *buff, unsigned int buff_size)
{
const char *str =
(n == CCP_CLOSE_RPC_INITIATED_DISCONNECT)
? "Connection closed by administrator request" :
(n == CCP_CLOSE_DISCONNECTED_BY_OTHERCONNECTION)
? "Another connection was made to the session" :
(n == CCP_CLOSE_LOGOFF_BY_USER)
? "The user logged out of the session" :
/* Default */ NULL;
if (str == NULL)
{
(void)snprintf(buff, buff_size, "[ccp reason code #%d]", (int)n);
}
else
{
(void)snprintf(buff, buff_size, "%s", str);
}
return buff;
}
+52
View File
@@ -0,0 +1,52 @@
/**
* xrdp: A Remote Desktop Protocol server.
*
* Copyright (C) Jay Sorg 2004-2022, all xrdp contributors
*
* 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.
*/
/**
*
* @file libipm/ccp_application_types.h
* @brief ccp type declarations intended for use in the application
* @author Simone Fedele/ Matt Burt
*/
#ifndef CCP_APPLICATION_TYPES_H
#define CCP_APPLICATION_TYPES_H
#include <sys/types.h>
/**
* Select the reason for a close connection request
*/
enum ccp_close_reason_type
{
CCP_CLOSE_RPC_INITIATED_DISCONNECT = 1,
CCP_CLOSE_DISCONNECTED_BY_OTHERCONNECTION,
CCP_CLOSE_LOGOFF_BY_USER
};
/**
* Convert an ccp_close_reason_type to a readable string for output
* @param n Message code
* @param buff to contain string
* @param buff_size length of buff
* @return buff is returned for convenience.
*/
const char *
ccp_close_reason_to_str(enum ccp_close_reason_type n,
char *buff, unsigned int buff_size);
#endif /* CCP_APPLICATION_TYPES_H */
+1
View File
@@ -30,6 +30,7 @@ enum libipm_facility
LIBIPM_FAC_SCP = 1, /**< SCP - Sesman Control Protocol */
LIBIPM_FAC_EICP, /**< EICP - Executive Initialization Control Protocol */
LIBIPM_FAC_ERCP, /**< ERCP - Executive Run-time Control Protocol */
LIBIPM_FAC_CCP, /**< CCP - Connection Control Protocol */
LIBIPM_FAC_TEST = 65535 /**< Used for unit testing */
};