[debian-edu-commits] debian-edu/ 01/04: /tmp changes

Dominik George natureshadow-guest at moszumanska.debian.org
Thu Oct 6 20:59:56 UTC 2016


This is an automated email from the git hooks/post-receive script.

natureshadow-guest pushed a commit to annotated tag v0.6.0
in repository xrdp.

commit 3d888c22809ce7c80c3ba1858808242210117460
Author: sorg <sorg at sorg-Gazelle-Professional.(none)>
Date:   Sat Feb 18 23:02:10 2012 -0800

    /tmp changes
---
 common/arch.h            |   2 +-
 common/os_calls.c        | 111 +++++++++++++++++++++++++++++++++++++++++------
 common/os_calls.h        |   6 +++
 sesman/chansrv/chansrv.c |   2 +-
 sesman/env.c             |   2 +
 sesman/sesman.c          |  12 ++++-
 sesman/sessvc/sessvc.c   |   7 ++-
 sesman/tools/dis.c       |   2 +-
 xrdp/xrdp.c              |   9 ++++
 xrdp/xrdp.ini            |   2 +
 xrdp/xrdp_mm.c           |   2 +-
 11 files changed, 136 insertions(+), 21 deletions(-)

diff --git a/common/arch.h b/common/arch.h
index a380511..799b540 100644
--- a/common/arch.h
+++ b/common/arch.h
@@ -1,5 +1,5 @@
 /*
-   Copyright (c) 2004-2010 Jay Sorg
+   Copyright (c) 2004-2012 Jay Sorg
 
    Permission is hereby granted, free of charge, to any person obtaining a
    copy of this software and associated documentation files (the "Software"),
diff --git a/common/os_calls.c b/common/os_calls.c
index a38eb39..692dc01 100644
--- a/common/os_calls.c
+++ b/common/os_calls.c
@@ -79,29 +79,84 @@ extern char** environ;
 #define INADDR_NONE ((unsigned long)-1)
 #endif
 
-static char g_temp_base[64] = "";
+static char g_temp_base[128] = "";
+static char g_temp_base_org[128] = "";
 
 /*****************************************************************************/
-void APP_CC
-g_init(const char* app_name)
+int APP_CC
+g_rm_temp_dir(void)
 {
-#if defined(_WIN32)
-  WSADATA wsadata;
+  if (g_temp_base[0] != 0)
+  {
+    if (!g_remove_dir(g_temp_base))
+    {
+      printf("g_rm_temp_dir: removing temp directory [%s] failed\n", g_temp_base);
+    }
+    g_temp_base[0] = 0;
+  }
+  return 0;
+}
 
-  WSAStartup(2, &wsadata);
-#endif
-  setlocale(LC_CTYPE, "");
+/*****************************************************************************/
+int APP_CC
+g_mk_temp_dir(const char* app_name)
+{
   if (app_name != 0)
   {
     if (app_name[0] != 0)
     {
-      snprintf(g_temp_base, sizeof(g_temp_base), "/tmp/%s-XXXXXX", app_name);
+      if (!g_directory_exist("/tmp/.xrdp"))
+      {
+        if (!g_create_dir("/tmp/.xrdp"))
+        {
+          printf("g_mk_temp_dir: g_create_dir failed\n");
+          return 1;
+        }
+        g_chmod_hex("/tmp/.xrdp", 0x1777);
+      }
+      snprintf(g_temp_base, sizeof(g_temp_base),
+               "/tmp/.xrdp/%s-XXXXXX", app_name);
+      snprintf(g_temp_base_org, sizeof(g_temp_base_org),
+               "/tmp/.xrdp/%s-XXXXXX", app_name);
       if (mkdtemp(g_temp_base) == 0)
       {
-        printf("g_init: mkdtemp failed [%s]\n", g_temp_base);
+        printf("g_mk_temp_dir: mkdtemp failed [%s]\n", g_temp_base);
+        return 1;
       }
     }
+    else
+    {
+      printf("g_mk_temp_dir: bad app name\n");
+      return 1;
+    }
+  }
+  else
+  {
+    if (g_temp_base_org[0] == 0)
+    {
+      printf("g_mk_temp_dir: g_temp_base_org not set\n");
+      return 1;
+    }
+    g_strncpy(g_temp_base, g_temp_base_org, 127);
+    if (mkdtemp(g_temp_base) == 0)
+    {
+      printf("g_mk_temp_dir: mkdtemp failed [%s]\n", g_temp_base);
+    }
   }
+  return 0;
+}
+
+/*****************************************************************************/
+void APP_CC
+g_init(const char* app_name)
+{
+#if defined(_WIN32)
+  WSADATA wsadata;
+
+  WSAStartup(2, &wsadata);
+#endif
+  setlocale(LC_CTYPE, "");
+  g_mk_temp_dir(app_name);
 }
 
 /*****************************************************************************/
