Re: [PATCH 04/18] Make default_security and channels_security non-global

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



> 
> From: Jonathon Jongsma <jjongsma@xxxxxxxxxx>
> 
> Move them into the RedsState struct, adjust functions that use these
> variables to take a RedsState arg.
> ---
>  server/reds-private.h |  4 ++++
>  server/reds.c         | 27 ++++++++++++---------------
>  2 files changed, 16 insertions(+), 15 deletions(-)
> 
> diff --git a/server/reds-private.h b/server/reds-private.h
> index 427ce8e..285f226 100644
> --- a/server/reds-private.h
> +++ b/server/reds-private.h
> @@ -135,6 +135,8 @@ typedef struct RedsClientMonitorsConfig {
>      int buffer_pos;
>  } RedsClientMonitorsConfig;
>  
> +typedef struct ChannelSecurityOptions ChannelSecurityOptions;
> +
>  struct RedsState {
>      int listen_socket;
>      int secure_listen_socket;
> @@ -191,6 +193,8 @@ struct RedsState {
>      int mm_time_enabled;
>      uint32_t mm_time_latency;
>  
> +    int default_channel_security;
> +    ChannelSecurityOptions *channels_security;
>      const char *default_renderer;
>  
>      int spice_port;
> diff --git a/server/reds.c b/server/reds.c
> index 30b2736..feae0cc 100644
> --- a/server/reds.c
> +++ b/server/reds.c
> @@ -193,7 +193,6 @@ typedef struct RedSSLParameters {
>      char ciphersuite[256];
>  } RedSSLParameters;
>  
> -typedef struct ChannelSecurityOptions ChannelSecurityOptions;
>  struct ChannelSecurityOptions {
>      uint32_t channel_id;
>      uint32_t options;
> @@ -213,15 +212,11 @@ static VDIReadBuf *vdi_port_read_buf_get(RedsState
> *reds);
>  static VDIReadBuf *vdi_port_read_buf_ref(VDIReadBuf *buf);
>  static void vdi_port_read_buf_unref(RedsState *reds, VDIReadBuf *buf);
>  
> -static ChannelSecurityOptions *channels_security = NULL;
> -static int default_channel_security =
> -    SPICE_CHANNEL_SECURITY_NONE | SPICE_CHANNEL_SECURITY_SSL;
> -
>  static RedSSLParameters ssl_parameters;
>  
> -static ChannelSecurityOptions *find_channel_security(int id)
> +static ChannelSecurityOptions *reds_find_channel_security(RedsState *reds,
> int id)
>  {
> -    ChannelSecurityOptions *now = channels_security;
> +    ChannelSecurityOptions *now = reds->channels_security;
>      while (now && now->channel_id != id) {
>          now = now->next;
>      }
> @@ -2148,8 +2143,8 @@ static void reds_handle_auth_mechanism(void *opaque)
>  
>  static int reds_security_check(RedLinkInfo *link)
>  {
> -    ChannelSecurityOptions *security_option =
> find_channel_security(link->link_mess->channel_type);
> -    uint32_t security = security_option ? security_option->options :
> default_channel_security;
> +    ChannelSecurityOptions *security_option =
> reds_find_channel_security(reds, link->link_mess->channel_type);
> +    uint32_t security = security_option ? security_option->options :
> reds->default_channel_security;
>      return (reds_stream_is_ssl(link->stream) && (security &
>      SPICE_CHANNEL_SECURITY_SSL)) ||
>          (!reds_stream_is_ssl(link->stream) && (security &
>          SPICE_CHANNEL_SECURITY_NONE));
>  }
> @@ -2801,19 +2796,19 @@ static void
> set_image_compression(SpiceImageCompression val)
>      red_dispatcher_on_ic_change();
>  }
>  
> -static void set_one_channel_security(int id, uint32_t security)
> +static void reds_set_one_channel_security(RedsState *reds, int id, uint32_t
> security)
>  {
>      ChannelSecurityOptions *security_options;
>  
> -    if ((security_options = find_channel_security(id))) {
> +    if ((security_options = reds_find_channel_security(reds, id))) {
>          security_options->options = security;
>          return;
>      }
>      security_options = spice_new(ChannelSecurityOptions, 1);
>      security_options->channel_id = id;
>      security_options->options = security;
> -    security_options->next = channels_security;
> -    channels_security = security_options;
> +    security_options->next = reds->channels_security;
> +    reds->channels_security = security_options;
>  }
>  
>  #define REDS_SAVE_VERSION 1
> @@ -3442,6 +3437,8 @@ SPICE_GNUC_VISIBLE SpiceServer *spice_server_new(void)
>      spice_assert(reds == NULL);
>  
>      reds = spice_new0(RedsState, 1);
> +    reds->default_channel_security =
> +        SPICE_CHANNEL_SECURITY_NONE | SPICE_CHANNEL_SECURITY_SSL;
>      reds->default_renderer = "sw";
>      reds->spice_port = -1;
>      reds->spice_secure_port = -1;
> @@ -3743,12 +3740,12 @@ SPICE_GNUC_VISIBLE int
> spice_server_set_channel_security(SpiceServer *s, const c
>      spice_assert(reds == s);
>  
>      if (channel == NULL) {
> -        default_channel_security = security;
> +        s->default_channel_security = security;
>          return 0;
>      }
>      for (i = 0; i < SPICE_N_ELEMENTS(names); i++) {
>          if (names[i] && strcmp(names[i], channel) == 0) {
> -            set_one_channel_security(i, security);
> +            reds_set_one_channel_security(s, i, security);
>              return 0;
>          }
>      }

Acked-by: Frediano Ziglio <fziglio@xxxxxxxxxx>

Frediano
_______________________________________________
Spice-devel mailing list
Spice-devel@xxxxxxxxxxxxxxxxxxxxx
http://lists.freedesktop.org/mailman/listinfo/spice-devel




[Index of Archives]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [ECOS]     [Asterisk Internet PBX]     [Linux API]     [Monitors]