[Spice-commits] 3 commits - server/reds.c server/reds-private.h

Frediano Ziglio fziglio at kemper.freedesktop.org
Mon Feb 1 07:11:07 PST 2016


 server/reds-private.h |    7 +++++
 server/reds.c         |   62 ++++++++++++++++++++++++--------------------------
 2 files changed, 37 insertions(+), 32 deletions(-)

New commits:
commit fdcd8980ce100cbdd32e069dbb0eadda8c7486ad
Author: Jonathon Jongsma <jjongsma at redhat.com>
Date:   Tue Jan 27 13:43:56 2015 -0600

    Move sasl_enabled, sasl_appname to RedsState struct
    
    Removing more global variables
    
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/reds-private.h b/server/reds-private.h
index 6b8e12a..484b296 100644
--- a/server/reds-private.h
+++ b/server/reds-private.h
@@ -202,6 +202,10 @@ struct RedsState {
     int spice_family;
     TicketAuthentication taTicket;
 
+    int sasl_enabled;
+#if HAVE_SASL
+    char *sasl_appname;
+#endif
 };
 
 #endif
diff --git a/server/reds.c b/server/reds.c
index c92f32c..9a4ea3e 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -144,10 +144,6 @@ static SpiceCoreInterfaceInternal core_interface_adapter = {
 #define REDS_TOKENS_TO_SEND 5
 #define REDS_VDI_PORT_NUM_RECEIVE_BUFFS 5
 
-static int sasl_enabled = 0; // sasl disabled by default
-#if HAVE_SASL
-static char *sasl_appname = NULL; // default to "spice" if NULL
-#endif
 static char *spice_name = NULL;
 static bool spice_uuid_is_set = FALSE;
 static uint8_t spice_uuid[16] = { 0, };
@@ -1376,7 +1372,7 @@ int reds_handle_migrate_data(RedsState *reds, MainChannelClient *mcc,
 
 static void reds_channel_init_auth_caps(RedLinkInfo *link, RedChannel *channel)
 {
-    if (sasl_enabled && !link->skip_auth) {
+    if (reds->sasl_enabled && !link->skip_auth) {
         red_channel_set_common_cap(channel, SPICE_COMMON_CAP_AUTH_SASL);
     } else {
         red_channel_set_common_cap(channel, SPICE_COMMON_CAP_AUTH_SPICE);
@@ -1438,7 +1434,7 @@ static int reds_send_link_ack(RedsState *reds, RedLinkInfo *link)
     hdr_size += channel_caps->num_caps * sizeof(uint32_t);
     header.size = GUINT32_TO_LE(hdr_size);
     ack.caps_offset = GUINT32_TO_LE(sizeof(SpiceLinkReply));
-    if (!sasl_enabled
+    if (!reds->sasl_enabled
         || !red_link_info_test_capability(link, SPICE_COMMON_CAP_AUTH_SASL)) {
         if (!(link->tiTicketing.rsa = RSA_new())) {
             spice_warning("RSA new failed");
@@ -2121,7 +2117,7 @@ static void reds_handle_auth_mechanism(void *opaque)
 
     link->auth_mechanism.auth_mechanism = GUINT32_FROM_LE(link->auth_mechanism.auth_mechanism);
     if (link->auth_mechanism.auth_mechanism == SPICE_COMMON_CAP_AUTH_SPICE
-        && !sasl_enabled
+        && !reds->sasl_enabled
         ) {
         reds_get_spice_ticket(link);
 #if HAVE_SASL
@@ -2131,7 +2127,7 @@ static void reds_handle_auth_mechanism(void *opaque)
 #endif
     } else {
         spice_warning("Unknown auth method, disconnecting");
-        if (sasl_enabled) {
+        if (reds->sasl_enabled) {
             spice_warning("Your client doesn't handle SASL?");
         }
         reds_send_link_error(link, SPICE_LINK_ERR_INVALID_DATA);
@@ -2196,7 +2192,7 @@ static void reds_handle_read_link_done(void *opaque)
     }
 
     if (!auth_selection) {
-        if (sasl_enabled && !link->skip_auth) {
+        if (reds->sasl_enabled && !link->skip_auth) {
             spice_warning("SASL enabled, but peer supports only spice authentication");
             reds_send_link_error(link, SPICE_LINK_ERR_VERSION_MISMATCH);
             return;
@@ -3397,8 +3393,8 @@ static int do_spice_init(RedsState *reds, SpiceCoreInterface *core_interface)
     }
 #if HAVE_SASL
     int saslerr;
-    if ((saslerr = sasl_server_init(NULL, sasl_appname ?
-                                    sasl_appname : "spice")) != SASL_OK) {
+    if ((saslerr = sasl_server_init(NULL, reds->sasl_appname ?
+                                    reds->sasl_appname : "spice")) != SASL_OK) {
         spice_error("Failed to initialize SASL auth %s",
                   sasl_errstring(saslerr, NULL, NULL));
         goto err;
@@ -3435,6 +3431,10 @@ SPICE_GNUC_VISIBLE SpiceServer *spice_server_new(void)
     reds->spice_secure_port = -1;
     reds->spice_listen_socket_fd = -1;
     reds->spice_family = PF_UNSPEC;
+    reds->sasl_enabled = 0; // sasl disabled by default
+#if HAVE_SASL
+    reds->sasl_appname = NULL; // default to "spice" if NULL
+#endif
     return reds;
 }
 
@@ -3565,7 +3565,7 @@ SPICE_GNUC_VISIBLE int spice_server_set_sasl(SpiceServer *s, int enabled)
 {
     spice_assert(reds == s);
 #if HAVE_SASL
-    sasl_enabled = enabled;
+    s->sasl_enabled = enabled;
     return 0;
 #else
     return -1;
@@ -3576,8 +3576,8 @@ SPICE_GNUC_VISIBLE int spice_server_set_sasl_appname(SpiceServer *s, const char
 {
     spice_assert(reds == s);
 #if HAVE_SASL
-    free(sasl_appname);
-    sasl_appname = spice_strdup(appname);
+    free(s->sasl_appname);
+    s->sasl_appname = spice_strdup(appname);
     return 0;
 #else
     return -1;
commit 47c42d4f7593d3dcf0dfb0c9dd6cc0a23ff9e60b
Author: Jonathon Jongsma <jjongsma at redhat.com>
Date:   Tue Jan 27 13:41:33 2015 -0600

    Move taTicket to RedsState struct
    
    Removing more global variables
    
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/reds-private.h b/server/reds-private.h
index 18c2e4e..6b8e12a 100644
--- a/server/reds-private.h
+++ b/server/reds-private.h
@@ -200,6 +200,8 @@ struct RedsState {
     int spice_listen_socket_fd;
     char spice_addr[256];
     int spice_family;
+    TicketAuthentication taTicket;
+
 };
 
 #endif
diff --git a/server/reds.c b/server/reds.c
index c2b04a7..c92f32c 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -144,8 +144,6 @@ static SpiceCoreInterfaceInternal core_interface_adapter = {
 #define REDS_TOKENS_TO_SEND 5
 #define REDS_VDI_PORT_NUM_RECEIVE_BUFFS 5
 
-static TicketAuthentication taTicket;
-
 static int sasl_enabled = 0; // sasl disabled by default
 #if HAVE_SASL
 static char *sasl_appname = NULL; // default to "spice" if NULL
@@ -1956,15 +1954,15 @@ static void reds_handle_ticket(void *opaque)
     password[password_size] = '\0';
 
     if (ticketing_enabled && !link->skip_auth) {
-        int expired =  taTicket.expiration_time < ltime;
+        int expired =  reds->taTicket.expiration_time < ltime;
 
-        if (strlen(taTicket.password) == 0) {
+        if (strlen(reds->taTicket.password) == 0) {
             spice_warning("Ticketing is enabled, but no password is set. "
                           "please set a ticket first");
             goto error;
         }
 
-        if (expired || strcmp(password, taTicket.password) != 0) {
+        if (expired || strcmp(password, reds->taTicket.password) != 0) {
             if (expired) {
                 spice_warning("Ticket has expired");
             } else {
@@ -3558,7 +3556,7 @@ SPICE_GNUC_VISIBLE int spice_server_set_exit_on_disconnect(SpiceServer *s, int f
 SPICE_GNUC_VISIBLE int spice_server_set_noauth(SpiceServer *s)
 {
     spice_assert(reds == s);
-    memset(taTicket.password, 0, sizeof(taTicket.password));
+    memset(s->taTicket.password, 0, sizeof(s->taTicket.password));
     ticketing_enabled = 0;
     return 0;
 }
@@ -3617,18 +3615,18 @@ SPICE_GNUC_VISIBLE int spice_server_set_ticket(SpiceServer *s,
     on_activating_ticketing(reds);
     ticketing_enabled = 1;
     if (lifetime == 0) {
-        taTicket.expiration_time = INT_MAX;
+        reds->taTicket.expiration_time = INT_MAX;
     } else {
         time_t now = time(NULL);
-        taTicket.expiration_time = now + lifetime;
+        reds->taTicket.expiration_time = now + lifetime;
     }
     if (passwd != NULL) {
         if (strlen(passwd) > SPICE_MAX_PASSWORD_LENGTH)
             return -1;
-        g_strlcpy(taTicket.password, passwd, sizeof(taTicket.password));
+        g_strlcpy(reds->taTicket.password, passwd, sizeof(reds->taTicket.password));
     } else {
-        memset(taTicket.password, 0, sizeof(taTicket.password));
-        taTicket.expiration_time = 0;
+        memset(reds->taTicket.password, 0, sizeof(reds->taTicket.password));
+        reds->taTicket.expiration_time = 0;
     }
     return 0;
 }
commit 1333e0ee8c5dbf85043039536df0a7f19f028c2a
Author: Jonathon Jongsma <jjongsma at redhat.com>
Date:   Tue Jan 27 13:40:01 2015 -0600

    Move spice_family to RedsState struct
    
    Removing more global variables
    
    Acked-by: Frediano Ziglio <fziglio at redhat.com>

diff --git a/server/reds-private.h b/server/reds-private.h
index 96a6f4d..18c2e4e 100644
--- a/server/reds-private.h
+++ b/server/reds-private.h
@@ -199,6 +199,7 @@ struct RedsState {
     SpiceMigrateInstance *migration_interface;
     int spice_listen_socket_fd;
     char spice_addr[256];
+    int spice_family;
 };
 
 #endif
diff --git a/server/reds.c b/server/reds.c
index 16d7219..c2b04a7 100644
--- a/server/reds.c
+++ b/server/reds.c
@@ -146,7 +146,6 @@ static SpiceCoreInterfaceInternal core_interface_adapter = {
 
 static TicketAuthentication taTicket;
 
-static int spice_family = PF_UNSPEC;
 static int sasl_enabled = 0; // sasl disabled by default
 #if HAVE_SASL
 static char *sasl_appname = NULL; // default to "spice" if NULL
@@ -2565,8 +2564,8 @@ void reds_set_client_mm_time_latency(RedsState *reds, RedClient *client, uint32_
 
 static int reds_init_net(RedsState *reds)
 {
-    if (reds->spice_port != -1 || spice_family == AF_UNIX) {
-        reds->listen_socket = reds_init_socket(reds->spice_addr, reds->spice_port, spice_family);
+    if (reds->spice_port != -1 || reds->spice_family == AF_UNIX) {
+        reds->listen_socket = reds_init_socket(reds->spice_addr, reds->spice_port, reds->spice_family);
         if (-1 == reds->listen_socket) {
             return -1;
         }
@@ -2581,7 +2580,7 @@ static int reds_init_net(RedsState *reds)
 
     if (reds->spice_secure_port != -1) {
         reds->secure_listen_socket = reds_init_socket(reds->spice_addr, reds->spice_secure_port,
-                                                      spice_family);
+                                                      reds->spice_family);
         if (-1 == reds->secure_listen_socket) {
             return -1;
         }
@@ -3437,6 +3436,7 @@ SPICE_GNUC_VISIBLE SpiceServer *spice_server_new(void)
     reds->spice_port = -1;
     reds->spice_secure_port = -1;
     reds->spice_listen_socket_fd = -1;
+    reds->spice_family = PF_UNSPEC;
     return reds;
 }
 
@@ -3531,11 +3531,11 @@ SPICE_GNUC_VISIBLE void spice_server_set_addr(SpiceServer *s, const char *addr,
     g_strlcpy(s->spice_addr, addr, sizeof(s->spice_addr));
 
     if (flags == SPICE_ADDR_FLAG_IPV4_ONLY) {
-        spice_family = PF_INET;
+        s->spice_family = PF_INET;
     } else if (flags == SPICE_ADDR_FLAG_IPV6_ONLY) {
-        spice_family = PF_INET6;
+        s->spice_family = PF_INET6;
     } else if (flags == SPICE_ADDR_FLAG_UNIX_ONLY) {
-        spice_family = AF_UNIX;
+        s->spice_family = AF_UNIX;
     } else if (flags != 0) {
         spice_warning("unknown address flag: 0x%X", flags);
     }


More information about the Spice-commits mailing list