@@ -111,7 +166,7 @@ g_deinit(void)
 #if defined(_WIN32)
   WSACleanup();
 #endif
-  g_remove_dir(g_temp_base);
+  g_rm_temp_dir();
 }
 
 /*****************************************************************************/
@@ -1829,7 +1884,12 @@ g_execvp(const char* p1, char* args[])
 #if defined(_WIN32)
   return 0;
 #else
-  return execvp(p1, args);
+  int rv;
+
+  g_rm_temp_dir();
+  rv = execvp(p1, args);
+  g_mk_temp_dir(0);
+  return rv;
 #endif
 }
 
@@ -1841,7 +1901,12 @@ g_execlp3(const char* a1, const char* a2, const char* a3)
 #if defined(_WIN32)
   return 0;
 #else
-  return execlp(a1, a2, a3, (void*)0);
+  int rv;
+
+  g_rm_temp_dir();
+  rv = execlp(a1, a2, a3, (void*)0);
+  g_mk_temp_dir(0);
+  return rv;
 #endif
 }
 
@@ -1913,13 +1978,31 @@ g_signal_pipe(void (*func)(int))
 
 /*****************************************************************************/
 /* does not work in win32 */
+void APP_CC
+g_signal_usr1(void (*func)(int))
+{
+#if defined(_WIN32)
+#else
+  signal(SIGUSR1, func);
+#endif
+}
+
+/*****************************************************************************/
+/* does not work in win32 */
 int APP_CC
 g_fork(void)
 {
 #if defined(_WIN32)
   return 0;
 #else
-  return fork();
+  int rv;
+
+  rv = fork();
+  if (rv == 0) /* child */
+  {
+    g_mk_temp_dir(0);
+  }
+  return rv;
 #endif
 }
 
diff --git a/common/os_calls.h b/common/os_calls.h
index e5625d1..5c7d848 100644
--- a/common/os_calls.h
+++ b/common/os_calls.h
@@ -31,6 +31,10 @@
 
 #include "arch.h"
 
+int APP_CC
+g_rm_temp_dir(void);
+int APP_CC
+g_mk_temp_dir(const char* app_name);
 void APP_CC
 g_init(const char* app_name);
 void APP_CC
@@ -218,6 +222,8 @@ void APP_CC
 g_signal_terminate(void (*func)(int));
 void APP_CC
 g_signal_pipe(void (*func)(int));
+void APP_CC
+g_signal_usr1(void (*func)(int));
 int APP_CC
 g_fork(void);
 int APP_CC
