]> andersk Git - test.git/commitdiff
Added a ${url} parameter that can be used in the service description
authorMarkus Gutschke <markus@shellinabox.com>
Wed, 19 Aug 2009 19:08:30 +0000 (19:08 +0000)
committerMarkus Gutschke <markus@shellinabox.com>
Wed, 19 Aug 2009 19:08:30 +0000 (19:08 +0000)
ChangeLog
config.h
configure
configure.ac
demo/vt100.js
shellinabox/launcher.c
shellinabox/launcher.h
shellinabox/shell_in_a_box.js
shellinabox/shellinaboxd.c
shellinabox/shellinaboxd.man.in
shellinabox/vt100.js

index 763b71878c4bb03fa2917d56fcaefb1b5ae0db1c..f76c74280b2573c3c36e7a149a0f188d39ea8734 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-08-19  Markus Gutschke  <markus@shellinabox.com>
+
+       * Added a ${url} parameter that can be used in the service description.
+
 2009-08-11  Markus Gutschke  <markus@shellinabox.com>
 
        * Added support for user selectable style sheets. Included example
index 895a91802307d64cc0ede5151f02119b2cf86bc1..16c487b6ed93ce333e81a6225c233ad0feb5721b 100644 (file)
--- a/config.h
+++ b/config.h
 #define STDC_HEADERS 1
 
 /* Most recent revision number in the version control system */
-#define VCS_REVISION "172"
+#define VCS_REVISION "174"
 
 /* Version number of package */
 #define VERSION "2.9"
index b399573ed176a9acda0ed28636709f852adf9874..ae4769fd7ee095f80fcf417a57bf682ca944ebed 100755 (executable)
--- a/configure
+++ b/configure
@@ -2317,7 +2317,7 @@ ac_link='$CC -o conftest$ac_exeext $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext $
 ac_compiler_gnu=$ac_cv_c_compiler_gnu
 
 
-VCS_REVISION=172
+VCS_REVISION=174
 
 
 cat >>confdefs.h <<_ACEOF
index b8031608dfb8836903afa807077defd2f1007ea5..1cbaa0fae5f882d41de39a0c470da2db4bc43f79 100644 (file)
@@ -2,7 +2,7 @@ AC_PREREQ(2.57)
 
 dnl This is the one location where the authoritative version number is stored
 AC_INIT(shellinabox, 2.9, markus@shellinabox.com)
-VCS_REVISION=172
+VCS_REVISION=174
 AC_SUBST(VCS_REVISION)
 AC_DEFINE_UNQUOTED(VCS_REVISION, "${VCS_REVISION}",
                    [Most recent revision number in the version control system])
