[PATCH v1] refactor configuration API of rdp-backend

Hardening rdp.effort at gmail.com
Fri Apr 22 21:57:11 UTC 2016


Le 22/04/2016 17:05, Benoit Gschwind a écrit :
> Implement a "well" defined API to configure the rdp backend.
> Following according to discution about libweston API.
> ---
> v1:
>  - Fix the patch log
> v0:
>   - Nothing particular.
> 
> Signed-off-by: Benoit Gschwind <gschwind at gnu-log.net>
> 
>  Makefile.am          |  1 +
>  src/compositor-rdp.c | 71 +++++++++++++++++++++-------------------------------
>  src/compositor-rdp.h | 54 +++++++++++++++++++++++++++++++++++++++
>  src/main.c           | 56 +++++++++++++++++++++++++++++++++++++++--
>  4 files changed, 137 insertions(+), 45 deletions(-)
>  create mode 100644 src/compositor-rdp.h
> 
> diff --git a/Makefile.am b/Makefile.am
> index c042c68..a4dcd57 100644
> --- a/Makefile.am
> +++ b/Makefile.am
> @@ -73,6 +73,7 @@ weston_SOURCES =					\
>  	src/compositor.c				\
>  	src/compositor.h				\
>  	src/compositor-headless.h		\
> +	src/compositor-rdp.h		\
>  	src/input.c					\
>  	src/data-device.c				\
>  	src/screenshooter.c				\
> diff --git a/src/compositor-rdp.c b/src/compositor-rdp.c
> index 773b6b5..2860556 100644
> --- a/src/compositor-rdp.c
> +++ b/src/compositor-rdp.c
> @@ -67,23 +67,13 @@
>  
>  #include "shared/helpers.h"
>  #include "compositor.h"
> +#include "compositor-rdp.h"
>  #include "pixman-renderer.h"
>  
>  #define MAX_FREERDP_FDS 32
>  #define DEFAULT_AXIS_STEP_DISTANCE 10
>  #define RDP_MODE_FREQ 60 * 1000
>  
> -struct rdp_backend_config {
> -	int width;
> -	int height;
> -	char *bind_address;
> -	int port;
> -	char *rdp_key;
> -	char *server_cert;
> -	char *server_key;
> -	int env_socket;
> -	int no_clients_resize;
> -};
>  
>  struct rdp_output;
>  
> @@ -138,20 +128,6 @@ struct rdp_peer_context {
>  typedef struct rdp_peer_context RdpPeerContext;
>  
>  static void
> -rdp_backend_config_init(struct rdp_backend_config *config)
> -{
> -	config->width = 640;
> -	config->height = 480;
> -	config->bind_address = NULL;
> -	config->port = 3389;
> -	config->rdp_key = NULL;
> -	config->server_cert = NULL;
> -	config->server_key = NULL;
> -	config->env_socket = 0;
> -	config->no_clients_resize = 0;
> -}
> -
> -static void
>  rdp_peer_refresh_rfx(pixman_region32_t *damage, pixman_image_t *image, freerdp_peer *peer)
>  {
>  	int width, height, nrects, i;
> @@ -1195,8 +1171,7 @@ rdp_incoming_peer(freerdp_listener *instance, freerdp_peer *client)
>  
>  static struct rdp_backend *
>  rdp_backend_create(struct weston_compositor *compositor,
> -		   struct rdp_backend_config *config,
> -		   int *argc, char *argv[], struct weston_config *wconfig)
> +		   struct weston_rdp_backend_config *config)
>  {
>  	struct rdp_backend *b;
>  	char *fd_str;
> @@ -1274,39 +1249,49 @@ err_free_strings:
>  	return NULL;
>  }
>  
> +static void
> +config_init_to_defaults(struct weston_rdp_backend_config *config)
> +{
> +	config->width = 640;
> +	config->height = 480;
> +	config->bind_address = NULL;
> +	config->port = 3389;
> +	config->rdp_key = NULL;
> +	config->server_cert = NULL;
> +	config->server_key = NULL;
> +	config->env_socket = 0;
> +	config->no_clients_resize = 0;
> +}
> +
>  WL_EXPORT int
>  backend_init(struct weston_compositor *compositor, int *argc, char *argv[],
>  	     struct weston_config *wconfig,
>  	     struct weston_backend_config *config_base)
>  {
>  	struct rdp_backend *b;
> -	struct rdp_backend_config config;
> -	rdp_backend_config_init(&config);
> +	struct weston_rdp_backend_config config = {{ 0, }};
>  	int major, minor, revision;
>  
>  	freerdp_get_version(&major, &minor, &revision);
>  	weston_log("using FreeRDP version %d.%d.%d\n", major, minor, revision);
>  
> -	const struct weston_option rdp_options[] = {
> -		{ WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
> -		{ WESTON_OPTION_INTEGER, "width", 0, &config.width },
> -		{ WESTON_OPTION_INTEGER, "height", 0, &config.height },
> -		{ WESTON_OPTION_STRING,  "address", 0, &config.bind_address },
> -		{ WESTON_OPTION_INTEGER, "port", 0, &config.port },
> -		{ WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
> -		{ WESTON_OPTION_STRING,  "rdp4-key", 0, &config.rdp_key },
> -		{ WESTON_OPTION_STRING,  "rdp-tls-cert", 0, &config.server_cert },
> -		{ WESTON_OPTION_STRING,  "rdp-tls-key", 0, &config.server_key }
> -	};
> -
> -	parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
> +	if (config_base == NULL ||
> +	    config_base->struct_version != WESTON_RDP_BACKEND_CONFIG_VERSION ||
> +	    config_base->struct_size > sizeof(struct weston_rdp_backend_config)) {
> +		weston_log("RDP backend config structure is invalid\n");
> +		return -1;
> +	}
> +
> +	config_init_to_defaults(&config);
> +	memcpy(&config, config_base, config_base->struct_size);
> +
>  	if (!config.rdp_key && (!config.server_cert || !config.server_key)) {
>  		weston_log("the RDP compositor requires keys and an optional certificate for RDP or TLS security ("
>  				"--rdp4-key or --rdp-tls-cert/--rdp-tls-key)\n");
>  		return -1;
>  	}
>  
> -	b = rdp_backend_create(compositor, &config, argc, argv, wconfig);
> +	b = rdp_backend_create(compositor, &config);
>  	if (b == NULL)
>  		return -1;
>  	return 0;
> diff --git a/src/compositor-rdp.h b/src/compositor-rdp.h
> new file mode 100644
> index 0000000..dfa1759
> --- /dev/null
> +++ b/src/compositor-rdp.h
> @@ -0,0 +1,54 @@
> +/*
> + * Copyright © 2016 Benoit Gschwind
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining
> + * a copy of this software and associated documentation files (the
> + * "Software"), to deal in the Software without restriction, including
> + * without limitation the rights to use, copy, modify, merge, publish,
> + * distribute, sublicense, and/or sell copies of the Software, and to
> + * permit persons to whom the Software is furnished to do so, subject to
> + * the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the
> + * next paragraph) shall be included in all copies or substantial
> + * portions of the Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
> + * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
> + * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
> + * NONINFRINGEMENT.  IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
> + * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
> + * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
> + * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
> + * SOFTWARE.
> + */
> +
> +#ifndef WESTON_COMPOSITOR_RDP_H
> +#define WESTON_COMPOSITOR_RDP_H
> +
> +#ifdef  __cplusplus
> +extern "C" {
> +#endif
> +
> +#include "compositor.h"
> +
> +#define WESTON_RDP_BACKEND_CONFIG_VERSION 1
> +
> +struct weston_rdp_backend_config {
> +	struct weston_backend_config base;
> +	int width;
> +	int height;
> +	char *bind_address;
> +	int port;
> +	char *rdp_key;
> +	char *server_cert;
> +	char *server_key;
> +	int env_socket;
> +	int no_clients_resize;
> +};
> +
> +#ifdef  __cplusplus
> +}
> +#endif
> +
> +#endif /* WESTON_COMPOSITOR_RDP_H */
> diff --git a/src/main.c b/src/main.c
> index fc97dd8..55da7b2 100644
> --- a/src/main.c
> +++ b/src/main.c
> @@ -48,6 +48,7 @@
>  #include "version.h"
>  
>  #include "compositor-headless.h"
> +#include "compositor-rdp.h"
>  
>  static struct wl_list child_process_list;
>  static struct weston_compositor *segv_compositor;
> @@ -717,12 +718,65 @@ load_headless_backend(struct weston_compositor *c, char const * backend,
>  	return ret;
>  }
>  
> +static void
> +weston_rdp_backend_config_init(struct weston_rdp_backend_config *config)
> +{
> +	config->base.struct_version = WESTON_RDP_BACKEND_CONFIG_VERSION;
> +	config->base.struct_size = sizeof(struct weston_rdp_backend_config);
> +
> +	config->width = 640;
> +	config->height = 480;
> +	config->bind_address = NULL;
> +	config->port = 3389;
> +	config->rdp_key = NULL;
> +	config->server_cert = NULL;
> +	config->server_key = NULL;
> +	config->env_socket = 0;
> +	config->no_clients_resize = 0;
> +}
> +
> +static int
> +load_rdp_backend(struct weston_compositor *c, char const * backend,
> +		int *argc, char *argv[], struct weston_config *wc)
> +{
> +	struct weston_rdp_backend_config config  = {{ 0, }};
> +	int ret = 0;
> +
> +	weston_rdp_backend_config_init(&config);
> +
> +	const struct weston_option rdp_options[] = {
> +		{ WESTON_OPTION_BOOLEAN, "env-socket", 0, &config.env_socket },
> +		{ WESTON_OPTION_INTEGER, "width", 0, &config.width },
> +		{ WESTON_OPTION_INTEGER, "height", 0, &config.height },
> +		{ WESTON_OPTION_STRING,  "address", 0, &config.bind_address },
> +		{ WESTON_OPTION_INTEGER, "port", 0, &config.port },
> +		{ WESTON_OPTION_BOOLEAN, "no-clients-resize", 0, &config.no_clients_resize },
> +		{ WESTON_OPTION_STRING,  "rdp4-key", 0, &config.rdp_key },
> +		{ WESTON_OPTION_STRING,  "rdp-tls-cert", 0, &config.server_cert },
> +		{ WESTON_OPTION_STRING,  "rdp-tls-key", 0, &config.server_key }
> +	};
> +
> +	parse_options(rdp_options, ARRAY_LENGTH(rdp_options), argc, argv);
> +
> +	ret = load_backend_new(c, backend, &config.base);
> +
> +	free(config.bind_address);
> +	free(config.rdp_key);
> +	free(config.server_cert);
> +	free(config.server_key);
> +	return ret;
> +
> +}
> +
> +
>  static int
>  load_backend(struct weston_compositor *compositor, const char *backend,
>  	     int *argc, char **argv, struct weston_config *config)
>  {
>  	if (strstr(backend, "headless-backend.so"))
>  		return load_headless_backend(compositor, backend, argc, argv, config);
> +	else if (strstr(backend, "rdp-backend.so"))
> +		return load_rdp_backend(compositor, backend, argc, argv, config);
>  #if 0
>  	else if (strstr(backend, "drm-backend.so"))
>  		return load_drm_backend(compositor, backend, argc, argv, config);
> @@ -734,8 +788,6 @@ load_backend(struct weston_compositor *compositor, const char *backend,
>  		return load_fbdev_backend(compositor, backend, argc, argv, config);
>  	else if (strstr(backend, "rpi-backend.so"))
>  		return load_rpi_backend(compositor, backend, argc, argv, config);
> -	else if (strstr(backend, "rdp-backend.so"))
> -		return load_rdp_backend(compositor, backend, argc, argv, config);
>  #endif
>  
>  	return load_backend_old(compositor, backend, argc, argv, config);
> 

It looks good to me.
I'm just wondering if there should be some ifdefery if the RDP
compositor is not built (in src/main.c)?

-- 
David FORT
website: http://www.hardening-consulting.com/



More information about the wayland-devel mailing list