[icecast-dev] [PATCH] is it of any interest ?

Jerome Alet alet at unice.fr
Wed Nov 7 07:10:11 PST 2001



Hi,

While looking at icecast's sources, I wondered if this was feasible, so
I've tried and it seems to work:

the attached patch allows a /cgi-bin/ url in icecast-1.3.11 to launch cgi
scripts directly from within icecast.

you have to put the real absolute pathname to the cgi script, and it seems
to more or less work.

WARNING: you must use two slashes after "cgi-bin" for an absolute path,
else the script will be launched from icecast's current directory.

of course this is not secure at all yet, but anyway maybe it's useful to
someone as a starting point.

any comment ?

Jerome Alet - alet at unice.fr - http://cortex.unice.fr/~jerome
Fac de Medecine de Nice        http://wwwmed.unice.fr 
Tel: (+33) 4 93 37 76 30     Fax: (+33) 4 93 53 15 15
28 Avenue de Valombrose - 06107 NICE Cedex 2 - FRANCE




diff -ubrw icecast-1.3.11/src/client.c icecast-1.3.11-cgipatch/src/client.c
--- icecast-1.3.11/src/client.c	Thu Aug  2 01:06:53 2001
+++ icecast-1.3.11-cgipatch/src/client.c	Wed Nov  7 15:26:24 2001
@@ -206,6 +206,42 @@
                 return;
         }
         
+#ifdef HAVE_UNISTD_H
+	if (ice_strncmp(req.path, "/cgi-bin/", 9) == 0) {
+		char *fname;
+		FILE *cgioutput;
+		char buffer[8192];
+		int status;
+		size_t count;
+
+		thread_rename("CGI Script Thread");
+		fname = req.path + 9;
+		if (*fname) {
+			cgioutput = popen(fname, "r");
+			if (cgioutput != NULL) {
+				while ((count = fread(buffer, 1, sizeof(buffer), cgioutput))) {
+					sock_write_bytes(con->sock, buffer, count);
+				}
+				status = pclose(cgioutput);
+				if (WIFEXITED(status)) {
+					if (WEXITSTATUS(status)) {
+						kick_not_connected(con, "CGI Script terminated with an error");
+					} else {
+						kick_not_connected(con, "CGI Script terminated with no error");
+					}
+				} else {
+					kick_not_connected(con, "CGI Script terminated abnormally");
+				}
+			} else {
+				kick_not_connected(con, "Error in popen");
+			}
+		} else {
+			kick_not_connected(con, "No CGI Script name");
+		}
+		return;
+	}
+#endif
+
         xa_debug (1, "Looking for mount [%s:%d%s]", req.host, req.port, req.path);
         
         /* Try to find a mount point with this name */

--- >8 ----
List archives:  http://www.xiph.org/archives/
icecast project homepage: http://www.icecast.org/
To unsubscribe from this list, send a message to 'icecast-dev-request at xiph.org'
containing only the word 'unsubscribe' in the body.  No subject is needed.
Unsubscribe messages sent to the list will be ignored/filtered.



More information about the Icecast-dev mailing list