[xiph-commits] r8792 - icecast/branches/kh/icecast/src

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Wed Jan 26 07:20:49 PST 2005


Author: karl
Date: 2005-01-26 07:20:45 -0800 (Wed, 26 Jan 2005)
New Revision: 8792

Modified:
   icecast/branches/kh/icecast/src/auth.c
   icecast/branches/kh/icecast/src/auth.h
   icecast/branches/kh/icecast/src/auth_cmd.c
   icecast/branches/kh/icecast/src/auth_url.c
   icecast/branches/kh/icecast/src/source.c
Log:
fixes to auth handling


Modified: icecast/branches/kh/icecast/src/auth.c
===================================================================
--- icecast/branches/kh/icecast/src/auth.c	2005-01-26 13:09:33 UTC (rev 8791)
+++ icecast/branches/kh/icecast/src/auth.c	2005-01-26 15:20:45 UTC (rev 8792)
@@ -168,12 +168,29 @@
         thread_mutex_unlock (&source->lock);
     }
     avl_tree_unlock (global.source_tree);
-    if (ret < 0)
-        auth_close_client (client);
     return ret;
 }
 
 
+void auth_failed_client (const char *mount)
+{
+    source_t *source;
+
+    avl_tree_rlock (global.source_tree);
+    source = source_find_mount (mount);
+    if (source)
+    {
+        thread_mutex_lock (&source->lock);
+
+        if (source->new_listeners)
+            source->new_listeners--;
+
+        thread_mutex_unlock (&source->lock);
+    }
+    avl_tree_unlock (global.source_tree);
+}
+
+
 void auth_close_client (client_t *client)
 {
     /* failed client, drop global count */

Modified: icecast/branches/kh/icecast/src/auth.h
===================================================================
--- icecast/branches/kh/icecast/src/auth.h	2005-01-26 13:09:33 UTC (rev 8791)
+++ icecast/branches/kh/icecast/src/auth.h	2005-01-26 15:20:45 UTC (rev 8792)
@@ -56,6 +56,7 @@
 int auth_postprocess_client (const char *mount, client_t *client);
 void auth_close_client (client_t *client);
 int add_authenticated_client (source_t *source, client_t *client);
+void auth_failed_client (const char *mount);
 void add_client (char *mount, client_t *client);
 
 #endif

Modified: icecast/branches/kh/icecast/src/auth_cmd.c
===================================================================
--- icecast/branches/kh/icecast/src/auth_cmd.c	2005-01-26 13:09:33 UTC (rev 8791)
+++ icecast/branches/kh/icecast/src/auth_cmd.c	2005-01-26 15:20:45 UTC (rev 8792)
@@ -113,6 +113,8 @@
             auth_postprocess_client (auth_user->mount, auth_user->client);
             send_fail = 0;
         }
+        else
+            auth_failed_client (auth_user->mount);
     }
     if (send_fail == 404)
         client_send_404 (client, "Mount not available");

Modified: icecast/branches/kh/icecast/src/auth_url.c
===================================================================
--- icecast/branches/kh/icecast/src/auth_url.c	2005-01-26 13:09:33 UTC (rev 8791)
+++ icecast/branches/kh/icecast/src/auth_url.c	2005-01-26 15:20:45 UTC (rev 8792)
@@ -122,20 +122,20 @@
         DEBUG0("starting auth thread");
         username = util_url_escape (client->username);
         password = util_url_escape (client->password);
-        snprintf (post, 1024,"action=remove&id=%ld&mount=%s&user=%s&pass=%s&duration=%ld",
-                client->con->id, auth_user->mount, username, password, duration);
+        snprintf (post, sizeof (post), "action=remove&id=%ld&mount=%s&user=%s&pass=%s&duration=%lu",
+                client->con->id, auth_user->mount, username, password, (long unsigned)duration);
         free (username);
         free (password);
         handle = curl_easy_init ();
         if (handle)
         {
-            int res;
+            int res = 0;
             char errormsg [CURL_ERROR_SIZE];
             char *userpass = NULL;
 
             if (auth_user->username && auth_user->password)
             {
-                unsigned len = strlen (auth_user->username) + strlen (auth_user->password) + 1;
+                unsigned len = strlen (auth_user->username) + strlen (auth_user->password) + 2;
                 userpass = malloc (len);
                 snprintf (userpass, len, "%s:%s", auth_user->username, auth_user->password);
                 curl_easy_setopt (handle, CURLOPT_USERPWD, userpass);
@@ -172,7 +172,7 @@
 {
     auth_client *auth_user = arg;
     client_t *client = auth_user->client;
-    int res;
+    int res = 0;
     char *agent, *user_agent, *username, *password;
     CURL *handle;
     char post[1024];
@@ -199,7 +199,7 @@
 
         if (auth_user->username && auth_user->password)
         {
-            unsigned len = strlen (auth_user->username) + strlen (auth_user->password) + 1;
+            unsigned len = strlen (auth_user->username) + strlen (auth_user->password) + 2;
             userpass = malloc (len);
             snprintf (userpass, len, "%s:%s", auth_user->username, auth_user->password);
             curl_easy_setopt (handle, CURLOPT_USERPWD, userpass);
@@ -217,10 +217,12 @@
         res = curl_easy_perform (handle);
         curl_easy_cleanup (handle);
         free (userpass);
+        // auth_user->authenticated = 1;
 
         if (res)
         {
             WARN2 ("auth to server %s failed with %s", auth_user->addurl, errormsg);
+            auth_failed_client (auth_user->mount);
             auth_close_client (client);
         }
         else
@@ -232,6 +234,8 @@
                 {
                     /* do cleanup, and exit as the remove does cleanup as well */
                     free (auth_user->addurl);
+                    auth_user->addurl = NULL;
+                    auth_failed_client (auth_user->mount);
                     auth_removeurl_thread (auth_user);
                     return NULL;
                 }
@@ -239,12 +243,16 @@
             else
             {
                 DEBUG0 ("client authentication failed");
+                auth_failed_client (auth_user->mount);
                 auth_close_client (client);
             }
         }
     }
     else
+    {
+        auth_failed_client (auth_user->mount);
         auth_close_client (client);
+    }
 
     free (auth_user->username);
     free (auth_user->password);

Modified: icecast/branches/kh/icecast/src/source.c
===================================================================
--- icecast/branches/kh/icecast/src/source.c	2005-01-26 13:09:33 UTC (rev 8791)
+++ icecast/branches/kh/icecast/src/source.c	2005-01-26 15:20:45 UTC (rev 8792)
@@ -250,6 +250,7 @@
     source->format = NULL;
 
     auth_clear (source->authenticator);
+    source->authenticator = NULL;
 
     source->burst_point = NULL;
     source->burst_size = 0;
@@ -957,6 +958,7 @@
     global_unlock();
     stats_event_dec(NULL, "clients");
 
+    client_set_queue (client, NULL);
     if (source && source->authenticator && source->authenticator->release_client)
     {
         source->authenticator->release_client (source, client);



More information about the commits mailing list