diff --git a/sesman/chansrv/chansrv.c b/sesman/chansrv/chansrv.c
index 77fbcd5..f2ca961 100644
--- a/sesman/chansrv/chansrv.c
+++ b/sesman/chansrv/chansrv.c
@@ -411,7 +411,7 @@ setup_listen(void)
   if (g_use_unix_socket)
   {
     g_lis_trans = trans_create(2, 8192, 8192);
-    g_snprintf(port, 255, "/tmp/xrdp_chansrv_socket_%d", 7200 + g_display_num);
+    g_snprintf(port, 255, "/tmp/.xrdp/xrdp_chansrv_socket_%d", 7200 + g_display_num);
   }
   else
   {
diff --git a/sesman/env.c b/sesman/env.c
index 9766d84..4bcb22e 100644
--- a/sesman/env.c
+++ b/sesman/env.c
@@ -74,6 +74,7 @@ env_set_user(char* username, char* passwd_file, int display)
                          pw_gecos);
   if (error == 0)
   {
+    g_rm_temp_dir();
     error = g_setgid(pw_gid);
     if (error == 0)
     {
@@ -84,6 +85,7 @@ env_set_user(char* username, char* passwd_file, int display)
       uid = pw_uid;
       error = g_setuid(uid);
     }
+    g_mk_temp_dir(0);
     if (error == 0)
     {
       g_clearenv();
diff --git a/sesman/sesman.c b/sesman/sesman.c
index 7bf794e..5a23041 100644
--- a/sesman/sesman.c
+++ b/sesman/sesman.c
@@ -167,6 +167,7 @@ main(int argc, char** argv)
     g_printf("-k, --kill           kills running sesman\n");
     g_printf("-h, --help           shows this help\n");
     g_printf("if no command is specified, sesman is started in background");
+    g_deinit();
     g_exit(0);
   }
   else if ((2 == argc) && ((0 == g_strcasecmp(argv[1], "--kill")) ||
@@ -178,6 +179,7 @@ main(int argc, char** argv)
     if (!g_file_exist(pid_file))
     {
       g_printf("sesman is not running (pid file not found - %s)\n", pid_file);
+      g_deinit();
       g_exit(1);
     }
 
@@ -194,6 +196,7 @@ main(int argc, char** argv)
     {
       g_printf("error reading pid file: %s\n", g_get_strerror());
       g_file_close(fd);
+      g_deinit();
       g_exit(error);
     }
     g_file_close(fd);
@@ -208,7 +211,7 @@ main(int argc, char** argv)
     {
       g_file_delete(pid_file);
     }
-
+    g_deinit();
     g_exit(error);
   }
   else
@@ -217,6 +220,7 @@ main(int argc, char** argv)
     g_printf("sesman - xrdp session manager\n\n");
     g_printf("error: invalid command line\n");
     g_printf("usage: sesman [ --nodaemon | --kill | --help ]\n");
+    g_deinit();
     g_exit(1);
   }
 
@@ -226,6 +230,7 @@ main(int argc, char** argv)
     g_printf("if it's not running, try removing ");
     g_printf(pid_file);
     g_printf("\n");
+    g_deinit();
     g_exit(1);
   }
 
@@ -234,12 +239,14 @@ main(int argc, char** argv)
   if (0 == g_cfg)
   {
     g_printf("error creating config: quitting.\n");
+    g_deinit();
     g_exit(1);
   }
   g_cfg->log.fd = -1; /* don't use logging before reading its config */
   if (0 != config_read(g_cfg))
   {
     g_printf("error reading config: %s\nquitting.\n", g_get_strerror());
+    g_deinit();
     g_exit(1);
   }
 
@@ -257,6 +264,7 @@ main(int argc, char** argv)
         g_printf("error opening log file [%s]. quitting.\n", g_cfg->log.log_file);
         break;
     }
+    g_deinit();
     g_exit(1);
   }
 
@@ -270,6 +278,7 @@ main(int argc, char** argv)
 
     if (0 != g_pid)
     {
+      g_deinit();
       g_exit(0);
     }
 
@@ -312,6 +321,7 @@ main(int argc, char** argv)
                   "error opening pid file[%s]: %s",
                   pid_file, g_get_strerror());
       log_end(&(g_cfg->log));
+      g_deinit();
       g_exit(1);
     }
     g_sprintf(pid_s, "%d", g_pid);
diff --git a/sesman/sessvc/sessvc.c b/sesman/sessvc/sessvc.c
index fe268ab..1ca32b0 100644
--- a/sesman/sessvc/sessvc.c
+++ b/sesman/sessvc/sessvc.c
@@ -56,12 +56,12 @@ chansrv_cleanup(int pid)
 {
   char text[256];
 
-  g_snprintf(text, 255, "/tmp/xrdp_chansrv_%8.8x_main_term", pid);
+  g_snprintf(text, 255, "/tmp/.xrdp/xrdp_chansrv_%8.8x_main_term", pid);
   if (g_file_exist(text))
   {
     g_file_delete(text);
   }
-  g_snprintf(text, 255, "/tmp/xrdp_chansrv_%8.8x_thread_done", pid);
+  g_snprintf(text, 255, "/tmp/.xrdp/xrdp_chansrv_%8.8x_thread_done", pid);
   if (g_file_exist(text))
   {
     g_file_delete(text);
@@ -86,6 +86,7 @@ main(int argc, char** argv)
   if (argc < 3)
   {
     g_writeln("xrdp-sessvc: exiting, not enough parameters");
+    g_deinit();
     return 1;
   }
   g_signal_kill(term_signal_handler); /* SIGKILL */
@@ -101,6 +102,7 @@ main(int argc, char** argv)
   if (chansrv_pid == -1)
   {
     g_writeln("xrdp-sessvc: fork error");
+    g_deinit();
     return 1;
   }
   else if (chansrv_pid == 0) /* child */
@@ -110,6 +112,7 @@ main(int argc, char** argv)
     g_execlp3(exe_path, "xrdp-chansrv", 0);
     /* should not get here */
     g_writeln("xrdp-sessvc: g_execlp3() failed");
+    g_deinit();
     return 1;
   }
   lerror = 0;
diff --git a/sesman/tools/dis.c b/sesman/tools/dis.c
index 4a1ef78..0dbc74d 100644
--- a/sesman/tools/dis.c
+++ b/sesman/tools/dis.c
@@ -49,7 +49,7 @@ int main(int argc, char** argv)
   dis = strtol(display + 1, &p, 10);
   memset(&sa, 0, sizeof(sa));
   sa.sun_family = AF_UNIX;
-  sprintf(sa.sun_path, "/tmp/xrdp_disconnect_display_%d", dis);
+  sprintf(sa.sun_path, "/tmp/.xrdp/xrdp_disconnect_display_%d", dis);
   if (access(sa.sun_path, F_OK) != 0)
   {
     printf("not in an xrdp session\n");
diff --git a/xrdp/xrdp.c b/xrdp/xrdp.c
index bbe6c6a..fb8dfbc 100644
--- a/xrdp/xrdp.c
+++ b/xrdp/xrdp.c
@@ -279,6 +279,7 @@ main(int argc, char** argv)
     g_writeln("Unknown Parameter");
     g_writeln("xrdp -h for help");
     g_writeln("");
+    g_deinit();
     g_exit(0);
   }
 
@@ -311,6 +312,7 @@ main(int argc, char** argv)
       }
       g_file_close(fd);
     }
