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

karl at motherfish-iii.xiph.org karl at motherfish-iii.xiph.org
Tue Jun 14 19:44:08 PDT 2005


Author: karl
Date: 2005-06-14 19:44:02 -0700 (Tue, 14 Jun 2005)
New Revision: 9454

Modified:
   icecast/branches/kh/icecast/src/auth.c
   icecast/branches/kh/icecast/src/auth_cmd.c
   icecast/branches/kh/icecast/src/auth_htpasswd.c
   icecast/branches/kh/icecast/src/auth_url.c
Log:
update auth. small mem leaks fixed. make user pass requirement dependent on
specific auth component. pass original listener url request in auth url


Modified: icecast/branches/kh/icecast/src/auth.c
===================================================================
--- icecast/branches/kh/icecast/src/auth.c	2005-06-15 02:32:26 UTC (rev 9453)
+++ icecast/branches/kh/icecast/src/auth.c	2005-06-15 02:44:02 UTC (rev 9454)
@@ -51,37 +51,42 @@
     char *userpass, *tmp;
     char *username, *password;
 
-    if (header == NULL || strncmp(header, "Basic ", 6))
+    do
     {
-        INFO0("Authorization not using Basic");
-        return;
-    }
+        if (header == NULL)
+            break;
 
-    userpass = util_base64_decode (header+6);
-    if (userpass == NULL)
-    {
-        WARN1("Base64 decode of Authorization header \"%s\" failed",
-                header+6);
-        return;
-    }
+        if (strncmp(header, "Basic ", 6) == 0)
+        {
+            userpass = util_base64_decode (header+6);
+            if (userpass == NULL)
+            {
+                WARN1("Base64 decode of Authorization header \"%s\" failed",
+                        header+6);
+                return;
+            }
 
-    tmp = strchr(userpass, ':');
-    if (tmp == NULL)
-    { 
-        free (userpass);
-        return;
-    }
+            tmp = strchr(userpass, ':');
+            if (tmp == NULL)
+            { 
+                free (userpass);
+                return;
+            }
 
-    *tmp = 0;
-    username = userpass;
-    password = tmp+1;
+            *tmp = 0;
+            username = userpass;
+            password = tmp+1;
+            client->username = strdup (username);
+            client->password = strdup (password);
+            free (userpass);
+            break;
+        }
+        INFO1 ("unhandled authorization header: %s", header);
 
+    } while (0);
+
     client->auth = mountinfo->auth;
     client->auth->refcount++;
-    client->username = strdup (username);
-    client->password = strdup (password);
-
-    free(userpass);
 }
 
 
@@ -127,6 +132,7 @@
             client_send_401 (client);
         auth_user->client = NULL;
     }
+    free (auth_user->mount);
     free (auth_user);
 }
 
@@ -330,6 +336,11 @@
         auth_client_setup (mountinfo, client);
         config_release_config ();
 
+        if (client->auth == NULL)
+        {
+            client_send_401 (client);
+            return;
+        }
         /* config lock taken in here */
         if (connection_check_relay_pass(client->parser))
         {
@@ -337,7 +348,7 @@
             INFO0 ("client connected as slave");
         }
         auth_user = calloc (1, sizeof (auth_client));
