ImperialViolet

RTSP (09 Jan 2003)

RTSP is the protocol used by RealPlayer to stream its stuff. Now RealPlayer is pretty evil, but RTSP looks slightly open. At least Real provides a proxy server for it.

We'll see how it works tomorrow, but for the moment the essential agl patch; chroot and setuidgid.

--- rtspproxy.cpp	Fri Feb  9 23:38:53 2001
+++ rtspproxy.cpp	Thu Jan  9 17:10:32 2003
@@ -12,6 +12,9 @@
 #include <string.h>
 #include <signal.h>
 #include <stdarg.h>
+#include <sys/types.h>
+#include <unistd.h>
+#include <grp.h>
 
 #include "app.h"
 #include "rtspproxy.h"
@@ -1277,6 +1280,8 @@
     printf( "    -v              Print version information.\n");
     printf( "    -h              Display this help message.\n");
     printf( "    -d              Enable useful debug messages.\n");
+    printf( "    -u <uid> <gid>  Set UID and GID.\n");
+    printf( "    -c <path>       Chroot to path.\n");
 }
 
 int main( int argc, char** argv )
@@ -1328,6 +1333,31 @@
         {
             g_DebugFlagTurnedOn = true;
         }
+	else if ( strcasecmp (argv[i], "-c" ) == 0 ) {
+		if (i + 1 >= argc) { Usage (argv[0]); exit(1); }
+		i++;
+		if (chroot (argv[i]) == -1) { perror ("Failed to chroot"); exit(1); }
+		if (chdir ("/") == -1) { perror ("Failed to chdir after chroot"); exit (1); }
+	}
+	else if ( strcasecmp (argv[i], "-u" ) == 0 ) {
+		if (i + 1 >= argc) { Usage (argv[0]); exit(1); }
+		i++;
+		INT16 uid = atoi ( argv[i] );
+		if (uid == 0) { printf ("Bad uid\n"); exit (1); }
+		if (i + 1 >= argc) { Usage (argv[0]); exit(1); }
+		i++;
+		gid_t gid = atoi ( argv[i] );
+		if (gid == 0) { printf ("Bad uid\n"); exit (1); }
+		
+		if (setgroups (1, &gid) == -1) {
+			perror ("failed to set groups");
+			exit (1);
+		}
+		if (setuid (uid) == -1) {
+			perror ("failed to set uid");
+			exit (1);
+		}
+	}
     }
 
     app.Run();