index 9f8cc89a77eb9770c56ba7719e25e9d5eb1da997..f4bd7d074941148b37643a0d55aae763b41cf3d0 100644 (file)
@@ -1892,7 +1892,7 @@ VT100.prototype.toggleBell = function() {
 };
 
 VT100.prototype.about = function() {
-  alert("VT100 Terminal Emulator " + "2.9 (revision 172)" +
+  alert("VT100 Terminal Emulator " + "2.9 (revision 174)" +
         "\nCopyright 2008-2009 by Markus Gutschke\n" +
         "For more information check http://shellinabox.com");
 };
index 26976fbd2e89443551e354e5f36fe78ed361ca5b..3bf3933134cf1965d1fb79e21f7bb131523654ad 100644 (file)
@@ -401,21 +401,27 @@ static int getpwuid_r(uid_t uid, struct passwd *pwd, char *buf, size_t buflen,
 }
 #endif
 
-int launchChild(int service, struct Session *session) {
+int launchChild(int service, struct Session *session, const char *url) {
   if (launcher < 0) {
     errno              = EINVAL;
     return -1;
   }
 
-  struct LaunchRequest request = {
-    .service           = service,
-    .width             = session->width,
-    .height            = session->height };
-  strncat(request.peerName, httpGetPeerName(session->http),
-          sizeof(request.peerName) - 1);
-  if (NOINTR(write(launcher, &request, sizeof(request))) != sizeof(request)) {
+  struct LaunchRequest *request;
+  size_t len           = sizeof(struct LaunchRequest) + strlen(url) + 1;
+  check(request        = calloc(len, 1));
+  request->service     = service;
+  request->width       = session->width;
+  request->height      = session->height;
+  strncat(request->peerName, httpGetPeerName(session->http),
+          sizeof(request->peerName) - 1);
+  request->urlLength   = strlen(url);
+  memcpy(&request->url, url, request->urlLength);
+  if (NOINTR(write(launcher, request, len)) != len) {
+    free(request);
     return -1;
   }
+  free(request);
   pid_t pid;
   char cmsg_buf[CMSG_SPACE(sizeof(int))];
   struct iovec iov     = { 0 };
@@ -1023,7 +1029,8 @@ static void destroyVariableHashEntry(void *arg, char *key, char *value) {
 }
 
 static void execService(int width, int height, struct Service *service,
-                        const char *peerName, char **environment) {
+                        const char *peerName, char **environment,
+                        const char *url) {
   // Create a hash table with all the variables that we can expand. This
   // includes all environment variables being passed to the child.
   HashMap *vars;
@@ -1059,6 +1066,8 @@ static void execService(int width, int height, struct Service *service,
   addToHashMap(vars, key, value);
   check(key                   = strdup("uid"));
   addToHashMap(vars, key, stringPrintf(NULL, "%d", service->uid));
+  check(key                   = strdup("url"));
+  addToHashMap(vars, key, strdup(url));
 
   enum { ENV, ARGS } state    = ENV;
   enum { NONE, SINGLE, DOUBLE
@@ -1110,11 +1119,26 @@ static void execService(int width, int height, struct Service *service,
         if (ch) {
           end++;
         }
+        int incr              = replLen - (end - ptr);
+        if (incr > 0) {
+          char *oldCmdline    = cmdline;
+          check(cmdline       = realloc(cmdline,
+                                        (end - cmdline) + strlen(end) +
+                                        incr + 1));
+          ptr                += cmdline - oldCmdline;
+          end                += cmdline - oldCmdline;
+          if (key) {
+            key              += cmdline - oldCmdline;
+          }
+          if (value) {
+            value            += cmdline - oldCmdline;
+          }
+        }
         memmove(ptr + replLen, end, strlen(end) + 1);
         if (repl) {
           memcpy(ptr, repl, replLen);
         }
-        ptr                  += replLen;
+        ptr                  += replLen - 1;
       }
       break;
     case '\\':
@@ -1168,7 +1192,7 @@ static void execService(int width, int height, struct Service *service,
         } else {
           // Add entry to argv.
           state               = ARGS;
-          argv[argc++]        = key;
+          argv[argc++]        = strdup(key);
           check(argv          = realloc(argv, (argc + 1)*sizeof(char *)));
         }
       }
@@ -1183,6 +1207,7 @@ static void execService(int width, int height, struct Service *service,
     }
   }
  done:
+  free(cmdline);
   argv[argc]                  = NULL;
   deleteHashMap(vars);
   check(argc);
@@ -1217,7 +1242,8 @@ void setWindowSize(int pty, int width, int height) {
 }
 
 static void childProcess(struct Service *service, int width, int height,
-                         struct Utmp *utmp, const char *peerName) {
+                         struct Utmp *utmp, const char *peerName,
+                         const char *url) {
   // Set initial window size
   setWindowSize(0, width, height);
 
@@ -1343,7 +1369,7 @@ static void childProcess(struct Service *service, int width, int height,
     execle("/usr/bin/login", "login", "-p", "-h", peerName,
            (void *)0, environment);
   } else {
-    execService(width, height, service, peerName, environment);
+    execService(width, height, service, peerName, environment, url);
   }
   _exit(1);
 }
@@ -1363,6 +1389,9 @@ static void launcherDaemon(int fd) {
     errno                     = 0;
     int len                   = read(fd, &request, sizeof(request));
     if (len != sizeof(request) && errno != EINTR) {
+      if (len) {
+        debug("Failed to read launch request");
+      }
       break;
     }
 
@@ -1381,6 +1410,26 @@ static void launcherDaemon(int fd) {
       continue;
     }
 
+    char *url;
+    check(url                 = calloc(request.urlLength + 1, 1));
+  readURL:
+    len                       = read(fd, url, request.urlLength + 1);
+    if (len != request.urlLength + 1 && errno != EINTR) {
+      debug("Failed to read URL");
+      free(url);
+      break;
+    }
+    while (NOINTR(pid = waitpid(-1, &status, WNOHANG)) > 0) {
+      if (WIFEXITED(pid) || WIFSIGNALED(pid)) {
+        char key[32];
+        snprintf(&key[0], sizeof(key), "%d", pid);
+        deleteFromHashMap(childProcesses, key);
+      }
+    }
+    if (len != request.urlLength + 1) {
+      goto readURL;
+    }
+
     check(request.service >= 0);
     check(request.service < numServices);
 
@@ -1403,11 +1452,13 @@ static void launcherDaemon(int fd) {
                                         services[request.service]->useLogin,
                                         &utmp, request.peerName)) == 0) {
       childProcess(services[request.service], request.width, request.height,
-                   utmp, request.peerName);
+                   utmp, request.peerName, url);
+      free(url);
       _exit(1);
     } else {
       // Remember the utmp entry so that we can clean up when the child
       // terminates.
+      free(url);
       if (pid > 0) {
         if (!childProcesses) {
           childProcesses      = newHashMap(destroyUtmpHashEntry, NULL);
index fc5fc44dc49f443e82ba7fc06837a3fb5a3572ba..945bccc1b6bad99492c209d2730be9805b1a242a 100644 (file)
@@ -55,10 +55,12 @@ struct LaunchRequest {
   int  service;
   int  width, height;
   char peerName[128];
+  int  urlLength;
+  char url[0];
 };
 
 int  supportsPAM(void);
-int  launchChild(int service, struct Session *session);
+int  launchChild(int service, struct Session *session, const char *url);
 void setWindowSize(int pty, int width, int height);
 int  forkLauncher(void);
 void terminateLauncher(void);
index ab52210f41340a1e8e2a7f17b3d75a9f6cb8a0d4..f66323f666438f14f93f462a832745926b8e0199 100644 (file)
@@ -355,7 +355,7 @@ ShellInABox.prototype.extendContextMenu = function(entries, actions) {
 };
 
 ShellInABox.prototype.about = function() {
-  alert("Shell In A Box version " + "2.9 (revision 172)" +
+  alert("Shell In A Box version " + "2.9 (revision 174)" +
         "\nCopyright 2008-2009 by Markus Gutschke\n" +
         "For more information check http://shellinabox.com" +
         (typeof serverSupportsSSL != 'undefined' && serverSupportsSSL ?
index 350e3136fc1486dc4b702f09cdb5e3b6fe8b2d0f..027f03c5de8778a3d063a2929773975636f39e38 100644 (file)
@@ -341,6 +341,7 @@ static int dataHandler(HttpConnection *http, struct Service *service,
   const char *width       = getFromHashMap(args, "width");
   const char *height      = getFromHashMap(args, "height");
   const char *keys        = getFromHashMap(args, "keys");
+  const char *rootURL     = getFromHashMap(args, "rooturl");
 
   // Adjust window dimensions if provided by client
   if (width && height) {
@@ -362,7 +363,8 @@ static int dataHandler(HttpConnection *http, struct Service *service,
       goto bad_new_session;
     }
     session->http         = http;
-    if (launchChild(service->id, session) < 0) {
+    if (launchChild(service->id, session,
+                    rootURL && *rootURL ? rootURL : urlGetURL(url)) < 0) {
       abandonSession(session);
       httpSendReply(http, 500, "Internal Error", NO_MSG);
       return HTTP_DONE;
@@ -809,7 +811,7 @@ static void parseArgs(int argc, char * const argv[]) {
   HashMap *serviceTable    = newHashMap(destroyServiceHashEntry, NULL);
   extern char stylesStart[];
   extern char stylesEnd[];
-  check(cssStyleSheet      = malloc(stylesEnd - stylesStart));
+  check(cssStyleSheet      = malloc(stylesEnd - stylesStart + 1));
   memcpy(cssStyleSheet, stylesStart, stylesEnd - stylesStart);
   cssStyleSheet[stylesEnd - stylesStart] = '\000';
 
index 4dd43a8a65a10e08ae11f4825a70d33d68f7fcad..74034472ccf368cf0cda85acb36438d8743d1a01 100644 (file)
@@ -403,6 +403,9 @@ name of remote peer.
 .B ${uid}
 numeric user id.
 .TP
+.B ${url}
+the URL that serves the terminal session.
+.TP
 .B ${user}
 user name.
 .P
index 9f8cc89a77eb9770c56ba7719e25e9d5eb1da997..f4bd7d074941148b37643a0d55aae763b41cf3d0 100644 (file)
@@ -1892,7 +1892,7 @@ VT100.prototype.toggleBell = function() {
 };
 
 VT100.prototype.about = function() {
-  alert("VT100 Terminal Emulator " + "2.9 (revision 172)" +
+  alert("VT100 Terminal Emulator " + "2.9 (revision 174)" +
         "\nCopyright 2008-2009 by Markus Gutschke\n" +
         "For more information check http://shellinabox.com");
 };
This page took 0.067415 seconds and 5 git commands to generate.