-        if (auth_user == NULL || client->auth == NULL)
+        if (auth_user == NULL)
         {
             client_send_401 (client);
             return;

Modified: icecast/branches/kh/icecast/src/auth_cmd.c
===================================================================
--- icecast/branches/kh/icecast/src/auth_cmd.c	2005-06-15 02:32:26 UTC (rev 9453)
+++ icecast/branches/kh/icecast/src/auth_cmd.c	2005-06-15 02:44:02 UTC (rev 9454)
@@ -63,6 +63,9 @@
     int status, len;
     char str[512];
 
+    if (client->username == NULL || client->password == NULL)
+        return AUTH_FAILED;
+
     if (pipe (fd) == 0)
     {
         pid = fork();

Modified: icecast/branches/kh/icecast/src/auth_htpasswd.c
===================================================================
--- icecast/branches/kh/icecast/src/auth_htpasswd.c	2005-06-15 02:32:26 UTC (rev 9453)
+++ icecast/branches/kh/icecast/src/auth_htpasswd.c	2005-06-15 02:44:02 UTC (rev 9454)
@@ -33,7 +33,7 @@
 #include "md5.h"
 
 #include "logging.h"
-#define CATMODULE "auth"
+#define CATMODULE "auth_htpasswd"
 
 static auth_result htpasswd_adduser (auth_t *auth, const char *username, const char *password);
 static auth_result htpasswd_deleteuser(auth_t *auth, const char *username);
@@ -88,10 +88,14 @@
     auth_t *auth = auth_user->client->auth;
     htpasswd_auth_state *state = auth->state;
     client_t *client = auth_user->client;
-    FILE *passwdfile = fopen(state->filename, "rb");
+    FILE *passwdfile;
     char line[MAX_LINE_LEN];
     char *sep;
 
+    if (client->username == NULL || client->password == NULL)
+        return AUTH_FAILED;
+
+    passwdfile = fopen(state->filename, "rb");
     thread_rwlock_rlock(&state->file_rwlock);
     if(passwdfile == NULL) {
         WARN2("Failed to open authentication database \"%s\": %s", 
@@ -155,7 +159,6 @@
 
     if(!state->filename) {
         free(state);
-        free(authenticator);
         ERROR0("No filename given in options for authenticator.");
         return -1;
     }

Modified: icecast/branches/kh/icecast/src/auth_url.c
===================================================================
--- icecast/branches/kh/icecast/src/auth_url.c	2005-06-15 02:32:26 UTC (rev 9453)
+++ icecast/branches/kh/icecast/src/auth_url.c	2005-06-15 02:44:02 UTC (rev 9454)
@@ -84,11 +84,14 @@
 {
     auth_url *url = self->state;
     curl_easy_cleanup (url->handle);
-    free(url->username);
-    free(url->password);
-    free(url->removeurl);
-    free(url->addurl);
-    free(url);
+    free (url->username);
+    free (url->password);
+    free (url->removeurl);
+    free (url->addurl);
+    free (url->stream_start);
+    free (url->stream_end);
+    free (url->auth_header);
+    free (url);
 }
 
 
@@ -121,7 +124,7 @@
     client_t *client = auth_user->client;
     auth_t *auth = client->auth;
     auth_url *url = auth->state;
-    time_t duration = time(NULL) - client->con->con_time;
+    time_t duration = global.time - client->con->con_time;
     char *username, *password, *mount, *server;
     ice_config_t *config;
     char post[1024];
@@ -131,15 +134,29 @@
     config = config_get_config ();
     server = util_url_escape (config->hostname);
     config_release_config ();
-    username = util_url_escape (client->username);
-    password = util_url_escape (client->password);
-    mount = util_url_escape (auth_user->mount);
 
+    if (client->username)
+        username = util_url_escape (client->username);
+    else
+        username = strdup ("");
+
+    if (client->password)
+        password = util_url_escape (client->password);
+    else
+        password = strdup ("");
+
+    /* get the full uri (with query params if available) */
+    mount = httpp_getvar (client->parser, HTTPP_VAR_RAWURI);
+    if (mount == NULL)
+        mount = httpp_getvar (client->parser, HTTPP_VAR_URI);
+    mount = util_url_escape (mount);
+
     snprintf (post, sizeof (post),
             "action=remove&server=%sclient=%lu&mount=%s"
             "&user=%s&pass=%s&duration=%lu",
             server, client->con->id, mount, username,
             password, (long unsigned)duration);
+    free (server);
     free (mount);
     free (username);
     free (password);
@@ -180,9 +197,20 @@
     if (agent == NULL)
         agent = "-";
     user_agent = util_url_escape (agent);
-    username  = util_url_escape (client->username);
-    password  = util_url_escape (client->password);
-    mount = util_url_escape (auth_user->mount);
+    if (client->username)
+        username  = util_url_escape (client->username);
+    else
+        username = strdup ("");
+    if (client->password)
+        password  = util_url_escape (client->password);
+    else
+        password = strdup ("");
+
+    /* get the full uri (with query params if available) */
+    mount = httpp_getvar (client->parser, HTTPP_VAR_RAWURI);
+    if (mount == NULL)
+        mount = httpp_getvar (client->parser, HTTPP_VAR_URI);
+    mount = util_url_escape (mount);
     ipaddr = util_url_escape (client->con->ip);
 
     snprintf (post, sizeof (post),
@@ -190,6 +218,7 @@
             "&user=%s&pass=%s&ip=%s&agent=%s",
             server, client->con->id, mount, username,
             password, ipaddr, user_agent);
+    free (server);
     free (mount);
     free (user_agent);
     free (username);
@@ -361,7 +390,6 @@
     if (url_info->handle == NULL)
     {
         free (url_info);
-        free (authenticator);
         return -1;
     }
     if (url_info->auth_header)



More information about the commits mailing list