+    g_deinit();
     g_exit(0);
   }
   if (startup_params->no_daemon)
@@ -329,6 +331,7 @@ main(int argc, char** argv)
     g_writeln("   -nodaemon: don't fork into background");
     g_writeln("   -kill: shut down xrdp");
     g_writeln("");
+    g_deinit();
     g_exit(0);
   }
   if (startup_params->version)
@@ -339,12 +342,14 @@ main(int argc, char** argv)
     g_writeln("See http://xrdp.sourceforge.net for more information.");
     g_writeln("Version %s",PACKAGE_VERSION);
     g_writeln("");
+    g_deinit();
     g_exit(0);
   }
   if (g_file_exist(pid_file)) /* xrdp.pid */
   {
     g_writeln("It looks like xrdp is allready running,");
     g_writeln("if not delete the xrdp.pid file and try again");
+    g_deinit();
     g_exit(0);
   }
   if (!no_daemon)
@@ -354,11 +359,13 @@ main(int argc, char** argv)
     if (fd == -1)
     {
       g_writeln("running in daemon mode with no access to pid files, quitting");
+      g_deinit();
       g_exit(0);
     }
     if (g_file_write(fd, "0", 1) == -1)
     {
       g_writeln("running in daemon mode with no access to pid files, quitting");
+      g_deinit();
       g_exit(0);
     }
     g_file_close(fd);
@@ -371,12 +378,14 @@ main(int argc, char** argv)
     if (pid == -1)
     {
       g_writeln("problem forking");
+      g_deinit();
       g_exit(1);
     }
     if (0 != pid)
     {
       g_writeln("process %d started ok", pid);
       /* exit, this is the main process */
+      g_deinit();
       g_exit(0);
     }
     g_sleep(1000);
diff --git a/xrdp/xrdp.ini b/xrdp/xrdp.ini
index 9bc29ae..433aaa7 100644
--- a/xrdp/xrdp.ini
+++ b/xrdp/xrdp.ini
@@ -59,6 +59,8 @@ name=freerdp-any
 lib=libxrdpfreerdp1.so
 ip=ask
 port=ask3389
+username=ask
+password=ask
 
 [xrdp7]
 name=sesman-X11rdp
diff --git a/xrdp/xrdp_mm.c b/xrdp/xrdp_mm.c
index be6786a..d8c9c58 100644
--- a/xrdp/xrdp_mm.c
+++ b/xrdp/xrdp_mm.c
@@ -702,7 +702,7 @@ xrdp_mm_process_login_response(struct xrdp_mm* self, struct stream* s)
         {
           /* unix socket */
           self->chan_trans = trans_create(TRANS_MODE_UNIX, 8192, 8192);
-          g_snprintf(port, 255, "/tmp/xrdp_chansrv_socket_%d", 7200 + display);
+          g_snprintf(port, 255, "/tmp/.xrdp/xrdp_chansrv_socket_%d", 7200 + display);
         }
         else
         {

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/debian-edu/pkg-team/xrdp.git



More information about the debian-edu-commits mailing list